Skip to content

Commit acfa53b

Browse files
committed
fix pinning docker issue
1 parent 97fa737 commit acfa53b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

remediation/workflow/pin/pindocker.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func PinDocker(inputYaml string) (string, bool, error) {
2828
for jobName, job := range workflow.Jobs {
2929

3030
for _, step := range job.Steps {
31-
if len(step.Uses) > 0 && strings.HasPrefix(step.Uses, "docker://") {
31+
if len(step.Uses) > 0 && strings.HasPrefix(step.Uses, "docker://") && !strings.Contains(step.Uses, "@") {
3232
localUpdated := false
3333
out, localUpdated = pinDocker(step.Uses, jobName, out)
3434
updated = updated || localUpdated
@@ -68,6 +68,8 @@ func pinDocker(action, jobName, inputYaml string) (string, bool) {
6868

6969
pinnedAction := fmt.Sprintf("%s:%s@%s # %s", leftOfAt[0], leftOfAt[1], imghash.String(), tag)
7070
inputYaml = strings.ReplaceAll(inputYaml, action, pinnedAction)
71+
// Revert the extra hash for already pinned docker actions
72+
inputYaml = strings.ReplaceAll(inputYaml, pinnedAction+"@", action+"@")
7173
updated = !strings.EqualFold(action, pinnedAction)
7274
return inputYaml, updated
7375
}

testfiles/pindockers/input/dockeraction.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
with:
3939
args: sh -c "cd conker && make --jobs"
4040
- name: Perform make replace
41-
uses: docker://docker.io/markstreet/conker:latest
41+
uses: docker://docker.io/markstreet/conker@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0 # latest
4242
with:
4343
args: sh -c "cd conker && make replace"
4444

0 commit comments

Comments
 (0)