fix(validate): run the sensitive-source scan from any checkout #11

Merged
donghyeon.kang merged 3 commits from donghyeon.kang/w6-scanner-fix AGit into main 2026-11-11 23:46:20 +00:00
Owner

무엇을, 왜

scripts/validate/scan-platform-sensitive-source.sh가 main에서도 실패했다(W1 로그 SCANNER_ERROR: renderer failed: observability-core RC=23). 원인은 셋이다.

  1. 경로 고정. 스캐너가 늘 /home/donghyeon/workspace/platform을 검사했다. 임시 사본이나 runner에서 돌리면 자기 자신이 아니라 desktop checkout을 보거나 아무것도 못 봤다. 단위 시험도 정본 경로가 아니면 첫 검사에서 실패했다.
  2. 남은 차트 캐시. desktop 운영 checkout에 2026-08-11에 남은 .helm 캐시 8개가 있다(git이 무시하는 파일). 관측 core 렌더러는 이미 있는 캐시를 거부한다. 그래서 렌더 단계에서 RC=23으로 멈췄다.
  3. CNPG Secret 참조 오탐. 1·2가 풀리면 PR #10의 cluster-backup-patch.yaml과 restore-drill/cluster.yaml이 CREDENTIAL_LITERAL로 걸린다. s3Credentials.secretAccessKey: {name, key}는 Secret 참조인데 값으로 읽었다.

커밋 하나가 원인 하나를 고친다.

커밋 고치는 것
fix(validate): scan the checkout that holds the sensitive-source scanner 스캐너가 있는 checkout을 검사한다. --docs-root DIR, --platform-only
fix(validate): render the sensitive-source scan from a clean copy git checkout이면 추적·미추적(무시 제외) 파일만 임시 사본으로 옮겨 렌더한다
fix(validate): accept CloudNativePG s3Credentials Secret references s3Credentials 바로 아래 accessKeyId·secretAccessKey가 {name, key}뿐이면 참조로 본다

고른 방법과 버린 대안

  • --platform-root 옵션은 넣지 않았다. 다른 트리의 스캐너로 검사하면 검사 규칙과 검사 대상이 어긋날 수 있다.
  • 문서 루트가 없으면 조용히 덜 검사하지 않는다. exit 2로 멈추고 --docs-root·--platform-only를 알려 준다.
  • 캐시만 지우는 안은 버렸다. 그 호스트만 고치고, 캐시가 다시 남으면 또 막힌다. 렌더러의 「기존 캐시 거부」는 차트 digest 검사를 지키는 장치라 그대로 둔다.
    운영 checkout의 캐시는 따로 옮긴다(공유 노트 owner-sudo-bundle.md A-1, 총괄 몫).
  • 「name과 key만 있으면 언제나 참조」 같은 넓은 규칙은 버렸다. 다른 자격 증명 키 아래 숨긴 값도 통과시킨다. 부모가 s3Credentials이고 키 이름이 둘 중 하나일 때만 허용한다.

위험과 영향

  • desktop에서 인자 없이 돌리는 기본 동작은 같다(같은 두 루트를 검사한다).
  • 렌더 사본에는 git이 무시하는 파일이 없다. 지금 그런 파일을 읽는 렌더러는 없다. 생기면 그 렌더가 실패한다(덜 검사하지 않는다).
  • 스캐너 출력은 그대로 파일 이름과 발견 종류만 찍는다. 값은 찍지 않는다.

검증

모두 desktop에서, 운영 checkout이 아닌 main 205927f clone에서 했다.

  • 단위 시험 test-scan-platform-sensitive-source.sh: 커밋마다 통과(128 → 131 → 135개). 각 커밋의 새 시험은 그 전 커밋에서 실패했다.
    • 커밋 2 앞: FAIL: an ignored chart cache in a git checkout blocked the renderers
    • 커밋 3 앞: FAIL: a CloudNativePG s3Credentials Secret reference remains a reference
    • main 스캐너 + 정본이 아닌 경로: FAIL: canonical scanner test content leaf found a credential literal
  • 실제 렌더러(남은 캐시 8개를 clone에 복사):
    • main 스캐너: phase1·phase2·admin 통과 뒤 SCANNER_ERROR: renderer failed: observability-core RC=23(W1 오류 재현)
    • 이 브랜치, 인자 없이 전체 실행: 렌더러 다섯 개 PASS, PLATFORM RENDERED SECRET SCAN PASS, PLATFORM SENSITIVE SOURCE SCAN PASS, exit 0
    • 검사한 clone의 캐시 8개는 그대로, /tmp에 렌더 사본이 남지 않음
    • --docs-root relative → exit 2, --platform-only 원본 검사 통과
  • main 스캐너의 원본 검사(운영 checkout): 위 두 파일 CREDENTIAL_LITERAL. 이 PR 뒤 통과.

리뷰어가 볼 곳

  • scan_platform_renderer_secrets의 사본 만들기: git ls-files --cached --others --exclude-standard에서 --deleted를 뺀 목록, 사본 정리 trap.
  • permitted_s3_credentials_reference: 허용 범위가 좁은지.

관련 문서

  • 원인 기록과 소유자 단계: 공유 노트 k3s-maturity-review.md, owner-sudo-bundle.md(A-1 캐시 옮기기). 검증 로그: 공유 노트 k3s-w6-scanner-fix-verify.log.
  • 같은 캐시 문제를 drift 검사에서 고친 PR #9.
## 무엇을, 왜 `scripts/validate/scan-platform-sensitive-source.sh`가 main에서도 실패했다(W1 로그 `SCANNER_ERROR: renderer failed: observability-core RC=23`). 원인은 셋이다. 1. **경로 고정.** 스캐너가 늘 `/home/donghyeon/workspace/platform`을 검사했다. 임시 사본이나 runner에서 돌리면 자기 자신이 아니라 desktop checkout을 보거나 아무것도 못 봤다. 단위 시험도 정본 경로가 아니면 첫 검사에서 실패했다. 2. **남은 차트 캐시.** desktop 운영 checkout에 2026-08-11에 남은 `.helm` 캐시 8개가 있다(git이 무시하는 파일). 관측 core 렌더러는 이미 있는 캐시를 거부한다. 그래서 렌더 단계에서 RC=23으로 멈췄다. 3. **CNPG Secret 참조 오탐.** 1·2가 풀리면 PR #10의 `cluster-backup-patch.yaml`과 `restore-drill/cluster.yaml`이 `CREDENTIAL_LITERAL`로 걸린다. `s3Credentials.secretAccessKey: {name, key}`는 Secret 참조인데 값으로 읽었다. 커밋 하나가 원인 하나를 고친다. | 커밋 | 고치는 것 | | --- | --- | | `fix(validate): scan the checkout that holds the sensitive-source scanner` | 스캐너가 있는 checkout을 검사한다. `--docs-root DIR`, `--platform-only` | | `fix(validate): render the sensitive-source scan from a clean copy` | git checkout이면 추적·미추적(무시 제외) 파일만 임시 사본으로 옮겨 렌더한다 | | `fix(validate): accept CloudNativePG s3Credentials Secret references` | `s3Credentials` 바로 아래 `accessKeyId`·`secretAccessKey`가 `{name, key}`뿐이면 참조로 본다 | ## 고른 방법과 버린 대안 - `--platform-root` 옵션은 넣지 않았다. 다른 트리의 스캐너로 검사하면 검사 규칙과 검사 대상이 어긋날 수 있다. - 문서 루트가 없으면 조용히 덜 검사하지 않는다. exit 2로 멈추고 `--docs-root`·`--platform-only`를 알려 준다. - 캐시만 지우는 안은 버렸다. 그 호스트만 고치고, 캐시가 다시 남으면 또 막힌다. 렌더러의 「기존 캐시 거부」는 차트 digest 검사를 지키는 장치라 그대로 둔다. 운영 checkout의 캐시는 따로 옮긴다(공유 노트 `owner-sudo-bundle.md` A-1, 총괄 몫). - 「name과 key만 있으면 언제나 참조」 같은 넓은 규칙은 버렸다. 다른 자격 증명 키 아래 숨긴 값도 통과시킨다. 부모가 `s3Credentials`이고 키 이름이 둘 중 하나일 때만 허용한다. ## 위험과 영향 - desktop에서 인자 없이 돌리는 기본 동작은 같다(같은 두 루트를 검사한다). - 렌더 사본에는 git이 무시하는 파일이 없다. 지금 그런 파일을 읽는 렌더러는 없다. 생기면 그 렌더가 실패한다(덜 검사하지 않는다). - 스캐너 출력은 그대로 파일 이름과 발견 종류만 찍는다. 값은 찍지 않는다. ## 검증 모두 desktop에서, 운영 checkout이 아닌 main `205927f` clone에서 했다. - 단위 시험 `test-scan-platform-sensitive-source.sh`: 커밋마다 통과(128 → 131 → 135개). 각 커밋의 새 시험은 그 전 커밋에서 실패했다. - 커밋 2 앞: `FAIL: an ignored chart cache in a git checkout blocked the renderers` - 커밋 3 앞: `FAIL: a CloudNativePG s3Credentials Secret reference remains a reference` - main 스캐너 + 정본이 아닌 경로: `FAIL: canonical scanner test content leaf found a credential literal` - 실제 렌더러(남은 캐시 8개를 clone에 복사): - main 스캐너: phase1·phase2·admin 통과 뒤 `SCANNER_ERROR: renderer failed: observability-core RC=23`(W1 오류 재현) - 이 브랜치, 인자 없이 전체 실행: 렌더러 다섯 개 PASS, `PLATFORM RENDERED SECRET SCAN PASS`, `PLATFORM SENSITIVE SOURCE SCAN PASS`, exit 0 - 검사한 clone의 캐시 8개는 그대로, `/tmp`에 렌더 사본이 남지 않음 - `--docs-root relative` → exit 2, `--platform-only` 원본 검사 통과 - main 스캐너의 원본 검사(운영 checkout): 위 두 파일 `CREDENTIAL_LITERAL`. 이 PR 뒤 통과. ## 리뷰어가 볼 곳 - `scan_platform_renderer_secrets`의 사본 만들기: `git ls-files --cached --others --exclude-standard`에서 `--deleted`를 뺀 목록, 사본 정리 trap. - `permitted_s3_credentials_reference`: 허용 범위가 좁은지. ## 관련 문서 - 원인 기록과 소유자 단계: 공유 노트 `k3s-maturity-review.md`, `owner-sudo-bundle.md`(A-1 캐시 옮기기). 검증 로그: 공유 노트 `k3s-w6-scanner-fix-verify.log`. - 같은 캐시 문제를 drift 검사에서 고친 PR #9.
donghyeon.kang added 3 commits 2026-11-11 23:37:10 +00:00
scan-platform-sensitive-source.sh always scanned the fixed path
/home/donghyeon/workspace/platform, and its list of shell files with
embedded Python held the same fixed paths. Run from a temporary copy
or a CI runner, it scanned the desktop checkout instead of itself, or
nothing at all. Its own test failed at the first assertion in any
other checkout: the test file lost its embedded-Python context there
and was reported as a credential literal.

The platform root is now the checkout that contains the scanner
(dirname of BASH_SOURCE, physical path), and the embedded-Python list
is resolved under that root. The central documentation root stays the
desktop default. --docs-root DIR replaces it and --platform-only skips
it, for a copy or runner that has no central docs. A missing docs root
stops with exit 2 and names both options instead of scanning less.

Rejected: a --platform-root option. Scanning a tree with a scanner
from another tree would let a scanned tree differ from the rules that
scan it.

Risk: on the desktop host the default run is unchanged. A caller that
passed arguments before got usage and exit 2. It now gets the new
options.

Verification: on desktop, a non-canonical clone of main 205927f with
this change: test-scan-platform-sensitive-source.sh passes. Before the
change the same test in a worktree copy failed with "canonical scanner
test content leaf found a credential literal".
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.
PR #10 added the platform-postgres backup patch and its restore-drill
Cluster. Both hold barmanObjectStore.s3Credentials, where accessKeyId
and secretAccessKey are SecretKeySelectors (name and key). The
structured scan treats any non-string value under a key ending in
"access key" as a credential literal, so the source scan reported
CREDENTIAL_LITERAL for both files on main.

An entry directly under s3Credentials, named accessKeyId or
secretAccessKey, whose value is a mapping of exactly name and key
with non-empty strings, is now a reference. This mirrors the existing
exact rule for the Grafana client-secret secretKeyRef.

Rejected: a general "name and key is always a reference" rule. It
would also pass a literal hidden under some other credential key that
happens to have those two fields.

Risk: none beyond the two key names under that one parent. A literal
string, an extra child, or the same mapping under another parent is
still rejected (new test cases).

Verification: on desktop, the source scan of main 205927f reported the
two files before this change and passes after it. The unit test
passes in a non-canonical clone.
donghyeon.kang merged commit 5d27096ed0 into main 2026-11-11 23:46:20 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: donghyeon.kang/platform-core#11