Skip to content

Commit ac14791

Browse files
committed
Install trusted certs instead of copy
1 parent 3a97288 commit ac14791

File tree

4 files changed

+71
-11
lines changed

4 files changed

+71
-11
lines changed

.github/workflows/style.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ jobs:
3737
with:
3838
dockerfile: Dockerfile
3939

40+
- name: Run hadolint Konflux
41+
uses: hadolint/hadolint-action@v3.3.0
42+
with:
43+
dockerfile: konflux.Dockerfile
44+
4045
- name: Create ../results directory for SARIF report files
4146
shell: bash
4247
run: mkdir -p ../results

Dockerfile

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Used images
44
ARG GOLANG_BUILDER=registry.access.redhat.com/ubi10/go-toolset:1.25
55
ARG MCP_SERVER_BASE_IMAGE=registry.access.redhat.com/ubi10/ubi-micro:10.1
6+
ARG PACKAGE_INSTALLER_IMAGE=registry.access.redhat.com/ubi10/ubi:10.1
67

78
# Build arguments for multi-arch build support
89
ARG BUILDPLATFORM
@@ -43,18 +44,46 @@ RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
4344
-o /tmp/stackrox-mcp \
4445
./cmd/stackrox-mcp
4546

46-
# Stage 2: Runtime - Minimal runtime image
47-
FROM $MCP_SERVER_BASE_IMAGE
47+
# Stage 2: Runtime base - used to preserve rpmdb when installing packages
48+
FROM $MCP_SERVER_BASE_IMAGE AS ubi-micro-base
49+
50+
51+
# Stage 3: Package installer - installs ca-certificates and openssl into /ubi-micro-base-root/
52+
FROM --platform=$BUILDPLATFORM $PACKAGE_INSTALLER_IMAGE AS package_installer
53+
54+
# Support multi-arch target builds
55+
ARG TARGETARCH
56+
57+
# Copy ubi-micro base to /ubi-micro-base-root/ to preserve its rpmdb
58+
COPY --from=ubi-micro-base / /ubi-micro-base-root/
59+
60+
# Install packages directly to /ubi-micro-base-root/ using --installroot
61+
# Note: --forcearch maps Docker's arch name to RPM arch name to install target-arch packages on the build platform.
62+
# hadolint ignore=DL3041 # We are installing ca-certificates and openssl only to include trusted certs.
63+
RUN TARGETARCH_RPM=$([ "$TARGETARCH" = "amd64" ] && echo "x86_64" || [ "$TARGETARCH" = "arm64" ] && echo "aarch64" || echo "$TARGETARCH") && \
64+
dnf install -y \
65+
--installroot=/ubi-micro-base-root/ \
66+
--releasever=10 \
67+
--forcearch="$TARGETARCH_RPM" \
68+
--setopt=install_weak_deps=False \
69+
--setopt=reposdir=/etc/yum.repos.d \
70+
--nodocs \
71+
ca-certificates \
72+
openssl && \
73+
dnf clean all --installroot=/ubi-micro-base-root/ && \
74+
rm -rf /ubi-micro-base-root/var/cache/*
75+
76+
77+
# Stage 4: Runtime - Minimal runtime image
78+
FROM ubi-micro-base
4879

4980
# Set default environment variables
5081
ENV LOG_LEVEL=INFO
5182

5283
# Set working directory
5384
WORKDIR /app
5485

55-
# Copy trusted certificates from builder
56-
COPY --from=builder /etc/pki/ca-trust/extracted/ /etc/pki/ca-trust/extracted/
57-
COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs/
86+
COPY --from=package_installer /ubi-micro-base-root/ /
5887

5988
# Copy binary from builder
6089
COPY --from=builder /tmp/stackrox-mcp /app/stackrox-mcp

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ image: ## Build the docker image
5757
.PHONY: dockerfile-lint
5858
dockerfile-lint: ## Run hadolint for Dockerfile
5959
$(DOCKER_CMD) run --rm -i --env HADOLINT_FAILURE_THRESHOLD=info ghcr.io/hadolint/hadolint < Dockerfile
60+
$(DOCKER_CMD) run --rm -i --env HADOLINT_FAILURE_THRESHOLD=info ghcr.io/hadolint/hadolint < konflux.Dockerfile
6061

6162
.PHONY: helm-lint
6263
helm-lint: ## Run helm lint for Helm chart

konflux.Dockerfile

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ COPY . .
2323
# Build the binary with optimizations
2424
# Output to "/tmp" directory, because user can not copy built binary to "/workspace"
2525
# Go build uses "venodr" mode and that fails, that's why explicit "-mod=mod" is set.
26-
RUN RACE=0 CGO_ENABLED=0 GOOS=$(go env GOOS) GOARCH=$(go env GOARCH) \
26+
RUN RACE=0 GOOS=$(go env GOOS) GOARCH=$(go env GOARCH) \
2727
go build \
2828
-mod=mod \
2929
-ldflags="-w -s \
@@ -34,18 +34,43 @@ RUN RACE=0 CGO_ENABLED=0 GOOS=$(go env GOOS) GOARCH=$(go env GOARCH) \
3434
-o /tmp/stackrox-mcp \
3535
./cmd/stackrox-mcp
3636

37-
# Stage 2: Runtime - Minimal runtime image
38-
FROM registry.access.redhat.com/ubi9/ubi-micro@sha256:093a704be0eaef9bb52d9bc0219c67ee9db13c2e797da400ddb5d5ae6849fa10
37+
38+
# Stage 2: Runtime base - used to preserve rpmdb when installing packages
39+
FROM registry.access.redhat.com/ubi9/ubi-micro:latest@sha256:093a704be0eaef9bb52d9bc0219c67ee9db13c2e797da400ddb5d5ae6849fa10 AS ubi-micro-base
40+
41+
42+
# Stage 3: Package installer - installs ca-certificates and openssl into /ubi-micro-base-root/
43+
FROM registry.access.redhat.com/ubi9/ubi:latest@sha256:05fa0100593c08b5e9dde684cd3eaa94b4d5d7b3cc09944f1f73924e49fde036 AS package_installer
44+
45+
# Copy ubi-micro base to /ubi-micro-base-root/ to preserve its rpmdb
46+
COPY --from=ubi-micro-base / /ubi-micro-base-root/
47+
48+
# Install packages directly to /ubi-micro-base-root/ using --installroot
49+
# Note: --setopt=reposdir=/etc/yum.repos.d instructs dnf to use repo configurations pointing to RPMs
50+
# prefetched by Hermeto/Cachi2, instead of installroot's default UBI repos.
51+
# hadolint ignore=DL3041 # We are installing ca-certificates and openssl only to include trusted certs.
52+
RUN dnf install -y \
53+
--installroot=/ubi-micro-base-root/ \
54+
--releasever=9 \
55+
--setopt=install_weak_deps=False \
56+
--setopt=reposdir=/etc/yum.repos.d \
57+
--nodocs \
58+
ca-certificates \
59+
openssl && \
60+
dnf clean all --installroot=/ubi-micro-base-root/ && \
61+
rm -rf /ubi-micro-base-root/var/cache/*
62+
63+
64+
# Stage 4: Runtime - Minimal runtime image
65+
FROM ubi-micro-base
3966

4067
# Set default environment variables
4168
ENV LOG_LEVEL=INFO
4269

4370
# Set working directory
4471
WORKDIR /app
4572

46-
# Copy trusted certificates from builder
47-
COPY --from=builder /etc/pki/ca-trust/extracted/ /etc/pki/ca-trust/extracted/
48-
COPY --from=builder /etc/ssl/certs/ /etc/ssl/certs/
73+
COPY --from=package_installer /ubi-micro-base-root/ /
4974

5075
# Copy binary from builder
5176
COPY --from=builder /tmp/stackrox-mcp /app/stackrox-mcp

0 commit comments

Comments
 (0)