Harden toolkit-plus-feeds per Red Hat container best practices; fix root-owned HOME (#58) #61
<h3>Code Review by Qodo</h3>
<code>🐞 Bugs (1)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<br/>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
<details>
<summary> 1. <s>Docker runs cannot create journals</s> <code>✓ Resolved</code></summary>
<br/>
<p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-cli/commit/8298fa5926b05a9772fdd5528ab5963b036e97eb"><code>8298fa5</code></a></p>
<details>
><summary>Resolution reason</summary>
><br/>
><pre>
>The commit adds <b><i>mkdir -p /opt/traust/.traust/cli/runs</i></b> in the Containerfile's pre-copy RUN step
>(before the VOLUME declaration), with the directory delivered as 1001:0 and group-writable via the
>existing <b><i>chmod -R g=u</i></b> and <b><i>COPY --chown=1001:0</i></b>. This is the suggested fix: the runs directory now
>exists in the image before VOLUME is declared, so Docker inherits the writable ownership. The
>CHANGELOG and docs were updated to explain it. The regression-check part of the suggestion is not
>present in this diff.
></pre>
></details>
<!-- qodo-finding-reference
<code>↗ Containerfile.toolkit-plus-feeds[R241]</code>
-->
<details>
><summary>Description</summary>
><br/>
><pre>
>The new <b><i>VOLUME</i></b> targets a runs directory that image assembly never creates, so Docker creates an
>empty root-owned mount rather than inheriting the workspace's writable ownership. On the first
><b><i>run</i></b>, <b><i>NewJournal</i></b> attempts to create a child directory as UID 1001 and fails before the harness
>launches.
></pre>
></details>
<hr/>
</details>
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 2. Read-only audits cannot write reports <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
<details open>
><summary>Description</summary>
><br/>
><pre>
>The read-only setup mounts only the journal directory and <b><i>/tmp</i></b>, while the runner launches the
>harness in the unmounted repository directory and expects standalone audit reports there. With
><b><i>SKIP_FEED_UPDATE=1</i></b> and <b><i>--read-only</i></b>, an audit cannot write its normal JSON artifact there, and
>rendering a report at that location also cannot write its Markdown companion.
></pre>
></details>
<details>
><summary>Code</summary>
><br/>
><code>[docs/konflux.md[R273-275]](https://github.com/traust-security/traust-cli/pull/61/files#diff-1649768c4aaeb76274eee18782e031eba7d4ced4f9761ad5da9c97f5ce352dbaR273-R275)</code>
>>+identity, so host-owned bind mounts stay group-accessible. Read-only runs >+write only to the declared volumes — everything under `/opt/traust` >+(including the feed refresh) must be skipped or provided via mounts. >
></details>
<details>
><summary>Evidence</summary>
><br/>
><pre>
>The new documentation promises that read-only runs write only to the declared volumes. The runner
>instead sets the harness working directory to the repository, the artifact-discovery convention
>expects standalone reports in that directory, and rendering writes Markdown beside each report; none
>of those paths is covered by the new mounts.
></pre>
> <code>[Containerfile.toolkit-plus-feeds\[235-241\]](https://github.com/traust-security/traust-cli/blob/8298fa5926b05a9772fdd5528ab5963b036e97eb/Containerfile.toolkit-plus-feeds/#L235-L241)</code>
<code>[docs/konflux.md\[264-275\]](https://github.com/traust-security/traust-cli/blob/8298fa5926b05a9772fdd5528ab5963b036e97eb/docs/konflux.md/#L264-L275)</code>
<code>[internal/runner/runner.go\[214-225\]](https://github.com/traust-security/traust-cli/blob/8298fa5926b05a9772fdd5528ab5963b036e97eb/internal/runner/runner.go/#L214-L225)</code>
<code>[internal/runner/postrun.go\[88-101\]](https://github.com/traust-security/traust-cli/blob/8298fa5926b05a9772fdd5528ab5963b036e97eb/internal/runner/postrun.go/#L88-L101)</code>
<code>[internal/runner/postrun.go\[301-318\]](https://github.com/traust-security/traust-cli/blob/8298fa5926b05a9772fdd5528ab5963b036e97eb/internal/runner/postrun.go/#L301-L318)</code>
></details>
<details>
><summary>Agent prompt</summary>
><br/>
>>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >## Issue description >Skipping the feed refresh and mounting journals and `/tmp` does not make a normal audit usable with a read-only root filesystem: the harness and report renderer also write beneath the baked repository. > >## Fix Focus Areas >- Containerfile.toolkit-plus-feeds[235-241] >- docs/konflux.md[264-275] >- internal/runner/runner.go[214-225] >- internal/runner/postrun.go[88-101] > >## Recommended Fix >Give audit outputs a writable location in read-only runs, including the harness's standalone output convention and rendered companions, or explicitly narrow the documented read-only support to commands that do not produce those artifacts. Verify the chosen behavior with an actual `secure-code-audit` container run under `--read-only`. >
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-self-review-slot -->
<!-- qodo-context:start -->
<details><summary><strong>Context sources</strong></summary>
<div>✅ Linked PRs:</div>
<div> <code>🌐 PR #59</code></div>
<div>❌ Tickets: failed to load — Ticket collection could not establish complete evidence</div>
<div>Review mode: <code>Auto: ⚖️ Balanced</code>: Container runtime and filesystem behavior changes carry genuine configuration risk.</div>
<div>✅ Fix-loop round: <code>fix loop</code></div>
<!-- qodo-context:end -->
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:start -->
<details>
<summary><strong>Tip of the day</strong></summary>
<br/>
<pre>💡 Did you know, you can open the rule or relationship behind a finding in one click</pre>
<a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:end -->
<!-- https://github.com/traust-security/traust-cli/commit/8298fa5926b05a9772fdd5528ab5963b036e97eb -->
<!-- qodo-previous-reviews:start -->
<!-- FOLDED_SECTION_START -->
<details>
<summary><strong>Previous reviews</strong></summary>
<br/>
Review updated until commit <a href="https://github.com/traust-security/traust-cli/commit/8298fa5926b05a9772fdd5528ab5963b036e97eb">8298fa5</a>
<details><summary>Results up to commit 124c26b <code>⚖️ Balanced</code></summary>
<br><code>🐞 Bugs (1)</code> <code>📘 Rule violations (0)</code> <code>📎 Requirement gaps (0)</code> <code>🎨 UX issues (0)</code> <code>🔗 Cross-repo conflicts (0)</code> <code>📜 Skill insights (0)</code>
<br/>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
<details>
<summary> 1. <s>Docker runs cannot create journals</s> <code>✓ Resolved</code></summary>
<br/>
<p><b>Resolving commit:</b> <a href="https://github.com/traust-security/traust-cli/commit/8298fa5926b05a9772fdd5528ab5963b036e97eb"><code>8298fa5</code></a></p>
<details>
><summary>Resolution reason</summary>
><br/>
><pre>
>The commit adds <b><i>mkdir -p /opt/traust/.traust/cli/runs</i></b> in the Containerfile's pre-copy RUN step
>(before the VOLUME declaration), with the directory delivered as 1001:0 and group-writable via the
>existing <b><i>chmod -R g=u</i></b> and <b><i>COPY --chown=1001:0</i></b>. This is the suggested fix: the runs directory now
>exists in the image before VOLUME is declared, so Docker inherits the writable ownership. The
>CHANGELOG and docs were updated to explain it. The regression-check part of the suggestion is not
>present in this diff.
></pre>
></details>
<!-- qodo-finding-reference
<code>↗ Containerfile.toolkit-plus-feeds[R241]</code>
-->
<details>
><summary>Description</summary>
><br/>
><pre>
>The new <b><i>VOLUME</i></b> targets a runs directory that image assembly never creates, so Docker creates an
>empty root-owned mount rather than inheriting the workspace's writable ownership. On the first
><b><i>run</i></b>, <b><i>NewJournal</i></b> attempts to create a child directory as UID 1001 and fails before the harness
>launches.
></pre>
></details>
<hr/>
</details>
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 2. Read-only audits cannot write reports <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
<details open>
><summary>Description</summary>
><br/>
><pre>
>The read-only setup mounts only the journal directory and <b><i>/tmp</i></b>, while the runner launches the
>harness in the unmounted repository directory and expects standalone audit reports there. With
><b><i>SKIP_FEED_UPDATE=1</i></b> and <b><i>--read-only</i></b>, an audit cannot write its normal JSON artifact there, and
>rendering a report at that location also cannot write its Markdown companion.
></pre>
></details>
<details>
><summary>Code</summary>
><br/>
><code>[docs/konflux.md[R273-275]](https://github.com/traust-security/traust-cli/pull/61/files#diff-1649768c4aaeb76274eee18782e031eba7d4ced4f9761ad5da9c97f5ce352dbaR273-R275)</code>
>>+identity, so host-owned bind mounts stay group-accessible. Read-only runs >+write only to the declared volumes — everything under `/opt/traust` >+(including the feed refresh) must be skipped or provided via mounts. >
></details>
<details>
><summary>Evidence</summary>
><br/>
><pre>
>The new documentation promises that read-only runs write only to the declared volumes. The runner
>instead sets the harness working directory to the repository, the artifact-discovery convention
>expects standalone reports in that directory, and rendering writes Markdown beside each report; none
>of those paths is covered by the new mounts.
></pre>
> <code>[Containerfile.toolkit-plus-feeds\[235-241\]](https://github.com/traust-security/traust-cli/blob/8298fa5926b05a9772fdd5528ab5963b036e97eb/Containerfile.toolkit-plus-feeds/#L235-L241)</code>
<code>[docs/konflux.md\[264-275\]](https://github.com/traust-security/traust-cli/blob/8298fa5926b05a9772fdd5528ab5963b036e97eb/docs/konflux.md/#L264-L275)</code>
<code>[internal/runner/runner.go\[214-225\]](https://github.com/traust-security/traust-cli/blob/8298fa5926b05a9772fdd5528ab5963b036e97eb/internal/runner/runner.go/#L214-L225)</code>
<code>[internal/runner/postrun.go\[88-101\]](https://github.com/traust-security/traust-cli/blob/8298fa5926b05a9772fdd5528ab5963b036e97eb/internal/runner/postrun.go/#L88-L101)</code>
<code>[internal/runner/postrun.go\[301-318\]](https://github.com/traust-security/traust-cli/blob/8298fa5926b05a9772fdd5528ab5963b036e97eb/internal/runner/postrun.go/#L301-L318)</code>
></details>
<details>
><summary>Agent prompt</summary>
><br/>
>>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution > >## Issue description >Skipping the feed refresh and mounting journals and `/tmp` does not make a normal audit usable with a read-only root filesystem: the harness and report renderer also write beneath the baked repository. > >## Fix Focus Areas >- Containerfile.toolkit-plus-feeds[235-241] >- docs/konflux.md[264-275] >- internal/runner/runner.go[214-225] >- internal/runner/postrun.go[88-101] > >## Recommended Fix >Give audit outputs a writable location in read-only runs, including the harness's standalone output convention and rendered companions, or explicitly narrow the documented read-only support to commands that do not produce those artifacts. Verify the chosen behavior with an actual `secure-code-audit` container run under `--read-only`. >
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<!-- qodo-self-review-slot -->
</details>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-previous-reviews:end -->
<a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>
Both Qodo findings are addressed in 8298fa5 — both were valid, thank you.
1. "Docker runs cannot create journals" (High) — confirmed: bootstrap creates the workspace, bin and state dirs but never cli/runs, and NewJournal relies on MkdirAll at runtime. Rootless podman masked this because it chowns anonymous volumes to the container user; Docker (and rootful podman) create a missing mountpoint root-owned. Fix: the assemble stage now pre-creates /opt/traust/.traust/cli/runs before the chmod -R g=u, so the existing COPY --chown=1001:0 delivers it with no extra final-stage layer. Verified in the saved layer tar (drwxrwxr-x 1001/0 opt/traust/.traust/cli/runs/) and at runtime: journal-style MkdirAll + write succeeds as uid 1001 by default, and as uid 1234:0 under --read-only --network=none.
2. "Read-only audits cannot write reports" (Medium) — confirmed and fixed by narrowing the claim rather than the code: the harness runs with Cwd = state.TraustRepo() (the baked checkout), standalone reports are discovered there and rendered beside their source, and agent harnesses keep state under $HOME — so a full run genuinely needs the writable image layer. The docs and the Containerfile VOLUME comment now say read-only rootfs (with SKIP_FEED_UPDATE=1) suits read-only commands (--version, skills, doctor) only. Moving audit outputs to a writable location in read-only runs would be an upstream runner design change, out of scope for an image-hardening PR — happy to file an issue for it if wanted.
---
🤖 This comment was drafted with AI assistance (GLM-5.3).
Code review by qodo was updated up to the latest commit https://github.com/traust-security/traust-cli/commit/8298fa5926b05a9772fdd5528ab5963b036e97eb
Follow-up on the updated Qodo review (up to 8298fa5):
Finding 1 is marked resolved — thanks. Noted caveat accepted: the regression check was performed manually (saved-layer tar shows drwxrwxr-x 1001/0 opt/traust/.traust/cli/runs/; journal-style MkdirAll + write verified as uid 1001 and as uid 1234:0 under --read-only), since the repo has no container test infrastructure. A documented smoke line wouldn't catch the Docker-specific failure anyway — rootless podman chowns anonymous volumes, so it passes there regardless.
Finding 2 remains open, but its code excerpt is stale: it quotes the pre-8298fa5 text ("Read-only runs write only to the declared volumes…", the 124c26b diff hunk at docs/konflux.md R273-275). The current head narrows exactly that claim: read-only rootfs (with SKIP_FEED_UPDATE=1) suits read-only commands (--version, skills, doctor) only, and a full run needs the writable layer. That is option (b) of the finding's own recommended fix ("explicitly narrow the documented read-only support to commands that do not produce those artifacts"), implemented in both docs/konflux.md and the Containerfile VOLUME comment.
The underlying behavior is real and intentionally not changed here: the harness runs with Cwd = state.TraustRepo() (the baked checkout) and reports are rendered beside their sources, so making audits read-only-capable means giving the runner a configurable writable output location — an upstream runner design change, out of scope for an image-hardening PR. The requested verification ("an actual secure-code-audit run under --read-only") also can't be performed without live harness credentials; the write paths are established from the code instead. Happy to file the upstream issue for read-only-capable audit outputs if maintainers want one.
---
🤖 This comment was drafted with AI assistance (GLM-5.3).
/lgtm
/approve
gurnben
pshickeydev
Fixes #58
Supersedes #59 — it includes that PR's commit verbatim (cherry-picked, @dmaniloff's authorship and sign-off preserved) and additionally closes the
.npmresidual that PR deliberately left open.Summary
Three commits:
1. Harden the image per Red Hat's container-image guidance (OCP "Creating images" guidelines, Red Hat Container Certification best practices):
-
dnf update-minimal --security --sec-severity=Important --sec-severity=Criticalin the published stage — the base image is digest-pinned, so errata newer than that release would otherwise never reach the image.-
VOLUME ["/opt/traust/.traust/cli/runs", "/tmp"]— run journals persist across containers and/tmpstays writable underpodman run --read-only(pair withSKIP_FEED_UPDATE=1).- The entrypoint now relays SIGTERM/SIGINT to the feed refresh (bash as PID 1 does not forward signals) and exits 143 instead of falling through to
execthe workload being stopped;podman stopreturns in ~0.2s instead of waiting outFEED_UPDATE_TIMEOUTand SIGKILLing.2.
5392234(from #59):RUN mkdir -p "${HOME}" && chown 1001:0 "${HOME}" && chmod g=u "${HOME}"before the workspaceCOPY—COPYmerges directory contents without fixing a pre-existing directory's ownership, and the build-timenpm install -g(as root,HOME=/opt/traust) had created/opt/traustasroot:root 0755, so the runtime user could not write its own home (opengrep's~/.opengrepfailed every invocation).3. Keep npm's build-time cache out of
HOME:npm_config_cache=/tmp/npm-cachefor the install RUN, so no root-owned/opt/traust/.npmis created at all (the assemble stage already removes its own before the copy) — closing the residual called out in #59's review.Verification
On a locally rebuilt image (
SKIP_GRYPE_DB=1, defaultclaudeharness), rootless podman 5:--version,skills --jsonclean;doctor --jsonshows exactly the documented expected state (sole non-green: the deliberately unbaked estatecorpus-config.yaml, plus the intentionalfeeds.yamlair-gapped flip warning; all 7 toolchain scanners OK).podman run --rm --network=none … -c 'mkdir /opt/traust/.opengrep'as uid 1001 succeeds;/opt/traustis1001:0 drwxrwxr-x; no/opt/traust/.npmin the image.podman stopexits 0.2s / code 143, no exec fall-through.--version): default rootless,--user 1234:0(arbitrary uid, root group),--userns=keep-id(real and simulated uid), and--read-onlyall behave as documented indocs/konflux.md.Docs (
docs/konflux.md) and CHANGELOG updated alongside.---
🤖 This pull request description was drafted with AI assistance (GLM-5.3); the commits are GPG-signed and dmaniloff's commit from #59 is preserved verbatim.