Repository navigation
Expand file tree
/
Copy pathContainerfile.fips
More file actions
188 lines (156 loc) · 8.84 KB
/
Copy pathContainerfile.fips
File metadata and controls
188 lines (156 loc) · 8.84 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# syntax=docker/dockerfile:1
# ------------------------------------------------------------------------------
# FIPS build of praxis on Red Hat Universal Base Image 9
# ------------------------------------------------------------------------------
#
# Four stages, all driven by the Makefile:
#
# toolchain Red Hat's own Rust toolchain and OpenSSL on ubi9/ubi, with
# cargo-auditable and cargo-fips-check, no sources; also the
# image the test suites run in on a FIPS host, against a
# bind-mounted checkout (make test-fips-host)
# builder builds the FIPS feature set of praxis in that toolchain
# (make container-fips, make fips-check)
# report runs `cargo fips-check report` on that binary and keeps the
# result (make fips-check)
# runtime the shippable image on ubi9/ubi-minimal (make container-fips)
#
# The FIPS build differs from the standard build only in its cargo features.
# The default leaves Policy out: its ordinary bundle carries its own
# cryptography, and only the profiles built on Policy's OpenSSL FIPS backend
# are FIPS candidates. CARGO_FEATURES defaults to the Makefile's
# FIPS_BASE_FEATURES (make fips-deps checks the two match); a Policy profile
# (make container-fips FIPS_POLICY_PROFILE=jwt) passes its own list as a
# build arg and is tagged apart from the published image.
#
# Both base images are pinned by digest and their Red Hat signatures are
# verified by `make fips-verify-image` before any build. Update the digests
# here and in the Makefile together, after `cargo fips-check verify-image`
# has accepted the new ones.
ARG UBI9_DIGEST=sha256:a4b9ec09b1e790a53ef25b7777c539976abe519248264298e5194dcbceac8c31
ARG UBI9_MINIMAL_DIGEST=sha256:8ebe2ad8fdf3cab3e5a53c1edc69194c98209cfadab24b884f4ad9ebcf7bbbfc
# Red Hat's rust-toolset may trail the workspace's rust-version; the build
# passes --ignore-rust-version so the toolchain Red Hat ships is what gets
# exercised. If the tree needs a newer compiler, this step is where it shows.
ARG CARGO_FEATURES="pingora,config-reload,admin-api"
ARG CARGO_ARGS="--ignore-rust-version"
# ------------------------------------------------------------------------------
# Stage 1: Red Hat's toolchain
# ------------------------------------------------------------------------------
FROM registry.access.redhat.com/ubi9/ubi@${UBI9_DIGEST} AS toolchain
# Everything comes from Red Hat's UBI repositories (GPG-checked by dnf):
# rust-toolset Red Hat's rustc and cargo
# openssl-devel headers so openssl-sys links the system libcrypto
RUN dnf install -y --setopt=install_weak_deps=False \
rust-toolset openssl-devel gcc gcc-c++ cmake make \
&& dnf clean all
# Never vendor OpenSSL; the system library is the validated module.
ENV OPENSSL_NO_VENDOR=1 \
CARGO_HOME=/cargo
# The build caches below carry explicit ids. Without them podman and BuildKit
# key a cache mount by its target path, so this file and Containerfile (which
# also builds under /src/target, with a different toolchain) would share one
# target directory, and a `cargo clean` here could delete the binary the other
# build is about to copy.
# cargo-auditable embeds the list of crates compiled into the binary, which is
# the manifest Red Hat's scanner reads to find pure-Rust cryptography that
# leaves no symbol. Not a Red Hat package: installed from crates.io at a pinned
# version (Rust Secure Code Working Group; see docs/developing/fips.md).
ARG CARGO_AUDITABLE_VERSION=0.7.6
RUN --mount=type=cache,id=praxis-fips-registry,target=/cargo/registry \
cargo install cargo-auditable --version "${CARGO_AUDITABLE_VERSION}" --locked
# cargo-fips-check writes the compliance report of the report stage. The same
# commit the Makefile installs on the host (FIPS_CHECK_REV; make fips-deps
# checks the two match), built here with Red Hat's toolchain. Installed under
# /usr/local so it is on PATH for whichever user runs the image.
ARG CARGO_FIPS_CHECK_REV=a8dae23f90eb77e6890cc86df5ec6cf6da4e2e79
RUN --mount=type=cache,id=praxis-fips-registry,target=/cargo/registry \
--mount=type=cache,id=praxis-fips-git,target=/cargo/git \
cargo install --locked --git https://github.com/praxis-proxy/cargo-fips-check \
--rev "${CARGO_FIPS_CHECK_REV}" --root /usr/local cargo-fips-check
WORKDIR /src
# ------------------------------------------------------------------------------
# Stage 2: build the FIPS feature set
# ------------------------------------------------------------------------------
FROM toolchain AS builder
# The whole workspace, so the build resolves the committed lockfile as is
# (--locked), and what `cargo fips-check report` reads in the report stage.
COPY Cargo.toml Cargo.lock fips-check.toml ./
COPY crates crates
COPY tests tests
COPY xtask xtask
COPY examples examples
ARG CARGO_FEATURES
ARG CARGO_ARGS
# The embedded manifest must list exactly the crates compiled in. On a stable
# toolchain cargo-auditable derives it from `cargo metadata`, which activates
# weak features the build never enables (rustls-webpki's `ring?/alloc` puts
# ring in the manifest of a binary that never compiled it) and unifies
# features across workspace members; the scanner fails on the name alone.
# Cargo's SBOM precursor is the exact list but unstable (-Zsbom):
# RUSTC_BOOTSTRAP=1 lets Red Hat's stable cargo accept the flag, and the env
# overrides hand rustc and every build script RUSTC_BOOTSTRAP=-1, which forbids
# unstable features, so the code compiled is the stable code. Drop this once
# cargo's `build.sbom` is stable (rust-lang/cargo#13709).
#
# cargo before 1.99 does not relink a binary when only the SBOM setting
# changed (rust-lang/cargo#15695, fixed by #17216), so the old binary in the
# cached target goes first. Drop the clean once rust-toolset is 1.99 or newer.
RUN --mount=type=cache,id=praxis-fips-registry,target=/cargo/registry \
--mount=type=cache,id=praxis-fips-target,target=/src/target \
cargo clean --locked --release -p praxis-proxy \
&& RUSTC_BOOTSTRAP=1 CARGO_BUILD_SBOM=true \
cargo auditable -Zsbom \
--config 'env.RUSTC_BOOTSTRAP.value="-1"' \
--config 'env.RUSTC_BOOTSTRAP.force=true' \
build --release --locked -p praxis-proxy \
--no-default-features --features "${CARGO_FEATURES}" ${CARGO_ARGS} \
&& mkdir -p /fips \
&& cp target/release/praxis /fips/praxis
# ------------------------------------------------------------------------------
# Stage 3: compliance report
# ------------------------------------------------------------------------------
# Only built when this stage is the target (make fips-check), so publishing
# the runtime image never runs it. The report runs at build time, while the
# cargo cache is mounted, so `cargo tree` can resolve the graph offline.
# The exit status is kept so the image can be run to print the report and
# fail accordingly. A run that wrote no report (a fetch failure) fails the
# build instead, so the failure is not cached and replayed.
FROM builder AS report
ARG CARGO_FEATURES
RUN --mount=type=cache,id=praxis-fips-registry,target=/cargo/registry \
cargo fips-check report /fips/praxis --features "${CARGO_FEATURES}" --offline --out /fips/report.txt; \
status=$?; \
[ -f /fips/report.txt ] || exit "$status"; \
echo "$status" > /fips/status
CMD ["sh", "-c", "cat /fips/report.txt; exit $(cat /fips/status)"]
# ------------------------------------------------------------------------------
# Stage 4: runtime
# ------------------------------------------------------------------------------
FROM registry.access.redhat.com/ubi9/ubi-minimal@${UBI9_MINIMAL_DIGEST} AS runtime
LABEL org.opencontainers.image.source="https://github.com/praxis-proxy/praxis" \
org.opencontainers.image.description="Praxis proxy server (FIPS build on UBI 9)" \
org.opencontainers.image.licenses="Apache-2.0"
# ubi9/ubi-minimal already ships what the binary needs at runtime, all from
# Red Hat: openssl-libs (libcrypto.so.3, libssl.so.3), the FIPS provider
# module (openssl-fips-provider-so), ca-certificates, and curl-minimal for the
# health check. Nothing is installed here, so the image stays exactly what
# Red Hat signed plus the praxis binary and its config.
#
# ubi-minimal has no useradd; add the unprivileged user directly.
RUN echo 'praxis:x:1001:1001:praxis:/nonexistent:/sbin/nologin' >> /etc/passwd \
&& echo 'praxis:x:1001:' >> /etc/group \
&& mkdir -p /etc/praxis
COPY --from=builder --chown=root:root --chmod=0555 \
/fips/praxis /usr/local/bin/praxis
COPY --chown=1001:1001 --chmod=0444 \
examples/configs/operations/container-default.yaml \
/etc/praxis/config.yaml
USER 1001:1001
WORKDIR /etc/praxis
# Port 8080: proxy listener (see container-default.yaml)
# Port 9902: health checks and metrics
EXPOSE 8080 9902
HEALTHCHECK --interval=5s --timeout=3s --start-period=2s \
CMD curl -fsS http://127.0.0.1:9902/healthy || exit 1
ENTRYPOINT ["praxis", "-c", "/etc/praxis/config.yaml"]