Repository navigation
Expand file tree
/
Copy pathContainerfile.fips
More file actions
215 lines (182 loc) · 10.5 KB
/
Copy pathContainerfile.fips
File metadata and controls
215 lines (182 loc) · 10.5 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# syntax=docker/dockerfile:1
# ------------------------------------------------------------------------------
# FIPS build of praxis-ai on Red Hat Universal Base Image 9
# ------------------------------------------------------------------------------
#
# Four stages, all driven by the Makefile:
#
# toolchain Red Hat's Rust toolchain and OpenSSL, no sources; also the
# image `make test-fips-host` runs the suites in on a FIPS host
# (make fips-toolchain)
# builder builds the FIPS feature set of praxis-ai with that toolchain
# (make container-fips, make fips-check)
# report runs the crypto unit tests on the FIPS provider and
# `cargo fips-check report` on that binary, and keeps the
# results (make fips-check)
# runtime the shippable image on ubi9/ubi-minimal (make container-fips)
#
# The FIPS build differs from the published build only in its cargo features:
# it turns off what is known not to be FIPS compliant yet (the policy engine,
# SQLite, and other feature groups whose dependencies carry their own
# cryptography; see the Makefile's FIPS section). PostgreSQL storage uses the
# certificate-only SQLx profile.
# CARGO_FEATURES defaults to the Makefile's FIPS_FEATURES; keep the two in
# sync.
#
# 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="aws-sigv4-filter"
ARG CARGO_ARGS="--ignore-rust-version"
# ------------------------------------------------------------------------------
# Stage 1: Red Hat's toolchain and OpenSSL
# ------------------------------------------------------------------------------
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-ai-fips-registry,target=/cargo/registry \
cargo install cargo-auditable --version "${CARGO_AUDITABLE_VERSION}" --locked
# Keep this pin in sync with FIPS_CHECK_REV in the Makefile.
ARG CARGO_FIPS_CHECK_REV=a8dae23f90eb77e6890cc86df5ec6cf6da4e2e79
RUN --mount=type=cache,id=praxis-ai-fips-registry,target=/cargo/registry \
--mount=type=cache,id=praxis-ai-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 the report stage can run `cargo fips-check`. The legal files
# are for the runtime stage (Apache-2.0 section 4).
COPY Cargo.toml Cargo.lock fips-check.toml LICENSE NOTICE ./
COPY store store
COPY store-lifecycle store-lifecycle
COPY store-backends store-backends
COPY apis apis
COPY filters filters
COPY server server
COPY integrations integrations
COPY tests tests
COPY xtask xtask
COPY benchmarks benchmarks
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-ai-fips-registry,target=/cargo/registry \
--mount=type=cache,id=praxis-ai-fips-target,target=/src/target \
cargo clean --release -p praxis-ai-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-ai-proxy \
--no-default-features --features "${CARGO_FEATURES}" ${CARGO_ARGS} \
&& mkdir -p /fips \
&& cp target/release/praxis-ai /fips/praxis-ai
# ------------------------------------------------------------------------------
# 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.
FROM builder AS report
ARG CARGO_FEATURES
ARG CARGO_ARGS
# The digest and signing tests of the apis and filters crates (`hash::`,
# `aws::`), run on the FIPS provider that UBI ships: OPENSSL_CONF reaches the
# test binaries through cargo's runner (cargo's own libgit2 cannot run under
# it), and PRAXIS_TEST_FIPS_PROVIDER makes each test process assert that the
# provider reports FIPS and refuses MD5, so a run that never reached the
# provider fails. Release profile, to share the builder's compiled crates.
# The rest of the unit tests run in the standard CI (`make test-fips`).
RUN --mount=type=cache,id=praxis-ai-fips-registry,target=/cargo/registry \
--mount=type=cache,id=praxis-ai-fips-target,target=/src/target \
{ features="praxis-ai-proxy/$(printf '%s' "${CARGO_FEATURES}" | sed 's#,#,praxis-ai-proxy/#g')"; \
PRAXIS_TEST_FIPS_PROVIDER=1 cargo test --release --locked --lib \
-p praxis-ai-proxy -p praxis-ai-filters -p praxis-ai-apis \
--no-default-features --features "${features}" ${CARGO_ARGS} \
--config 'target."cfg(all())".runner=["env","OPENSSL_CONF=/src/xtask/assets/fips/fips-provider.cnf"]' \
-- hash:: aws:: > /fips/tests.txt 2>&1; \
echo $? > /fips/tests-status; } \
; true
RUN --mount=type=cache,id=praxis-ai-fips-registry,target=/cargo/registry \
cargo fips-check report /fips/praxis-ai --features "${CARGO_FEATURES}" --offline --out /fips/report.txt; \
status=$?; \
[ -s /fips/report.txt ] || exit 1; \
echo "$status" > /fips/status
CMD ["sh", "-c", "cat /fips/tests.txt /fips/report.txt; test \"$(cat /fips/tests-status)\" -eq 0 && exit $(cat /fips/status); echo 'crypto unit tests on the FIPS provider failed (see above)'; exit 1"]
# ------------------------------------------------------------------------------
# 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/ai" \
org.opencontainers.image.description="Praxis AI 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-ai binary and the legal files.
#
# 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
# Apache-2.0 (section 4) requires object-form recipients to receive the License
# and the applicable NOTICE attributions, as the standard image ships them. The
# root NOTICE references integrations/llmd/ext-proc/NOTICE relative to this
# directory, so preserve that subpath to keep the pointer resolvable.
COPY --from=builder --chown=root:root --chmod=0444 /src/LICENSE /usr/share/licenses/praxis-ai/LICENSE
COPY --from=builder --chown=root:root --chmod=0444 /src/NOTICE /usr/share/licenses/praxis-ai/NOTICE
COPY --from=builder --chown=root:root --chmod=0444 /src/integrations/llmd/ext-proc/NOTICE \
/usr/share/licenses/praxis-ai/integrations/llmd/ext-proc/NOTICE
COPY --from=builder --chown=root:root --chmod=0555 \
/fips/praxis-ai /usr/local/bin/praxis-ai
USER 1001:1001
WORKDIR /etc/praxis
# Port 8080: proxy listener, port 9901: admin API for the health check and
# metrics, both from the built-in default config, as in the standard image.
EXPOSE 8080 9901
HEALTHCHECK --interval=5s --timeout=3s --start-period=2s \
CMD curl -fsS http://127.0.0.1:9901/healthy || exit 1
ENTRYPOINT ["praxis-ai"]