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

fix: decrypt postgres password for use in connection string #41

Merged
merged 5 commits into from
Jul 27, 2021

Conversation

qdzlug
Copy link
Contributor

@qdzlug qdzlug commented Jul 26, 2021

Proposed changes

This addresses a bug introduced with #30 - the password is part of the connection string, but pulumi does not decrypt it for use in the string concatenation needed to build it. This has been fixed by using the Output.unsecret method.

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have written my commit messages in the Conventional Commits format.
  • I have read the CONTRIBUTING doc
  • I have added tests (when possible) that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto master
  • I will ensure my PR is targeting the master branch and pulling from my branch from my own fork

@qdzlug qdzlug requested a review from dekobon July 26, 2021 23:14
# The database password is a secret, and in order to use it in a string concat
# we need to decrypt the password with Output.unsecret() before we use it.
# This function provides the logic to accomplish this.
accounts_db_uri = pulumi.Output.unsecret(accounts_pwd).apply(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider modifying this such that Pulumi continues to use secrets:

def create_pg_uri(password_object):
    user = str(accounts_admin)
    password = str(password_object)
    database = str(accounts_db)
    uri = f'postgresql://{user}:{password}@accounts-db:5432/{database}'
    return pulumi.Output.secret(uri)


accounts_db_uri = pulumi.Output.unsecret(accounts_pwd).apply(create_pg_uri)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed; that's a great example construct for this use case.

@@ -141,7 +147,7 @@ def add_namespace(obj):
})

# Configuration Values are stored in the configuration:
# ../config/Pulumi.STACKNAME.yaml
# ./config/Pulumi.STACKNAME.yaml
config = pulumi.Config('anthos')
demo_pwd = config.require_secret('demo_pwd')

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's delete the demo_login and demo_pwd bits.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and updated in all other locations and configs.

@qdzlug
Copy link
Contributor Author

qdzlug commented Jul 27, 2021

Running full test overnight.

@dekobon dekobon merged commit a2d334b into nginxinc:master Jul 27, 2021
@qdzlug qdzlug deleted the jayreview branch August 10, 2021 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants