You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: GHA_Codebuild_Runner.md
+69-7Lines changed: 69 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
This document serves as a documented reference to findings found when evaluating `AWS Codebuild Projects` as `Github Action Runners`
3
3
All testing and evaluation was done in the `regtech/devpub` IAM account.
4
4
5
+
---
5
6
6
7
### Components and Use Cases Evaluated
7
8
@@ -14,31 +15,42 @@ All testing and evaluation was done in the `regtech/devpub` IAM account.
14
15
- Passing in `buildspec.yml` (overriding) from GHA to Codebuild project
15
16
- Codebuild Runner Project Role and Permissions
16
17
18
+
---
19
+
17
20
### AWS Setup
18
21
This section outlines the configurations made in the AWS console to implement the testing that was performed.
19
22
20
23
- Create new Codebuild Project `cfpb-regtech-gha-test-1`. [Referenced](https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html)
21
24
- Create github PAT for AWS webhook and codebuild credential (github account)
22
25
- 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.
24
28
- Create Custom inline policy for the role `RegtechCodeBuildGHARunner`.
25
29
- this policy was started from the builtin `AWSCodeBuildDeveloperAccess` policy and upadated as needed.
26
30
- 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
+
---
28
36
29
37
### Github Setup
30
38
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.
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.
35
43
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
+
---
37
48
38
49
### Log Output Codebuild vs Github
39
50
Each side of this itegration keep its own logs. Neither Github Action or Codebuild logs are exposed on the other end.
40
51
This is a good thing.
41
52
53
+
##### From the Github Side
42
54
All actions taken in GHA workflow, including reading secrets from AWS, are logged only to the GHA output. Nothing shows on the Cloudformation logs.
43
55
Example from GHA workflow kicking off the Codebuild Runner.....
44
56
```
@@ -48,6 +60,19 @@ Example from GHA workflow kicking off the Codebuild Runner.....
48
60
> 2025-01-17T21:14:21.926Z
49
61
> 2025-01-17 21:14:21Z: Job test1 completed with result: Succeeded
50
62
```
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
+
---
51
76
52
77
### Testing Secrets and Masking in Github Workflow
53
78
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
83
108
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:;`.
84
109
It's not a very user-freindly or smart way to handle secrets. The Action plugin, should just mask them automatically!
85
110
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.
87
112
88
113
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.
89
114
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.
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
+
---
90
152
91
153
### Misc
92
154
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.
94
156
This Marketplace Action also provides auto-triggering Codebuild from Github pull requests, mergers etc...
0 commit comments