Skip to content

Commit a69dac8

Browse files
committed
[sdlf-cicd] artifacts buckets
1 parent efd3d80 commit a69dac8

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

sdlf-cicd/template-cicd-generic-git.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ Resources:
338338
Value: !Ref pDataAccountId
339339
- Name: ARTIFACTS_BUCKET
340340
Type: PLAINTEXT
341-
Value: !Ref rArtifactsBucket
341+
Value: !Sub "sdlf-${AWS::Region}-${pDataAccountId}-${pCodeBuildSuffix}-cicd-cfn-artifacts"
342342
- Name: TEMPLATE_PREFIXES
343343
Type: PLAINTEXT
344344
Value: !Ref pTemplatePrefixes
@@ -370,7 +370,7 @@ Resources:
370370
do
371371
build_id=$(aws codebuild --endpoint-url "$CODEBUILD_ENDPOINT_URL" start-build \
372372
--project-name sdlf-cicd-bootstrap \
373-
--environment-variables-override name=TARGET_ACCOUNT,value="$TARGET_ACCOUNT" name=SDLF_CONSTRUCTS,value="$SDLF_CONSTRUCT" name=SDLF_STAGE_CONSTRUCTS,value="" name=DEPLOYMENT_TYPE,value="$DEPLOYMENT_TYPE" \
373+
--environment-variables-override name=ARTIFACTS_BUCKET,value="$ARTIFACTS_BUCKET" name=TARGET_ACCOUNT,value="$TARGET_ACCOUNT" name=SDLF_CONSTRUCTS,value="$SDLF_CONSTRUCT" name=SDLF_STAGE_CONSTRUCTS,value="" name=DEPLOYMENT_TYPE,value="$DEPLOYMENT_TYPE" \
374374
--query "build.id" --output text)
375375
echo "Building $SDLF_CONSTRUCT: $build_id"
376376
build_ids+=("$build_id")
@@ -399,7 +399,7 @@ Resources:
399399
do
400400
build_id=$(aws codebuild --endpoint-url "$CODEBUILD_ENDPOINT_URL" start-build \
401401
--project-name sdlf-cicd-bootstrap \
402-
--environment-variables-override name=TARGET_ACCOUNT,value="$TARGET_ACCOUNT" name=SDLF_CONSTRUCTS,value="$SDLF_CONSTRUCT" name=SDLF_STAGE_CONSTRUCTS,value="" name=DEPLOYMENT_TYPE,value="$DEPLOYMENT_TYPE" \
402+
--environment-variables-override name=ARTIFACTS_BUCKET,value="$ARTIFACTS_BUCKET" name=TARGET_ACCOUNT,value="$TARGET_ACCOUNT" name=SDLF_CONSTRUCTS,value="$SDLF_CONSTRUCT" name=SDLF_STAGE_CONSTRUCTS,value="" name=DEPLOYMENT_TYPE,value="$DEPLOYMENT_TYPE" \
403403
--query "build.id" --output text)
404404
echo "Building $SDLF_CONSTRUCT: $build_id"
405405
build_ids+=("$build_id")

sdlf-cicd/template-cicd-generic-role.yaml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,82 @@ Parameters:
1818
Description: "sdlf-cicd-CodeBuildSuffix CodeBuild IAM role name"
1919
Type: String
2020

21+
Conditions:
22+
NotCodeBuildAccount: !Not [!Equals [!Ref pCodeBuildAccountId, !Ref AWS::AccountId]]
23+
2124
Resources:
25+
rKMSKey:
26+
Type: AWS::KMS::Key
27+
Condition: NotCodeBuildAccount
28+
UpdateReplacePolicy: Retain
29+
DeletionPolicy: Delete
30+
Metadata:
31+
cfn-lint:
32+
config:
33+
ignore_checks:
34+
- I3042
35+
Properties:
36+
Description: SDLF KMS key for encryption of CodeBuild artifacts
37+
Enabled: true
38+
EnableKeyRotation: true
39+
KeyPolicy:
40+
Version: "2012-10-17"
41+
Statement:
42+
- Sid: Allow administration of the key
43+
Effect: Allow
44+
Principal:
45+
AWS: !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:root
46+
Action: kms:*
47+
Resource: "*"
48+
- Sid: Allow logs access
49+
Effect: Allow
50+
Principal:
51+
Service: !Sub logs.${AWS::Region}.amazonaws.com
52+
Action:
53+
- kms:Decrypt
54+
- kms:DescribeKey
55+
- kms:Encrypt
56+
- kms:GenerateDataKey*
57+
- kms:ReEncrypt*
58+
Resource: "*"
59+
60+
rArtifactsBucket:
61+
Type: AWS::S3::Bucket
62+
Condition: NotCodeBuildAccount
63+
UpdateReplacePolicy: Delete
64+
DeletionPolicy: Delete
65+
Properties:
66+
BucketName: !Sub "sdlf-${AWS::Region}-${AWS::AccountId}-${pCodeBuildSuffix}-cicd-cfn-artifacts"
67+
BucketEncryption:
68+
ServerSideEncryptionConfiguration:
69+
- BucketKeyEnabled: True
70+
ServerSideEncryptionByDefault:
71+
KMSMasterKeyID: !Ref rKMSKey
72+
SSEAlgorithm: aws:kms
73+
PublicAccessBlockConfiguration:
74+
BlockPublicAcls: True
75+
BlockPublicPolicy: True
76+
IgnorePublicAcls: True
77+
RestrictPublicBuckets: True
78+
79+
rArtifactsBucketPolicy:
80+
Type: AWS::S3::BucketPolicy
81+
Condition: NotCodeBuildAccount
82+
Properties:
83+
Bucket: !Ref rArtifactsBucket
84+
PolicyDocument:
85+
Statement:
86+
- Sid: AllowSSLRequestsOnly
87+
Action: s3:*
88+
Effect: Deny
89+
Resource:
90+
- !Sub arn:${AWS::Partition}:s3:::${rArtifactsBucket}/*
91+
- !Sub arn:${AWS::Partition}:s3:::${rArtifactsBucket}
92+
Condition:
93+
Bool:
94+
aws:SecureTransport: False
95+
Principal: "*"
96+
2297
rSdlfCicdCodeBuildRole:
2398
Type: AWS::IAM::Role
2499
Properties:

0 commit comments

Comments
 (0)