Skip to content

Commit 5a8fe57

Browse files
committed
Bug fix for handling uppercase username in PostgreSQL rotation lambda
1 parent 0ec2e9d commit 5a8fe57

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

SecretsManagerRDSPostgreSQLRotationMultiUser/lambda_function.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ def set_secret(service_client, arn, token):
187187
# If the user exists, just update the password
188188
cur.execute("SELECT 1 FROM pg_roles where rolname = %s", (pending_dict['username'],))
189189
if len(cur.fetchall()) == 0:
190-
create_role = "CREATE ROLE %s" % pending_dict['username']
190+
create_role = "CREATE ROLE \"%s\"" % pending_dict['username']
191191
cur.execute(create_role + " WITH LOGIN PASSWORD %s", (pending_dict['password'],))
192-
cur.execute("GRANT %s TO %s" % (current_dict['username'], pending_dict['username']))
192+
cur.execute("GRANT \"%s\" TO \"%s\"" % (current_dict['username'], pending_dict['username']))
193193
else:
194-
alter_role = "ALTER USER %s" % pending_dict['username']
194+
alter_role = "ALTER USER \"%s\"" % pending_dict['username']
195195
cur.execute(alter_role + " WITH PASSWORD %s", (pending_dict['password'],))
196196

197197
conn.commit()

SecretsManagerRDSPostgreSQLRotationSingleUser/lambda_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def set_secret(service_client, arn, token):
169169
# Now set the password to the pending password
170170
try:
171171
with conn.cursor() as cur:
172-
alter_role = "ALTER USER %s" % pending_dict['username']
172+
alter_role = "ALTER USER \"%s\"" % pending_dict['username']
173173
cur.execute(alter_role + " WITH PASSWORD %s", (pending_dict['password'],))
174174
conn.commit()
175175
logger.info("setSecret: Successfully set password for user %s in PostgreSQL DB for secret arn %s." % (pending_dict['username'], arn))

0 commit comments

Comments
 (0)