Skip to content

Commit f9c7396

Browse files
committed
add more content to eval
1 parent 57bdcea commit f9c7396

File tree

1 file changed

+69
-7
lines changed

1 file changed

+69
-7
lines changed

GHA_Codebuild_Runner.md

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This document serves as a documented reference to findings found when evaluating `AWS Codebuild Projects` as `Github Action Runners`
33
All testing and evaluation was done in the `regtech/devpub` IAM account.
44

5+
---
56

67
### Components and Use Cases Evaluated
78

@@ -14,31 +15,42 @@ All testing and evaluation was done in the `regtech/devpub` IAM account.
1415
- Passing in `buildspec.yml` (overriding) from GHA to Codebuild project
1516
- Codebuild Runner Project Role and Permissions
1617

18+
---
19+
1720
### AWS Setup
1821
This section outlines the configurations made in the AWS console to implement the testing that was performed.
1922

2023
- Create new Codebuild Project `cfpb-regtech-gha-test-1`. [Referenced](https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html)
2124
- Create github PAT for AWS webhook and codebuild credential (github account)
2225
- Create new Service Role for codebuild project `cfpb-dev-regtech-codebuild-gha-test`
23-
- Create new SecretsManager Secret for PAT `cfpb/team/regtech/gha-codebuild-runner-test`
26+
- Create new SecretsManager Secret for PAT `cfpb/team/regtech/gha-codebuild-runner-test`
27+
- Required to set Webhook `WORKFLOW_JOB_QUEUED` for all runners.
2428
- Create Custom inline policy for the role `RegtechCodeBuildGHARunner`.
2529
- this policy was started from the builtin `AWSCodeBuildDeveloperAccess` policy and upadated as needed.
2630
- Create Cloudformation log group
27-
-
31+
- Created custom Cloudwatch streams and log events from GHA workflow.
32+
33+
> **NOTE** IAM Roles are region based. We will need a minimum of one Codebuild Runner Role configured for each region. Decisions will need to be made based on implementation requirments for how the runner roles are to be used. Options such as a role per product, per team, per repo etc... should be considered. In addition to the scope of Runner Roles, we need to determine what permissions are needed for each Role. Permission requirements might also determine how many roles we need. Limited risk of secrets expose and such can be achieved by controlling the role permission policies.
34+
35+
---
2836

2937
### Github Setup
3038
This section outlines the configurations made in Github to implement the testing that was performed.
31-
`cfpb/regtech-deployments` was used for this testing.
39+
`cfpb/regtech-deployments` was used for this testing.
3240
[Reference Source Repository/Branch](https://github.com/cfpb/regtech-deployments/tree/test/gha-codebuild-runner)
3341

34-
1. A prerequisite for creating a Codebuild project using Github as the source was to have a Personal Access Token (PAT) configured in the Github account. I used my github account `thetoolsmith` which is configured in the CFPB Github Org.
42+
- Prerequisite for creating a Codebuild project using Github as the source was to have a Personal Access Token (PAT) configured in the Github account. I used my github account `thetoolsmith` which is configured in the CFPB Github Org.
3543
The PAT needs to be configured with some required options. [Here](https://docs.aws.amazon.com/codebuild/latest/userguide/access-tokens-github.html) is a reference.
36-
1. Created a test `buildspec.yml` in `regtech-deployments`
44+
- Created a test `buildspec.yml` in `regtech-deployments`
45+
- tested ECR access, Github Container Registry Access and some other basic things
46+
47+
---
3748

3849
### Log Output Codebuild vs Github
3950
Each side of this itegration keep its own logs. Neither Github Action or Codebuild logs are exposed on the other end.
4051
This is a good thing.
4152

53+
##### From the Github Side
4254
All actions taken in GHA workflow, including reading secrets from AWS, are logged only to the GHA output. Nothing shows on the Cloudformation logs.
4355
Example from GHA workflow kicking off the Codebuild Runner.....
4456
```
@@ -48,6 +60,19 @@ Example from GHA workflow kicking off the Codebuild Runner.....
4860
> 2025-01-17T21:14:21.926Z
4961
> 2025-01-17 21:14:21Z: Job test1 completed with result: Succeeded
5062
```
63+
That ↑ is pretty much all we get in GHA logs when kicking off a job that has many steps but is running on a Codebuild project Runner.
64+
65+
##### From the Codebuild Side
66+
All codebuild project actions are logged to Cloudwatch.
67+
We created the Cloudwatch Log Group `/aws/codebuild/cfpb-regtech-gha-test-1` through AWS console.
68+
All codebuild (runner) instances create logstreams for each `codebuild build run`. The streams can be matched up to the unique identifier in the build run name.
69+
The basis high level Codebuild Steps are logged and whatever the `buildspec.yml` is doing if that was set as an override. See Overriding Buildspec Section.
70+
71+
> **NOTE** There will be one `codebuild build run` in the history for each GHA ***Job*** executed during a single Github Action workflow run. In our test, 3 GHA jobs were run each time the workflow run ocurred (update to the pull request).
72+
73+
> **WARNING** There is no easy visual way to match up a failed `Build run` in the codebuild UI with the matching Github Action Workflow **JOB**. For troubleshooting, you must click on the failed build run in the codebuild run history, and analyze the output to determine which github action workflow job caused it. The Github Action Job specific identifiers are not available on the AWS Codebuild project runner side. This makes sense being that nothing output from GHA workflow is logged on the Codebuild side.
74+
75+
---
5176

5277
### Testing Secrets and Masking in Github Workflow
5378
Github Secrets are automatically transformed into environment variable and automatically masked. This is the default behavior in Github Actions for Github Secrets.
@@ -83,14 +108,51 @@ From the point where you ***mask*** the secret through the rest of the workflow
83108
IF we are getting many secrets, we can pass in the `secret-ids` list easily. But, we will need to write a function to iterate over all the retreived secrets and assure each one is passed to `::add-mask:;`.
84109
It's not a very user-freindly or smart way to handle secrets. The Action plugin, should just mask them automatically!
85110

86-
We did extensive testing around this to deternine the best way this could be used. Not much options. We tried wrapping both the get and the masking build steps into a Custom Composite Action, but that doesn't make the process anymore easy or secure.
111+
We did extensive testing around this to determine the best way this could be used. Not much options. We tried wrapping both the get and the masking build steps into a Custom Composite Action, but that doesn't make the process anymore easy or secure.
87112

88113
A decision will need to be made if the `aws-actions/aws-secretsmanager-get-secrets@v2` action should be used. We could not allow the Codebuild Project runner role access to SecretsManager which would prevent GHA workflows from being able to pull aws secrets.
89114

115+
---
116+
117+
### Performance
118+
Without doing high scale performance testing, initial observations are that this implementation is pretty quick and snappy.
119+
It's a matter of seconds before the codebuild runner starts from a new pr commit or whatever trigger we use.
120+
121+
I didn't notice any lag compared to using Github Action default public runners.
122+
123+
There is a 20 concurrent runner limit which is a default in AWS. This can be bumped as needed.
124+
No testing was done on running more that one runner at a time for this initial analysis.
125+
126+
We didn't experience any hang on either the codebuild or github side.
127+
128+
##### Codebuild status via Github
129+
By default, we do not get any status updates from Codebuild runs in the Github workflow run logs when passing in `buildspec.yml` override. [Buildspec Override Reference](https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html)
130+
131+
As the aws documentation states, codebuild project runners use `buildspec` as well. So you override some of the codebuild phases by passing in a custom `buildspec.yml` from the Github source repo. But, you cannot use the BUILD phase.
132+
133+
> **NOTE** When passing in buildspec from the source github repo, if it fails during the build run in Codebuild, we do NOT get that failure back on the Github side. The GHA workflow run will show Success. This could lead to some false positve github workflow runs. There are a couple configuration options in Codebuild Projects that talk about providing status back to the provider. This will require some addition research. It appears that we need to configure [api calls](https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#update-a-pull-request) to update the Pull Request or other that is triggering the Codebuild run.
134+
135+
##### Report Codebuild Status back to Github
136+
- https://docs.aws.amazon.com/codebuild/latest/userguide/change-project.html
137+
- https://docs.aws.amazon.com/codebuild/latest/userguide/access-tokens-github.html
138+
139+
##### Access Tokens
140+
As noted above, a Github Access Token is required in the Codebuild Project Configuration when creating a Runner project.
141+
This token allows for the AWS to Github webhooks. So the token must have the repo webhook (or higher) permissions along with everything else that it might need.
142+
143+
This token does ***NOT*** grant Codebuild runner (or the IAM role) access to Github Container Registry.
144+
We also noticed that a GHA workflow that is authenticated to GHCR by way of doing a Login in the workflow, does not persist on the Codebuild side when executing a `buildspec.yml` passed in as override.
145+
146+
The `buildspec.yml` runs ion the context of the Codebuild project Service Role, but access to the Github Container Registry from within the `buildspec.yml` is not allowed by default even when the Github Action workflow that is passing in the `buildspec.yml` has authenticated to the GHCR.
147+
This was a little unexpected.
148+
149+
If there is a use case for us to build and perform other tasks on an image that will be published to Github Container Registry, we will still need to authenticate to GHCR from within the `buildspec.yml` code.
150+
151+
---
90152

91153
### Misc
92154

93-
Passing `Github Action` vaiable to `Codebuild`, you can use the `env-vars-for-codebuild` option in the [AWS Codebuild Marketplace Action](https://github.com/marketplace/actions/aws-codebuild-run-build-action-for-github-actions#aws-codebuild-run-build-for-github-actions) for Github Actions.
155+
For passing `Github Action` variables to `Codebuild`, you can use the `env-vars-for-codebuild` option in the [AWS Codebuild Marketplace Action](https://github.com/marketplace/actions/aws-codebuild-run-build-action-for-github-actions#aws-codebuild-run-build-for-github-actions) for Github Actions.
94156
This Marketplace Action also provides auto-triggering Codebuild from Github pull requests, mergers etc...
95157

96158

0 commit comments

Comments
 (0)