From fb7ca13b60b8efcc4a8dee7055057a7c1409694d Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Sat, 21 Nov 2026 14:50:41 +0900 Subject: [PATCH] =?UTF-8?q?fix(build)!:=20=EA=B3=B5=EA=B0=9C=20=EA=B2=BD?= =?UTF-8?q?=EB=A1=9C=20=EC=8A=A4=EB=83=85=EC=88=8F=20=EB=B9=84=EA=B5=90=20?= =?UTF-8?q?lane=EC=9D=B4=20=EA=B8=B0=EC=A4=80=EC=84=A0=EC=9D=84=20?= =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20=EC=93=B0=EC=A7=80=20=EC=95=8A=EB=8A=94?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: :app-bootstrap:publicPathSnapshotTest(루트 verifyPublicPathSnapshot)는 빌드에 approvePublicPathChange가 있으면 publicpath.snapshot.write=true를 시험에 주었고, 시험은 기준선을 먼저 쓴 뒤 그 파일과 비교해 늘 통과했다. project.hasProperty는 -P뿐 아니라 gradle.properties(저장소·GRADLE_USER_HOME), ORG_GRADLE_PROJECT_ 환경 변수, GRADLE_OPTS의 -Dorg.gradle.project.에서도 참이라, 한 줄로 보안 기준선 게이트가 말없이 꺼졌다. 고른 방법: API surface 태스크와 같은 모양으로 나눈다. 비교 lane은 쓰기 스위치를 false로 고정하고, 실행 전(doFirst)에 셋 중 하나면 「read-only」로 실패한다. (1) 빌드에 승인 속성이 있다. (2) 시험 JVM이 받을 publicpath.snapshot.write가 false가 아니다. (3) 상속한 JAVA_TOOL_OPTIONS· JDK_JAVA_OPTIONS·_JAVA_OPTIONS에 그 스위치가 있다. 고정값은 앞의 두 변수를 이긴다(JVM이 Gradle의 -D보다 먼저 읽는다). _JAVA_OPTIONS는 뒤에 읽혀 고정값을 이기므로(기준 main에서도 같은 빈틈) (3)이 막는다. main 단계 lane이라 up-to-date·캐시가 없어 mainCheck·releaseCheck마다 검사가 돈다. 쓰기는 새 Test 태스크 :app-bootstrap:publicPathSnapshotUpdate(루트 별칭 updatePublicPathSnapshot)가 같은 tag 시험을 쓰기 스위치를 켜고 돌린다. 승인 속성이 없으면 쓰기 전에 실패하고, 어떤 단계에도 들지 않으며, 매번 다시 돈다. 버린 대안: 쓴 뒤 「기준선을 다시 썼다, 커밋하라」로 실패시키기 — 한 lane 안에서 통과·실패의 뜻이 갈려 lane 결과 판정과 섞인다. update를 explicitOnly strict lane으로 두기 — TEST lane은 캐시되어 쓰기를 건너뛸 수 있고 집계 태스크마다 안내가 찍힌다. 위험·한계: 승인 명령이 verifyPublicPathSnapshot -P…에서 updatePublicPathSnapshot -P…로 바뀐다. 승인 속성을 상시로 둔 파생 서비스는 mainCheck·releaseCheck가 실패한다(docs/upgrade/2026-11-round9-public-surface.md 5행). 기준선 머리 주석의 명령 한 줄만 바뀌고 경로 내용은 그대로다. 갱신 명령을 적은 곳(docs/build.md, be-security 스킬, 제거 표 docs/capability-status.md·build-logic/README.md)도 함께 고친다. 검증: desktop 공유 잠금 아래 detached worktree, --no-build-cache. 변이 = gradle.properties의 approvePublicPathChange=true + SecurityConfig의 requestMatchers("/v1/admin/**").permitAll() 한 줄. - RED(기준 96c0b4c7): 변이에서 verifyPublicPathSnapshot rc=0, 기준선에 permitAll 줄이 덧붙었다. permitAll + _JAVA_OPTIONS로 쓰기 스위치를 준 것도 rc=0(JAVA_TOOL_OPTIONS·JDK_JAVA_OPTIONS는 rc=1). - GREEN(이 커밋 트리 3958ac3e): - 변이 없음 verifyPublicPathSnapshot rc=0. - 변이, -P, ORG_GRADLE_PROJECT_ 각각 rc=1 「is read-only」. - permitAll + 세 JVM 옵션 변수 각각 rc=1 「is read-only」. - 빌드 스크립트가 쓰기 스위치를 true로 덮으면 rc=1 「is read-only」. - permitAll만 rc=1 「surface changed」. - 승인 없는 updatePublicPathSnapshot rc=1, 기준선 그대로. - updatePublicPathSnapshot -PapprovePublicPathChange rc=0, 새 줄이 들어가고 이어서 verifyPublicPathSnapshot rc=0. - scripts/ci/verify-configuration-cache.sh rc=0. - scripts/verify.sh(트리 3958ac3e, 「HEAD 트리와 같음」): desktop leaf :app-bootstrap --no-cache rc=0(tests=330 failures=0), desktop pr --no-cache rc=0(tests=7329 failures=0), 노트북 docs rc=0. BREAKING CHANGE: 공개 경로 스냅숏 갱신은 ./gradlew updatePublicPathSnapshot -PapprovePublicPathChange다. verifyPublicPathSnapshot·mainCheck·releaseCheck는 approvePublicPathChange가 어디서든 켜져 있으면 실패한다. Refs: REV-BE-0011 --- .claude/skills/be-security/SKILL.md | 2 +- build-logic/README.md | 2 +- build.gradle | 8 ++- docs/build.md | 9 ++- docs/capability-status.md | 2 +- docs/security/public-paths-snapshot.txt | 2 +- docs/upgrade/2026-11-round9-public-surface.md | 10 ++- src/bootstrap/app/build.gradle | 63 ++++++++++++++++++- .../security/PublicPathSnapshotTest.java | 12 ++-- 9 files changed, 92 insertions(+), 18 deletions(-) diff --git a/.claude/skills/be-security/SKILL.md b/.claude/skills/be-security/SKILL.md index 9f49deeb..719abbc3 100644 --- a/.claude/skills/be-security/SKILL.md +++ b/.claude/skills/be-security/SKILL.md @@ -77,7 +77,7 @@ paths: Gradle·Docker는 desktop에서 돈다(`docs/work/operate.md` 4.1절). 명령은 저장소 루트에서다. -- 공개 경로·보안 체인을 바꿨으면 `./gradlew verifyPublicPathSnapshot`. 스냅숏 갱신은 리뷰 뒤 `-PapprovePublicPathChange`. — `docs/work/reference/gates.md` 2절 +- 공개 경로·보안 체인을 바꿨으면 `./gradlew verifyPublicPathSnapshot`. 스냅숏 갱신은 리뷰 뒤 `./gradlew updatePublicPathSnapshot -PapprovePublicPathChange`(verify는 승인 속성이 있으면 실패한다). — `docs/work/reference/gates.md` 2절 - JWT·JWKS·CORS 경계: `:adapter:inbound:web:webSecurityBoundaryTest`(skip 거부), 오류 디스패치는 `JwtChainErrorDispatchIT`(web `systemTest`). - 권한 구조: `./gradlew :app-bootstrap:architectureTest`(`ApplicationBoundaryArchitectureTest`, `RequiresPermissionProxyabilityTest`, `ForbiddenApiArchitectureTest`). - 비밀·로그: `SecretsClassificationRegistryTest`와 `ManagementActuatorSecurityContractTest`의 registry 메서드(`document-contract` → `:app-bootstrap:documentContractTest`), `SqlLoggingForbiddenContractTest`(`repository-contract` → `:app-bootstrap:repositoryContractTest`), `PiiTokenBodyForbiddenContractTest`의 `requestLoggingHasNoBodyCapturePath`(`repository-contract`), `PiiTokenBodyForbiddenContractTest`·`ManagementActuatorSecurityContractTest`의 나머지(app-bootstrap `test` → `scripts/verify.sh leaf :app-bootstrap`) diff --git a/build-logic/README.md b/build-logic/README.md index f5e800fa..cabe4ce9 100644 --- a/build-logic/README.md +++ b/build-logic/README.md @@ -46,7 +46,7 @@ JMH benchmark는 커뮤니티 플러그인 `me.champeau.jmh`를 쓴다. `ca.qual | `ca.jmh-benchmarks` | `me.champeau.jmh` | | build-tools `ca.jpa-evidence`, `ca.jpa-qualification`(+ `junit` 증거 읽기) | 소유자 결정 4: persistence-jpa `JpaReadinessRegistryTest`, 인용한 시나리오를 모두 요구하고 건너뛰기를 거절하는 readiness lane, `src/adapter/outbound/persistence-jpa/release/release-registry.json`을 묶는 leaf의 `jpaReleaseQualification` | | build-tools `ca.config-contract` | 바꾸지 않고 여기로 옮겼다 | -| `ca.public-path-snapshot` | app-bootstrap `PublicPathSnapshotTest`(lane `publicPathSnapshotTest`, 루트 별칭 `verifyPublicPathSnapshot`) | +| `ca.public-path-snapshot` | app-bootstrap `PublicPathSnapshotTest`(비교 lane `publicPathSnapshotTest`, 루트 별칭 `verifyPublicPathSnapshot`; 갱신 `publicPathSnapshotUpdate`, 루트 별칭 `updatePublicPathSnapshot`) | | `ca.archive-hygiene` | 치울 것이 없다: leaf 버전이 더는 revision을 싣지 않으니 낡은 추적 가능 jar가 생기지 않는다 | | `ca.developer-bootstrap` | `scripts/bootstrap-local.sh` | | `JpaAdopterApiSurfaceTest`(persistence-jpa의 정규식 import 검사) | `ca.api-surface` `adopterBaseline` | diff --git a/build.gradle b/build.gradle index 54a12cff..4ed0ece2 100644 --- a/build.gradle +++ b/build.gradle @@ -280,12 +280,18 @@ strictLaneStages { } // The deny-by-default public path baseline: app-bootstrap's approval-test lane under its old name. -// `-PapprovePublicPathChange` rewrites the baseline after review. +// It only compares, and fails when the build sets approvePublicPathChange. After review, +// `updatePublicPathSnapshot -PapprovePublicPathChange` rewrites the baseline. tasks.register('verifyPublicPathSnapshot') { group = 'verification' description = 'Fails when the public path surface (default, profile overrides, filter-chain permitAll and securityMatcher statements) drifts from docs/security/public-paths-snapshot.txt.' dependsOn ':app-bootstrap:publicPathSnapshotTest' } +tasks.register('updatePublicPathSnapshot') { + group = 'verification' + description = 'Rewrites docs/security/public-paths-snapshot.txt from the current public path surface after review. Requires -PapprovePublicPathChange.' + dependsOn ':app-bootstrap:publicPathSnapshotUpdate' +} // The checks that only matter for a release artifact. Not `ci` again: a release tag is cut from a // main commit that the pull-request gate and the main stage already ran on (review BUILD-중복-6). diff --git a/docs/build.md b/docs/build.md index 31782548..7a6112f7 100644 --- a/docs/build.md +++ b/docs/build.md @@ -167,8 +167,13 @@ Checkstyle은 파싱된 파일에 같은 질문을 하고, leaf 단위로 돈다 넓어진 pattern) 스냅숏이 바뀐다. - **못 보는 것.** 운영자가 배포 env(`SECURITY_PUBLIC_PATHS`)로 준 값, 그리고 matcher를 상수나 변수로 다른 줄에서 만든 경우의 그 값(문장 글자만 본다). 그런 변경은 리뷰가 본다. -- **승인 방법.** 리뷰가 변경을 받은 뒤 `./gradlew verifyPublicPathSnapshot -PapprovePublicPathChange`로 스냅숏을 다시 - 쓰고 함께 커밋한다. 플래그 없이 돌리면 비교만 한다. +- **승인 방법.** 리뷰가 변경을 받은 뒤 `./gradlew updatePublicPathSnapshot -PapprovePublicPathChange`로 스냅숏을 다시 + 쓰고 함께 커밋한다. 쓰는 것은 이 태스크(`:app-bootstrap:publicPathSnapshotUpdate`)뿐이고, 승인 속성이 없으면 + 쓰기 전에 실패한다. `verifyPublicPathSnapshot`은 비교만 하고, 빌드에 `approvePublicPathChange`가 있으면 어디서 + 왔든(`-P`, `gradle.properties`, `ORG_GRADLE_PROJECT_` 환경 변수, `GRADLE_OPTS`의 `-Dorg.gradle.project.`) 실패한다. + 쓰는 lane이 자기가 쓴 파일과 비교하면 늘 통과하기 때문이다. 같은 이유로 비교 lane은 시험의 쓰기 스위치 + (`publicpath.snapshot.write`)를 `false`로 고정하고, 상속한 `JAVA_TOOL_OPTIONS`·`JDK_JAVA_OPTIONS`·`_JAVA_OPTIONS`에 + 그 스위치가 있으면 실패한다. API surface 태스크(`verify…`·`update…`)와 같은 모양이다. - **결정 — 무엇을 스냅숏하나.** 기동한 `SecurityFilterChain`의 matcher를 reflection으로 읽는 안은 Spring 버전마다 깨진다(`permitAll` matcher가 `RequestMatcherDelegatingAuthorizationManager`의 private 필드에 있다). 그래서 설정의 기본값과 소스의 `permitAll` 문장을 글자로 고정한다. diff --git a/docs/capability-status.md b/docs/capability-status.md index aca930bd..32659d61 100644 --- a/docs/capability-status.md +++ b/docs/capability-status.md @@ -397,7 +397,7 @@ web 경로의 `W/`는 `src/adapter/inbound/web/src/main/java/dev/caskeleton/adap | `jpaReleaseQualification`(루트) | persistence-jpa 같은 이름 태스크 | `release.yml` `jpa-release-gate` | | `JpaAdopterApiSurfaceTest` | `:adapter:outbound:persistence-jpa:verifyJpaApiSurface` adopter 검사 | `ci`(leaf `check`) | | `verifyEnvKeys`(build-tools) | build-logic `ca.config-contract`, 태스크 동일 | `mainCheck`(`configContractCheck`) | -| `verifyPublicPathSnapshot`/`updatePublicPathSnapshot`(플러그인) | `:app-bootstrap:publicPathSnapshotTest`(루트 별칭 `verifyPublicPathSnapshot`) + 렌더링 단위 테스트 3개(`test`) | `mainCheck`, `releaseCheck`, `ci`(단위) | +| `verifyPublicPathSnapshot`/`updatePublicPathSnapshot`(플러그인) | `:app-bootstrap:publicPathSnapshotTest`(루트 별칭 `verifyPublicPathSnapshot`, 비교만) + 갱신 `:app-bootstrap:publicPathSnapshotUpdate`(루트 별칭 `updatePublicPathSnapshot`) + 렌더링 단위 테스트 3개(`test`) | `mainCheck`, `releaseCheck`, `ci`(단위) | | `verifyNoStaleTraceableJars` | 해당 없음 — leaf jar 이름에 revision이 없어 stale jar가 생기지 않음 | — | | `GrpcStableReleaseGate`/`GrpcAdvancedPromotionGate` | 게이트에 연결된 적 없음(자기 테스트만). release `grpc-stable-release-gate` job은 그대로 | — | | notification evidence·env registry·mongo lane 계약(`test`) | `notificationDocumentContractTest`·`notificationEnvironmentContractTest`·`mongoDocumentContractTest` | `mainCheck` | diff --git a/docs/security/public-paths-snapshot.txt b/docs/security/public-paths-snapshot.txt index a75b6f16..65ff86e4 100644 --- a/docs/security/public-paths-snapshot.txt +++ b/docs/security/public-paths-snapshot.txt @@ -2,7 +2,7 @@ # SSOT: app.security.public-paths default in src/bootstrap/app/src/main/resources/config/security.yml # -> SecurityConfig permitAll(); anyRequest authenticated. An operator's own SECURITY_PUBLIC_PATHS # overrides it at run time and is outside this snapshot. -# Update only after review with: ./gradlew verifyPublicPathSnapshot -PapprovePublicPathChange +# Update only after review with: ./gradlew updatePublicPathSnapshot -PapprovePublicPathChange /v1/healthcheck # Profile overrides of app.security.public-paths profile local: /api/healthcheck diff --git a/docs/upgrade/2026-11-round9-public-surface.md b/docs/upgrade/2026-11-round9-public-surface.md index 2400bfe8..7a4b73cc 100644 --- a/docs/upgrade/2026-11-round9-public-surface.md +++ b/docs/upgrade/2026-11-round9-public-surface.md @@ -1,7 +1,8 @@ # 업그레이드 안내 — 2026-11 공개 경로 스냅숏과 관리 포트 -- 범위: 공개 경로 스냅숏(`docs/security/public-paths-snapshot.txt`)이 보는 범위를 넓힌 변경과, compose가 관리 포트·JMX를 - publish하던 줄을 지운 변경. 앱이 여는 경로와 기본 설정은 바뀌지 않았다. +- 범위: 공개 경로 스냅숏(`docs/security/public-paths-snapshot.txt`)이 보는 범위를 넓힌 변경, 스냅숏을 다시 쓰는 일을 + 비교 lane에서 떼어 낸 변경(2026-11-21), compose가 관리 포트·JMX를 publish하던 줄을 지운 변경. 앱이 여는 경로와 기본 + 설정은 바뀌지 않았다. - 근거: 2026-11-12 전체 리뷰(`docs/reviews/2026-11-12-round9-review/`)의 공개 경로·관리 포트 발견 ## 1. 누가 읽나 @@ -14,10 +15,11 @@ compose lane으로 JVM을 원격 JMX로 보던 사람이다. | # | 할 일 | 안 하면 | 해당 서비스 | | --- | --- | --- | --- | -| 1 | merge 뒤 `./gradlew verifyPublicPathSnapshot`을 돌린다. 실패하면 스냅숏에 새로 든 두 절(profile이 덮는 값, filter chain의 `permitAll`·`securityMatcher` 문장)을 읽고, 의도한 공개면 `./gradlew verifyPublicPathSnapshot -PapprovePublicPathChange`로 다시 쓴 파일을 보안 리뷰와 함께 커밋한다 | `mainCheck`·`releaseCheck`의 `:app-bootstrap:publicPathSnapshotTest`가 실패한다 | 자기 chain이나 profile 덮어쓰기가 있는 서비스 | +| 1 | merge 뒤 `./gradlew verifyPublicPathSnapshot`을 돌린다. 실패하면 스냅숏에 새로 든 두 절(profile이 덮는 값, filter chain의 `permitAll`·`securityMatcher` 문장)을 읽고, 의도한 공개면 `./gradlew updatePublicPathSnapshot -PapprovePublicPathChange`로 다시 쓴 파일을 보안 리뷰와 함께 커밋한다 | `mainCheck`·`releaseCheck`의 `:app-bootstrap:publicPathSnapshotTest`가 실패한다 | 자기 chain이나 profile 덮어쓰기가 있는 서비스 | | 2 | Kubernetes 배포는 `MANAGEMENT_SERVER_ADDRESS`를 pod IP에서 닿는 주소(예: `0.0.0.0`과 NetworkPolicy)로 두거나 같은 pod의 sidecar로 읽는다. 기본값 `127.0.0.1`은 2026-11-12 main 병합(관리 포트 loopback 고정)부터다 | kubelet 프로브가 관리 포트에 닿지 않아 liveness 실패로 재시작하고 readiness가 오지 않는다. Prometheus도 못 읽는다 | Kubernetes 배포 | | 3 | compose에서 관리 포트를 호스트로 읽던 명령(`curl localhost:9001/...`)을 `docker compose exec app wget -qO- http://localhost:9001/actuator/health`로 바꾼다 | 호스트 포트가 없어 연결이 거절된다. 지운 publish 줄도 컨테이너 loopback에 닿지 않아 원래 아무것도 답하지 않았다 | compose로 띄우는 사람 | | 4 | dev lane에서 원격 JMX(9999) 대신 `docker compose exec app jcmd 1 <명령>`(`VM.flags`, `Thread.print`, `JFR.start`)을 쓴다 | 9999 연결이 거절된다 | dev lane으로 JVM을 보던 사람 | +| 5 | 스냅숏을 다시 쓸 때는 `./gradlew updatePublicPathSnapshot -PapprovePublicPathChange`를 쓴다. `approvePublicPathChange`를 `gradle.properties`(저장소나 `GRADLE_USER_HOME`), `ORG_GRADLE_PROJECT_approvePublicPathChange` 환경 변수, `GRADLE_OPTS`, CI·스크립트의 `verifyPublicPathSnapshot` 명령에 두었다면 지운다 | `verifyPublicPathSnapshot`·`mainCheck`·`releaseCheck`의 `:app-bootstrap:publicPathSnapshotTest`가 「read-only」로 실패한다. 전에는 그 속성이 있으면 스냅숏을 다시 쓰고 통과했다 | 스냅숏을 승인하는 명령을 스크립트로 둔 서비스, 승인 속성을 상시로 켜 둔 서비스 | ## 3. 바뀐 것 @@ -25,4 +27,6 @@ compose lane으로 JVM을 원격 JMX로 보던 사람이다. 운영 코드의 `permitAll`·`securityMatcher` 문장. 알림 callback chain과 actuator chain이 셋째 절에 든다. - 스냅숏이 못 보는 것은 운영자가 배포 env(`SECURITY_PUBLIC_PATHS`)로 준 값과, matcher를 상수나 변수로 다른 줄에서 만든 경우의 그 값이다. 그런 변경은 리뷰가 본다(`docs/build.md` 「`verifyPublicPathSnapshot`」). +- 스냅숏을 쓰는 것은 `updatePublicPathSnapshot`(`:app-bootstrap:publicPathSnapshotUpdate`)뿐이고 승인 속성이 없으면 쓰기 전에 + 실패한다. 비교 lane은 승인 속성을 보면 실패한다. 전에는 비교 lane이 그 속성을 보면 스냅숏을 먼저 쓰고 자기와 비교했다. - dev lane의 원격 JMX는 인증·TLS 없이 열려 있었고 `jmxremote.host`가 없어 모든 인터페이스에 묶였다. 그래서 지웠다. diff --git a/src/bootstrap/app/build.gradle b/src/bootstrap/app/build.gradle index 4bf8e1e7..e7e93770 100644 --- a/src/bootstrap/app/build.gradle +++ b/src/bootstrap/app/build.gradle @@ -499,15 +499,23 @@ springBoot { // The deny-by-default public path baseline (docs/security/public-paths-snapshot.txt) is an approval // test beside the security configuration it pins, not a build-logic plugin (review BUILD-O3-5). The -// root `verifyPublicPathSnapshot` names this lane; `-PapprovePublicPathChange` rewrites the baseline -// after review instead of comparing it. +// root `verifyPublicPathSnapshot` names this lane, and the lane only compares. Recording a reviewed +// change is a task of its own, `publicPathSnapshotUpdate` below (root `updatePublicPathSnapshot`), +// the same split as the API surface tasks. The lane used to rewrite the baseline whenever the build +// had `approvePublicPathChange`, and then compared the file with itself: one line in a +// gradle.properties or an ORG_GRADLE_PROJECT_ variable turned the gate into a pass (2026-11-21). +def publicPathChangeApproved = project.hasProperty('approvePublicPathChange') +def publicPathWriteProperty = 'publicpath.snapshot.write' strictTestLanes { lane('publicPathSnapshotTest') { tag = 'public-path-snapshot' description = 'Compares the public path surface (default, profile overrides, filter-chain permit statements) with the reviewed baseline.' rejectSkipped = true mainStage() - systemProperty 'publicpath.snapshot.write', project.hasProperty('approvePublicPathChange') ? 'true' : 'false' + // Pinned off, not left unset: the JVM reads JAVA_TOOL_OPTIONS and JDK_JAVA_OPTIONS before + // the -D that Gradle passes, so the pin wins over a switch hidden there. _JAVA_OPTIONS comes + // after it and wins (measured 2026-11-21), so the doFirst below also rejects all three. + systemProperty publicPathWriteProperty, 'false' } } // The snapshot also lists every filter-chain statement that permits requests, in any leaf, and the @@ -519,6 +527,55 @@ tasks.named('publicPathSnapshotTest', Test) { }).withPathSensitivity(PathSensitivity.RELATIVE) .ignoreEmptyDirectories() .withPropertyName('securitySourcesAndBaseline') + // A main-stage lane runs every time (never up to date, never from the cache), so this check + // runs in every mainCheck and releaseCheck, wherever the property comes from. + doFirst { running -> + if (publicPathChangeApproved) { + throw new GradleException( + "${running.path} is read-only, and this build sets approvePublicPathChange (-P," + + ' a gradle.properties, ORG_GRADLE_PROJECT_approvePublicPathChange, or' + + ' -Dorg.gradle.project.approvePublicPathChange in GRADLE_OPTS). Record a' + + ' reviewed change with ./gradlew updatePublicPathSnapshot' + + ' -PapprovePublicPathChange and keep the property out of every other build.') + } + def write = String.valueOf(running.systemProperties[publicPathWriteProperty]) + if (write != 'false') { + throw new GradleException( + "${running.path} is read-only, but its test JVM would get ${publicPathWriteProperty}=${write}" + + ' from this project\'s build instead of the pinned false. Only' + + ' publicPathSnapshotUpdate writes the baseline; delete the override.') + } + def inherited = ['JAVA_TOOL_OPTIONS', 'JDK_JAVA_OPTIONS', '_JAVA_OPTIONS'].findAll { name -> + [running.environment[name], System.getenv(name)].any { value -> + value != null && String.valueOf(value).contains(publicPathWriteProperty) + } + } + if (inherited) { + throw new GradleException( + "${running.path} is read-only, but ${inherited.join(', ')} would hand its test JVM" + + " ${publicPathWriteProperty}. Only publicPathSnapshotUpdate writes the" + + ' baseline; remove the option from the environment.') + } + } +} +// Writes the baseline from the current surface: the same tagged test with the write switch on. It +// is in no stage and never up to date, and it refuses to run without the approval property. +tasks.register('publicPathSnapshotUpdate', Test) { + group = 'verification' + description = 'Rewrites docs/security/public-paths-snapshot.txt from the current public path surface. Run after review, through the root updatePublicPathSnapshot -PapprovePublicPathChange.' + testClassesDirs = sourceSets.test.output.classesDirs + classpath = sourceSets.test.runtimeClasspath + useJUnitPlatform { includeTags 'public-path-snapshot' } + systemProperty publicPathWriteProperty, 'true' + outputs.upToDateWhen { false } + outputs.doNotCacheIf('it writes the committed baseline, which is not a task output') { true } + doFirst { running -> + if (!publicPathChangeApproved) { + throw new GradleException( + "${running.path} rewrites docs/security/public-paths-snapshot.txt. Review the change," + + ' then run ./gradlew updatePublicPathSnapshot -PapprovePublicPathChange.') + } + } } tasks.register('stageDockerJar', Sync) { diff --git a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/security/PublicPathSnapshotTest.java b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/security/PublicPathSnapshotTest.java index 712351fd..41cf8c32 100644 --- a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/security/PublicPathSnapshotTest.java +++ b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/security/PublicPathSnapshotTest.java @@ -22,9 +22,11 @@ import org.junit.jupiter.api.Test; *

An approval test rather than the build-logic {@code ca.public-path-snapshot} plugin it * replaced (review 2026-09-24 BUILD-O3-5): the rule is about this composition root's shipped * security configuration, so it lives beside it. The repository comparison runs in the main-stage - * lane {@code publicPathSnapshotTest} (root alias {@code verifyPublicPathSnapshot}); approving a - * reviewed change is {@code ./gradlew verifyPublicPathSnapshot -PapprovePublicPathChange}, which - * rewrites the baseline instead of comparing. The rendering cases run in {@code test}. + * lane {@code publicPathSnapshotTest} (root alias {@code verifyPublicPathSnapshot}), which only + * compares and fails when the build carries the approval property. Approving a reviewed change is + * {@code ./gradlew updatePublicPathSnapshot -PapprovePublicPathChange}: the task {@code + * publicPathSnapshotUpdate} runs this test with {@code publicpath.snapshot.write=true}, and only + * that task writes the baseline. The rendering cases run in {@code test}. */ class PublicPathSnapshotTest { @@ -44,7 +46,7 @@ class PublicPathSnapshotTest { # SSOT: app.security.public-paths default in src/bootstrap/app/src/main/resources/config/security.yml # -> SecurityConfig permitAll(); anyRequest authenticated. An operator's own SECURITY_PUBLIC_PATHS # overrides it at run time and is outside this snapshot. - # Update only after review with: ./gradlew verifyPublicPathSnapshot -PapprovePublicPathChange + # Update only after review with: ./gradlew updatePublicPathSnapshot -PapprovePublicPathChange """; @Test @@ -68,7 +70,7 @@ class PublicPathSnapshotTest { assertThat(committed) .as( "the deny-by-default public path surface changed, so a protected endpoint may now be" - + " public. Review it, then run ./gradlew verifyPublicPathSnapshot" + + " public. Review it, then run ./gradlew updatePublicPathSnapshot" + " -PapprovePublicPathChange") .isEqualTo(rendered); } -- 2.54.0