Skip to content

Commit 97fa737

Browse files
Merge pull request #1988 from Devils-Knight/bug
[FIX] Docker Image is pinned for already pinned Images
2 parents e4612f7 + 6d49773 commit 97fa737

File tree

4 files changed

+65
-0
lines changed

4 files changed

+65
-0
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 {
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/

0 commit comments

Comments
 (0)