Skip to content

Commit 6fcdaa9

Browse files
Release v1.3.1 (#2008)
1 parent b6ea952 commit 6fcdaa9

File tree

11 files changed

+94
-18
lines changed

11 files changed

+94
-18
lines changed

remediation/docker/securedockerfile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ func SecureDockerFile(inputDockerFile string) (*SecureDockerfileResponse, error)
7171
}
7272
new_cmd := strings.ReplaceAll(c.Original, c.Value[0], fmt.Sprintf("%s:%s@%s", image, tag, sha))
7373
response.FinalOutput = strings.ReplaceAll(response.FinalOutput, c.Original, new_cmd)
74+
// Revert the extra hash for already pinned docker images
75+
response.FinalOutput = strings.ReplaceAll(response.FinalOutput, new_cmd+"@", c.Original+"@")
7476
response.IsChanged = true
7577

7678
}

remediation/docker/securedockerfile_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func TestSecureDockerFile(t *testing.T) {
4545
}{
4646
{fileName: "Dockerfile-not-pinned", isChanged: true},
4747
{fileName: "Dockerfile-not-pinned-as", isChanged: true},
48+
{fileName: "Dockerfile-multiple-images", isChanged: true},
4849
}
4950

5051
for _, test := range tests {

remediation/workflow/pin/pindocker.go

Lines changed: 10 additions & 3 deletions
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
@@ -42,7 +42,11 @@ func PinDocker(inputYaml string) (string, bool, error) {
4242
func pinDocker(action, jobName, inputYaml string) (string, bool) {
4343
updated := false
4444
leftOfAt := strings.Split(action, ":")
45-
tag := leftOfAt[2]
45+
tag := "latest"
46+
// Reference :latest tag if no tag is present
47+
if len(leftOfAt) > 2 {
48+
tag = leftOfAt[2]
49+
}
4650
image := leftOfAt[1][2:]
4751

4852
ref, err := name.ParseReference(image, name.WithDefaultTag(tag))
@@ -62,8 +66,11 @@ func pinDocker(action, jobName, inputYaml string) (string, bool) {
6266
return inputYaml, updated
6367
}
6468

65-
pinnedAction := fmt.Sprintf("%s:%s@%s # %s", leftOfAt[0], leftOfAt[1], imghash.String(), tag)
69+
pinnedAction := fmt.Sprintf("%s:%s:%s@%s", leftOfAt[0], leftOfAt[1], tag, imghash.String())
6670
inputYaml = strings.ReplaceAll(inputYaml, action, pinnedAction)
71+
// Revert the extra hash for already pinned docker actions
72+
inputYaml = strings.ReplaceAll(inputYaml, pinnedAction+"@", action+"@")
73+
inputYaml = strings.ReplaceAll(inputYaml, pinnedAction+":", action+":")
6774
updated = !strings.EqualFold(action, pinnedAction)
6875
return inputYaml, updated
6976
}

testfiles/addworkflow/expected-dependency-review.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Dependency Review Action
22
#
3-
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
3+
# This Action will scan dependency manifest files that change as part of a Pull Request,
4+
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
5+
# Once installed, if the workflow run is marked as required,
6+
# PRs introducing known-vulnerable packages will be blocked from merging.
47
#
58
# Source repository: https://github.com/actions/dependency-review-action
6-
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
79
name: 'Dependency Review'
810
on: [pull_request]
911

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM python:3.7 AS builder
2+
3+
RUN apt-get update
4+
RUN apt-get install -y build-essential autoconf libxml2-dev libssl-dev zlib1g-dev curl
5+
6+
# Install bomutils
7+
RUN curl -L https://github.com/hogliux/bomutils/archive/0.2.tar.gz > bomutils.tar.gz && \
8+
echo "fb1f4ae37045eaa034ddd921ef6e16fb961e95f0364e5d76c9867bc8b92eb8a4 bomutils.tar.gz" | sha256sum --check && \
9+
tar -xzf bomutils.tar.gz
10+
RUN cd bomutils-0.2 && make && make install
11+
12+
# Install xar
13+
RUN curl -L https://github.com/mackyle/xar/archive/refs/tags/xar-1.6.1.tar.gz > xar.tar.gz && \
14+
echo "5e7d50dab73f5cb1713b49fa67c455c2a0dd2b0a7770cbc81b675e21f6210e25 xar.tar.gz" | sha256sum --check && \
15+
tar -xzf xar.tar.gz
16+
# Note this needs patching due to newer version of OpenSSL
17+
# See https://github.com/mackyle/xar/pull/23
18+
COPY patch.txt .
19+
RUN cd xar-xar-1.6.1/xar && patch < ../../patch.txt && autoconf && ./configure && make && make install
20+
21+
22+
FROM python:3.7
23+
24+
FROM python:3.7
25+
26+
FROM python:3.7
27+
28+
RUN apt-get update && apt-get install -y --no-install-recommends libxml2 && rm -rf /var/lib/apt/lists/*
29+
COPY --from=builder /usr/bin /usr/bin/
30+
COPY --from=builder /usr/local/bin /usr/local/bin/
31+
COPY --from=builder /usr/local/lib /usr/local/lib/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FROM python:3.7@sha256:5fb6f4b9d73ddeb0e431c938bee25c69157a1e3c880a81ff72c43a8055628de5 AS builder
2+
3+
RUN apt-get update
4+
RUN apt-get install -y build-essential autoconf libxml2-dev libssl-dev zlib1g-dev curl
5+
6+
# Install bomutils
7+
RUN curl -L https://github.com/hogliux/bomutils/archive/0.2.tar.gz > bomutils.tar.gz && \
8+
echo "fb1f4ae37045eaa034ddd921ef6e16fb961e95f0364e5d76c9867bc8b92eb8a4 bomutils.tar.gz" | sha256sum --check && \
9+
tar -xzf bomutils.tar.gz
10+
RUN cd bomutils-0.2 && make && make install
11+
12+
# Install xar
13+
RUN curl -L https://github.com/mackyle/xar/archive/refs/tags/xar-1.6.1.tar.gz > xar.tar.gz && \
14+
echo "5e7d50dab73f5cb1713b49fa67c455c2a0dd2b0a7770cbc81b675e21f6210e25 xar.tar.gz" | sha256sum --check && \
15+
tar -xzf xar.tar.gz
16+
# Note this needs patching due to newer version of OpenSSL
17+
# See https://github.com/mackyle/xar/pull/23
18+
COPY patch.txt .
19+
RUN cd xar-xar-1.6.1/xar && patch < ../../patch.txt && autoconf && ./configure && make && make install
20+
21+
22+
FROM python:3.7@sha256:5fb6f4b9d73ddeb0e431c938bee25c69157a1e3c880a81ff72c43a8055628de5
23+
24+
FROM python:3.7@sha256:5fb6f4b9d73ddeb0e431c938bee25c69157a1e3c880a81ff72c43a8055628de5
25+
26+
FROM python:3.7@sha256:5fb6f4b9d73ddeb0e431c938bee25c69157a1e3c880a81ff72c43a8055628de5
27+
28+
RUN apt-get update && apt-get install -y --no-install-recommends libxml2 && rm -rf /var/lib/apt/lists/*
29+
COPY --from=builder /usr/bin /usr/bin/
30+
COPY --from=builder /usr/local/bin /usr/local/bin/
31+
COPY --from=builder /usr/local/lib /usr/local/lib/

testfiles/pindockers/input/dockeraction.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ 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:latest@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0
4242
with:
4343
args: sh -c "cd conker && make replace"
4444

4545
- name: Perform make
46-
uses: docker://docker.io/markstreet/conker:latest
46+
uses: docker://docker.io/markstreet/conker
4747
with:
4848
args: make --jobs
4949

testfiles/pindockers/output/dockeraction.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,30 @@ jobs:
2525
run: echo ${{ secrets.CONKER_BASEROM_US }} | openssl enc -d -aes-256-cbc -pass stdin -pbkdf2 -in baserom/baserom.us.z64.aes -out baserom.us.z64
2626

2727
- name: Perform make extract (rom)
28-
uses: docker://docker.io/markstreet/conker@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0 # latest
28+
uses: docker://docker.io/markstreet/conker:latest@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0
2929
with:
3030
args: make extract
3131

3232
- name: Perform make extract (code)
33-
uses: docker://docker.io/markstreet/conker@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0 # latest
33+
uses: docker://docker.io/markstreet/conker:latest@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0
3434
with:
3535
args: sh -c "cd conker && make extract"
3636
- name: Perform make (code)
37-
uses: docker://docker.io/markstreet/conker@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0 # latest
37+
uses: docker://docker.io/markstreet/conker:latest@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0
3838
with:
3939
args: sh -c "cd conker && make --jobs"
4040
- name: Perform make replace
41-
uses: docker://docker.io/markstreet/conker@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0 # latest
41+
uses: docker://docker.io/markstreet/conker:latest@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0
4242
with:
4343
args: sh -c "cd conker && make replace"
4444

4545
- name: Perform make
46-
uses: docker://docker.io/markstreet/conker@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0 # latest
46+
uses: docker://docker.io/markstreet/conker:latest@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0
4747
with:
4848
args: make --jobs
4949

5050
- name: Create progress.csv
51-
uses: docker://docker.io/markstreet/conker@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0 # latest
51+
uses: docker://docker.io/markstreet/conker:latest@sha256:1efef3bbdd297d1b321b9b4559092d3131961913bc68b7c92b681b4783d563f0
5252
with:
5353
args: sh -c "cd conker && make progress"
5454

testfiles/pindockers/output/gcraction.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ jobs:
1919
go-version: ${{ env.GO_VERSION }}
2020

2121
- name: Container structure test (scratch)
22-
uses: docker://gcr.io/gcp-runtimes/container-structure-test@sha256:4affda1c8f058f8d6c86dcad965cdb438a3d1d9a982828ff6737ea492b6bc8ce # latest
22+
uses: docker://gcr.io/gcp-runtimes/container-structure-test:latest@sha256:4affda1c8f058f8d6c86dcad965cdb438a3d1d9a982828ff6737ea492b6bc8ce
2323
with:
2424
args: 'test --image ffurrer/semver:latest --config test/semver_container_test.yml'
2525

2626
- name: Container structure test (alpine)
27-
uses: docker://gcr.io/gcp-runtimes/container-structure-test@sha256:4affda1c8f058f8d6c86dcad965cdb438a3d1d9a982828ff6737ea492b6bc8ce # latest
27+
uses: docker://gcr.io/gcp-runtimes/container-structure-test:latest@sha256:4affda1c8f058f8d6c86dcad965cdb438a3d1d9a982828ff6737ea492b6bc8ce
2828
with:
2929
args: 'test --image ffurrer/semver:alpine --config test/semver_alpine_container_test.yml'
3030

testfiles/pindockers/output/ghcraction.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ jobs:
1212
- name: Checkout
1313
uses: actions/checkout@v1
1414
- name: Integration test
15-
uses: docker://ghcr.io/step-security/integration-test/int@sha256:f1f95204dc1f12a41eaf41080185e2d289596b3e7637a8c50a3f6fbe17f99649 # latest
15+
uses: docker://ghcr.io/step-security/integration-test/int:latest@sha256:f1f95204dc1f12a41eaf41080185e2d289596b3e7637a8c50a3f6fbe17f99649
1616
env:
1717
PAT: ${{ secrets.PAT }}

0 commit comments

Comments
 (0)