-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EES-5329 Create new database users for local environment and new public_data_read_write
group role
#5044
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public_data
app user for local environment and new public_data_admin
group role for granting privilegespublic_data
app user for local environment and new public_data_admin
group role for granting privileges
public_data
app user for local environment and new public_data_admin
group role for granting privilegespublic_data_admin
group role for maintenance in Azure
...n.ExploreEducationStatistics.Public.Data.Model/Migrations/20240501113006_InitialMigration.cs
Outdated
Show resolved
Hide resolved
...n.ExploreEducationStatistics.Public.Data.Model/Migrations/20240501113006_InitialMigration.cs
Outdated
Show resolved
Hide resolved
...n.ExploreEducationStatistics.Public.Data.Model/Migrations/20240501113006_InitialMigration.cs
Outdated
Show resolved
Hide resolved
...ionStatistics.Public.Data.Model/Migrations/20240628135434_EES5235_GrantSequencePrivileges.cs
Outdated
Show resolved
Hide resolved
...nStatistics.Public.Data.Model/Migrations/20240710081112_EES5329_CreatePublicDataAdminRole.cs
Outdated
Show resolved
Hide resolved
...n.ExploreEducationStatistics.Public.Data.Model/Migrations/20240501113006_InitialMigration.cs
Outdated
Show resolved
Hide resolved
....ExploreEducationStatistics.Public.Data.Model/Migrations/PublicDataDbContextModelSnapshot.cs
Outdated
Show resolved
Hide resolved
duncan-at-hiveit
approved these changes
Jul 22, 2024
public_data_admin
group role for maintenance in Azurepublic_data_read_writ
group role
public_data_read_writ
group rolepublic_data_read_write
group role
…Configure role privileges in Postgres init script for local environment and in database migration for non-local environment.
This was referenced Jul 22, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds new application user roles for running locally and a new
public_data_read_write
group role to be applied to application user or individual user roles needing read and write permissions on public schema objects.New version of Public API seed data
There is a new version
public-api-16.zip
of the seed data to reflect the changes in ownership of the public schema objects and grants after introducing new application user roles.New application user roles for running locally
Up until now we have configured application services running locally to use the
postgres
superuser. That doesn't reflect how we run the services in Azure where they each have their own application user role with privileges granted.This PR adds a new Postgres initialisation script which is run by the Docker entrypoint and creates new application user roles:
app_public_data_api
app_public_data_processor
app_admin
app_publisher
Each of the services application settings files are changed to use these new user roles for the database logon.
The initialisation script grants the
app_public_data_api
roleCREATE
privilege to create new objects which it will own on the public schema, and grants all the other application user rolesUSAGE
privilege to access objects on the public schema . This doesn't grant any additional permissions (e.g.SELECT
).Granting read and write privileges for public tables and sequences using the
public_data_read_write
roleWe are currently limited by the amount of maintenance we can perform on the Postgres database because our own Azure administrator roles don't have any permission to write data. By default, every object created is owned by the role that created it. In our case that's the Public API's application role which is responsible for running database migrations.
Our administrator roles inherit role
azure_pg_admin
but this doesn't have sufficient rights to write data. Roleazure_pg_admin
inherits predefined rolepg_read_all_data
, the equivalent of having as SELECT rights on objects, and USAGE rights on all schemas. However Azure Database for PostgreSQL - Flexible Server does not allow users to be granted the predefined rolepg_write_all_data
.In this PR we add the ability to manage data ourselves by granting privileges to a new
public_data_read_write
role which can be granted to our own individual Azure administrator roles if they require read and write privileges on public schema objects.The initialisation script when running locally, or the initial migration run by
Public.Data.Api
in Azure environments will grant privileges by default to the 'public_data_read_write' group role for objects in the public schema subsequently created by thePublic.Data.API
applications user role.Setting up
public_data_read_write
in AzureIn Azure environments this role needs to be created manually before the database migration is run which grants privileges:
Membership of this role can be granted to our administrator roles in Azure who require rights to write data on public schema objects.
Using
public_data_read_write
locallyIn the local environment the
public_data_read_write
role is created by the initialisation script. Using it locally is optional since you can continue to connect to the database with thepostgres
superuser using your preferred tool of choice.If you do want to set up a personal user role which is a member of
public_data_read_write
:Then use that to connect:
Testing
public_data_read_write
Create a new user
test_user_1
withoutpublic_data_read_write
role membership:Attempt to SELECT from a table in the public schema logged in as
test_user_1
:🔴 Prints
Attempt to INSERT into a table in the public schema logged in as
test_user_1
:🔴 Prints
Attempt to UPDATE into a table in the public schema logged in as
test_user_1
:🔴 Prints
Attempt to DELETE from a table in the public schema logged in as
test_user_1
:🔴 Prints
Attempt to TRUNCATE a table in the public schema logged in as
test_user_1
:🔴 Prints
Create a new user
test_user_2
withpublic_data_read_write
role membership:Attempt to SELECT from a table in the public schema logged in as
test_user_2
:🟢 Prints
Attempt to INSERT into a table in the public schema logged in as
test_user_2
:🟢 Prints
Attempt to UPDATE into a table in the public schema logged in as
test_user_2
:🟢 Prints
Attempt to DELETE from a table in the public schema logged in as
test_user_2
:🟢 Prints
Attempt to TRUNCATE a table in the public schema logged in as
test_user_2
:🟢 Prints