Skip to content

Commit b7d6ac7

Browse files
committed
feat(build): embed auditable Rust dependency metadata
Signed-off-by: Adrien Langou <alangou@nvidia.com>
1 parent 701382d commit b7d6ac7

9 files changed

Lines changed: 128 additions & 4 deletions

File tree

‎.agents/skills/sbom/SKILL.md‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,37 @@ Generate CycloneDX SBOMs, resolve missing licenses, and export to CSV for compli
99

1010
## Overview
1111

12-
The OpenShell SBOM tooling produces CycloneDX JSON SBOMs using Syft, resolves missing or hash-based licenses by querying public registries (crates.io, npm, PyPI), and exports the results to CSV for stakeholder review.
12+
The OpenShell SBOM tooling produces source-tree CycloneDX JSON SBOMs using Syft, resolves missing or hash-based licenses by querying public registries (crates.io, npm, PyPI), and exports the results to CSV for stakeholder review.
1313

1414
SBOMs are **release artifacts only** -- they are generated on demand and not committed to the repository. Output lands in `deploy/sbom/output/` (gitignored).
1515

16+
Release Dev and Release Tag image builds separately embed cargo-auditable metadata in the staged gateway and supervisor binaries. This metadata describes the binary's Rust dependency graph and lets Syft discover Cargo packages from the binary itself. It is not a complete image SBOM and is not an OCI SBOM attestation; publishing such an attestation remains separate work.
17+
1618
## Prerequisites
1719

1820
- `mise install` has been run (installs Syft and other tools)
1921
- The repository is checked out at the root
2022

23+
## Inspecting an Auditable Image Binary
24+
25+
Opt into auditable metadata when staging a local image binary:
26+
27+
```bash
28+
OPENSHELL_AUDITABLE=1 PREBUILT_ARCH=amd64 \
29+
tasks/scripts/stage-prebuilt-binaries.sh gateway
30+
```
31+
32+
Scan the staged binary rather than the source tree:
33+
34+
```bash
35+
mise x -- syft \
36+
"file:deploy/docker/.build/prebuilt-binaries/amd64/openshell-gateway" \
37+
-o cyclonedx-json
38+
```
39+
40+
This output is limited to packages Syft discovers from that binary. Use
41+
`mise run sbom` for the broader source-tree license-compliance inventory.
42+
2143
## Workflow 1: Full SBOM Generation (One Command)
2244

2345
```bash

‎.github/workflows/docker-build.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ on:
3232
required: false
3333
type: string
3434
default: ""
35+
auditable:
36+
description: "Embed cargo-auditable dependency metadata in image binaries"
37+
required: false
38+
type: boolean
39+
default: false
3540
image-tag:
3641
description: "Image tag base to build/push (defaults to the GitHub SHA)"
3742
required: false
@@ -177,6 +182,7 @@ jobs:
177182
image-tag: ${{ needs.resolve.outputs.image_tag_base }}
178183
checkout-ref: ${{ inputs['checkout-ref'] }}
179184
features: ${{ needs.resolve.outputs.features }}
185+
auditable: ${{ inputs.auditable }}
180186
artifact-name: ${{ needs.resolve.outputs.artifact_prefix }}-linux-${{ matrix.arch }}
181187
secrets: inherit
182188

‎.github/workflows/release-dev.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ jobs:
5959
with:
6060
component: gateway
6161
cargo-version: ${{ needs.compute-versions.outputs.cargo_version }}
62+
auditable: true
6263

6364
build-supervisor:
6465
needs: [compute-versions]
6566
uses: ./.github/workflows/docker-build.yml
6667
with:
6768
component: supervisor
6869
cargo-version: ${{ needs.compute-versions.outputs.cargo_version }}
70+
auditable: true
6971

7072
e2e:
7173
needs: [build-gateway, build-supervisor]

‎.github/workflows/release-tag.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
cargo-version: ${{ needs.compute-versions.outputs.cargo_version }}
8282
image-tag: ${{ needs.compute-versions.outputs.source_sha }}
8383
checkout-ref: ${{ inputs.tag || github.ref }}
84+
auditable: true
8485

8586
build-supervisor:
8687
needs: [compute-versions]
@@ -90,6 +91,7 @@ jobs:
9091
cargo-version: ${{ needs.compute-versions.outputs.cargo_version }}
9192
image-tag: ${{ needs.compute-versions.outputs.source_sha }}
9293
checkout-ref: ${{ inputs.tag || github.ref }}
94+
auditable: true
9395

9496
e2e:
9597
needs: [compute-versions, build-gateway, build-supervisor]

‎.github/workflows/rust-native-build.yml‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ on:
4040
required: false
4141
type: string
4242
default: ""
43+
auditable:
44+
description: "Embed cargo-auditable dependency metadata in the binary"
45+
required: false
46+
type: boolean
47+
default: false
4348
retention-days:
4449
description: "Artifact retention period"
4550
required: false
@@ -265,6 +270,7 @@ jobs:
265270
mise x -- rustup target add "${{ steps.target.outputs.target }}"
266271
267272
cargo_cmd=(cargo build)
273+
cargo_env=()
268274
build_target="${{ steps.target.outputs.target }}"
269275
args=()
270276
@@ -278,6 +284,13 @@ jobs:
278284
# accepts -static for *-linux-gnu and links dynamically anyway.
279285
export RUSTFLAGS="${RUSTFLAGS:-} -C target-feature=+crt-static"
280286
fi
287+
if [[ "${{ inputs.auditable }}" == "true" ]]; then
288+
cargo_cmd=("${cargo_cmd[0]}" auditable "${cargo_cmd[@]:1}")
289+
# mise.toml injects RUSTC_WRAPPER=sccache. Unset it after mise has
290+
# constructed the environment so it cannot wrap cargo-auditable's
291+
# RUSTC_WORKSPACE_WRAPPER and misidentify that wrapper as rustc.
292+
cargo_env=(env -u RUSTC_WRAPPER)
293+
fi
281294
args+=(
282295
--release
283296
--target "$build_target"
@@ -290,7 +303,7 @@ jobs:
290303
if [[ -n "${{ steps.version.outputs.cargo_version }}" ]]; then
291304
export GIT_DIR=/nonexistent
292305
fi
293-
mise x -- "${cargo_cmd[@]}" "${args[@]}"
306+
mise x -- "${cargo_env[@]}" "${cargo_cmd[@]}" "${args[@]}"
294307
295308
- name: Verify packaged binary
296309
run: |
@@ -307,6 +320,22 @@ jobs:
307320
exit 1
308321
fi
309322
323+
- name: Verify auditable dependency metadata
324+
if: inputs.auditable
325+
run: |
326+
set -euo pipefail
327+
BIN="target/${{ steps.target.outputs.target }}/release/${{ steps.target.outputs.binary }}"
328+
cargo_packages="$(
329+
SYFT_CHECK_FOR_APP_UPDATE=false \
330+
mise x -- syft "file:$BIN" -o cyclonedx-json |
331+
jq '[.components[]? | select((.purl // "") | startswith("pkg:cargo/"))] | length'
332+
)"
333+
if [[ "$cargo_packages" -eq 0 ]]; then
334+
echo "Syft did not decode any Cargo packages from $BIN" >&2
335+
exit 1
336+
fi
337+
echo "auditable dependency metadata: $cargo_packages Cargo packages"
338+
310339
- name: Verify glibc symbol floor
311340
if: inputs.component == 'gateway'
312341
run: |

‎architecture/build.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,27 @@ step via the `rust-native-build.yml` workflow (per-architecture, per-component)
130130
and uploads the result as an artifact that the image build job downloads back
131131
into the staging directory before running Buildx.
132132

133+
Gateway and supervisor binaries staged into Release Dev and Release Tag images
134+
are compiled through `cargo auditable` (pinned in `mise.toml`), which embeds a
135+
`.dep-v0` section describing the Rust dependencies actually compiled into the
136+
binary. That section holds data rather than symbols, so it survives the
137+
workspace's `strip = true` release profile, and Syft can catalog the crates
138+
present in image binaries instead of inferring them from the source tree. This
139+
is a different artifact from the source SBOM produced by `syft dir:.` in
140+
`tasks/sbom.toml`, which describes the checkout, and from an OCI SBOM
141+
attestation, which remains out of scope.
142+
143+
Only release image builds are auditable. `docker-build.yml` and
144+
`rust-native-build.yml` take an `auditable` input that defaults to false, so PR
145+
and E2E image builds and standalone release artifacts remain non-auditable. The
146+
CI image gains the pinned `cargo-auditable` tool through `mise install --locked`
147+
but ships no auditable OpenShell binary of its own. Local staging opts in with
148+
`OPENSHELL_AUDITABLE=1`. sccache's `RUSTC_WRAPPER` is unset only around auditable
149+
builds, because it would otherwise wrap `cargo-auditable`'s workspace wrapper and
150+
be misidentified as `rustc`. Auditable builds are verified by scanning the built
151+
binary with Syft and requiring at least one decoded Cargo package; the check runs
152+
only for those builds.
153+
133154
Runtime layout:
134155

135156
- **Gateway**: `gcr.io/distroless/cc-debian13:nonroot` base, GNU-linked binary at

‎mise.lock‎

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎mise.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ k3d = { version = "5.8.3", os = ["macos"] }
4242
"github:EmbarkStudios/cargo-about" = { version = "0.8.4", version_prefix = "" }
4343
"github:EmbarkStudios/cargo-deny" = { version = "0.20.2", version_prefix = "" }
4444
zig = "0.14.1"
45+
"github:rust-secure-code/cargo-auditable" = "0.7.5"
4546
"github:rust-cross/cargo-zigbuild" = "0.22.3"
4647
"npm:markdownlint-cli2" = "0.22.0"
4748

‎tasks/scripts/stage-prebuilt-binaries.sh‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ build_component_for_arch() {
165165
local target
166166
local stage
167167
local features
168-
local cargo_subcommand
168+
local -a cargo_subcommand
169+
local -a cargo_env
169170
local build_target
170171
local current_host_os
171172
local current_host_arch
@@ -183,6 +184,7 @@ build_component_for_arch() {
183184
current_host_arch="$(host_arch)"
184185

185186
cargo_subcommand=(cargo build)
187+
cargo_env=()
186188
build_target="$target"
187189
build_rustflags="${RUSTFLAGS:-}"
188190

@@ -221,6 +223,13 @@ build_component_for_arch() {
221223
fi
222224
fi
223225

226+
if [[ "${OPENSHELL_AUDITABLE:-0}" == "1" ]]; then
227+
cargo_subcommand=("${cargo_subcommand[0]}" auditable "${cargo_subcommand[@]:1}")
228+
# mise.toml injects RUSTC_WRAPPER=sccache. Unset it after mise constructs
229+
# the environment so it cannot wrap cargo-auditable's workspace wrapper.
230+
cargo_env=(env -u RUSTC_WRAPPER)
231+
fi
232+
224233
echo "Building ${binary} for linux/${arch} (${build_target}, libc: ${target_libc})..."
225234
mise x -- rustup target add "$target" >/dev/null 2>&1 || true
226235

@@ -245,7 +254,7 @@ build_component_for_arch() {
245254
if [[ -n "$build_rustflags" ]]; then
246255
export RUSTFLAGS="$build_rustflags"
247256
fi
248-
CARGO_INCREMENTAL=0 mise x -- "${cargo_subcommand[@]}" "${args[@]}"
257+
CARGO_INCREMENTAL=0 mise x -- "${cargo_env[@]}" "${cargo_subcommand[@]}" "${args[@]}"
249258
)
250259

251260
binary_path="${ROOT}/target/${target}/release/${binary}"
@@ -269,6 +278,14 @@ if [[ "$#" -gt 0 ]]; then
269278
exit 1
270279
fi
271280

281+
case "${OPENSHELL_AUDITABLE:-0}" in
282+
0|1) ;;
283+
*)
284+
echo "unsupported OPENSHELL_AUDITABLE: ${OPENSHELL_AUDITABLE} (expected 0 or 1)" >&2
285+
exit 1
286+
;;
287+
esac
288+
272289
restore_cargo_toml=0
273290
trap restore_workspace_version EXIT
274291

0 commit comments

Comments
 (0)