fix(validate): render the sensitive-source scan from a clean copy

The scanner ran the five renderers inside the scanned checkout. The
desktop checkout holds eight .helm chart caches left on 2026-08-11
(ignored by git), and render-observability-core.sh refuses an existing
exact chart cache. The scan stopped with "renderer failed:
observability-core RC=23" before it checked any rendered Secret, on
main and on every branch.

In a git checkout the renderers now run from a private 0700 copy in
/tmp of the tracked and not-ignored files, minus files deleted from
the working tree (git ls-files, then tar). The copy is removed with
the other renderer temp paths. A tree that is not a git checkout, such
as the test fixtures, still renders in place.

Rejected: deleting the stale caches only. That fixes one host until a
cache is left again, and the scanner is not the place to delete files
in the tree it scans. The renderer's refusal of an existing cache
stays; it guards the chart digest checks.

Risk: an ignored file is not in the copy. No renderer reads one today
(no renderer references .env, local-recovery.env, .superpowers or
secrets/). If one ever does, its render fails closed rather than
scanning less.

Verification: on desktop, real renderers against a clone of main
205927f with the eight stale caches copied in. Before: phase1, phase2
and admin pass, then "renderer failed: observability-core RC=23".
With this branch: all five renderers pass, "PLATFORM RENDERED SECRET
SCAN PASS", the eight caches in the scanned clone are untouched and no
render copy is left in /tmp. The new test cases fail before this
change and pass after it.
This commit is contained in:
DongHyeonka
2026-11-12 08:36:38 +09:00
parent 149b885e35
commit 27eb8c1799
2 changed files with 104 additions and 5 deletions
@@ -967,6 +967,16 @@ label="$(basename -- "$0")"
handoff=no
[[ -z "$out" ]] || handoff=yes
printf '%s\n' "$label${component:+:$component}:handoff=$handoff" >>"$PLATFORM_SENSITIVE_SOURCE_RENDER_LOG"
root="$(cd -- "$(dirname -- "$0")/../.." && pwd -P)"
if [[ "${PLATFORM_SENSITIVE_SOURCE_FAKE_REJECT_CACHE:-0}" != 0 ]] && \
[[ -n "$(find "$root" -name .helm -type d -print -quit)" ]]; then
printf 'REJECT: exact chart cache already exists\n' >&2
exit 23
fi
if [[ -n "${PLATFORM_SENSITIVE_SOURCE_FAKE_REQUIRE_INPUT:-}" && \
! -f "$root/$PLATFORM_SENSITIVE_SOURCE_FAKE_REQUIRE_INPUT" ]]; then
exit 42
fi
emit_phase1_log() {
local publish=$1 name
@@ -1438,6 +1448,41 @@ for injected_renderer in \
fail "$injected_renderer unexpected stdout leaked content"
pass "$injected_renderer stdout is restricted to its bounded grammar"
done
# A git checkout renders from a private copy of its tracked and not-ignored files,
# so an ignored chart cache left in the checkout cannot stop the renderers (the
# real renderers refuse a pre-existing exact cache with RC=23).
command -v git >/dev/null 2>&1 || fail 'git is required for the clean render copy test'
printf '.helm/\n' >"$WORK/platform/.gitignore"
git -C "$WORK/platform" init -q
git -C "$WORK/platform" add -A
git -C "$WORK/platform" -c user.name=fixture -c user.email=fixture@example.invalid \
commit -q -m fixture
mkdir -p "$WORK/platform/services/observability/.helm/charts/stale-1.0.0"
printf 'untracked\n' >"$WORK/platform/services/observability/untracked-input.yaml"
: >"$WORK/renderer.log"
renderer_rc=0
renderer_output="$(PLATFORM_SENSITIVE_SOURCE_FAKE_REJECT_CACHE=1 \
PLATFORM_SENSITIVE_SOURCE_FAKE_REQUIRE_INPUT=services/observability/untracked-input.yaml \
scan_platform_renderer_secrets "$WORK/platform" 2>&1)" || renderer_rc=$?
(( renderer_rc == 0 )) || {
printf '%s\n' "$renderer_output" >&2
fail 'an ignored chart cache in a git checkout blocked the renderers'
}
[[ -d "$WORK/platform/services/observability/.helm/charts/stale-1.0.0" ]] || \
fail 'the renderer scan changed the ignored cache in the scanned checkout'
pass 'a git checkout renders from a clean copy, so an ignored chart cache cannot block it'
pass 'the clean render copy keeps untracked files that git does not ignore'
rm -f -- "$WORK/platform/services/observability/untracked-input.yaml"
rm -f -- "$WORK/platform/scripts/validate/render-phase2.sh"
renderer_rc=0
renderer_output="$(scan_platform_renderer_secrets "$WORK/platform" 2>&1)" || renderer_rc=$?
(( renderer_rc != 0 )) || fail 'a renderer deleted from the working tree was still run'
[[ "$renderer_output" == *'required renderer is unsafe: phase2'* ]] || {
printf '%s\n' "$renderer_output" >&2
fail 'a renderer deleted from the working tree did not fail at the renderer check'
}
pass 'the clean render copy leaves out files deleted from the working tree'
unset PLATFORM_SENSITIVE_SOURCE_RENDER_LOG
new_fixture