-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
94 lines (75 loc) · 3.37 KB
/
Copy pathDockerfile
File metadata and controls
94 lines (75 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# syntax=docker/dockerfile:1
################################################
# Stage 0: define build args
################################################
ARG USER_UID=65534
ARG USER_GID=65534
ARG USER_NAME=nobody
ARG BUILD_DATE="unknown"
ARG VERSION="dev"
###############################################
# Stage 1: build CA bundle from CCADB + user roots
###############################################
FROM alpine:3.20 AS builder
ARG USER_UID USER_GID USER_NAME
# Build arg to control the CCADB export URL without changing the Dockerfile
ARG CCADB_URL="https://ccadb.my.salesforce-sites.com/mozilla/IncludedRootsPEMTxt?TrustBitsInclude=Websites"
# Minimal tools needed by scripts
RUN apk add --no-cache curl openssl coreutils busybox
WORKDIR /work
# Copy scripts and optional user roots from repo
COPY roots.sh ./roots.sh
COPY user-roots/ ./user-roots/
# Output locations
ENV OUT_PEM=/work/out/ca-bundle.pem \
HASHED_DIR=/work/out/certs
# Run the consolidating script to produce the bundle
RUN mkdir -p /work/out \
&& set -eux; \
sh ./roots.sh \
--url "$CCADB_URL" \
--out "$OUT_PEM" \
--hashed-dir "$HASHED_DIR"; \
test -s "$OUT_PEM"; \
ls -l "$OUT_PEM"
# Prepare minimal passwd/group for the final image (cannot RUN in scratch)
# UID, GID, and USERNAME configurable via build args USER_UID, USER_GID, USER_NAME
RUN mkdir -p /work/system && \
echo "${USER_NAME}:x:${USER_UID}:${USER_GID}:${USER_NAME}:/:/bin/false" > /work/system/passwd && \
echo "${USER_NAME}:x:${USER_GID}:" > /work/system/group && \
mkdir -p /work/system/bin && \
echo '#!/bin/sh' > /work/system/bin/false && \
echo 'exit 1' >> /work/system/bin/false && \
chmod +x /work/system/bin/false
# Create /etc/os-release file for compatibility with security tools
RUN mkdir -p /work/os && \
printf 'NAME="substrate"\nID=substrate\nVERSION_ID="%s"\nPRETTY_NAME="Substrate Static Base"\n' "$VERSION" > /work/os/os-release
###############################################
# Stage 2: final minimal image
###############################################
FROM scratch
ARG BUILD_DATE VERSION
# OCI labels for provenance
LABEL org.opencontainers.image.source="https://github.com/haukened/substrate" \
org.opencontainers.image.authors="https://github.com/haukened" \
org.opencontainers.image.title="substrate" \
org.opencontainers.image.description="Minimal base with Mozilla CCADB website roots and non-root user." \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.created=$BUILD_DATE \
org.opencontainers.image.version=$VERSION
# Trust store
COPY --from=builder /work/out/ca-bundle.pem /etc/ssl/certs/ca-certificates.crt
# If you prefer the hashed directory, copy this instead:
# COPY --from=builder /work/out/certs/ /etc/ssl/certs/
# Minimal identity files for UID/GID mapping
COPY --from=builder /work/system/passwd /etc/passwd
COPY --from=builder /work/system/group /etc/group
COPY --from=builder /work/system/bin/false /bin/false
COPY --from=builder /work/os/os-release /etc/os-release
# UID and GID configurable via build args USER_UID and USER_GID
# Defaults defined once at the top; stages re-declare to use them
ARG USER_UID USER_GID
USER ${USER_UID}:${USER_GID}
# Provide a neutral default CMD; downstream images should override
# sharing the same command as the POSIX non-executable /bin/false reduces stuff in the image.
CMD ["/bin/false"]