Skip to content

Commit 7d0f5be

Browse files
adding staging bucket stack, arm builds, some directions (#3205)
* separated the merge-build and pr-build buildspecs * aim the codebuild stack at the right buildspec * updated the buildspecs to release and sign arm variants as well * updated the build infrastructure to build for arm as well as amd archs * added a note about adding more artifacts to be signed and copied * fixing a couple of other things found in review * added a bucket stack with a bucket policy * missed a letter in the arm build naming * added a missed file in the build directory structure * updated the descriptions for all of the codebuild projects
1 parent 34394b7 commit 7d0f5be

9 files changed

+353
-81
lines changed

build-infrastructure/README.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,27 @@ The directory structure that is expected is as follows,
4242

4343
```
4444
buildspecs/
45-
|- build.yml
45+
|- merge-build.yml
46+
|- pr-build.yml
4647
|- signing.yml
4748
|- copy.yml
4849
```
4950

5051
Everything else is already set up for you.
5152

53+
## Adding a new artifact get signed and copied
54+
55+
There are a few changes that need to be made to add another artifact that needs to be signed and copied to the CodePipeline. They are as follows,
56+
57+
1. The CodeBuild project that feeds into the signer has to export a variable that carries the name of the artifact to sign. Check out the `exported-variables` key within `merge-build.yml` for an example of how to set this up. You create an environment variable and any defined environment variable can be exported from a codebuild project.
58+
1. In `release-pipeline-stack.yml`, add the project that will feed into the signer, and add an IAM role to go with it. See the `AmdBuildCodeBuildProjectServiceRole` and `AmdBuildCodeBuildProject` keys in the file for examples. Follow established naming conventions.
59+
1. In `release-pipeline-stack.yml`, add an action to the appropriate stage under the `BuildAndSignCodePipeline` key. Likely, you're going to want to define a new item in the `Actions` list under one of the `Stages`. Pay close attention to define both `OutputArtifacts` and `Namespace` for your new action. See `Action` with the `Name` called `MakeAmd` for an example.
60+
1. In `release-pipeline-stack.yml`, add a new entry in the `InputArtifacts` list for the `Action` with `Name` called `GPG`. This name should correspond to the `OutputArtifacts` name that you defined above.
61+
1. In `release-pipeline-stack.yml`, the `Action` with `Name` called `GPG` has a key called `EnvironmentVariables` with a JSON string as value. Be careful not to unstringify the JSON, CodePipeline through CloudFormation expects this key to have stringified JSON, and nothing else. Add an entry to this declaring the new artifact that you want to sign. Your exported variable from the CodeBuild buildspec and the `Namespace` that you declared comes into play here. You can find the name of the artifact in the value specified by `#{<namespace_name>.<exported_variable_name>}`. Create a new JSON object with the `name` key containing the environment variable name you'd like to be set, the `value` key containing something akin to `#{something.something}`, and the `type` key set to `PLAINTEXT`.
62+
1. Within the signing CodeBuild environment, the primary source is the directory that the build starts out in. All the other input sources are what CodeBuild considers secondary sources and they get their own directories within the build environment. Those directories are stored in environment variables in the format `$CODEBUILD_SRC_DIR_<output_artifact_name>`. This allows you to locate the new artifact that needs to be signed and call the `sign_file` function with the new artifact.
63+
1. The signing is going to generate a new file that ends in `.asc`. You have to export that out of the signing environment for it to be picked up by the Copy to S3 CodeBuild project.
64+
1. The Copy to S3 CodeBuild project is already written to handle multiple files so no changes are required there.
65+
5266
## Secrets Manager access logs
5367

5468
There is a separate template called `audit-logs-stack.yml` that contains audit logging for the key stored in AWS Secrets Manager. You can use CloudTrail to find the `GetSecretValue` events using the Event Name filter or using `secretsmanager.amazonaws.com` as the Event Source. This applies for the last 90 days.

build-infrastructure/audit-logs-stack.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
AWSTemplateFormatVersion: "2010-09-09"
2+
AWSTemplateFormatVersion: '2010-09-09'
33
Description: A template that creates an audit log and associated logs and buckets
44

55
Parameters:
@@ -44,13 +44,13 @@ Resources:
4444
AuditLogsBucket:
4545
Type: AWS::S3::Bucket
4646
Properties:
47-
BucketName: !Sub "audit-logs-bucket-${AWS::AccountId}"
47+
BucketName: !Sub 'audit-logs-bucket-${AWS::AccountId}'
4848

4949
AuditLogsBucketPolicy:
5050
DependsOn: AuditLogsBucket
5151
Type: AWS::S3::BucketPolicy
5252
Properties:
53-
Bucket: !Sub "audit-logs-bucket-${AWS::AccountId}"
53+
Bucket: !Sub 'audit-logs-bucket-${AWS::AccountId}'
5454
PolicyDocument:
5555
Version: 2012-10-17
5656
Statement:
@@ -59,25 +59,25 @@ Resources:
5959
Principal:
6060
Service: cloudtrail.amazonaws.com
6161
Action: s3:GetBucketAcl
62-
Resource: !Sub "arn:aws:s3:::audit-logs-bucket-${AWS::AccountId}"
62+
Resource: !Sub 'arn:aws:s3:::audit-logs-bucket-${AWS::AccountId}'
6363
Condition:
6464
StringEquals:
65-
AWS:SourceArn: !Sub "arn:aws:cloudtrail:${AWS::Region}:${AWS::AccountId}:trail/${KeyAccessTrailName}"
65+
AWS:SourceArn: !Sub 'arn:aws:cloudtrail:${AWS::Region}:${AWS::AccountId}:trail/${KeyAccessTrailName}'
6666
- Sid: AWSCloudTrailWrite20150319
6767
Effect: Allow
6868
Principal:
6969
Service: cloudtrail.amazonaws.com
7070
Action: s3:PutObject
71-
Resource: !Sub "arn:aws:s3:::audit-logs-bucket-${AWS::AccountId}/AWSLogs/${AWS::AccountId}/*"
71+
Resource: !Sub 'arn:aws:s3:::audit-logs-bucket-${AWS::AccountId}/AWSLogs/${AWS::AccountId}/*'
7272
Condition:
7373
StringEquals:
7474
s3:x-amz-acl: bucket-owner-full-control
75-
AWS:SourceArn: !Sub "arn:aws:cloudtrail:${AWS::Region}:${AWS::AccountId}:trail/${KeyAccessTrailName}"
75+
AWS:SourceArn: !Sub 'arn:aws:cloudtrail:${AWS::Region}:${AWS::AccountId}:trail/${KeyAccessTrailName}'
7676

7777
KeyAccessCloudTrailCloudWatchLogsRole:
7878
Type: AWS::IAM::Role
7979
Properties:
80-
RoleName: !Sub "key-access-cloudtrail-service-role-${AWS::Region}"
80+
RoleName: !Sub 'key-access-cloudtrail-service-role-${AWS::Region}'
8181
AssumeRolePolicyDocument:
8282
Version: 2012-10-17
8383
Statement:
@@ -96,14 +96,14 @@ Resources:
9696
- logs:CreateLogStream
9797
Resource:
9898
- !GetAtt KeyAccessAuditLogGroup.Arn
99-
- !Sub "${KeyAccessAuditLogGroup.Arn}:*"
99+
- !Sub '${KeyAccessAuditLogGroup.Arn}:*'
100100
- Sid: CloudTrailLogStreamEventAccess
101101
Effect: Allow
102102
Action:
103103
- logs:PutLogEvents
104104
Resource:
105105
- !GetAtt KeyAccessAuditLogGroup.Arn
106-
- !Sub "${KeyAccessAuditLogGroup.Arn}:*"
106+
- !Sub '${KeyAccessAuditLogGroup.Arn}:*'
107107

108108
KeyAccessCloudTrailAuditLog:
109109
DependsOn:
@@ -118,4 +118,4 @@ Resources:
118118
IsLogging: true
119119
IsMultiRegionTrail: true
120120
TrailName: !Ref KeyAccessTrailName
121-
S3BucketName: !Sub "audit-logs-bucket-${AWS::AccountId}"
121+
S3BucketName: !Sub 'audit-logs-bucket-${AWS::AccountId}'

build-infrastructure/codebuild-devbuild-stack.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Resources:
4242
QueuedTimeoutInMinutes: 60
4343
ServiceRole: !Ref ServiceRoleArm
4444
Source:
45-
BuildSpec: buildspecs/build.yml
45+
BuildSpec: buildspecs/pr-build.yml
4646
Location: !Ref GithubFullRepoName
4747
Type: GITHUB
4848
TimeoutInMinutes: 60
@@ -96,7 +96,7 @@ Resources:
9696
QueuedTimeoutInMinutes: 60
9797
ServiceRole: !Ref ServiceRoleAmd
9898
Source:
99-
BuildSpec: buildspecs/build.yml
99+
BuildSpec: buildspecs/pr-build.yml
100100
Location: !Ref GithubFullRepoName
101101
Type: GITHUB
102102
TimeoutInMinutes: 60
@@ -145,13 +145,13 @@ Resources:
145145
Statement:
146146
- Effect: Allow
147147
Resource:
148-
- !Join
148+
- !Join
149149
- ':'
150150
- - 'arn:aws:logs'
151151
- !Ref 'AWS::Region'
152152
- !Ref 'AWS::AccountId'
153153
- !Sub 'log-group:/aws/codebuild/${BuildProjectName}-amd'
154-
- !Join
154+
- !Join
155155
- ':'
156156
- - 'arn:aws:logs'
157157
- !Ref 'AWS::Region'
@@ -172,7 +172,7 @@ Resources:
172172
- 's3:GetBucketLocation'
173173
- Effect: Allow
174174
Resource:
175-
- !Sub '${BuildBucketArn}/*'
175+
- !Sub '${BuildBucketArn}/*'
176176
Action:
177177
- 's3:GetObject'
178178
- 's3:PutObject'
@@ -198,13 +198,13 @@ Resources:
198198
Statement:
199199
- Effect: Allow
200200
Resource:
201-
- !Join
201+
- !Join
202202
- ':'
203203
- - 'arn:aws:logs'
204204
- !Ref 'AWS::Region'
205205
- !Ref 'AWS::AccountId'
206206
- !Sub 'log-group:/aws/codebuild/${BuildProjectName}-arm'
207-
- !Join
207+
- !Join
208208
- ':'
209209
- - 'arn:aws:logs'
210210
- !Ref 'AWS::Region'

0 commit comments

Comments
 (0)