Skip to content

Commit

Permalink
fix: DBTP-1010 Readonly postgres user doesn't have read perms (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabelton authored May 30, 2024
1 parent 9be7595 commit 1628440
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions application-load-balancer/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ resource "aws_lb_listener" "alb-listener" {
}

resource "aws_security_group" "alb-security-group" {
# checkov:skip=CKV2_AWS_5:Security group is used by VPC. Ticket to investigate: https://uktrade.atlassian.net/browse/DBTP-1039
for_each = local.protocols
name = "${var.application}-${var.environment}-alb-${each.key}"
vpc_id = data.aws_vpc.vpc.id
Expand Down
4 changes: 2 additions & 2 deletions postgres/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ resource "aws_lambda_invocation" "create-readonly-user" {
CopilotApplication = var.application
CopilotEnvironment = var.environment
MasterUserSecretArn = aws_db_instance.default.master_user_secret[0].secret_arn
SecretDescription = "RDS application user secret for ${local.name}"
SecretDescription = "RDS readonly user secret for ${local.name}"
SecretName = "/copilot/${var.application}/${var.environment}/secrets/${local.read_only_secret_name}"
Username = "readonly_user"
Permissions = [
"SELECT",
"SELECT"
],
DbHost = aws_db_instance.default.address,
DbPort = aws_db_instance.default.port,
Expand Down
2 changes: 1 addition & 1 deletion postgres/manage_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def create_db_user(conn, cursor, username, password, permissions):
cursor.execute(f"CREATE USER {username} WITH ENCRYPTED PASSWORD '%s'" % password)
cursor.execute(f"GRANT {username} to postgres;")
cursor.execute(f"GRANT {', '.join(permissions)} ON ALL TABLES IN SCHEMA public TO {username};")
cursor.execute(f"ALTER DEFAULT PRIVILEGES FOR USER {username} IN SCHEMA public GRANT {', '.join(permissions)} ON TABLES TO {username};")
cursor.execute(f"ALTER DEFAULT PRIVILEGES FOR USER application_user IN SCHEMA public GRANT {', '.join(permissions)} ON TABLES TO {username};")

if 'INSERT' in permissions:
cursor.execute(f"GRANT CREATE ON SCHEMA public TO {username};")
Expand Down

0 comments on commit 1628440

Please sign in to comment.