Skip to content

Commit e2e19e7

Browse files
committed
updated the stack to use secrets manageer to store the database password so it will no longer be visable in the stack or the config.php file
1 parent 5904c2e commit e2e19e7

File tree

3 files changed

+168
-119
lines changed

3 files changed

+168
-119
lines changed

templates/00-master.yaml

+33-24
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Metadata:
5656
- DatabaseEncrpytedBoolean
5757
- DatabaseCmk
5858
- DatabaseMasterUsername
59-
- DatabaseMasterPassword
59+
# - DatabaseMasterPassword
6060
- DatabaseName
6161
- Label:
6262
default: Caching Tier
@@ -95,8 +95,8 @@ Metadata:
9595
default: DB Instance Class
9696
DatabaseMasterUsername:
9797
default: DB Master Username
98-
DatabaseMasterPassword:
99-
default: DB Master Password
98+
# DatabaseMasterPassword:
99+
# default: DB Master Password
100100
DatabaseName:
101101
default: DB Name
102102
EfsCmk:
@@ -319,14 +319,14 @@ Parameters:
319319
MinLength: 1
320320
Type: String
321321
Default: moodle
322-
DatabaseMasterPassword:
323-
AllowedPattern: ^([a-zA-Z0-9`~!#$%^&*()_+,\\-])*$
324-
ConstraintDescription: Must be letters (upper or lower), numbers, spaces, and these special characters `~!#$%^&*()_+,-
325-
Description: The Amazon RDS master password. Letters, numbers, spaces, and these special characters `~!#$%^&*()_+,-
326-
MaxLength: 41
327-
MinLength: 8
328-
NoEcho: true
329-
Type: String
322+
# DatabaseMasterPassword:
323+
# AllowedPattern: ^([a-zA-Z0-9`~!#$%^&*()_+,\\-])*$
324+
# ConstraintDescription: Must be letters (upper or lower), numbers, spaces, and these special characters `~!#$%^&*()_+,-
325+
# Description: The Amazon RDS master password. Letters, numbers, spaces, and these special characters `~!#$%^&*()_+,-
326+
# MaxLength: 41
327+
# MinLength: 8
328+
# NoEcho: true
329+
# Type: String
330330
DatabaseName:
331331
AllowedPattern: ^([a-zA-Z0-9]*)$
332332
Description: The Amazon RDS master database name.
@@ -806,6 +806,15 @@ Conditions:
806806
!Equals [ true, !Ref UseCloudFrontBoolean ]
807807

808808
Resources:
809+
MyRDSInstanceSecret:
810+
Type: AWS::SecretsManager::Secret
811+
Properties:
812+
Description: 'This is the secret for my RDS instance'
813+
GenerateSecretString:
814+
SecretStringTemplate: !Sub '{"username": "${DatabaseMasterUsername}"}'
815+
GenerateStringKey: 'password'
816+
PasswordLength: 16
817+
ExcludeCharacters: '"@/\'
809818
vpc:
810819
Type: AWS::CloudFormation::Stack
811820
Properties:
@@ -900,16 +909,16 @@ Resources:
900909
!GetAtt [ vpc, Outputs.Vpc ]
901910
TemplateURL: https://s3.amazonaws.com/aws-refarch/moodle/latest/templates/03-publicalb.yaml
902911
rds:
903-
DependsOn: [ securitygroups, securitygroups ]
912+
DependsOn: [ securitygroups ]
904913
Type: AWS::CloudFormation::Stack
905914
Properties:
906915
Parameters:
907916
DatabaseInstanceType:
908917
!Ref DatabaseInstanceType
909-
DatabaseMasterUsername:
910-
!Ref DatabaseMasterUsername
911-
DatabaseMasterPassword:
912-
!Ref DatabaseMasterPassword
918+
# DatabaseMasterUsername:
919+
# !Ref DatabaseMasterUsername
920+
MyRDSInstanceSecretArn:
921+
!Ref MyRDSInstanceSecret
913922
DatabaseName:
914923
!Ref DatabaseName
915924
DatabaseEncrpytedBoolean:
@@ -989,10 +998,10 @@ Resources:
989998
Parameters:
990999
DatabaseClusterEndpointAddress:
9911000
!GetAtt [ rds, Outputs.DatabaseClusterEndpointAddress ]
992-
DatabaseMasterUsername:
993-
!Ref DatabaseMasterUsername
994-
DatabaseMasterPassword:
995-
!Ref DatabaseMasterPassword
1001+
# DatabaseMasterUsername:
1002+
# !Ref DatabaseMasterUsername
1003+
MyRDSInstanceSecretArn:
1004+
!Ref MyRDSInstanceSecret
9961005
DatabaseName:
9971006
!Ref DatabaseName
9981007
ElasticFileSystem:
@@ -1032,10 +1041,10 @@ Resources:
10321041
Parameters:
10331042
DatabaseClusterEndpointAddress:
10341043
!GetAtt [ rds, Outputs.DatabaseClusterEndpointAddress ]
1035-
DatabaseMasterUsername:
1036-
!Ref DatabaseMasterUsername
1037-
DatabaseMasterPassword:
1038-
!Ref DatabaseMasterPassword
1044+
# DatabaseMasterUsername:
1045+
# !Ref DatabaseMasterUsername
1046+
MyRDSInstanceSecretArn:
1047+
!Ref MyRDSInstanceSecret
10391048
DatabaseName:
10401049
!Ref DatabaseName
10411050
ElasticFileSystem:

templates/03-rds.yaml

+25-23
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ Metadata:
1010
default: Database Parameters
1111
Parameters:
1212
- DatabaseInstanceType
13-
- DatabaseMasterUsername
14-
- DatabaseMasterPassword
13+
# - DatabaseMasterUsername
14+
# - DatabaseMasterPassword
1515
- DatabaseName
1616
- DatabaseEncrpytedBoolean
1717
- DatabaseCmk
@@ -25,10 +25,10 @@ Metadata:
2525
default: AWS KMS Customer Master Key (CMK) to encrypt DB
2626
DatabaseInstanceType:
2727
default: DB Instance Class
28-
DatabaseMasterUsername:
29-
default: DB Master Username
30-
DatabaseMasterPassword:
31-
default: DB Master Password
28+
# DatabaseMasterUsername:
29+
# default: DB Master Username
30+
# DatabaseMasterPassword:
31+
# default: DB Master Password
3232
DatabaseName:
3333
default: DB Name
3434
DatabaseSecurityGroup:
@@ -62,20 +62,22 @@ Parameters:
6262
Default: db.r4.large
6363
Description: The Amazon RDS database instance class.
6464
Type: String
65-
DatabaseMasterUsername:
66-
AllowedPattern: ^([a-zA-Z0-9]*)$
67-
Description: The Amazon RDS master username.
68-
ConstraintDescription: Must contain only alphanumeric characters and be at least 8 characters.
69-
MaxLength: 16
70-
MinLength: 1
71-
Type: String
72-
DatabaseMasterPassword:
73-
AllowedPattern: ^([a-z0-9A-Z`~!#$%^&*()_+,\\-])*$
74-
ConstraintDescription: Must be letters (upper or lower), numbers, and these special characters '_'`~!#$%^&*()_+,-
75-
Description: The Amazon RDS master password.
76-
MaxLength: 41
77-
MinLength: 8
78-
NoEcho: true
65+
# DatabaseMasterUsername:
66+
# AllowedPattern: ^([a-zA-Z0-9]*)$
67+
# Description: The Amazon RDS master username.
68+
# ConstraintDescription: Must contain only alphanumeric characters and be at least 8 characters.
69+
# MaxLength: 16
70+
# MinLength: 1
71+
# Type: String
72+
# DatabaseMasterPassword:
73+
# AllowedPattern: ^([a-z0-9A-Z`~!#$%^&*()_+,\\-])*$
74+
# ConstraintDescription: Must be letters (upper or lower), numbers, and these special characters '_'`~!#$%^&*()_+,-
75+
# Description: The Amazon RDS master password.
76+
# MaxLength: 41
77+
# MinLength: 8
78+
# NoEcho: true
79+
# Type: String
80+
MyRDSInstanceSecretArn:
7981
Type: String
8082
DatabaseName:
8183
AllowedPattern: ^([a-zA-Z0-9]*)$
@@ -142,7 +144,6 @@ Conditions:
142144
!Equals ['', !Ref DatabaseCmk]
143145

144146
Resources:
145-
146147
DatabaseCluster:
147148
Type: AWS::RDS::DBCluster
148149
Properties:
@@ -153,8 +154,8 @@ Resources:
153154
DBClusterParameterGroupName: default.aurora-postgresql11
154155
KmsKeyId:
155156
!If [ UseAWS-ManagedCMK, !Ref 'AWS::NoValue', !Ref DatabaseCmk ]
156-
MasterUsername: !Ref DatabaseMasterUsername
157-
MasterUserPassword: !Ref DatabaseMasterPassword
157+
MasterUsername: !Join ['', ['{{resolve:secretsmanager:', !Ref MyRDSInstanceSecretArn, ':SecretString:username}}' ]]
158+
MasterUserPassword: !Join ['', ['{{resolve:secretsmanager:', !Ref MyRDSInstanceSecretArn, ':SecretString:password}}' ]]
158159
Port: 5432
159160
StorageEncrypted: !Ref DatabaseEncrpytedBoolean
160161
Tags:
@@ -231,4 +232,5 @@ Outputs:
231232
Value: !Ref DataSubnetGroup
232233
DatabaseClusterEndpointAddress:
233234
Value: !GetAtt DatabaseCluster.Endpoint.Address
235+
234236

0 commit comments

Comments
 (0)