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: enforce ssl on s3 deployment bucket #13857

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -26,6 +26,53 @@
}
}
},
"DeploymentBucketBlockHTTP": {
"Type": "AWS::S3::BucketPolicy",
"Properties": {
"Bucket": {
"Ref": "DeploymentBucketName"
awsluja marked this conversation as resolved.
Show resolved Hide resolved
},
"PolicyDocument": {
"Statement": [
{
"Action": "s3:*",
"Effect": "Deny",
"Principal": "*",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "DeploymentBucketName"
},
"/*"
]
]
},
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "DeploymentBucketName"
}
]
]
}
],
"Condition": {
"Bool": {
"aws:SecureTransport": false
}
}
}
]
}
}
},
"AuthRole": {
"Type": "AWS::IAM::Role",
"Properties": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,53 @@ exports[`Check RootStack Template generates root stack Template 1`] = `
"Type": "AWS::S3::Bucket",
"UpdateReplacePolicy": "Retain",
},
"DeploymentBucketBlockHTTP": {
"Properties": {
"Bucket": {
"Ref": "DeploymentBucketName",
},
"PolicyDocument": {
"Statement": [
{
"Action": "s3:*",
"Condition": {
"Bool": {
"aws:SecureTransport": false,
},
},
"Effect": "Deny",
"Principal": "*",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "DeploymentBucketName",
},
"/*",
],
],
},
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "DeploymentBucketName",
},
],
],
},
],
},
],
},
},
"Type": "AWS::S3::BucketPolicy",
},
"UnauthRole": {
"Properties": {
"AssumeRolePolicyDocument": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,53 @@ exports[`Root stack template tests Generated root stack template during init 1`]
"Type": "AWS::S3::Bucket",
"UpdateReplacePolicy": "Retain",
},
"DeploymentBucketBlockHTTP": {
"Properties": {
"Bucket": {
"Ref": "DeploymentBucketName",
},
"PolicyDocument": {
"Statement": [
{
"Action": "s3:*",
"Condition": {
"Bool": {
"aws:SecureTransport": false,
},
},
"Effect": "Deny",
"Principal": "*",
"Resource": [
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "DeploymentBucketName",
},
"/*",
],
],
},
{
"Fn::Join": [
"",
[
"arn:aws:s3:::",
{
"Ref": "DeploymentBucketName",
},
],
],
},
],
},
],
},
},
"Type": "AWS::S3::BucketPolicy",
},
"UnauthRole": {
"Properties": {
"AssumeRolePolicyDocument": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,32 @@ export class AmplifyRootStack extends cdk.Stack implements AmplifyRootStackTempl
}

generateRootStackResources = async (): Promise<void> => {
const bucketName = this._cfnParameterMap.get('DeploymentBucketName').valueAsString;
this.deploymentBucket = new s3.CfnBucket(this, 'DeploymentBucket', {
bucketName: this._cfnParameterMap.get('DeploymentBucketName').valueAsString,
bucketName: bucketName,
});

this.deploymentBucket.applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);

new s3.CfnBucketPolicy(this, 'DeploymentBucketBlockHTTP', {
bucket: bucketName,
policyDocument: {
Statement: [
{
Action: 's3:*',
Effect: 'Deny',
Principal: '*',
Resource: [`arn:aws:s3:::${bucketName}/*`, `arn:aws:s3:::${bucketName}`],
Condition: {
Bool: {
'aws:SecureTransport': false,
},
},
},
],
},
});

this.authRole = new iam.CfnRole(this, 'AuthRole', {
roleName: this._cfnParameterMap.get('AuthRoleName').valueAsString,
assumeRolePolicyDocument: {
Expand Down
Loading