← Back to Pull requests

Harden toolkit-plus-feeds per Red Hat container best practices; fix root-owned HOME (#58) #61

Merged
pshickeydev merged 4 files (113 lines) on Nov 12, 2026 22:03 UTC
View on GitHub
pshickeydev pshickeydev commented on Nov 12, 2026 20:23 UTC
Author

Fixes #58
Supersedes #59 — it includes that PR's commit verbatim (cherry-picked, @dmaniloff's authorship and sign-off preserved) and additionally closes the .npm residual 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=Critical in 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 /tmp stays writable under podman run --read-only (pair with SKIP_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 exec the workload being stopped; podman stop returns in ~0.2s instead of waiting out FEED_UPDATE_TIMEOUT and SIGKILLing.
2. 5392234 (from #59): RUN mkdir -p "${HOME}" && chown 1001:0 "${HOME}" && chmod g=u "${HOME}" before the workspace COPY — COPY merges directory contents without fixing a pre-existing directory's ownership, and the build-time npm install -g (as root, HOME=/opt/traust) had created /opt/traust as root:root 0755, so the runtime user could not write its own home (opengrep's ~/.opengrep failed every invocation).
3. Keep npm's build-time cache out of HOME: npm_config_cache=/tmp/npm-cache for the install RUN, so no root-owned /opt/traust/.npm is 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, default claude harness), rootless podman 5:

  • --version, skills --json clean; doctor --json shows exactly the documented expected state (sole non-green: the deliberately unbaked estate corpus-config.yaml, plus the intentional feeds.yaml air-gapped flip warning; all 7 toolchain scanners OK).

  • Issue #58 repro passes: podman run --rm --network=none … -c 'mkdir /opt/traust/.opengrep' as uid 1001 succeeds; /opt/traust is 1001:0 drwxrwxr-x; no /opt/traust/.npm in the image.

  • Signal relay: detached container mid-refresh, podman stop exits 0.2s / code 143, no exec fall-through.

  • Write matrix probed with real writes (not just --version): default rootless, --user 1234:0 (arbitrary uid, root group), --userns=keep-id (real and simulated uid), and --read-only all behave as documented in docs/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.

    Diff: 113 lines (+99 / -14) across 4 files Reviewer: gurnben Review duration: 99m
    All Vouch review confidence checks passed
    Residual risk 0.03 = Change Risk (0.36) × (1 − Review Confidence (0.92)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.36 · 113 lines diff across 4 files
    0.36
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.95 · 4 substantive comment(s)
    0.95
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    91%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.283
    Real PR Conversation Timeline
    6 items
    qodo-code-review[bot] qodo-code-review[bot] commented on Nov 12, 2026 20:26 UTC
    Bot

    <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&#x27;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&#x27;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>

    Dismiss ↗ | View ↗

    <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>&#x2705; Linked PRs:</div>
    <div>&nbsp;&nbsp;<code>🌐 PR #59</code></div>
    <div>&#x274C; 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>&#x2705; 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&#x27;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&#x27;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>

    Dismiss ↗ | View ↗

    <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>

    pshickeydev pshickeydev commented on Nov 12, 2026 20:35 UTC
    Author

    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).

    qodo-code-review[bot] qodo-code-review[bot] commented on Nov 12, 2026 20:36 UTC
    Bot
    pshickeydev pshickeydev commented on Nov 12, 2026 21:05 UTC
    Author

    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).

    gurnben gurnben approved these changes on Nov 12, 2026 21:09 UTC
    Approved Reviewer

    /lgtm
    /approve

    Reviewers
    Assignees
    pshickeydev pshickeydev
    Labels
    risk: low confidence: 91.6% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 35.7% (MEDIUM) · Higher = larger blast radius
    35.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 91.6% · Lower = rushed or shallow review
    91.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 3% · Safe to merge
    3%