Skip to content
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

Allow to set password_encryption algorithm #144

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions SecretsManagerRDSPostgreSQLRotationSingleUser/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ def lambda_handler(event, context):
# Setup the client
service_client = boto3.client('secretsmanager', endpoint_url=os.environ['SECRETS_MANAGER_ENDPOINT'])

password_encryption = os.environ.get('PASSWORD_ENCRYPTION')

# Make sure the version is staged correctly
metadata = service_client.describe_secret(SecretId=arn)
if "RotationEnabled" in metadata and not metadata['RotationEnabled']:
Expand All @@ -74,7 +76,7 @@ def lambda_handler(event, context):
create_secret(service_client, arn, token)

elif step == "setSecret":
set_secret(service_client, arn, token)
set_secret(service_client, arn, token, password_encryption)

elif step == "testSecret":
test_secret(service_client, arn, token)
Expand Down Expand Up @@ -121,7 +123,7 @@ def create_secret(service_client, arn, token):
logger.info("createSecret: Successfully put secret for ARN %s and version %s." % (arn, token))


def set_secret(service_client, arn, token):
def set_secret(service_client, arn, token, password_encryption):
"""Set the pending secret in the database

This method tries to login to the database with the AWSPENDING secret and returns on success. If that fails, it
Expand Down Expand Up @@ -199,6 +201,10 @@ def set_secret(service_client, arn, token):
cur.execute("SELECT quote_ident(%s)", (pending_dict['username'],))
escaped_username = cur.fetchone()[0]

# Set encryption algorithm
if password_encryption:
cur.execute("SET password_encryption=%s", (password_encryption,))

alter_role = "ALTER USER %s" % escaped_username
cur.execute(alter_role + " WITH PASSWORD %s", (pending_dict['password'],))
conn.commit()
Expand Down