|
| 1 | +# SPDX-FileCopyrightText: Sudo Apt Holdings LLC |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Slice 130: builds the hardened headless image from ci/ironbank/Dockerfile the way Iron Bank's |
| 5 | +# pipeline would (scripts/headless_image.sh stages every input from hardening_manifest.yaml and |
| 6 | +# checks its digest; the Dockerfile reaches no network), then checks the built image, never its |
| 7 | +# recipe (docs/regulated/headless-image.md): |
| 8 | +# |
| 9 | +# the submission tree and the published build's base pins mix trinity.ironbank.lint |
| 10 | +# the image starts its runtime bin/headless eval, then start |
| 11 | +# AC1 and AC6: user and layer contents mix trinity.image.inspect |
| 12 | +# AC3 and AC4: vulnerability scan against justifications grype, then mix trinity.image.findings |
| 13 | +# AC5: STIG applicability statement scripts/stig_scan.sh, then mix trinity.image.stig |
| 14 | +# |
| 15 | +# Every check after the build runs and reports even when an earlier one fails, so one red check |
| 16 | +# does not hide the others; the job fails if any did. It runs when an input of the image or of the |
| 17 | +# checks changes, on demand, and daily, because new advisories appear against an image that has |
| 18 | +# not changed (Iron Bank rescans its images on a schedule for the same reason). Nothing is pushed: |
| 19 | +# publishing and signing the image is slice 131's. |
| 20 | +name: headless-image |
| 21 | + |
| 22 | +on: |
| 23 | + push: |
| 24 | + paths: |
| 25 | + - ci/ironbank/** |
| 26 | + - ci/headless/** |
| 27 | + - scripts/headless_image.sh |
| 28 | + - scripts/stig_scan.sh |
| 29 | + - lib/mix/tasks/trinity.ironbank.lint.ex |
| 30 | + - lib/mix/tasks/trinity.image.*.ex |
| 31 | + - mix.exs |
| 32 | + - mix.lock |
| 33 | + - config/** |
| 34 | + - .tool-versions |
| 35 | + - ci/container.tool-versions |
| 36 | + - .github/workflows/headless-image.yml |
| 37 | + schedule: |
| 38 | + - cron: "17 6 * * *" |
| 39 | + workflow_dispatch: |
| 40 | + |
| 41 | +permissions: |
| 42 | + contents: read |
| 43 | + |
| 44 | +jobs: |
| 45 | + image: |
| 46 | + runs-on: ubuntu-latest |
| 47 | + # Not measured on a runner yet: OTP from source took 40 s and the dependency compile, EXLA's C++ |
| 48 | + # included, about 155 s on a 32-core machine (slice 130 NOTES). The ceiling is generous until the |
| 49 | + # first runs say otherwise. |
| 50 | + timeout-minutes: 120 |
| 51 | + env: |
| 52 | + IMAGE: trinity-headless:ci |
| 53 | + # grype v0.119.0, pinned by digest: a scanner is code that reads the image and runs in CI, and |
| 54 | + # a tag can be moved (slice 130 NOTES, D-130-6). |
| 55 | + GRYPE: anchore/grype:v0.119.0@sha256:8c2c9234a345577a6d321a4753aa3ee1276d8975c8452d2344a56b57733ecad3 |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 |
| 58 | + |
| 59 | + - uses: erlef/setup-beam@54075bcc5e249e4758d363f27d099f55d843f124 # v1.24.1 |
| 60 | + with: |
| 61 | + version-file: .tool-versions |
| 62 | + version-type: strict |
| 63 | + |
| 64 | + - uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0 |
| 65 | + with: |
| 66 | + path: | |
| 67 | + deps |
| 68 | + _build |
| 69 | + key: ${{ runner.os }}-mix-image-${{ hashFiles('mix.lock') }} |
| 70 | + restore-keys: ${{ runner.os }}-mix-image- |
| 71 | + |
| 72 | + - name: Compile the checks |
| 73 | + run: | |
| 74 | + mix deps.get |
| 75 | + mix compile |
| 76 | +
|
| 77 | + - name: The submission tree and the published build's base pins |
| 78 | + run: mix trinity.ironbank.lint |
| 79 | + |
| 80 | + - name: Build the image from staged, digest-checked resources |
| 81 | + id: build |
| 82 | + run: | |
| 83 | + scripts/headless_image.sh build "$IMAGE" |
| 84 | + docker image inspect "$IMAGE" --format 'id={{.Id}} size={{.Size}} user={{.Config.User}}' |
| 85 | + echo "digest=$(docker image inspect "$IMAGE" --format '{{.Id}}')" >> "$GITHUB_OUTPUT" |
| 86 | +
|
| 87 | + # `bin/headless version` exits 0 without starting the VM (slice 130 NOTES, measurement 1), so |
| 88 | + # this starts it: eval runs the runtime, and start must answer on its one port with a 401 for a |
| 89 | + # request without the bearer. |
| 90 | + - name: The image starts its runtime, read-only |
| 91 | + if: ${{ !cancelled() && steps.build.outcome == 'success' }} |
| 92 | + run: | |
| 93 | + docker run --rm --read-only --tmpfs /tmp "$IMAGE" /opt/trinity/bin/headless eval \ |
| 94 | + 'IO.puts("otp=#{System.otp_release()} fips_provider=#{inspect(:crypto.info()[:fips_provider_available])} node=#{inspect(Node.self())}")' |
| 95 | + cid=$(docker run -d --read-only --tmpfs /tmp --cap-drop ALL --security-opt no-new-privileges \ |
| 96 | + -p 127.0.0.1:4000:4000 -e TRINITY_MCP_SERVER_TOKEN=ci-token "$IMAGE") |
| 97 | + for _ in $(seq 1 60); do |
| 98 | + curl -s -o /dev/null http://127.0.0.1:4000/ && break |
| 99 | + sleep 1 |
| 100 | + done |
| 101 | + status=$(curl -s -o /dev/null -w '%{http_code}' -X POST http://127.0.0.1:4000/mcp \ |
| 102 | + -H 'content-type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"ping"}') |
| 103 | + docker logs "$cid" | tail -20 |
| 104 | + docker rm -f "$cid" >/dev/null |
| 105 | + echo "POST /mcp without a bearer: $status" |
| 106 | + test "$status" = 401 |
| 107 | +
|
| 108 | + - name: "AC1 and AC6: the image's user and its layers" |
| 109 | + if: ${{ !cancelled() && steps.build.outcome == 'success' }} |
| 110 | + run: mix trinity.image.inspect "$IMAGE" |
| 111 | + |
| 112 | + - name: "AC3: scan the image, with no network at scan time" |
| 113 | + id: scan |
| 114 | + if: ${{ !cancelled() && steps.build.outcome == 'success' }} |
| 115 | + run: | |
| 116 | + mkdir -p out/grype-db out/tmp |
| 117 | + docker save "$IMAGE" -o out/image.tar |
| 118 | + # TMPDIR on both runs: as a non-root user grype cannot write the image's /tmp, and the |
| 119 | + # update failed on its listing file without it (run 37764956008). |
| 120 | + docker run --rm --user "$(id -u):$(id -g)" -v "$PWD/out:/s" \ |
| 121 | + -e TMPDIR=/s/tmp -e GRYPE_DB_CACHE_DIR=/s/grype-db "$GRYPE" db update |
| 122 | + docker run --rm --network none --user "$(id -u):$(id -g)" -v "$PWD/out:/s" \ |
| 123 | + -e TMPDIR=/s/tmp -e GRYPE_DB_CACHE_DIR=/s/grype-db \ |
| 124 | + -e GRYPE_DB_AUTO_UPDATE=false -e GRYPE_CHECK_FOR_APP_UPDATE=false \ |
| 125 | + "$GRYPE" docker-archive:/s/image.tar -o json --file /s/grype.json |
| 126 | + rm -f out/image.tar |
| 127 | +
|
| 128 | + - name: "AC3 and AC4: findings against ci/headless/justifications.yaml" |
| 129 | + if: ${{ !cancelled() && steps.scan.outcome == 'success' }} |
| 130 | + run: mix trinity.image.findings --scan out/grype.json --out out/findings.csv |
| 131 | + |
| 132 | + - name: "AC5: the STIG applicability statement" |
| 133 | + if: ${{ !cancelled() && steps.build.outcome == 'success' }} |
| 134 | + run: | |
| 135 | + scripts/stig_scan.sh "$IMAGE" out/stig |
| 136 | + mix trinity.image.stig --results out/stig/stig-results.xml --out out/stig/stig-applicability.md \ |
| 137 | + --image "$IMAGE" --digest "${{ steps.build.outputs.digest }}" |
| 138 | +
|
| 139 | + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 140 | + if: ${{ !cancelled() }} |
| 141 | + with: |
| 142 | + name: headless-image-evidence |
| 143 | + path: | |
| 144 | + out/grype.json |
| 145 | + out/findings.csv |
| 146 | + out/stig/stig-results.xml |
| 147 | + out/stig/stig-report.html |
| 148 | + out/stig/stig-applicability.md |
| 149 | + if-no-files-found: warn |
0 commit comments