Skip to content

Comments

Add SSM Parameter option for DBOwner User and Database Name#8

Open
davidholsgrove wants to merge 3 commits intobinxio:masterfrom
biarri:ssmparams
Open

Add SSM Parameter option for DBOwner User and Database Name#8
davidholsgrove wants to merge 3 commits intobinxio:masterfrom
biarri:ssmparams

Conversation

@davidholsgrove
Copy link

  • Extending the use of SSM Parameters for the RDS DBOwner details, to match the Password capability.
  • Add log level in line with binxio cfn secret provider
  • Add is_valid_request in line with binxio cfn secret provider
  • Add 60 second connection timeout on db connection

@mvanholsteijn
Copy link
Member

Hi @davidholsgrove, good to see you this provider is useful for you. Can you explain me the rationale of getting everything from the parameter store? I only use the parameter store to avoid having the password in clear text in CloudFormation.

Would SSM parameter as CFN parameter solve your problem as well? https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html#parameters-section-ssm-examples

@davidholsgrove
Copy link
Author

Apologies @mvanholsteijn, my PR didn't describe the reason very well.

I have a cloudformation template database-and-user.yaml that is used by my team as a nested template they drive with by providing a small set of parameters, e.g;

TestDBAndUser:
    Type: "AWS::CloudFormation::Stack"
    Properties:
      TemplateURL: "../templates/postgres/database-and-user.yaml"
      Parameters:
        Company: example
        ProjectName: project
        CreateDatabase: "true"
        DeletionPolicy: "Retain"
        SSMParamsMasterDB: "/shared/devqa/database/master"
        DBEndpointAddress: !GetAtt SharedRDS.Outputs.RDSInstanceEndpoint

This nested template creates the following resources;

  • DatabaseAddress (AWS::SSM::Parameter)
  • DatabaseNameParam(AWS::SSM::Parameter)
  • DatabaseUserParam(AWS::SSM::Parameter)
  • DatabasePassword (Custom::Secret)
  • DatabaseAndUser (Custom::PostgreSQLUser)

with the custom PostgreSQLUser being created as;

DatabaseAndUser:
    Type: Custom::PostgreSQLUser
    Properties:
      Name: !GetAtt DatabaseNameParam.Value
      User: !GetAtt DatabaseUserParam.Value
      Password: !GetAtt DatabasePassword.Secret
      WithDatabase: !Ref CreateDatabase
      DeletionPolicy: !Ref DeletionPolicy
      # the database instance to create the new user or database in;
      Database:
        Host: !Ref DBEndpointAddress
        Port: !Ref DBInstancePort
        # The db owner details (database name, user and password) are retrieved from SSM by parameter name:
        DBNameParameterName: !Sub "${SSMParamsMasterDB}/dbname"
        UserParameterName: !Sub "${SSMParamsMasterDB}/user"
        PasswordParameterName: !Sub "${SSMParamsMasterDB}/password"
      ServiceToken: !Sub 'arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:binxio-cfn-postgresql-user-provider'

Being able to provide the db owner database name, user and password to the custom resource function the same way provides a consistent way to create those details, store them in SSM under a common prefix, and then allow them to be retrieved when needed.

I originally had my nested template take the db owner database name, etc as input SSM Parameters, and then the password as a string but felt that was a bit inconsistent?

DBInstanceAdminUserParamName:
    Type: AWS::SSM::Parameter::Value<String>
    Description: Name of SSM Parameter storing RDS Master Admin User

DBInstanceAdminPasswordParamName:
    Type: String
    Description: RDS Master Admin Password SSM Parameter Name

@mvanholsteijn
Copy link
Member

mvanholsteijn commented Sep 20, 2019 via email

@mvanholsteijn mvanholsteijn force-pushed the master branch 2 times, most recently from cb26ea0 to b42fdc6 Compare July 4, 2022 18:42
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