Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#parse("templates/global/sns-template.json.vpt")
#parse("templates/global/webacl-cloudwatch-loggroup.json.vpt")
#parse("templates/global/bedrock-kb-template.json.vpt")
#parse("templates/global/rds-snapshot-encryption-key.json.vpt")
},
"Outputs": {
"NotificationTopic": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
,
"${stack}RdsSnapshotCmk": {
"Type": "AWS::KMS::Key",
"Properties": {
"Description": "The encryption key for ${stack} stack RDS snapshots",
"EnableKeyRotation": true,
"KeyPolicy": {
"Version": "2012-10-17",
"Id": "key-default-1",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::#[[${AWS::AccountId}]]#:root" },
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "Allow access for Key Administrators",
"Effect": "Allow",
"Principal": {
"AWS":
#if(${stack} == 'prod')
{ "Fn::Sub": "arn:aws:iam::#[[${AWS::AccountId}]]#:role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_Administrator_6620166dd0e7f1b6" }
#else
{ "Fn::Sub": "arn:aws:iam::#[[${AWS::AccountId}]]#:role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_Administrator_693a85eb20cd5043" }
#end
},
"Action": [
"kms:Create*",
"kms:Describe*",
"kms:Enable*",
"kms:List*",
"kms:Put*",
"kms:Update*",
"kms:Revoke*",
"kms:Disable*",
"kms:Get*",
"kms:Delete*",
"kms:TagResource",
"kms:UntagResource",
"kms:ScheduleKeyDeletion",
"kms:CancelKeyDeletion",
"kms:RotateKeyOnDemand"
],
"Resource": "*"
},
{
"Sid": "Allow use of the key",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::766808016710:root" },
"Action": [
"kms:Decrypt",
"kms:DescribeKey"
],
"Resource": "*"
},
{
"Sid": "Allow attachment of persistent resources",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::766808016710:root" },
"Action": [
"kms:CreateGrant",
"kms:ListGrants",
"kms:RevokeGrant"
],
"Resource": "*",
"Condition": {
"StringEquals": { "kms:ViaService": "rds.us-east-1.amazonaws.com" },
"Bool": { "kms:GrantIsForAWSResource": "true" }
}
},
{
"Sid": "AllowRDSToDecryptSourceSnapshotForExport",
"Effect": "Allow",
"Principal": { "Service": "export.rds.amazonaws.com" },
"Action": [
"kms:Decrypt",
"kms:DescribeKey"
],
"Resource": "*"
}
]
}
}
},
"${stack}RdsSnapshotCmkAlias": {
"Type": "AWS::KMS::Alias",
"Properties": {
"AliasName": "alias/synapse/${stack}/rds-snapshot-cmk",
"TargetKeyId": { "Ref": "${stack}RdsSnapshotCmk" }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ public void testBuildGlobalResourcesDev() throws InterruptedException {
String expectedJson = new JSONObject(TemplateUtils.loadContentFromFile("global/dev-global-resources.json")).toString();

JSONObject templateJSON = new JSONObject(req.getTemplateBody());

System.out.println(templateJSON.toString(2));
// System.out.println(templateJSON.toString(2));

assertEquals(expectedJson, templateJSON.toString());

Expand Down Expand Up @@ -158,7 +157,8 @@ public void testBuildGlobalResourcesProd() throws InterruptedException {
String expectedJson = new JSONObject(TemplateUtils.loadContentFromFile("global/prod-global-resources.json")).toString();

JSONObject templateJSON = new JSONObject(req.getTemplateBody());

// System.out.println(templateJSON.toString(2));

assertEquals(expectedJson, templateJSON.toString());

verify(mockSesClient).setComplaintNotificationTopic(SES_SYNAPSE_DOMAIN, "complaintTopicArn");
Expand Down
112 changes: 97 additions & 15 deletions src/test/resources/global/dev-global-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,10 @@
"SynapseHelpKnowledgeBaseDataSourceSyncWaitCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": "SynapseHelpKnowledgeBaseDataSource",
"CreationPolicy": {
"ResourceSignal": {
"Timeout": "PT20M",
"Count": "1"
}
}
"CreationPolicy": {"ResourceSignal": {
"Timeout": "PT20M",
"Count": "1"
}}
},
Copy link
Member

Choose a reason for hiding this comment

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

Not of a fan of testing by comparing a file to what is seen in a test. I like to test by ensuring that the resulting JSON loads and is valid JSON. Then spot check the JSON for "key" resource.

"SynapseHelpKnowledgeBaseIngestionScheduleRole": {
"Type": "AWS::IAM::Role",
Expand Down Expand Up @@ -273,16 +271,100 @@
"SynapseHelpKnowledgeBaseIngestionScheduleRole",
"Arn"
]},
"Input": {
"Fn::Sub": [
"{\"KnowledgeBaseId\":\"${SynapseHelpKnowledgeBase}\",\"DataSourceId\":\"${dataSourceId}\"}",
{
"dataSourceId": { "Fn::GetAtt": ["SynapseHelpKnowledgeBaseDataSource", "DataSourceId"] }
}
]
}
"Input": {"Fn::Sub": [
"{\"KnowledgeBaseId\":\"${SynapseHelpKnowledgeBase}\",\"DataSourceId\":\"${dataSourceId}\"}",
{"dataSourceId": {"Fn::GetAtt": [
"SynapseHelpKnowledgeBaseDataSource",
"DataSourceId"
]}}
]}
}
}
},
"devRdsSnapshotCmk": {
"Type": "AWS::KMS::Key",
"Properties": {
"Description": "The encryption key for dev stack RDS snapshots",
"EnableKeyRotation": true,
"KeyPolicy": {
"Version": "2012-10-17",
"Id": "key-default-1",
"Statement": [
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::${AWS::AccountId}:root"},
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "Allow access for Key Administrators",
"Effect": "Allow",
"Principal": {"AWS": {"Fn::Sub": "arn:aws:iam::${AWS::AccountId}:role/aws-reserved/sso.amazonaws.com/AWSReservedSSO_Administrator_693a85eb20cd5043"}},
"Action": [
"kms:Create*",
"kms:Describe*",
"kms:Enable*",
"kms:List*",
"kms:Put*",
"kms:Update*",
"kms:Revoke*",
"kms:Disable*",
"kms:Get*",
"kms:Delete*",
"kms:TagResource",
"kms:UntagResource",
"kms:ScheduleKeyDeletion",
"kms:CancelKeyDeletion",
"kms:RotateKeyOnDemand"
],
"Resource": "*"
},
{
"Sid": "Allow use of the key",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::766808016710:root"},
"Action": [
"kms:Decrypt",
"kms:DescribeKey"
],
"Resource": "*"
},
{
"Sid": "Allow attachment of persistent resources",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::766808016710:root"},
"Action": [
"kms:CreateGrant",
"kms:ListGrants",
"kms:RevokeGrant"
],
"Resource": "*",
"Condition": {
"StringEquals": {"kms:ViaService": "rds.us-east-1.amazonaws.com"},
"Bool": {"kms:GrantIsForAWSResource": "true"}
}
},
{
"Sid": "AllowRDSToDecryptSourceSnapshotForExport",
"Effect": "Allow",
"Principal": {"Service": "export.rds.amazonaws.com"},
"Action": [
"kms:Decrypt",
"kms:DescribeKey"
],
"Resource": "*"
}
]
}
}
},
"devRdsSnapshotCmkAlias": {
"Type": "AWS::KMS::Alias",
"Properties": {
"AliasName": "alias/synapse/dev/rds-snapshot-cmk",
"TargetKeyId": {"Ref": "devRdsSnapshotCmk"}
}
}
},
"Outputs": {
Expand Down Expand Up @@ -368,4 +450,4 @@
]}}
}
}
}
}
Loading