-
Notifications
You must be signed in to change notification settings - Fork 16
Introduce a read-only user for data-replication #4551
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c440197
Introduce a read-only user for data-replication
TheOneFromNorway d3dc857
Working postgress connection
TheOneFromNorway e30021d
Add necessary permissions for data replication deployment
TheOneFromNorway 7bc4857
Ensure grafana can access vpc endpoints
TheOneFromNorway 93931bf
Add postgres data source
TheOneFromNorway ef49ad3
Expand out names
TheOneFromNorway 937ecd2
Expand abbreviation suffix for clarity
TheOneFromNorway File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Data replication script - creates read-only database role and keeps container running | ||
|
|
||
| set -e | ||
|
|
||
| echo "Starting data replication setup..." | ||
|
|
||
| if [ -z "$READ_ONLY_DB_PASSWORD" ]; then | ||
| echo "Error: READ_ONLY_DB_PASSWORD environment variable is not set" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Creating read-only database role..." | ||
|
|
||
| bundle exec rails runner " | ||
| begin | ||
| ActiveRecord::Base.connection.execute(\" | ||
| DO \$\$ | ||
| BEGIN | ||
| IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = 'grafana_read_only') THEN | ||
| CREATE ROLE grafana_read_only WITH LOGIN PASSWORD '#{ENV['READ_ONLY_DB_PASSWORD']}'; | ||
| ELSE | ||
| ALTER ROLE grafana_read_only WITH PASSWORD '#{ENV['READ_ONLY_DB_PASSWORD']}'; | ||
| END IF; | ||
| END | ||
| \$\$; | ||
| \") | ||
|
|
||
| ActiveRecord::Base.connection.execute(\" | ||
| GRANT CONNECT ON DATABASE #{ActiveRecord::Base.connection.current_database} TO grafana_read_only; | ||
| GRANT USAGE ON SCHEMA public TO grafana_read_only; | ||
| GRANT SELECT ON ALL TABLES IN SCHEMA public TO grafana_read_only; | ||
| ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO grafana_read_only; | ||
| \") | ||
|
|
||
| puts 'Read-only role created/updated successfully' | ||
| rescue => e | ||
| puts \"Error creating read-only role: \#{e.message}\" | ||
| exit 1 | ||
| end | ||
| " | ||
|
|
||
| echo "Data replication setup completed. Keeping container running..." | ||
|
|
||
| exec tail -f /dev/null |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| ephemeral "aws_secretsmanager_random_password" "read_only_db_password" { | ||
| } | ||
|
|
||
| resource "aws_secretsmanager_secret" "read_only_db_password" { | ||
| name = "${local.name_prefix}-grafana-read-only-db-password-${substr(uuid(), 0, 4)}" | ||
| description = "Read-only database user password for data replication" | ||
| recovery_window_in_days = 7 | ||
|
|
||
| tags = { | ||
| Name = "${local.name_prefix}-read-only-db-password" | ||
| } | ||
| lifecycle { | ||
| ignore_changes = [name] | ||
| } | ||
| } | ||
|
|
||
| resource "aws_secretsmanager_secret_version" "read_only_db_password" { | ||
| secret_id = aws_secretsmanager_secret.read_only_db_password.id | ||
| secret_string_wo = ephemeral.aws_secretsmanager_random_password.read_only_db_password.random_password | ||
| secret_string_wo_version = 1 | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.