Skip to content

Commit 48c7757

Browse files
mo-automoabu
andauthored
ci(pentest): encrypt artifacts, keep findings out of logs (#15740)
* ci(pentest): encrypt artifacts, keep findings out of logs Artifacts and run logs of a public repo are readable by any signed-in user, so the confidential report, raw scanner output and target logs were effectively public. All are now age-encrypted to PENTEST_AGE_KEY (run fails closed without it) and ZAP/nuclei stdout goes into the encrypted archive. Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com> Signed-off-by: moauto <54212639+mo-auto@users.noreply.github.com> * docs: document pen-test artifact encryption Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com> Signed-off-by: moauto <54212639+mo-auto@users.noreply.github.com> * ci(pentest): harden sealing and report restore - fail on invalid age identity; write archive only on success - AIO startup output into encrypted target logs - seal raw output and target logs in separate steps; skip empties - per-backend download and staged decrypt; release fails on bad backend Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com> Signed-off-by: moauto <54212639+mo-auto@users.noreply.github.com> * docs: pen-test report download and age version Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com> Signed-off-by: moauto <54212639+mo-auto@users.noreply.github.com> * ci(pentest): check uploaded backends, strict recipients - expected backends come from the run's uploaded artifacts - failed download or missing archive counts as not restored - reject non-bare entries in PENTEST_AGE_RECIPIENTS Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com> Signed-off-by: moauto <54212639+mo-auto@users.noreply.github.com> * docs: download pen-test report into fresh dir Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com> Signed-off-by: moauto <54212639+mo-auto@users.noreply.github.com> --------- Signed-off-by: moauto <54212639+mo-auto@users.noreply.github.com> Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com>
1 parent 65e934a commit 48c7757

3 files changed

Lines changed: 240 additions & 32 deletions

File tree

‎.github/workflows/scan-pentest.yml‎

Lines changed: 128 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
# PGSQL) in parallel, uploading raw scanner output. The `report` job ingests every
88
# available source (code-scanning alerts, Dependabot, Trivy, SBOM), optionally
99
# forwards results to a pluggable analysis endpoint, and produces ONE consolidated
10-
# CONFIDENTIAL report (PDF/JSON/MD/SARIF) uploaded as a workflow artifact only —
11-
# never attached to the public release. It does not fail on findings, but a release
10+
# CONFIDENTIAL report (PDF/JSON/MD/SARIF), age-encrypted and uploaded as a workflow
11+
# artifact only — never attached to the public release. Artifacts and logs of a
12+
# public repo are readable by any signed-in user, so every artifact is encrypted to
13+
# PENTEST_AGE_KEY and scanner output stays out of the logs. It does not fail on findings, but a release
1214
# run HARD-FAILS if the required upstream release assets (SBOM/Trivy) never publish.
1315

1416
name: "Scan: Pen Test (DAST)"
@@ -61,6 +63,11 @@ jobs:
6163
with:
6264
persist-credentials: false
6365

66+
- name: Install age
67+
env:
68+
PENTEST_AGE_KEY: ${{ secrets.PENTEST_AGE_KEY }}
69+
run: bash .github/workflows/scripts/pentest_seal.sh install
70+
6471
- name: Map FQDN to localhost (traefik publishes :443 on the runner)
6572
run: echo "127.0.0.1 ${JANS_FQDN}" | sudo tee -a /etc/hosts > /dev/null
6673

@@ -83,8 +90,15 @@ jobs:
8390
echo "AIO_IMAGE_TAG=${TAG}" >> "$GITHUB_ENV"
8491
echo "resolved AIO_IMAGE_TAG=${TAG}"
8592
93+
# On failure the launcher dumps container logs; keep them in the encrypted
94+
# target-log archive instead of the public run log.
8695
- name: Bring up AIO target
87-
run: bash automation/ci/run_aio_for_tf.sh
96+
run: |
97+
mkdir -p aio-logs
98+
if ! bash automation/ci/run_aio_for_tf.sh > aio-logs/startup.log 2>&1; then
99+
echo "::error::AIO did not start; see aio-logs/startup.log in the encrypted pentest-aio-logs artifact"
100+
exit 1
101+
fi
88102
89103
- name: Discover endpoints
90104
env:
@@ -105,7 +119,7 @@ jobs:
105119
run: |
106120
timeout 1500 docker run --rm --network host --add-host "${JANS_FQDN}:127.0.0.1" -v "$PWD/dast:/zap/wrk:rw" \
107121
ghcr.io/zaproxy/zaproxy:stable@sha256:781a2bdaea47324e7bab583e2263f21d257b0aee61ed51521a5be45f5f5081ef \
108-
zap-baseline.py -t "$JANS_URL" -J zap.json -I || true
122+
zap-baseline.py -t "$JANS_URL" -J zap.json -I > dast/zap-baseline.log 2>&1 || true
109123
110124
- name: DAST — API scans (in-repo OpenAPI specs)
111125
timeout-minutes: 240
@@ -135,7 +149,7 @@ jobs:
135149
timeout 2400 docker run --rm --network host --add-host "${JANS_FQDN}:127.0.0.1" -v "$PWD/dast:/zap/wrk:rw" \
136150
ghcr.io/zaproxy/zaproxy:stable@sha256:781a2bdaea47324e7bab583e2263f21d257b0aee61ed51521a5be45f5f5081ef \
137151
zap-api-scan.py -t "/zap/wrk/spec-${i}-${name}" -f openapi \
138-
-O "$JANS_URL" -J "zap-api-${i}.json" -I \
152+
-O "$JANS_URL" -J "zap-api-${i}.json" -I > "dast/zap-api-${i}.log" 2>&1 \
139153
|| echo "api scan ended (timeout/non-zero) for ${s}; continuing"
140154
done
141155
@@ -159,30 +173,53 @@ jobs:
159173
projectdiscovery/nuclei@sha256:582d5546902e67052097cb2d07296c642d50a1afc5e44623cb038845df9a32eb \
160174
-t /nt -l /data/targets.txt -jsonl -o /data/nuclei.jsonl \
161175
-severity low,medium,high,critical \
162-
-timeout 10 -retries 1 -no-mhe -duc \
176+
-timeout 10 -retries 1 -no-mhe -duc > dast/nuclei.log 2>&1 \
163177
|| echo "nuclei ended (timeout or non-zero exit); using partial results"
164178
165-
- name: Upload raw scan output
166-
if: always()
167-
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
168-
with:
169-
name: pentest-raw-${{ matrix.persistence }}
170-
path: dast/
171-
retention-days: 7
172-
173179
- name: Collect target logs
174180
if: always()
175181
run: |
176182
mkdir -p aio-logs
177183
docker logs traefik > aio-logs/traefik.log 2>&1 || true
178184
docker ps -a > aio-logs/containers.txt 2>&1 || true
179185
186+
- name: Encrypt raw scan output
187+
if: always()
188+
env:
189+
PENTEST_AGE_KEY: ${{ secrets.PENTEST_AGE_KEY }}
190+
PENTEST_AGE_RECIPIENTS: ${{ vars.PENTEST_AGE_RECIPIENTS }}
191+
run: |
192+
mkdir -p sealed
193+
if [ ! -d dast ] || [ -z "$(ls -A dast)" ]; then
194+
echo "no scanner output for this backend; nothing to seal"; exit 0
195+
fi
196+
bash .github/workflows/scripts/pentest_seal.sh seal dast sealed/pentest-raw.tar.gz.age
197+
198+
- name: Encrypt target logs
199+
if: always()
200+
env:
201+
PENTEST_AGE_KEY: ${{ secrets.PENTEST_AGE_KEY }}
202+
PENTEST_AGE_RECIPIENTS: ${{ vars.PENTEST_AGE_RECIPIENTS }}
203+
run: |
204+
mkdir -p sealed
205+
bash .github/workflows/scripts/pentest_seal.sh seal aio-logs sealed/pentest-aio-logs.tar.gz.age
206+
207+
- name: Upload raw scan output
208+
if: always()
209+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
210+
with:
211+
name: pentest-raw-${{ matrix.persistence }}
212+
path: sealed/pentest-raw.tar.gz.age
213+
if-no-files-found: ignore
214+
retention-days: 7
215+
180216
- name: Upload target logs
181217
if: always()
182218
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
183219
with:
184220
name: pentest-aio-logs-${{ matrix.persistence }}
185-
path: aio-logs/
221+
path: sealed/pentest-aio-logs.tar.gz.age
222+
if-no-files-found: ignore
186223
retention-days: 7
187224

188225
report:
@@ -193,6 +230,7 @@ jobs:
193230
permissions:
194231
contents: read
195232
security-events: read # pentest_ingest_scans.py lists code-scanning alerts via github.token
233+
actions: read # list this run's artifacts to know which backends uploaded
196234
env:
197235
PENTEST_AI_ENDPOINT: ${{ secrets.PENTEST_AI_ENDPOINT }}
198236
PENTEST_AI_TOKEN: ${{ secrets.PENTEST_AI_TOKEN }}
@@ -209,11 +247,64 @@ jobs:
209247
with:
210248
persist-credentials: false
211249

212-
- name: Download raw scan output
250+
# One download per backend into a fixed dir, so a single surviving
251+
# backend still lands where the report expects it.
252+
- name: Download raw scan output (MYSQL)
253+
id: dl_MYSQL
254+
continue-on-error: true
255+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
256+
with:
257+
name: pentest-raw-MYSQL
258+
path: sealed-raw/MYSQL
259+
260+
- name: Download raw scan output (PGSQL)
261+
id: dl_PGSQL
262+
continue-on-error: true
213263
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
214264
with:
215-
pattern: pentest-raw-*
216-
path: raw
265+
name: pentest-raw-PGSQL
266+
path: sealed-raw/PGSQL
267+
268+
# Each backend is unsealed into a staging dir and moved into place only on
269+
# success, so the report never reads partial output. A release report must
270+
# be complete: an unreadable backend fails the run. A manual run is
271+
# best-effort and reports the remaining backends.
272+
- name: Decrypt raw scan output
273+
env:
274+
PENTEST_AGE_KEY: ${{ secrets.PENTEST_AGE_KEY }}
275+
RELEASE_TAG: ${{ inputs.release_tag }}
276+
GH_TOKEN: ${{ github.token }}
277+
DL_MYSQL: ${{ steps.dl_MYSQL.outcome }}
278+
DL_PGSQL: ${{ steps.dl_PGSQL.outcome }}
279+
run: |
280+
bash .github/workflows/scripts/pentest_seal.sh install
281+
mkdir -p raw
282+
# Expected = what the scan jobs actually uploaded (a backend with no
283+
# scanner output uploads nothing by design).
284+
uploaded="$(gh api --paginate "repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts" \
285+
--jq '.artifacts[].name')"
286+
failed=""
287+
for b in MYSQL PGSQL; do
288+
grep -qx "pentest-raw-${b}" <<< "$uploaded" || continue
289+
outcome_var="DL_${b}"
290+
f="sealed-raw/${b}/pentest-raw.tar.gz.age"
291+
if [ "${!outcome_var}" != "success" ] || [ ! -f "$f" ]; then
292+
failed="${failed:+$failed,}${b}"; continue
293+
fi
294+
stage="raw/.staging-${b}"
295+
if bash .github/workflows/scripts/pentest_seal.sh unseal "$f" "$stage"; then
296+
mv "$stage" "raw/pentest-raw-${b}"
297+
else
298+
rm -rf "$stage"
299+
failed="${failed:+$failed,}${b}"
300+
fi
301+
done
302+
if [ -n "$failed" ]; then
303+
if [ -n "$RELEASE_TAG" ]; then
304+
echo "::error::could not restore raw output for: ${failed}" >&2; exit 1
305+
fi
306+
echo "::warning::could not restore raw output for: ${failed}; reporting the rest"
307+
fi
217308
218309
- name: Wait for release scan assets
219310
# Release runs only: the SBOM (scan-sbom.yml) and Trivy report
@@ -345,19 +436,30 @@ jobs:
345436
jq -r '"Pen-test report: \(.total) finding(s) " + (.summary | tojson)' \
346437
pentest-report.json >> "$GITHUB_STEP_SUMMARY"
347438
348-
# Artifact only — the report is CONFIDENTIAL and must NOT be attached to the
349-
# public release. GitHub Actions artifacts are restricted to users with repo
350-
# access; that is the report's only distribution channel.
439+
# The report is CONFIDENTIAL: never attach it to the public release, and
440+
# encrypt it, since any signed-in user can download this repo's artifacts.
441+
- name: Encrypt report
442+
if: always()
443+
env:
444+
PENTEST_AGE_KEY: ${{ secrets.PENTEST_AGE_KEY }}
445+
PENTEST_AGE_RECIPIENTS: ${{ vars.PENTEST_AGE_RECIPIENTS }}
446+
run: |
447+
mkdir -p report
448+
for f in pentest-report.pdf pentest-report.json pentest-report.md pentest-report.sarif; do
449+
if [ -f "$f" ]; then cp "$f" report/; fi
450+
done
451+
if [ -z "$(ls -A report)" ]; then
452+
echo "no report generated; nothing to upload"; exit 0
453+
fi
454+
bash .github/workflows/scripts/pentest_seal.sh seal report pentest-report.tar.gz.age
455+
351456
- name: Upload report artifact
352457
if: always()
353458
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
354459
with:
355460
name: pentest-report
356-
path: |
357-
pentest-report.pdf
358-
pentest-report.json
359-
pentest-report.md
360-
pentest-report.sarif
461+
path: pentest-report.tar.gz.age
462+
if-no-files-found: ignore
361463
retention-days: 30
362464

363465
# Post the PDF + a link to this run to Zulip #bot_reporter under its own
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
# Encrypt pen-test outputs with age. Artifacts and run logs of a public repo
3+
# are readable by any signed-in GitHub user.
4+
#
5+
# pentest_seal.sh install install pinned age to /usr/local/bin
6+
# pentest_seal.sh seal DIR OUT tar DIR, encrypt to OUT
7+
# pentest_seal.sh unseal IN DIR decrypt IN, extract into DIR
8+
#
9+
# Env: PENTEST_AGE_KEY (secret, age identity), PENTEST_AGE_RECIPIENTS (optional
10+
# extra recipients, one per line; same kind as the key, PQ or classic).
11+
set -euo pipefail
12+
13+
AGE_VERSION=v1.3.2
14+
AGE_SHA256=cbe24006683f8eb669266162894b9a522a1af52f2665fbc63a4bb032ed26ac10
15+
16+
require_key() {
17+
if [ -z "${PENTEST_AGE_KEY:-}" ]; then
18+
echo "::error::PENTEST_AGE_KEY secret is not set; refusing to publish pen-test output unencrypted" >&2
19+
exit 1
20+
fi
21+
}
22+
23+
# Fails on a key that is not an age identity (e.g. only the public-key line),
24+
# so nothing is ever sealed to the extra recipients alone.
25+
primary_recipient() {
26+
require_key
27+
local r
28+
if ! r="$(printf '%s\n' "${PENTEST_AGE_KEY}" | age-keygen -y 2>/dev/null)" || [[ "${r}" != age1* ]]; then
29+
echo "::error::PENTEST_AGE_KEY is not a valid age identity" >&2
30+
exit 1
31+
fi
32+
echo "${r}"
33+
}
34+
35+
recipients() {
36+
local f r
37+
r="$(primary_recipient)" || exit 1
38+
f="$(mktemp)"
39+
echo "${r}" > "${f}"
40+
local n=0 line
41+
while IFS= read -r line; do
42+
n=$((n + 1))
43+
line="${line#"${line%%[![:space:]]*}"}"; line="${line%"${line##*[![:space:]]}"}"
44+
[ -z "${line}" ] && continue
45+
# Only bare recipients: a pasted "# public key: ..." line would silently drop a reader.
46+
if [[ ! "${line}" =~ ^age1[0-9a-z]+$ ]]; then
47+
echo "::error::PENTEST_AGE_RECIPIENTS line ${n} is not a bare age recipient" >&2
48+
rm -f "${f}"; exit 1
49+
fi
50+
echo "${line}" >> "${f}"
51+
done <<< "${PENTEST_AGE_RECIPIENTS:-}"
52+
echo "${f}"
53+
}
54+
55+
case "${1:-}" in
56+
install)
57+
tmp="$(mktemp -d)"
58+
curl -sSfL -o "${tmp}/age.tgz" \
59+
"https://github.com/FiloSottile/age/releases/download/${AGE_VERSION}/age-${AGE_VERSION}-linux-amd64.tar.gz"
60+
echo "${AGE_SHA256} ${tmp}/age.tgz" | sha256sum -c -
61+
sudo tar xzf "${tmp}/age.tgz" -C /usr/local/bin --strip-components=1 age/age age/age-keygen
62+
primary_recipient > /dev/null
63+
;;
64+
seal)
65+
r="$(recipients)" || exit 1
66+
# Publish OUT only once both tar and age succeeded.
67+
if tar czf - -C "$2" . | age -R "${r}" -o "$3.tmp"; then
68+
mv "$3.tmp" "$3"
69+
rm -f "${r}"
70+
else
71+
rm -f "$3.tmp" "${r}"
72+
exit 1
73+
fi
74+
;;
75+
unseal)
76+
require_key
77+
mkdir -p "$3"
78+
age -d -i <(printf '%s\n' "${PENTEST_AGE_KEY}") "$2" | tar xzf - -C "$3"
79+
;;
80+
*)
81+
sed -n '2,10p' "$0" >&2
82+
exit 2
83+
;;
84+
esac

‎docs/contribute/ci-cd/security-scanning.md‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ output, and where results land, then describes the pen-test that correlates them
1919
| Scorecard | `scan-scorecard.yml` | supply-chain posture | SARIF | code scanning + artifact + OpenSSF |
2020
| SBOM (Parlay + sbomqs) | `scan-sbom.yml` | dependency graph + compliance | signed JSON | release assets |
2121
| CBOM (cbomkit) | `scan-cbom.yml` | crypto algorithms, protocols, certs, keys | signed CycloneDX 1.6 JSON | release asset `jans-cbom.json`; image CBOM workflow artifact only |
22-
| Pen-test (DAST) | `scan-pentest.yml` | live endpoints | PDF/JSON/MD/SARIF | workflow artifact only — CONFIDENTIAL, not attached to the public release |
22+
| Pen-test (DAST) | `scan-pentest.yml` | live endpoints | PDF/JSON/MD/SARIF | age-encrypted workflow artifact only — CONFIDENTIAL, not attached to the public release |
2323

2424
## CBOM
2525

@@ -109,16 +109,20 @@ Flow:
109109
assessment-coverage table (findings per dimension), a findings register (with a
110110
Backend column), detailed write-ups with recommendations for medium+ findings,
111111
and appendices for run metadata and the SBOM component inventory. All formats
112-
are uploaded **only** as a workflow artifact (30-day retention) — the report is
113-
CONFIDENTIAL and is never attached to the public release; GitHub Actions
114-
artifacts restrict access to users with repository access. The PDF and a link to
115-
the run are also posted to Zulip (`#bot_reporter`, topic `pen-test`) when
116-
`ZULIP_API_KEY` is set.
112+
are uploaded **only** as an age-encrypted workflow artifact
113+
(`pentest-report.tar.gz.age`, 30-day retention) — the report is CONFIDENTIAL and
114+
is never attached to the public release. Artifacts and run logs of a public repo
115+
are readable by any signed-in GitHub user, so raw scanner output and target logs
116+
are encrypted too, and scanner stdout goes to files inside them, not the log. The
117+
PDF and a link to the run are also posted to Zulip (`#bot_reporter`, topic
118+
`pen-test`) when `ZULIP_API_KEY` is set.
117119

118120
### Configuration
119121

120122
| Secret / Var | Required | Use |
121123
|---|---|---|
124+
| `PENTEST_AGE_KEY` (secret) | **required** | age identity; artifacts are encrypted to its public key. Without it the run fails before scanning |
125+
| `PENTEST_AGE_RECIPIENTS` (var) | optional | extra age recipients, one per line; must be the same kind as the key (PQ or classic) |
122126
| `PENTEST_AI_ENDPOINT` (secret) | optional | Messages API URL, e.g. `https://api.anthropic.com/v1/messages`; step skipped if unset |
123127
| `PENTEST_AI_TOKEN` (secret) | optional | API key, sent as the `x-api-key` header |
124128
| `PENTEST_AI_MODEL` (var) | optional | model id (default `claude-opus-5`) |
@@ -130,3 +134,21 @@ ingested context as a single user message with a system prompt instructing the
130134
model to return `{ "findings": [...] }`, then parses `.content[0].text`. Set
131135
`PENTEST_AI_MODEL` / `PENTEST_AI_API_VERSION` repository variables to override the
132136
defaults.
137+
138+
To read a report, download it (`gh run download` unpacks the artifact ZIP; from
139+
the browser, unzip it first) and decrypt it with age 1.3.0 or later:
140+
141+
```bash
142+
mkdir "report-RUN_ID" && cd "report-RUN_ID" && \
143+
gh run download RUN_ID -R JanssenProject/jans -n pentest-report && \
144+
age -d -i ../key.txt pentest-report.tar.gz.age | tar xz
145+
```
146+
147+
Create the key with `age-keygen -pq -o key.txt` (post-quantum hybrid, also age
148+
1.3.0+; CI pins 1.3.2); store the whole file as `PENTEST_AGE_KEY` and keep a copy
149+
with the security team. AIO startup output goes to `startup.log` inside the
150+
encrypted `pentest-aio-logs-*` artifact, not the run log.
151+
152+
If a backend uploaded raw output that cannot be downloaded or decrypted, a
153+
release run fails; a manual run warns and reports the remaining backend. A
154+
backend with no scanner output uploads nothing and is not counted.

0 commit comments

Comments
 (0)