Cloudformation generating RDS username and password?

0

I'm using Cloudformation to build out a stack that includes a Postgres RDS instance, defined in the code snippet below. What I have found is that the values I've specified in parameters for DatabaseUser and DatabasePassword are ultimately not the values being used. Browsing to RDS in the AWS console, I can see that the DatabaseUser seems to be a randomly generated string (rather than postgres as I've specified in parameters), and the password is not visible, but my attempts to connect to the RDS instance fail: FATAL: password authentication failed for user "<random string>". I assume the password has also been generated, rather than using the value I've configured in the parameter.

I appreciate there are more secure ways of authenticating (I'm now reading about SecretsManager), but I'm a beginner - one step at a time. Figuring out and adding SecretsManager here is a lot of overhead for me. Right now my RDS instance is on a private subnet and I'm having to connect using SSM Agent and port forwarding, I figure that's secure enough for a start.

Is it not possible to set DB user/pw using parameters in my Cloudformation configs?

This is somewhat important for me since I'm working on some further automation. Even if I do get this working, will the password eventually be rotated anyway? Would SecretsManager be the only reliable way for me to be able to automate connections to my RDS instance?

"Database": {
      "Type": "AWS::RDS::DBInstance",
      "DeletionPolicy": "Delete",
      "Properties": {
        "Engine"             : "postgres",
        "DBName"             : { "Fn::Join": [ "", { "Fn::Split": [ "-", { "Ref": "ApplicationName" } ]} ] },
        "DBInstanceClass"    : { "Ref": "DBInstanceType" },
        "DBSubnetGroupName"  : { "Ref": "DBSubnetGroup" },
        "StorageType"        : { "Ref": "DBStorageType" },
        "AllocatedStorage"   : { "Ref": "DBAllocatedStorage" },
        "MasterUsername"     : { "Ref": "DatabaseUser" },
        "MasterUserPassword" : { "Ref": "DatabasePassword" },
        "VPCSecurityGroups"  : [
          { "Ref": "DBSecurityGroup" }
        ]
      }
    }
1 Antwort
1
Akzeptierte Antwort

Hi,

I would recommend, as you hinted, to secure your password with Secret Managers.

This article contains a Cloudformation example which can inspire you: https://aws.amazon.com/blogs/mt/four-ways-to-retrieve-any-aws-service-property-using-aws-cloudformation-part-3-of-3/

Hope it helps ;)

profile picture
EXPERTE
beantwortet vor einem Jahr
profile pictureAWS
EXPERTE
überprüft vor einem Jahr

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen