Skip to content

Commit 8e5d1fb

Browse files
updating action name while getting image manifest for bundled actions
1 parent 59ccd75 commit 8e5d1fb

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

remediation/workflow/pin/action_image_manifest.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ func getOCIImageArtifactTypeForGhAction(action string) (string, error) {
6969
return "", fmt.Errorf("invalid action format")
7070
}
7171

72+
// For bundled actions like github/codeql-action/analyze@v3,
73+
// we only need the repository part (github/codeql-action) to check for immutability
74+
actionPath := parts[0]
75+
if strings.Count(parts[0], "/") > 1 {
76+
pathParts := strings.Split(parts[0], "/")
77+
actionPath = strings.Join(pathParts[:2], "/")
78+
}
79+
7280
// convert v1.x.x to 1.x.x which is
7381
// use regexp to match tag version format and replace v in prefix
7482
// as immutable actions image tag is in format 1.x.x (without v prefix)
@@ -79,7 +87,7 @@ func getOCIImageArtifactTypeForGhAction(action string) (string, error) {
7987
}
8088

8189
// Convert GitHub action to GHCR image reference using proper OCI reference format
82-
image := fmt.Sprintf("ghcr.io/%s:%s", parts[0], parts[1])
90+
image := fmt.Sprintf("ghcr.io/%s:%s", actionPath, parts[1])
8391
imageManifest, err := getOCIManifestForImage(image)
8492
if err != nil {
8593
return "", err

remediation/workflow/pin/pinactions_test.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,21 @@ func TestPinActions(t *testing.T) {
173173
}
174174
]`))
175175

176+
httpmock.RegisterResponder("GET", "https://api.github.com/repos/github/codeql-action/commits/v3",
177+
httpmock.NewStringResponder(200, `d68b2d4edb4189fd2a5366ac14e72027bd4b37dd`))
178+
179+
httpmock.RegisterResponder("GET", "https://api.github.com/repos/github/codeql-action/git/matching-refs/tags/v3.",
180+
httpmock.NewStringResponder(200,
181+
`[
182+
{
183+
"ref": "refs/tags/v3.28.2",
184+
"object": {
185+
"sha": "d68b2d4edb4189fd2a5366ac14e72027bd4b37dd",
186+
"type": "commit"
187+
}
188+
}
189+
]`))
190+
176191
// mock ping response
177192
httpmock.RegisterResponder("GET", "https://ghcr.io/v2/",
178193
httpmock.NewStringResponder(200, ``))
@@ -191,7 +206,8 @@ func TestPinActions(t *testing.T) {
191206
"repository:JS-DevTools/npm-publish:pull",
192207
"repository:elgohr/Publish-Docker-Github-Action:pull",
193208
"repository:brandedoutcast/publish-nuget:pull",
194-
"repository:rohith/publish-nuget:pull":
209+
"repository:rohith/publish-nuget:pull",
210+
"repository:github/codeql-action:pull":
195211
return httpmock.NewJsonResponse(http.StatusOK, map[string]string{
196212
"token": "test-token",
197213
"access_token": "test-token",
@@ -213,6 +229,7 @@ func TestPinActions(t *testing.T) {
213229
// the following list will contain the list of actions with versions
214230
// which are mocked to be immutable
215231
"actions/[email protected]",
232+
216233
}
217234

218235
for _, action := range manifestResponders {

testfiles/pinactions/input/immutableaction-1.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ jobs:
44
build:
55
runs-on: ubuntu-latest
66
steps:
7-
- uses: actions/[email protected]
7+
- uses: actions/checkout@v1
8+
- uses: github/codeql-action/analyze@v3
89
- uses: borales/[email protected]
910
with:
1011
auth-token: ${{ secrets.GITHUB_TOKEN }}

testfiles/pinactions/output/immutableaction-1.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ jobs:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/[email protected]
8+
- uses: github/codeql-action/[email protected]
89
- uses: borales/actions-yarn@4965e1a0f0ae9c422a9a5748ebd1fb5e097d22b9 # v2.3.0
910
with:
1011
auth-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)