diff --git a/.github/workflow-templates/fe/fe-release.yml b/.github/workflow-templates/fe/fe-release.yml index a8b1a6e..800cd9f 100644 --- a/.github/workflow-templates/fe/fe-release.yml +++ b/.github/workflow-templates/fe/fe-release.yml @@ -1,8 +1,8 @@ # Replaces the old two-file release (this file as tagger + fe-tag-pushed.yml / on_tag_pushed.yaml / tag_pushed.yml). -# Delete BOTH old caller files in the same commit that adds this one: the release flow still pushes -# the tag with the PAT, so a tag-push workflow left in the tree would publish that tag again (and -# release manually pushed tags). The release flow's guard job fails while an old caller exists. -# PFM-ISSUE-34282 (pushing the tag with GITHUB_TOKEN) removes the tag-push trigger for good. +# Delete BOTH old caller files in the same commit that adds this one: a tag-push workflow left in the tree +# would release manually pushed version/* tags, and an old fe-tag.yml caller would tag in parallel. The +# release flow's guard job fails while an old caller exists. The flow pushes its tag with GITHUB_TOKEN, +# which starts no workflow. name: 'Frontend Release CI' on: push: diff --git a/.github/workflows/fe-release-flow.yml b/.github/workflows/fe-release-flow.yml index da82266..a087487 100644 --- a/.github/workflows/fe-release-flow.yml +++ b/.github/workflows/fe-release-flow.yml @@ -21,8 +21,6 @@ on: required: true DOT_NPMRC: required: true - GIT_USER_TOKEN: - required: true GIT_USER: required: true GIT_USER_EMAIL: @@ -56,9 +54,9 @@ jobs: sparse-checkout: .github/workflows persist-credentials: false - # an old tag-push caller would publish manually pushed tags and fail on the tags of this flow; - # an old fe-tag.yml caller (branch push) would tag in parallel. Any trigger counts, comment - # lines do not (a commented-out caller is not active). + # an old tag-push caller would publish manually pushed version/* tags; an old fe-tag.yml caller + # (branch push) would tag in parallel with the PAT. Any trigger counts, comment lines do not + # (a commented-out caller is not active). - name: Check for old release callers run: | old=$(grep -lE '^[^#]*github-actions/\.github/workflows/(fe-release|fe-tag)\.yml@' .github/workflows/*.y*ml 2> /dev/null || true) @@ -108,7 +106,7 @@ jobs: && (github.event_name == 'push' || inputs.FORCE) runs-on: ubuntu-latest permissions: - contents: read + contents: write outputs: tag: ${{ steps.release.outputs.tag }} previous_tag: ${{ steps.release.outputs.previous_tag }} @@ -118,7 +116,6 @@ jobs: with: ref: '' fetch-depth: 0 - token: ${{ secrets.GIT_USER_TOKEN }} - uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 with: diff --git a/README.md b/README.md index 8155c1c..671c78d 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,11 @@ Migrate a branch of a consumer repo in **one commit**: - Set `RUN_E2E: false` only for repos that do not run e2e before a release. 2. **Delete the old release callers**: `fe-release.yml` as tagger, plus `fe-tag-pushed.yml` / `on_tag_pushed.yaml` / `tag_pushed.yml`. - - The release flow still pushes the tag with the PAT, so a tag-push workflow left in the tree - would try to publish that tag again, and would release manually pushed tags. + - The release flow pushes its tag with `GITHUB_TOKEN`, which starts no workflow. A tag-push + workflow left in the tree would still release manually pushed `version/*` tags, and an old + `fe-tag.yml` caller would tag in parallel. - The `guard` job fails while any workflow of the branch still calls `workflows/fe-release.yml` or `workflows/fe-tag.yml`. - - PFM-ISSUE-34282 (pushing the tag with `GITHUB_TOKEN`, which triggers no workflows) removes the - tag-push trigger for good. 3. **Update the PR and main callers.** `fe-install-deps.yml` no longer cancels superseded runs; each caller decides that itself now (see Concurrency). - `fe-pr.yml`: add the `concurrency` block of the template, so a new push to the PR cancels the @@ -84,8 +83,19 @@ run ends green with the warning "FORCE is ignored". ### Required secrets Passed with `secrets: inherit`: `JFROG_BASE64_TOKEN`, `JFROG_URL`, `JFROG_USER`, `DOT_NPMRC`, -`GIT_USER_TOKEN`, `GIT_USER`, `GIT_USER_EMAIL`, and optionally `PERCY_TOKEN`. The caller needs -`permissions: contents: write`. +`GIT_USER`, `GIT_USER_EMAIL`, and optionally `PERCY_TOKEN`. The caller needs +`permissions: contents: write`; the flow grants it only to the `release` and `github-release` jobs. + +The tag is pushed with `GITHUB_TOKEN`; the flow does not use `GIT_USER_TOKEN`. The deprecated +`fe-tag.yml` and `workflows/fe-release.yml` still need it: remove it from a repo only once none of +its branches calls them. + +### Tag rulesets + +The tag is pushed as GitHub Actions (`GITHUB_TOKEN`), after publish and promote. A ruleset that +restricts `version/*` tags must list GitHub Actions as a bypass actor. Otherwise the push is +rejected, the cleanup unpublishes the version, and the promoted packages lose `release-X.Y` (see +"Promote or tag push failed" under Recovery). ### Recovery @@ -143,5 +153,5 @@ publish distinct snapshot versions; the `snapshot` dist-tag ends up on the run t ### GitHub release -Created with `GITHUB_TOKEN`. The generated notes start at the previous tag of the same release line, +Created with `GITHUB_TOKEN`, like the tag. The generated notes start at the previous tag of the same release line, and "Latest" is set only for the highest `version/*` tag. diff --git a/specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md b/specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md index 0898b8b..4c4abe2 100644 --- a/specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md +++ b/specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md @@ -94,7 +94,9 @@ Major trade-offs we're accepting: 6. Normalizing caller filenames means the Actions run history starts fresh in repos that don't use template names (cplace-fe, office-reports, workflow-fe, loomeo, legacy-fe-assets, frontend-applications). What we're NOT doing (out of scope): -- A `version/*` tag ruleset or a tag-triggered recovery path (Q10, deferred). +- A `version/*` tag ruleset or a tag-triggered recovery path (Q10, deferred). Since PFM-ISSUE-34282 the + tag is pushed with `GITHUB_TOKEN`: such a ruleset must list GitHub Actions as a bypass actor, otherwise + the push is rejected after publish and promote. - Fixing the branch-off-day `.1` collision (Q9, deferred). - Skip-if-exists / resumable publish (rejected in research Q4). - Pushing the tag with `GITHUB_TOKEN` (PFM-ISSUE-34282) or enabling immutable releases (PFM-ISSUE-34284). diff --git a/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/design.md b/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/design.md new file mode 100644 index 0000000..704a1e3 --- /dev/null +++ b/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/design.md @@ -0,0 +1,211 @@ +--- +date: 2026-11-11 +branch: improvement/PFM-ISSUE-34282-Use-GITHUB_TOKEN-with-scoped-permissions-for +git_commit: 87feb8e4218d9fe87791883f9f683ddca3106e05 +topic: "PFM-ISSUE-34282 - Use GITHUB_TOKEN with scoped permissions for in-repo tag and release" +tags: [design, github-actions, fe-release-flow, github-token, permissions, pat] +status: draft +--- + +# Use GITHUB_TOKEN with scoped permissions for in-repo tag and release - Design Approach + +## Overview + +The consolidated FE release flow (`fe-release-flow.yml`, PR #183) pushes its `version/X.Y.Z` tag with the built-in `GITHUB_TOKEN` instead of the shared user PAT. The `release` job gets `contents: write` and nothing else. The PAT secret is dropped from the flow's contract. The docs that describe the PAT-pushed tag are reworded. + +## Problem Statement + +After #183, the shared user PAT is used for tagging/releasing in one place: the `release` job checks out with `token: ${{ secrets.GIT_USER_TOKEN }}` (`fe-release-flow.yml:121`). Checkout persists it in `.git/config`. The artifacts tool's `git push origin ` (`artifacts-handler.ts:313`) and the cleanup's `git ls-remote --exit-code` (`fe-release-flow.yml:176`) use it implicitly. The PAT's original purpose, making the tag push start the second run, disappeared with #183. What remains is a broad, long-lived, cross-repo credential next to `npm ci` and the artifacts tool. + +### Requirements +- In-repo tag and GitHub release authenticate with `GITHUB_TOKEN`. +- Write scope is granted per job, only where it has a consumer. Build/test/install jobs keep `contents: read`. +- Scopes without a consumer (`checks`, `pull-requests`, `issues`, `actions`) are not granted. +- The shared user PAT is no longer used or required by the tag/release path. + +### Constraints +- The caller's `permissions:` is a ceiling. Migrated callers grant `contents: write` only (template `fe-release.yml:18-19`). Requesting more fails every migrated consumer at startup. +- Callers use `secrets: inherit`, so removing a declared secret needs no caller edit. +- Inside `release` the order is publish → promote → tag. A rejected tag push is the most expensive failure: the version is unpublished and `release-X.Y` is lost on every promoted package until the next release. +- The deprecated `fe-tag.yml` / `fe-release.yml` reusables must keep working for unmigrated consumers (cplace-fe, 2lforge, release lines 25.4-26.4). +- Retiring `GIT_USER` / `GIT_USER_EMAIL` is PFM-ISSUE-34286 scope. + +## Design Decisions Summary + +1. **Permissions: `contents: write` only on `release`**: the job moves from `contents: read` to `contents: write`; no other scope is added anywhere. + - `github-release` stays `contents: write`; `guard`, `install-deps`, `build`, `e2e` stay `contents: read`. + - The ticket's "baseline" (`checks: write`, `pull-requests: write`) and the "confirm" scopes (`issues: read`, `actions: write`) are dropped: none has a consumer. The ticket text is updated to match. +2. **Credential: persisted default token**: the `release` checkout drops `token:` and persists `github.token`, as `fe-snapshot.yml` does since 34285. + - The `GIT_USER_TOKEN` declaration is removed from `workflow_call.secrets`. + - The artifacts tool and the cleanup's `ls-remote` are unchanged; they use whatever checkout persisted. +3. **No early push-rights check; document the ruleset requirement**: a `version/*` tag ruleset must list GitHub Actions as a bypass actor, otherwise a release fails after promote. + - The note goes into the README and onto 34283's Q10 (the unowned tag-ruleset item, `specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md:97`). +4. **Git identity stays for 34286**: the "Configure git user" step and the `GIT_USER` / `GIT_USER_EMAIL` declarations are untouched. +5. **Main chain unchanged**: the `fe-main.yml` template keeps its four-scope block. Follow-up PFM-ISSUE-35504 moves all seven FE templates to least privilege. +6. **Docs and guard reworded, guard logic unchanged**: the template header, README migration note, secrets list and release section describe the `GITHUB_TOKEN` tag push. + - Old callers must still be deleted in the migration commit: a tag-push caller would publish manually pushed tags; an old `fe-tag.yml` caller would tag in parallel with the PAT. + - Only the guard's comment changes; its check stays as validated in 34283 A1-A12. + +This means: +- A tag pushed by the flow starts no workflow. A tag-push caller left in a migrated tree can no longer re-publish the flow's own tags. +- Migrated consumers need no change: the template's `contents: write` ceiling and `secrets: inherit` already cover the switch. +- A repo can drop `GIT_USER_TOKEN` once all its branches run the new flow; `GIT_USER*` follow with 34286. +- Unmigrated consumers on the deprecated reusables keep the PAT and keep working. +- The live test plan's open points are settled: T1 expects `release` = `Contents: write` only; T3 and the `GIT_USER*` part of R6 do not apply; M1 is a plain regression check; open point 4 (credential isolation) is dropped. + +Major trade-offs we're accepting: +1. Write token next to third-party code: `npm ci` and the artifacts tool in the `release` job can read the persisted `GITHUB_TOKEN`. We give up full isolation and gain a three-line change that keeps #183's validated one-job publish/promote/tag/cleanup design. The exposure is still far smaller than the PAT's (this repo only, `contents` only, expires with the job). +2. Late ruleset rejection: a future `version/*` ruleset without an Actions bypass would reject the push after publish and promote. We rely on documentation instead of a pre-check that a dry-run probably cannot provide and a ruleset query would need extra scope for. +3. Unused shared-account secrets remain required: `GIT_USER` / `GIT_USER_EMAIL` stay declared until 34286, so the flow is not yet free of the shared account. +4. Deviation from the ticket's literal baseline: we follow its "drop any without a consumer" requirement over its listed baseline, and update the ticket text. + +What we're NOT doing (out of scope): +- Isolating the write token from third-party code (`persist-credentials: false` with a push-only credential, or a separate tag-push job). +- A pre-publish push-rights or ruleset check. +- Removing the git identity step or `GIT_USER` / `GIT_USER_EMAIL` (PFM-ISSUE-34286). +- Narrowing `fe-main.yml` or the other FE templates' permissions (follow-up PFM-ISSUE-35504), including the stale `actions: write` in cplace-fe `push_main.yaml`. +- Changing the deprecated `fe-tag.yml` / `fe-release.yml` reusables. +- The backend's credential-store approach (`prepare-git-environment`). +- JFrog secret changes. + +Success criteria: +- A push release in `clone-cplace-fe` tags and releases with no PAT: no canary run for the new tag, `release` job log shows `Contents: write` / `Metadata: read` only, no auth errors (live test R1, T1-T2, E7 Phase B). +- The failure cleanup still reads the remote: `ls-remote` exit code 2 and the unpublish run after a forced publish failure (R3). +- A migrated caller with the unchanged template starts without startup failure, and a release succeeds with the `GIT_USER_TOKEN` secret deleted (R0, R6). +- `git grep GIT_USER_TOKEN` finds nothing in `fe-release-flow.yml`; the deprecated reusables are byte-identical to PR #183. + +## Design Decisions - Details + +### Permission set of the `release` job + +**Chosen Approach:** `contents: write` only. + +**Rationale:** The only write consumers in the release chain are the tag push and `gh release create`, both under `contents`. Nothing in `fe-release-flow.yml`, the nested `fe-install-deps` / `fe-build` / `fe-e2e` workflows or the composite actions calls the Checks, Pull Requests, Issues or Actions APIs ([research §3](./research.md)). The ticket's baseline comes from the four-scope boilerplate in the other FE templates. Its own third requirement asks to drop scopes without a consumer. + +**Alternatives Considered:** +- **Ticket baseline (`contents` + `checks` + `pull-requests` write)**: Rejected because it grants unused scopes to a job that runs third-party code, and every migrated caller would have to raise its ceiling or fail at startup. + +**Implications:** +- The ticket's Requirements section is updated to state `contents: write` only and record why the other scopes were dropped. +- The caller template's `permissions: contents: write` stays as the ceiling. + +--- + +### Write-credential handling inside the `release` job + +**Chosen Approach:** Persisted default credential: checkout without `token:`, `fetch-depth: 0` kept. + +**Rationale:** The smallest change that removes the PAT, matching the 34285 precedent (`fe-snapshot.yml`) and every other FE checkout. The push and the cleanup's `ls-remote` keep working without touching the TS tool. `GITHUB_TOKEN` is limited to this repository and `contents`, and expires with the job. + +**Alternatives Considered:** +- **`persist-credentials: false` with the token injected only into the artifacts and cleanup steps**: Rejected because the artifacts action itself runs `npm ci` and ts-node with the token in env, so it isolates almost nothing, and it adds token handling to a tool that has none. +- **Tag push in a separate job without npm**: Rejected because it breaks #183's one-job publish → promote → tag → cleanup design (cross-job cleanup, more complex re-runs) and would invalidate the 34283 live validation. Listed as out of scope. + +**Implications:** +- `npm ci` and the artifacts tool can read a write-capable token during the job (trade-off 1). +- If an implementation step ever drops the persisted credential, the cleanup fails loudly ("Could not check whether … is pushed") instead of unpublishing. + +--- + +### Early check of push rights + +**Chosen Approach:** No pre-check; document that a `version/*` tag ruleset needs GitHub Actions as bypass actor. + +**Rationale:** A missing grant is already caught early (the caller ceiling at startup; the job grant is static). The only realistic late rejection is a future tag ruleset, which does not exist today in cplace-fe or clone-cplace-fe. GitHub evaluates rulesets on the actual ref update, so a `git push --dry-run` most likely would not detect one (not verified live). + +**Alternatives Considered:** +- **`git push --dry-run` of the tag before publishing**: Rejected because it likely does not catch ruleset rejections, and the tag name is computed inside the TS tool. +- **Query repository rulesets before publishing**: Rejected because org rulesets and bypass evaluation make it fragile, and reading bypass actors may need scope beyond `contents`. + +**Implications:** +- README: a ruleset note next to the Recovery section. +- 34283 design Q10 (`design.md:97`): the same note, so whoever takes up the ruleset sees it. + +--- + +### Git identity and `GIT_USER` / `GIT_USER_EMAIL` + +**Chosen Approach:** Leave them for PFM-ISSUE-34286. + +**Rationale:** The tag is lightweight and no commit is made, so the identity is unused but harmless. 34286 exists to retire `GIT_USER*` across all FE workflows in one pass. Keeping 34282 to the token keeps review and live validation focused. + +**Alternatives Considered:** +- **Remove the step and declarations in 34282**: Rejected because it takes 34286 scope for no functional gain. + +**Implications:** +- Live test rule T3 and the `GIT_USER*` part of R6 do not apply. +- The README secret list keeps `GIT_USER` / `GIT_USER_EMAIL`. + +--- + +### Main chain permissions (`fe-main.yml` template) + +**Chosen Approach:** Unchanged in 34282; follow-up PFM-ISSUE-35504 covers all FE templates. + +**Rationale:** The ticket covers the tag/release path. The four-scope block appears in seven FE templates, at least one with a real consumer (`fe-pr-snapshot.yml:76-88`), so a single audit is cleaner than narrowing one. A template change only reaches consumers when they re-copy it. + +**Alternatives Considered:** +- **Narrow `fe-main.yml` to `contents: read` in 34282**: Rejected because it extends the ticket scope and leaves six templates inconsistent. + +**Implications:** +- Follow-up PFM-ISSUE-35504: least-privilege `permissions:` for all FE templates, plus the stale `actions: write` in cplace-fe `push_main.yaml`. +- Live test M1 is a regression check only. + +--- + +### Docs, template header and guard wording + +**Chosen Approach:** Reword all PAT references; keep the guard check and the "delete old callers in the same commit" rule. + +**Rationale:** After the switch, the flow's own tags no longer re-fire tag-push callers, but two reasons to delete old callers remain: a tag-push caller would still publish manually pushed tags, and an old `fe-tag.yml` caller would tag in parallel with the PAT. + +**Alternatives Considered:** +- **Relax the guard to `fe-tag.yml` callers only**: Rejected because a leftover tag-push caller can still double-publish a manually pushed `version/*` tag, and it changes validated logic for no safety gain. + +**Implications:** +- `.github/workflow-templates/fe/fe-release.yml:1-5`: new header (no "still pushes the tag with the PAT", no "34282 removes …"). +- `README.md:54-59` migration note, `:84-88` secrets list without `GIT_USER_TOKEN`, `:146` "tag and GitHub release are created with `GITHUB_TOKEN`". +- `fe-release-flow.yml:59-61` guard comment. +- Migrated branches keep the old header comment until re-copied; harmless. + +--- + +## Overall Architecture + +The job structure of #183 stays. One job's scope changes, one secret leaves the contract, and the docs follow. + +### Key Components +1. **`fe-release-flow.yml` `release` job**: `permissions: contents: write`; checkout without `token:`; identity step unchanged; publish → promote → tag → cleanup unchanged. +2. **`fe-release-flow.yml` secret contract**: `GIT_USER_TOKEN` removed; `GIT_USER`, `GIT_USER_EMAIL`, JFrog, `DOT_NPMRC`, `PERCY_TOKEN` unchanged. +3. **Caller template `fe-release.yml`**: `contents: write` ceiling and `secrets: inherit` unchanged; header comment rewritten. +4. **README / guard comment / 34283 Q10**: wording and the ruleset note. + +### Data Flow +`actions/checkout` persists `github.token` (job scope `contents: write`) → the artifacts tool publishes and promotes on JFrog (JFrog credentials) → `git push origin version/X.Y.Z` with the persisted token, which triggers no workflow → on failure, `git ls-remote --exit-code` with the same token decides the unpublish → `github-release` creates the release with its own `github.token`. + +### Integration Points +- Migrated consumers: unchanged callers (template ceiling `contents: write`, `secrets: inherit`). +- Unmigrated consumers: the deprecated `fe-tag.yml` / `fe-release.yml` reusables, untouched and still PAT-based. +- Repository rulesets: none today; a future `version/*` ruleset needs a GitHub Actions bypass. + +## Known Risks + +1. **Compromised dependency with a write token**: code run by `npm ci` or the artifacts tool could push to this repo during the job. Mitigation: the token is limited to `contents` on one repo and expires with the job; full isolation is listed out of scope and can be its own ticket. +2. **Future tag ruleset rejects the push after promote**: the version is unpublished and `release-X.Y` is lost until the next release. Mitigation: README and 34283 Q10 note; README Recovery already covers restoring `release-X.Y`. +3. **A consumer branch mixes the old and new flow**: an unmigrated branch keeps needing `GIT_USER_TOKEN`. Mitigation: the secret is only deleted per repo once no branch uses the deprecated reusables; README says so. +4. **The dry-run assumption is unverified**: if a dry-run did detect ruleset rejections, a cheap pre-check would have been possible. Mitigation: revisit together with Q10 if a ruleset is planned. + +## Next Steps + +1. Review this design document +2. Done: PFM-ISSUE-34282 ticket text updated (permission baseline); follow-up PFM-ISSUE-35504 created +3. Proceed to implementation planning: `/spec-driven-development:create_plan specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/design.md` + +## References + +- Original ticket: [PFM-ISSUE-34282](https://base.cplace.io/pages/p9vu89ujy61fxb2nrrp6focwy/PFM-ISSUE-34282-Use-GITHUB-TOKEN-with-scoped-permissions-for-in-repo-tag-and-release) +- Related research: [Research](./research.md) +- Live test plan: [live-test-plan.md](./live-test-plan.md) +- Base design: [34283 design](../2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md) +- Similar change: PFM-ISSUE-34285 (commit faa4771, `fe-snapshot.yml` without `GIT_USER_TOKEN`) +- Backend pattern: `cplace-gh-workflows` commit 18ea38f3 (PAT removed, `GITHUB_TOKEN` tag push) diff --git a/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/live-test-plan.md b/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/live-test-plan.md new file mode 100644 index 0000000..a8fa1ad --- /dev/null +++ b/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/live-test-plan.md @@ -0,0 +1,325 @@ +--- +date: 2026-11-10 +last_updated: 2026-11-11 +branch: improvement/PFM-ISSUE-34282-Use-GITHUB_TOKEN-with-scoped-permissions-for (on top of PR #183) +topic: "Live test plan for PFM-ISSUE-34282 - GITHUB_TOKEN with scoped permissions for in-repo tag and release" +tags: [live-test, test-plan, clone-cplace-fe, fe-release-flow, fe-main, github-token, permissions, cplace-npm-test] +status: draft +--- + +# Live test plan: PFM-ISSUE-34282 in `clone-cplace-fe` + +This plan validates the PFM-ISSUE-34282 implementation **after** it exists. It runs on the test fork `collaborationFactory/clone-cplace-fe` and publishes only to the JFrog test registry `cplace-npm-test`. + +**The two core tests:** +- **M: a workflow on `main`.** A push to `main` runs the main CI (snapshot of the affected projects). A forced release-flow dispatch on `main` publishes a snapshot of all projects through the changed `release` job. +- **R: the release workflow on `release/26.4`.** A push with a real change publishes, tags with `GITHUB_TOKEN` and creates the GitHub release in one run. + +The supporting cases cover the paths the token switch can break: forced release, failure cleanup, the `github-release` re-run, the permission ceiling, and a run without the PAT secret. + +**What this plan reuses.** The test environment, tools, helper library, preflight, expected-state rules and JFrog rules are defined in the 34283 live-test document from PR #183: [`clone-cplace-fe-live-tests.md`](../2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/clone-cplace-fe-live-tests.md) (abbreviated **LT** below, e.g. "LT 2.2" is its helper library). This plan does not repeat them. It lists only the deltas for 34282 and the cases to run. LT Phase B (B0–B7) is the earlier sketch for this ticket. This plan replaces it: it adds the `main` cases and binds the expectations to the current repository state. + +**Workflow baseline.** All workflow references are to the PR #183 state (branch `improvement/PFM-ISSUE-34283-Consolidate-the-FE-2-0-release-flow-into-a-master`, head `4666f60`): +- `.github/workflows/fe-release-flow.yml`: jobs `guard`, `install-deps`, `build`, `e2e`, `release`, `github-release`. +- `.github/workflow-templates/fe/fe-release.yml`: the caller, `permissions: contents: write`, `secrets: inherit`. +- `.github/workflow-templates/fe/fe-main.yml` → `.github/workflows/fe-snapshot.yml`: the main CI. + +--- + +## 1. What 34282 is expected to change + +The expected state follows [`design.md`](./design.md) and [`plan.md`](./plan.md) in this directory, applied to the PR #183 workflows. + +| ID | Item | PR #183 state | Expected after 34282 | +|---|---|---|---| +| D1 | `release` job checkout | `token: ${{ secrets.GIT_USER_TOKEN }}` (`fe-release-flow.yml:121`) | no `token:` (default `github.token`), still `fetch-depth: 0` | +| D2 | `release` job permissions | `contents: read` (`:110-111`) | `contents: write` only | +| D3 | `GIT_USER_TOKEN` in `workflow_call.secrets` | `required: true` (`:24-25`) | removed | +| D4 | Other jobs | `guard`/`install-deps`/`build`/`e2e` `contents: read`, `github-release` `contents: write` | unchanged | +| D5 | "Configure git user" step and `GIT_USER`/`GIT_USER_EMAIL` | present (`:143-149`, `:26-29`) | unchanged (kept for PFM-ISSUE-34286) | +| D6 | Caller template `fe-release.yml` | `contents: write`; header says the PAT pushes the tag | `contents: write` unchanged; header comment updated | +| D7 | `fe-main.yml` template (four-scope block) | `contents/pull-requests: write`, `actions: read`, `checks: write` | unchanged (PFM-ISSUE-35504) | +| D8 | Deprecated `fe-tag.yml`/`fe-release.yml` (reusables) | PAT-based | unchanged (old consumers keep working) | +| D9 | README (`:54-59`, `:86-88`, `:146`), guard **comment**, 34283 design Q10 note | describe the PAT tag push; no tag-ruleset note | updated; new README section "Tag rulesets"; Q10 note names the GitHub Actions bypass actor; guard **message** unchanged | + +--- + +## 2. Test environment + +### 2.1 State on 2026-11-10 (read-only check) + +| Item | Value | +|---|---| +| Branches | `main`, `release/26.4`, `release/26.3` (LT A12), `fix/PFM-ISSUE-35119-…` (leftover) | +| Version tags | `version/26.3.1`, `version/26.4.1` … `version/26.4.7` | +| Latest release run (PAT baseline) | `42292826750` (LT A8 retest, `26.4.7`), canary run `42297425544` as actor `squad-fe` | +| `release/26.4` | migrated: `fe-release.yml` → `fe-release-flow.yml@test/PFM-ISSUE-34283-release-flow`; canary `zz-tag-push-canary.yml` present; tip `5d1491344` | +| `main` | **not migrated**: `push_to_release.yaml` and `on_tag_pushed.yaml` still present. `push_main.yaml` calls `fe-install-deps`/`fe-build`/`fe-snapshot` `@master`, with `permissions: contents: read, actions: write`. Tip `54ca47f60` | +| `main` push triggers | `push_main.yaml` only. `sonar-scan.yml`, `deploy_storybook.yaml`, `auto-pr-upmerge.yml` are manual. `xray-scan.yml` triggers on `package.json`/`package-lock.json` changes only, so a commit touching those files must not be pushed to `main` | +| Teardown | None wanted (test repo; see the project memory). Throwaway branches are still deleted inside their case | + +The next release on `26.4` is therefore `26.4.8`. + +**Not usable as evidence:** the repository activity API (`repos/$R/activity`) lists branch pushes but no tag pushes (checked 2026-11-10). Like the events API (LT 1.4), it cannot prove who pushed a tag. The canary (LT 1.6 S1) remains the proof. + +### 2.2 Placeholders (in addition to LT) + +| Name | Value | +|---|---| +| `TEST_BRANCH` | `test/PFM-ISSUE-34282-github-token` | +| `FB` | the 34282 feature branch (`improvement/PFM-ISSUE-34282-…`) | +| `BR` | `release/26.4` | +| `MB` | `main` | + +### 2.3 Setup steps + +Every push to `github-actions` is a stop (LT 2.1). Pushes to `clone-cplace-fe` are allowed. + +**T1: Build the test branch** (stop: push). +1. `git switch -c $TEST_BRANCH origin/$FB` in `github-actions`. +2. Commit 1: rewrite every internal ref to the test branch (`.github/workflows` and `.github/actions` only, not `workflow-templates`): + ```bash + grep -rlE 'collaborationFactory/github-actions/\.github/.+@master' .github/workflows .github/actions \ + | xargs sed -i "s#\(collaborationFactory/github-actions/\.github/[^@]*\)@master#\1@$TEST_BRANCH#g" + ``` +3. Commit 2: remove the e2e job, as in 34283 commit `b8ca5b4`: try `git cherry-pick b8ca5b4`; on conflict redo it by hand (drop the `e2e` job and the `RUN_E2E` input, `release.needs: build`, drop the `needs.e2e` condition). +4. Push. Run LT P2 and P3 against `$TEST_BRANCH`/`$FB`. +5. Recreate the test branch whenever `FB` changes (P3 detects it). + +**T2: Switch the release caller on `BR`** (= LT S2). +- One commit on `BR`: in `.github/workflows/fe-release.yml`, change `@test/PFM-ISSUE-34283-release-flow` to `@$TEST_BRANCH`. Copy the header comment from the 34282 template (D6). Change nothing else. +- Its push starts a release run with nothing affected: that run is case **R0**. + +**T3: Prepare `main`** (= LT S3, plus the main CI switch). One commit on `MB`, no other file: +- Add `.github/workflows/fe-release.yml` from the 34282 template, `uses:` → `@$TEST_BRANCH`. +- Delete `push_to_release.yaml` and `on_tag_pushed.yaml` (otherwise the guard fails every `main` dispatch). +- In `push_main.yaml`, change the three `@master` refs to `@$TEST_BRANCH`. Keep the fork's test-job removal. +- Check that the commit touches neither `package.json` nor `package-lock.json` (xray). +- Its push starts the main CI: that run is case **M0**. + +**T4: Preflight.** Run LT P1–P11 with the new `TEST_BRANCH`, plus: + +| ID | Check | Pass | +|---|---|---| +| P1m | `uses:` lines of `fe-release.yml` and `push_main.yaml` on `MB` | all `@$TEST_BRANCH` | +| P12 | Static diff `git diff origin/improvement/PFM-ISSUE-34283-…-master...origin/$FB -- .github README.md` | matches section 1 (D1–D9). No other workflow change. `fe-tag.yml` and `fe-release.yml` (reusables) untouched | +| P13 | `git grep -n GIT_USER_TOKEN origin/$TEST_BRANCH -- .github/workflows/fe-release-flow.yml` | empty | +| P14 | `actionlint` on `fe-release-flow.yml` of `$TEST_BRANCH` | no error | +| P15 | `gh api repos/$R/actions/permissions/workflow` | `default_workflow_permissions: read` (so any write must come from a job block) | + +### 2.4 Helper for snapshot versions + +LT 2.2 `snapshot()` filters snapshot tarballs out. For the `main` cases, add this to `$OUT/lib.sh`: + +```bash +# snap_tgz : @cplace-next snapshot tarballs created since the given time +snap_tgz() { + jf rt curl $J -s -XPOST /api/search/aql -H 'Content-Type: text/plain' -d \ + "items.find({\"repo\":\"cplace-npm-test\",\"path\":{\"\$match\":\"@cplace-next/*/-/@cplace-next\"},\"name\":{\"\$match\":\"*-0.0.0-SNAPSHOT-*.tgz\"},\"created\":{\"\$gte\":\"$1\"}}).include(\"path\",\"name\",\"created\")" \ + | jq -r '.results[] | "\(.path|split("/")[1])\t\(.name)\t\(.created)"' | sort > "$2" +} +``` + +### 2.5 Replay commits + +| Use | Upstream SHA | Kind | Subject | Projects | +|---|---|---|---|---| +| R1 (on `BR`) | `e2d33835d4b` | squash #2969 | 35090 Rich Text Editor too small | cf-editor-lib (LT 1.5 #5) | +| spare (on `BR`) | `4b83e9883e5` | merge #3010 | 35135 split ai-companion e2e | `-m 1`; adds apps (LT 1.5 #6) | +| M1 (on `MB`) | `97b45e73a1f` | squash #2971 | 34987 display aggregation rows in table | cf-frontend-sdk, libs/api, cf-e2e-testing-sdk | +| spare (on `MB`) | `7e81a3a8442` | squash #2991 | 35098 shared component for aggregations | cf-frontend-sdk, libs/api, cf-shell-lib | + +`main`'s fork point is upstream `320b61b22`; `#2989` is already replayed. The two upmerges `db7584e5a4f`/`750142f686a` were skipped. If `97b45e73a1f` conflicts outside fork-setup files, stop (LT replay rules). Recompute with `git log --first-parent --reverse 320b61b22..upstream/main` before use. + +--- + +## 3. Expected-state rules + +Use the LT 3.1 rules **RELEASE(N)** (E1–E8), **NO-RELEASE** (N1–N2) and **REJECTED** (X1–X2), with **E7 in its Phase B form**: no run of any workflow for `version/N`. Wait at least 3 minutes after the tag push before evaluating E7. + +Additional rules for this ticket: + +**T: token and authentication** (every case that runs the `release` job) + +| Row | Rule | Evidence | +|---|---|---| +| T1 | Each job log's `GITHUB_TOKEN Permissions` group lists exactly: `guard`/`install-deps`/`build (*)` → `Contents: read`, `Metadata: read`. `release` → `Contents: write`, `Metadata: read`. `github-release` → `Contents: write`, `Metadata: read`. No `Checks`, `PullRequests`, `Issues`, `Actions` | LT B2 extraction command | +| T2 | No authentication error in the `release` job log: no `Authentication failed`, `could not read Username`, `Permission to … denied`, `403`, on `git push`, `git ls-remote` or `git fetch` | `grep -inE 'authentication failed\|could not read username\|permission to .* denied\|returned error: 403' ` | +| T4 | The run was not started with a `startup_failure` and no `Secret GIT_USER_TOKEN is required` annotation | `run.json`, annotations | + +**S: snapshot on `main`** + +| Row | Rule | Evidence | +|---|---|---| +| S1 | Run `success`. Every job `success`, except `github-release` = `skipped` in the release flow | `jobs.tsv` | +| S2 | All tarballs created in the run window share **one** version `0.0.0-SNAPSHOT-`. The packages are: push (M1) = the affected publishable projects of the log's `Projects being processed`; forced (M2) = every publishable project (same count as the latest release, 27 unless a replay changed the set) | `snap_tgz`, log | +| S3 | `snapshot` dist-tag of each published package → the new version. `release-26.4` and `release-26.3` unchanged on every package. `latest` may move to the snapshot (Artifactory moves it to the newest version, as seen in LT 1.2); record but do not fail on it | `dist-tags.tsv` diff | +| S4 | `tags.txt`, `releases.txt`, `latest-release.txt` unchanged. No run of any workflow for a `version/*` ref in the window | `snapshot()` diff, `runs_since` | +| S5 | No release-version tarball (`npm-tgz.tsv` unchanged), nothing outside `@cplace-next/*` in the window | AQL | + +--- + +## 4. Test cases + +Run in this order, one at a time (LT 2.1 and 2.3). Each case computes `N` from its own before-snapshot. The versions below assume nothing else happens in between. + +| ID | Kind | Branch | Trigger | Outcome | Version | +|---|---|---|---|---|---| +| R0 | smoke | `BR` | T2 push (caller switch) | NO-RELEASE + T1, T4 | – | +| M0 | smoke | `MB` | T3 push (main prep) | main CI `success`, S4, S5 | – | +| **R1** | **core** | `BR` | push of replay `e2d33835d4b` | RELEASE(26.4.8) + T1, T2, T4 | 26.4.8 | +| **M1** | **core** | `MB` | push of replay `97b45e73a1f` | main CI snapshot of the affected projects, S1–S5 | snapshot | +| **M2** | **core** | `MB` | forced release-flow dispatch on `main` | snapshot of all projects, S1–S5, T1–T2 | snapshot | +| R2 | support | `BR` | forced dispatch, nothing affected | RELEASE(26.4.9) | 26.4.9 | +| R3 | support | `BR` | forced release, publish fails on the last package, then re-run | cleanup, then RELEASE(26.4.10) | 26.4.10 | +| R4 | support | `BR` | re-run of `github-release` (exists / deleted) | idempotent / recreated | 26.4.10 | +| R5 | negative | `test/ceiling` | caller ceiling `contents: read` | REJECTED at startup | – | +| R6 | optional, stop | `BR` | forced release with `GIT_USER_TOKEN` deleted | RELEASE(26.4.11) | 26.4.11 | + +### R0: Caller switch on `BR` + +- **Trigger:** the T2 push. +- **Expected:** NO-RELEASE (N1, N2). Log: `No projects are affected since version/26.4.7`. +- **Plus:** T4 (the caller ceiling `contents: write` covers the new `release: contents: write`, and the secret contract still validates). T1 for the jobs that ran. +- **Why:** a startup failure here would mean every migrated consumer breaks on the next push. + +### M0: `main` preparation push + +- **Trigger:** the T3 push. +- **Expected:** + - Exactly one "Frontend Main CI" run, `success`; no "Frontend Release CI" run (it triggers on `release/*` only); no xray run. + - The jobs use `@$TEST_BRANCH` (job log: `Uses: collaborationFactory/github-actions/.github/workflows/fe-snapshot.yml@refs/heads/test/PFM-ISSUE-34282-github-token`). + - Snapshot: workflow files are no project input, so the log is expected to list no projects and nothing is published. If the tool does publish, record the package list; S2–S5 apply then. + - S4, S5. + +### R1: Release on a real change (core) + +- **Purpose:** one push → one run that publishes, tags **with `GITHUB_TOKEN`**, and creates the GitHub release. The shared PAT is not used. +- **Trigger:** + ```bash + git -C "$WT" fetch origin && git -C "$WT" reset --hard origin/$BR + git -C "$WT" cherry-pick e2d33835d4b && git -C "$WT" push origin HEAD:$BR + SHA=$(git -C "$WT" rev-parse HEAD) + ``` +- **Expected:** RELEASE(26.4.8): E1–E8 with E7 Phase B, plus T1, T2, T4. In detail: + - **Build:** `install-deps`, `build (*)`, `release`, `github-release` `success`; the log lists cf-editor-lib among the affected projects (`Checking affected projects since version/26.4.7`). + - **Artifacts:** `Publish phase: publishing all publishable projects as 26.4.8`, then one `+ @cplace-next/

@26.4.8` per publishable project, then `Promote phase: moving release-26.4 to 26.4.8`, then `Tag phase: pushing version/26.4.8`. AQL count of `*-26.4.8.tgz` under `@cplace-next` = the publishable count (27 for the last release). `release-26.4` → `26.4.8` on every package, no `release-26.4-pending` left, `snapshot`/`latest` unchanged. + - **Tag:** `refs/tags/version/26.4.8`, type `commit` (lightweight), on `SHA`. No other tag added or moved. + - **GitHub release:** `version/26.4.8`, `draft=false`, `pre=false`, author `github-actions[bot]`, latest. Body ends with the compare link `version/26.4.7...version/26.4.8`. The cherry-picked commit is no PR of the clone, so "What's Changed" may be empty; that is not a failure. + - **PAT out of the path:** **no** canary run for `version/26.4.8` (the PAT baseline `26.4.7` had canary run `42297425544` as `squad-fe`). T1 shows `release` with `Contents: write`; the PAT baseline run `42292826750` showed `Contents: read`. +- **Record:** the publish order (R3 needs the last package) and the `release` job duration. + +### M1: Push to `main` with a real change (core) + +- **Purpose:** the main CI still builds and publishes snapshots with the 34282 test branch, and its jobs hold no more write scope than the caller grants. +- **Trigger:** + ```bash + git -C "$WT" fetch origin main && git -C "$WT" switch -C main-wt origin/main + git -C "$WT" cherry-pick 97b45e73a1f && git -C "$WT" push origin HEAD:main + ``` +- **Expected:** + - One "Frontend Main CI" run, `success`: `install-deps`, `build (*)`, `snapshot` `success`. + - **Build:** the build job builds the affected projects since `github.event.before` without error. + - **Artifacts:** S2 (push): one version `0.0.0-SNAPSHOT-` for the affected publishable projects, cf-frontend-sdk among them. Each `+ @cplace-next/

@0.0.0-SNAPSHOT-` log line has a matching tarball. + - S3, S4 (no tag, no GitHub release, no tag-triggered run), S5. + - **Permissions:** each job's `GITHUB_TOKEN Permissions` group matches the `push_main.yaml` grant (`Contents: read`, `Actions: write`, `Metadata: read`; `fe-main.yml` is unchanged by 34282, so this is a plain regression check). Record it next to the release flow's T1 result. + +### M2: Forced release-flow dispatch on `main` (core) + +- **Purpose:** the changed `release` job (D1–D3: no PAT, `contents: write`) also serves the default-branch path: it publishes a snapshot of all projects and pushes nothing. LT A13 skipped this in Phase A, so it is new coverage. +- **Precondition:** T3 done. Nothing in flight on `MB`. +- **Trigger:** `gh workflow run fe-release.yml -R $R --ref main -f force=true`, then find the run with `runs_since "$T0"` (event `workflow_dispatch`, branch `main`). +- **Expected:** + - `guard` `success` (default branch is allowed, no old caller on `MB`). + - `install-deps`, `build (*)`, `release` `success`; `github-release` `skipped` (no tag output). + - Release log: `Forced release flow on main: publishing a snapshot of all projects`. Step summary: `Published a snapshot of all projects as \`0.0.0-SNAPSHOT-\` (no tag, no GitHub release)`. + - S2 (forced: every publishable project), S3, S4, S5. + - T1 (the `release` job holds `Contents: write` here too) and T2. No `git push` in the log. +- **Non-forced variant (optional, cheap):** the same dispatch with `force=false`: `release` `skipped` (dry run), S4, and no new snapshot tarball. + +### R2: Forced release on `BR` + +- **Precondition:** nothing affected since `version/26.4.8` (true after R1, M cases do not touch `BR`). +- **Trigger:** `gh workflow run fe-release.yml -R $R --ref $BR -f force=true` +- **Expected:** RELEASE(26.4.9), E1–E8 with E7 Phase B, T1, T2, T4. Log `Force is set: skipping the affected check`. The tag is on the `BR` tip at dispatch. + +### R3: Failure cleanup with `GITHUB_TOKEN` + +- **Purpose:** the cleanup's `git ls-remote --exit-code` and the later tag push both work with the persisted `GITHUB_TOKEN`. An auth failure in `ls-remote` would end in the "Could not check whether … is pushed" error and leave a partial release. +- **Setup and trigger:** as LT A8 with `N = 26.4.10` and `LAST` = the last package of R1's publish order (stop: show the placeholder upload). +- **Expected, attempt 1:** + - `failure` on `LAST` ("cannot publish over the previously published versions: 26.4.10"). + - "Check for an incomplete release" logs `version/26.4.10 was not pushed: unpublishing its artifacts`, i.e. `ls-remote` exit code 2. **Exit code 128 or the `Could not check whether` error is a FAIL** (token cannot read the remote). + - One `Deleted artifact from Jfrog: …@26.4.10` per published package and the placeholder; AQL `*-26.4.10.tgz` = 0; `release-26.4` still `26.4.9` everywhere; no staging tag; no tag, no release; `github-release` skipped. +- **Trigger 2:** `gh run rerun $RUN -R $R --failed`. +- **Expected, attempt 2:** RELEASE(26.4.10), E1–E8 with E7 Phase B, T1, T2, T4. The same `N`, not `26.4.11`. + +### R4: `github-release` re-run + +- **Precondition:** R3's run is the most recent successful release (LT A10 precondition). +- **Steps and expectations:** as LT A10. + 1. Re-run `github-release`: `A GitHub release for version/26.4.10 already exists, nothing to do`; releases unchanged. + 2. Delete the release only (`gh api -X DELETE repos/$R/releases/`, check 404), re-run again: recreated, author `github-actions[bot]`, range `version/26.4.9...version/26.4.10`, latest. +- **Plus:** T1 for the re-run job (the fresh token still has `Contents: write`). + +### R5: Caller ceiling below the job request (negative) + +- **Setup:** branch `test/ceiling` from `BR` with one commit changing the caller's top-level `permissions` to `contents: read`. +- **Trigger:** `gh workflow run fe-release.yml -R $R --ref test/ceiling -f force=false` +- **Expected:** REJECTED at startup (X1, X2): no job started; the error names `release` (and `github-release`) requesting `contents: write` with only `contents: read` allowed. If `guard` runs and fails on the ref instead, the ceiling was not enforced: FAIL. +- **Cleanup:** delete `test/ceiling`. + +### R6 (optional, stop): Release without the PAT secret + +- **Purpose:** the strongest proof that the PAT is out of the tag and release path. +- **Precondition:** the user agrees to delete the `GIT_USER_TOKEN` secret of `R` (Phase A of LT can no longer run without it; the value must be re-supplied to restore it). +- **Step:** `gh secret delete GIT_USER_TOKEN -R $R`, then R2's trigger. +- **Expected:** RELEASE(26.4.11), E1–E8 with E7 Phase B, T1, T2, T4. `Secret GIT_USER_TOKEN is required, but not provided` is a FAIL (D3 missing). +- **Also run M1's spare replay (`7e81a3a8442`) afterwards** to show the main CI does not need the secret either. + +--- + +## 5. Pass criteria for the ticket + +The acceptance criteria of PFM-ISSUE-34282 are met when: + +| Acceptance criterion | Shown by | +|---|---| +| In-repo tag and release authenticate via `GITHUB_TOKEN` | R1/R2/R3: tag pushed with no canary run (E7 Phase B), T2 clean; `github-release` author `github-actions[bot]`; P13; R6 (if run) | +| Least-privilege, job-scoped permissions | T1 in R0, R1, M2: only `release` and `github-release` hold `Contents: write`; no unlisted scope; R5 | +| The shared user PAT is no longer used for tagging/releasing | P12/P13 (no `GIT_USER_TOKEN` in the flow), E7 Phase B, R6 | +| Builds and publishes still work | R1/R2 (release artifacts, tag, release notes), M1/M2 (snapshots on `main`), R3/R4 (recovery) | +| No regression for unmigrated consumers | P12: `fe-tag.yml`/`fe-release.yml` reusables unchanged | + +Any failed row stops the series (LT 2.1). Do not fix forward: record it, fix it on `FB`, recreate the test branch (T1) and rerun from the failed case. + +--- + +## 6. Report + +`$OUT/results.md` holds: +- the case table (ID, run ids and attempts, verdict, note); +- the PAT vs. `GITHUB_TOKEN` comparison: + + | | PAT baseline (`26.4.7`, run `42292826750`) | 34282 (R1) | + |---|---|---| + | `release` job token scope | `Contents: read` | `Contents: write` | + | Canary run on the new tag | `42297425544`, actor `squad-fe` | none | + | `GIT_USER_TOKEN` declared | yes | no | + | GitHub release author | `github-actions[bot]` | `github-actions[bot]` | + +- the `main` permissions (M1, M2) per job; +- deviations, each with its evidence file. + +Copy the case table and the comparison into the PFM-ISSUE-34282 PR description as the live-validation evidence. + +**Cleanup:** none beyond the throwaway branches (`test/ceiling`). Tags, releases, test tarballs and the migrated `main` stay (user decision for this test repo). The `github-actions` test branch is deleted only after the user confirms (stop). If R6 deleted secrets, ask whether to restore them. + +--- + +## 7. Settled by the design + +1. **`release` permissions**: `contents: write` only (D2). The caller template already grants it, so R0 must not fail at startup. +2. **Identity step**: kept for PFM-ISSUE-34286 (D5). No rule checks for a missing identity, and R6 deletes only `GIT_USER_TOKEN`. +3. **`fe-main.yml`**: unchanged (D7, narrowing is PFM-ISSUE-35504). M1 is a plain regression check. +4. **Credential style**: the persisted default `GITHUB_TOKEN` of the checkout (D1). No push-only credential, so no `extraheader` check. diff --git a/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/plan.md b/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/plan.md new file mode 100644 index 0000000..e127572 --- /dev/null +++ b/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/plan.md @@ -0,0 +1,425 @@ +--- +date: 2026-11-11 +branch: improvement/PFM-ISSUE-34282-Use-GITHUB_TOKEN-with-scoped-permissions-for +git_commit: 87feb8e4218d9fe87791883f9f683ddca3106e05 +topic: "PFM-ISSUE-34282 - Use GITHUB_TOKEN with scoped permissions for in-repo tag and release" +tags: [plan, github-actions, fe-release-flow, github-token, permissions, pat] +status: draft +--- + +# Use GITHUB_TOKEN with scoped permissions for in-repo tag and release - Implementation Plan + +## Overview + +The consolidated FE release flow (`fe-release-flow.yml`, PR #183) pushes its `version/X.Y.Z` tag with the +built-in `GITHUB_TOKEN` instead of the shared user PAT `GIT_USER_TOKEN`. The `release` job gets +`contents: write` and nothing else. `GIT_USER_TOKEN` leaves the flow's secret contract. The template header, +README and the 34283 Q10 note describe the new state. The live test plan is aligned with the design and run in +`clone-cplace-fe`. + +## Current State Analysis + +- The only PAT use on the tag/release path is the `release` job checkout: + `token: ${{ secrets.GIT_USER_TOKEN }}` (`.github/workflows/fe-release-flow.yml:117-121`). Checkout persists + it in `.git/config`. The artifacts tool's `git push origin ` (`tools/scripts/artifacts/artifacts-handler.ts:313`) + and the cleanup's `git ls-remote --exit-code` (`fe-release-flow.yml:176`) use it implicitly. +- The `release` job declares `contents: read` (`fe-release-flow.yml:110-111`). That works only because the PAT, + not `GITHUB_TOKEN`, carries the push. +- `GIT_USER_TOKEN` is declared `required: true` in `workflow_call.secrets` (`fe-release-flow.yml:24-25`). +- Every other job already narrows: `guard`, `install-deps`, `build`, `e2e` = `contents: read`; + `github-release` = `contents: write` with `GH_TOKEN: ${{ github.token }}` (`:198-222`). +- The caller template grants `permissions: contents: write` and passes `secrets: inherit` + (`.github/workflow-templates/fe/fe-release.yml:18-19`, `:32`). Its header (`:1-5`) still says the flow + "pushes the tag with the PAT". +- README describes the PAT tag push (`README.md:54-59`), lists `GIT_USER_TOKEN` as required (`:86-88`), and + says only the GitHub release uses `GITHUB_TOKEN` (`:146`). +- `actionlint` (`/c/Users/VladimirArsov/go/bin/actionlint`) is installed and passes on the current flow. +- The only spec file on the branch is `live-test-plan.md`. It still lists design decisions as open (section 1 + "There is no design or plan yet", rows D2/D5/D7, section 7) and has stale README line references in D9. + +## Desired End State + +- `fe-release-flow.yml`: no `GIT_USER_TOKEN` anywhere; `release` job `permissions: contents: write` only; the + release checkout has no `token:` and keeps `fetch-depth: 0`; guard check unchanged, guard comment reworded. +- No scope other than `contents` is granted anywhere in `fe-release-flow.yml`. +- The deprecated reusables `fe-tag.yml` and `workflows/fe-release.yml`, the `fe-main.yml` template, the TS + artifacts tool and the "Configure git user" step are unchanged. +- Template header and README describe the `GITHUB_TOKEN` tag push, the secret list has no `GIT_USER_TOKEN`, + and README has a tag-ruleset note. The 34283 design's Q10 bullet carries the same ruleset note. +- `live-test-plan.md` matches the design; the live series has run in `clone-cplace-fe` with the results + recorded. +- `research.md`, `design.md` and `plan.md` are committed on the branch. + +Verify with the automated checks of each phase and with the live test plan (Phase 4). + +### Key Discoveries: +- Pattern for the checkout: `.github/workflows/fe-snapshot.yml:26-29` (34285 precedent, commit `faa4771`): + `actions/checkout` with `ref` and `fetch-depth: 0`, no `token:`. +- Pattern for the secret contract: `fe-snapshot.yml:12-18` after 34285 (the declaration is simply removed). +- The caller grant is a ceiling: requesting a scope the caller does not grant fails every migrated consumer at + startup (research §4). `contents: write` is already granted, so the switch needs no caller change. +- `secrets: inherit` means an undeclared secret is simply not passed (research §4); removing the declaration + needs no caller change. +- The guard still has a purpose after the switch: an old tag-push caller would publish manually pushed tags, + and an old `fe-tag.yml` caller would tag in parallel with the PAT (design, "Docs, template header and guard + wording"). +- Q10 exists in the 34283 design only as the out-of-scope bullet at + `specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md:97`. +- Commit message style on this branch: `PFM-ISSUE-34282 - ` plus the `Co-Authored-By` + trailer. + +## What We're NOT Doing + +- Isolating the write token from third-party code (`persist-credentials: false` with a push-only credential, + or a separate tag-push job). +- A pre-publish push-rights or ruleset check. +- Removing the "Configure git user" step or `GIT_USER` / `GIT_USER_EMAIL` (PFM-ISSUE-34286). +- Narrowing `fe-main.yml` or the other FE templates' permissions (PFM-ISSUE-35504), including the stale + `actions: write` in cplace-fe `push_main.yaml`. +- Changing the deprecated `fe-tag.yml` / `workflows/fe-release.yml` reusables. +- Changing the guard's check or its error message. +- Changing the TS artifacts tool. +- JFrog secret changes; the backend credential-store approach. +- Deleting `GIT_USER_TOKEN` from any production repo. + +## Implementation Approach + +Three edits in one job of `fe-release-flow.yml` make the switch; everything else is wording. The workflow +change comes first and is verified statically. Docs and the live test plan follow, since the live test plan's +preflight P12 checks the docs (D9) as part of the expected state. The end-to-end proof is the live series in +`clone-cplace-fe` (Phase 4): phases 2 and 3 change no runtime behaviour, so it directly follows the code +change. + +The spec documents are committed in Phase 1 so the branch carries research, design and plan for review. + +--- + +## Phase 1: Workflow change + +### Overview +Switch the `release` job to the persisted default `GITHUB_TOKEN` with `contents: write`, drop +`GIT_USER_TOKEN` from the secret contract, reword the guard comment. Commit the spec documents. + +### Changes Required: + +#### 1. Spec documents +**Files**: `specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/research.md`, `design.md`, `plan.md` +**Changes**: Commit all three (they are untracked; `research.md` was removed from the branch in `0d0206b` and +is re-added on the user's decision). Separate commit from the workflow change, e.g. +`PFM-ISSUE-34282 - Add research, design and implementation plan`. Do not add `dist/`. + +#### 2. Secret contract +**File**: `.github/workflows/fe-release-flow.yml` +**Changes**: Remove the `GIT_USER_TOKEN` declaration (`:24-25`). `GIT_USER`, `GIT_USER_EMAIL`, JFrog, +`DOT_NPMRC` and `PERCY_TOKEN` stay. + +```yaml + DOT_NPMRC: + required: true + GIT_USER: + required: true + GIT_USER_EMAIL: + required: true + PERCY_TOKEN: + required: false +``` + +#### 3. `release` job permissions and checkout +**File**: `.github/workflows/fe-release-flow.yml` +**Changes**: `contents: read` → `contents: write` (`:110-111`); remove `token:` from the checkout (`:121`). + +```yaml + runs-on: ubuntu-latest + permissions: + contents: write + outputs: + ... + steps: + - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 + with: + ref: '' + fetch-depth: 0 +``` + +No other step of the job changes: the identity step stays (34286), the artifacts step and the cleanup use the +persisted credential. + +#### 4. Guard comment +**File**: `.github/workflows/fe-release-flow.yml` +**Changes**: Reword the comment at `:59-61`. The "fail on the tags of this flow" part goes (those tags no longer +trigger anything). The `run:` script, including the error message, stays byte-identical. + +```yaml + # an old tag-push caller would publish manually pushed version/* tags; an old fe-tag.yml caller + # (branch push) would tag in parallel with the PAT. Any trigger counts, comment lines do not + # (a commented-out caller is not active). +``` + +Commit the workflow change separately, e.g. +`PFM-ISSUE-34282 - Push the release tag with GITHUB_TOKEN instead of the PAT`. + +### Success Criteria: + +#### Automated Verification: +- [x] `actionlint .github/workflows/fe-release-flow.yml` reports no error +- [x] `git grep -n GIT_USER_TOKEN -- .github/workflows/fe-release-flow.yml` is empty +- [x] The only `write` scope lines in the flow are in `release` and `github-release`, and no scope other than + `contents` appears: `grep -nE '^\s+(contents|checks|pull-requests|issues|actions|packages|id-token|statuses|deployments):' .github/workflows/fe-release-flow.yml` + lists six `contents:` lines (`guard`, `install-deps`, `build`, `e2e` = `read`; `release`, + `github-release` = `write`) and nothing else +- [x] No checkout in the flow passes a token: `grep -n 'token:' .github/workflows/fe-release-flow.yml` (case-sensitive, + so `GH_TOKEN:` / `PERCY_TOKEN:` do not match) is empty, and the `release` checkout still has `fetch-depth: 0` +- [x] The guard script is unchanged: `git diff origin/improvement/PFM-ISSUE-34283-Consolidate-the-FE-2-0-release-flow-into-a-master -- .github/workflows/fe-release-flow.yml` + touches only the secret declaration, the guard comment lines, the `release` permission and the checkout `token:` line +- [x] Deprecated reusables, `fe-main.yml`, `fe-snapshot.yml` and the artifacts tool unchanged against PR #183: + `git diff --stat origin/improvement/PFM-ISSUE-34283-Consolidate-the-FE-2-0-release-flow-into-a-master -- .github/workflows/fe-tag.yml .github/workflows/fe-release.yml .github/workflow-templates/fe/fe-main.yml .github/workflows/fe-snapshot.yml tools/ .github/actions/` + is empty +- [x] `research.md`, `design.md` and `plan.md` are tracked: `git ls-files specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions` + lists all four spec files; `git ls-files dist` is empty +- [x] **HUMAN CHECKPOINT**: Call `AskUserQuestion` now with the question: "Phase 1 complete. Summary: release job now `contents: write` with the persisted default token, `GIT_USER_TOKEN` removed from the secret contract, guard comment reworded, spec documents committed. Please review the changes and reply 'yes' to continue to Phase 2." Do NOT proceed until the user explicitly approves. This checkpoint cannot be skipped or pre-checked. + +#### Manual Verification: +- [x] The diff of `fe-release-flow.yml` reads as the three-line switch plus the comment, nothing else + +--- + +## Phase 2: Docs, template header and 34283 Q10 note + +### Overview +Describe the `GITHUB_TOKEN` tag push everywhere the PAT push is described; add the tag-ruleset note. + +### Changes Required: + +#### 1. Caller template header +**File**: `.github/workflow-templates/fe/fe-release.yml` +**Changes**: Replace `:1-5`. Nothing below the header changes (`contents: write` ceiling, concurrency, +`secrets: inherit` stay). + +```yaml +# Replaces the old two-file release (this file as tagger + fe-tag-pushed.yml / on_tag_pushed.yaml / tag_pushed.yml). +# Delete BOTH old caller files in the same commit that adds this one: a tag-push workflow left in the tree +# would release manually pushed version/* tags, and an old fe-tag.yml caller would tag in parallel. The +# release flow's guard job fails while an old caller exists. The flow pushes its tag with GITHUB_TOKEN, +# which starts no workflow. +``` + +#### 2. README migration note +**File**: `README.md` +**Changes**: Replace the sub-bullets of step 2 (`:54-59`). + +```markdown +2. **Delete the old release callers**: `fe-release.yml` as tagger, plus `fe-tag-pushed.yml` / + `on_tag_pushed.yaml` / `tag_pushed.yml`. + - The release flow pushes its tag with `GITHUB_TOKEN`, which starts no workflow. A tag-push + workflow left in the tree would still release manually pushed `version/*` tags, and an old + `fe-tag.yml` caller would tag in parallel. + - The `guard` job fails while any workflow of the branch still calls `workflows/fe-release.yml` or + `workflows/fe-tag.yml`. +``` + +#### 3. README required secrets +**File**: `README.md` +**Changes**: Replace `:86-88`. + +```markdown +Passed with `secrets: inherit`: `JFROG_BASE64_TOKEN`, `JFROG_URL`, `JFROG_USER`, `DOT_NPMRC`, +`GIT_USER`, `GIT_USER_EMAIL`, and optionally `PERCY_TOKEN`. The caller needs +`permissions: contents: write`; the flow grants it only to the `release` and `github-release` jobs. + +The tag is pushed with `GITHUB_TOKEN`; the flow does not use `GIT_USER_TOKEN`. The deprecated +`fe-tag.yml` and `workflows/fe-release.yml` still need it: remove it from a repo only once none of +its branches calls them. +``` + +#### 4. README tag-ruleset note +**File**: `README.md` +**Changes**: New subsection between "Required secrets" and "Recovery". + +```markdown +### Tag rulesets + +The tag is pushed as GitHub Actions (`GITHUB_TOKEN`), after publish and promote. A ruleset that +restricts `version/*` tags must list GitHub Actions as a bypass actor. Otherwise the push is +rejected, the cleanup unpublishes the version, and the promoted packages lose `release-X.Y` (see +"Promote or tag push failed" under Recovery). +``` + +#### 5. README GitHub release section +**File**: `README.md` +**Changes**: `:146` "Created with `GITHUB_TOKEN`." → "Created with `GITHUB_TOKEN`, like the tag." + +#### 6. 34283 Q10 note +**File**: `specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md` +**Changes**: Extend the out-of-scope bullet at `:97`. + +```markdown +- A `version/*` tag ruleset or a tag-triggered recovery path (Q10, deferred). Since PFM-ISSUE-34282 the + tag is pushed with `GITHUB_TOKEN`: such a ruleset must list GitHub Actions as a bypass actor, otherwise + the push is rejected after publish and promote. +``` + +Commit, e.g. `PFM-ISSUE-34282 - Describe the GITHUB_TOKEN tag push in the docs`. + +### Success Criteria: + +#### Automated Verification: +- [x] No PAT tag-push wording left: `grep -nE 'with the PAT|GIT_USER_TOKEN|removes the tag-push trigger' README.md .github/workflow-templates/fe/fe-release.yml` + returns only the README sentence that the deprecated reusables still need `GIT_USER_TOKEN` +- [x] README has the ruleset note: `grep -n '### Tag rulesets' README.md` matches, placed before `### Recovery` +- [x] Template body unchanged below the header: `git diff origin/improvement/PFM-ISSUE-34283-Consolidate-the-FE-2-0-release-flow-into-a-master -- .github/workflow-templates/fe/fe-release.yml` + touches only lines 1-5 +- [x] `actionlint` does not apply to templates; check the template still parses: `python -c "import yaml,sys; yaml.safe_load(open('.github/workflow-templates/fe/fe-release.yml'))"` + (or any YAML parser available) exits 0 +- [x] 34283 design carries the note: `grep -n 'bypass actor' specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md` matches +- [x] **HUMAN CHECKPOINT**: Call `AskUserQuestion` now with the question: "Phase 2 complete. Summary: template header, README (migration note, secrets, new Tag rulesets section, GitHub release line) and the 34283 Q10 note now describe the GITHUB_TOKEN tag push. Please review the changes and reply 'yes' to continue to Phase 3." Do NOT proceed until the user explicitly approves. This checkpoint cannot be skipped or pre-checked. + +#### Manual Verification: +- [x] README "FE Release Flow" reads consistently top to bottom (What it does → Migration → Secrets → Tag rulesets → Recovery) + +--- + +## Phase 3: Align the live test plan with the design + +### Overview +Turn the open points of `live-test-plan.md` into the settled expectations, so the plan can run unchanged. + +### Changes Required: + +#### 1. Expected state +**File**: `specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/live-test-plan.md` +**Changes**: +- Frontmatter: `last_updated` to the edit date. +- Section 1 intro: replace "There is no design or plan yet … section 7)" with a sentence that the expected + state follows `design.md` and `plan.md` in the same directory (link both). +- D2: `contents: write` only. +- D5: kept for PFM-ISSUE-34286 (unchanged). +- D7: unchanged (PFM-ISSUE-35504). +- D9: `README.md:54-59`, `:86-88`, new "Tag rulesets" section, `:146`; guard **comment** (message unchanged); + 34283 design Q10 note. + +#### 2. Rules and cases +**File**: same +**Changes**: +- T1: drop "(+ only design additions)" and "unless the design lists them". +- T3 (rule): remove the row (the identity step stays). +- Setup T3 (prepare `main`): drop "If 34282 changes `fe-main.yml` (D7) …". +- M1: drop the "If D7 changed the template" bullet and the "(possibly narrowed)" / "the D7 block if 34282 + narrows the template" wording; M1 is a plain regression check. +- R6: drop the last bullet (`GIT_USER*` deletion). +- T1–T4 references in the case table and cases become T1, T2, T4. +- Section 7: replace the open points with a short "Settled by the design" list: `release` = `contents: write` + only; identity step kept (T3 and the `GIT_USER*` part of R6 do not apply); `fe-main.yml` unchanged (M1 is a + regression check); persisted default credential (open point 4 dropped). + +Commit, e.g. `PFM-ISSUE-34282 - Align the live test plan with the design`. + +### Success Criteria: + +#### Automated Verification: +- [x] No open-decision wording left: `grep -nE 'design\*|There is no design|depend on a decision|If D5|If D7|only design additions|unless the design' specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/live-test-plan.md` + is empty +- [x] No reference to rule T3: `grep -nE '\bT3\b' …/live-test-plan.md` matches only the setup step "T3: Prepare `main`" + and its references +- [x] D9's README line references (PR #183 state) point at the PAT/secret text that Phase 2 replaced: check each + cited range with `git show origin/improvement/PFM-ISSUE-34283-Consolidate-the-FE-2-0-release-flow-into-a-master:README.md | sed -n 'p'` +- [x] **HUMAN CHECKPOINT**: Call `AskUserQuestion` now with the question: "Phase 3 complete. Summary: live-test-plan.md now states the settled expectations (release = contents: write only, identity kept, fe-main unchanged); rule T3 and the GIT_USER* part of R6 removed; section 7 replaced. Please review the changes and reply 'yes' to continue to Phase 4 (live tests in clone-cplace-fe)." Do NOT proceed until the user explicitly approves. This checkpoint cannot be skipped or pre-checked. + +#### Manual Verification: +- [x] Section 1's Expected column matches the Phase 1 and Phase 2 diffs row by row + +--- + +## Phase 4: Live validation in `clone-cplace-fe` + +### Overview +Run `live-test-plan.md` against the branch. It is the end-to-end proof that the tag and release work with +`GITHUB_TOKEN` and that nothing else regressed. Follow the plan exactly; it reuses the 34283 live-test document +(LT) for environment, helpers, preflight and expected-state rules. + +### Changes Required: + +#### 1. Setup (live-test-plan section 2.3) +- **T1**: build `test/PFM-ISSUE-34282-github-token` from the pushed feature branch (rewrite internal `@master` + refs, drop e2e). **Stop before the push to `github-actions`** (LT 2.1). Requires phases 1-3 pushed to the + feature branch first, which is also a stop. +- **T2**: switch the release caller on `release/26.4` → case R0. +- **T3**: prepare `main` (new caller, delete old callers, `push_main.yaml` refs) → case M0. +- **T4**: preflight LT P1-P11 plus P1m, P12-P15. + +#### 2. Cases (live-test-plan section 4), in order, one at a time +R0, M0, **R1**, **M1**, **M2**, R2, R3, R4, R5. R6 only after the user explicitly agrees to delete the +`GIT_USER_TOKEN` secret of `clone-cplace-fe` (stop). Compute `N` per case from its before-snapshot. + +A failed row stops the series: record it, fix on the feature branch, recreate the test branch (T1), rerun from +the failed case (live-test-plan section 5). No teardown beyond throwaway branches (project memory); delete the +`github-actions` test branch only after the user confirms. + +#### 3. Results +**File**: `$OUT/results.md` (live-test working directory, per LT) and the PR #189 description +**Changes**: case table, PAT vs. `GITHUB_TOKEN` comparison, `main` permissions per job, deviations with evidence +(live-test-plan section 6). Copy the case table and comparison into the PR description. + +### Success Criteria: + +#### Automated Verification: +- [x] Preflight P12-P15 pass (static diff matches D1-D9, `GIT_USER_TOKEN` absent on the test branch flow, + actionlint clean, `default_workflow_permissions: read`) +- [x] R0: no startup failure, no `Secret GIT_USER_TOKEN is required` annotation (T4) +- [x] R1/R2/R3 attempt 2: RELEASE(N) E1-E8 with E7 Phase B (no run of any workflow for `version/N`), T1 + (`release` = `Contents: write`, `Metadata: read` only), T2 (no auth error in the `release` log) +- [x] R3 attempt 1: `ls-remote` exit code 2 path taken (`was not pushed: unpublishing its artifacts`), all + `*-N.tgz` removed +- [x] M1/M2: S1-S5; M2 `release` holds `Contents: write`, no `git push` in its log +- [x] R4: idempotent re-run, recreated release authored by `github-actions[bot]` +- [x] R5: rejected at startup, no job started +- [x] R6 (if agreed): RELEASE(N) with the secret deleted — skipped: the user chose not to delete the secret +- [x] **HUMAN CHECKPOINT**: Call `AskUserQuestion` now with the question: "Phase 4 complete. Summary: live series in clone-cplace-fe [list cases and verdicts, run ids]; results recorded in results.md and the PR description. Please review the results and reply 'yes' to finish." Do NOT proceed until the user explicitly approves. This checkpoint cannot be skipped or pre-checked. + +#### Manual Verification: +- [x] The R1 GitHub release and tag look right in the `clone-cplace-fe` UI (lightweight tag on the pushed SHA, + release notes range `version/26.4.7...version/26.4.8`) +- [x] The PR #189 description carries the case table and the PAT vs. `GITHUB_TOKEN` comparison + +--- + +## Testing Strategy + +### Unit Tests: +- None. The TS artifacts tool is unchanged; the change is workflow YAML and docs. + +### Static checks: +- `actionlint` on `fe-release-flow.yml`; greps for `GIT_USER_TOKEN` and granted scopes; `git diff` against the + PR #183 branch to prove the deprecated reusables, `fe-main.yml`, `fe-snapshot.yml` and the tool are untouched. + +### Integration Tests: +- The live series in `clone-cplace-fe` (Phase 4): release on `release/26.4` (R1-R4), main CI and forced + release-flow dispatch on `main` (M0-M2), the permission ceiling (R5), and optionally a release without the + PAT secret (R6). + +### Manual Testing Steps: +1. After R1, confirm there is no canary run for `version/26.4.8` and the `release` job's + `GITHUB_TOKEN Permissions` group shows `Contents: write`, `Metadata: read`. +2. After R3 attempt 1, confirm the cleanup log took the exit-code-2 branch. +3. After R5, confirm the startup error names `release` and `github-release`. + +## Performance Considerations + +None. The job structure and step count are unchanged. + +## Migration Notes + +- Migrated consumers need no change: the template's `contents: write` ceiling and `secrets: inherit` already + cover the switch. The change reaches them when `fe-release-flow.yml@master` is updated (after PR #183 and this + PR are merged). +- Unmigrated consumers keep using the deprecated reusables with the PAT. +- A repo can drop `GIT_USER_TOKEN` once none of its branches calls the deprecated reusables (README). +- Rollback: revert the Phase 1 workflow commit; the PAT secret is still present in every repo. + +## References + +- Research: [Research Document](./research.md) +- Design: [Design Document](./design.md) +- Live test plan: [live-test-plan.md](./live-test-plan.md) +- Original ticket: [PFM-ISSUE-34282](https://base.cplace.io/pages/p9vu89ujy61fxb2nrrp6focwy/PFM-ISSUE-34282-Use-GITHUB-TOKEN-with-scoped-permissions-for-in-repo-tag-and-release) +- Base: [34283 design](../2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md), [34283 live tests](../2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/clone-cplace-fe-live-tests.md) +- Similar implementation: `.github/workflows/fe-snapshot.yml:12-18`, `:26-29` (PFM-ISSUE-34285, commit `faa4771`) diff --git a/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/research.md b/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/research.md new file mode 100644 index 0000000..72033f1 --- /dev/null +++ b/specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/research.md @@ -0,0 +1,299 @@ +--- +date: 2026-10-26T17:16:49+01:00 +git_commit: 87feb8e4218d9fe87791883f9f683ddca3106e05 +branch: improvement/PFM-ISSUE-34282-Use-GITHUB_TOKEN-with-scoped-permissions-for +topic: "PFM-ISSUE-34282 - Use GITHUB_TOKEN with scoped permissions for in-repo tag and release" +tags: [research, codebase, github-actions, fe-release-flow, github-token, permissions, pat, git-user-token] +status: complete +last_updated: 2026-11-11 +last_updated_note: "Refreshed against PR #183 head 4666f60 (via 87feb8e): updated line references; added the promote phase, the ls-remote exit-code handling, the guard's comment handling and the fe-main.yml concurrency change" +--- + +# Research: Use GITHUB_TOKEN with scoped permissions for in-repo tag and release + +**Date**: 2026-10-26T17:16:49+01:00, refreshed 2026-11-11T11:41:22+01:00 +**Git Commit**: 87feb8e4218d9fe87791883f9f683ddca3106e05 (first version: 69021ec) +**Branch**: improvement/PFM-ISSUE-34282-Use-GITHUB_TOKEN-with-scoped-permissions-for, based on PR #183 head `4666f60` + +## Research Question + +How does the FE release flow authenticate its in-repo tag and release today? What has to change to move it to the built-in `GITHUB_TOKEN` with least-privilege, job-scoped permissions, following the backend pattern? Which of the ticket's candidate permissions actually have a consumer? + +The research builds on PR #183 (PFM-ISSUE-34283). That PR replaces `fe-tag.yml` + `fe-release.yml` with one consolidated flow: the reusable `.github/workflows/fe-release-flow.yml`, called from the `.github/workflow-templates/fe/fe-release.yml` caller template. 34282 applies to that consolidated flow, not to the deprecated pair. + +**Refresh (2026-11-11).** The first version was recorded at `69021ec`. PR #183 has had 11 more commits since (live tests and review fixes, up to `4666f60`). They changed `fe-release-flow.yml`, `fe-main.yml`, `README.md` and the artifacts tool. Every line reference below is re-checked against `87feb8e`. The section "Changes since the first version" lists what changed and how it affects this ticket. + +## PFM Ticket Context + +- **Ticket**: [PFM-ISSUE-34282](https://base.cplace.io/pages/p9vu89ujy61fxb2nrrp6focwy/PFM-ISSUE-34282-Use-GITHUB-TOKEN-with-scoped-permissions-for-in-repo-tag-and-release) +- **Title**: Use GITHUB_TOKEN with scoped permissions for in-repo tag and release +- **Type**: PFM Issue, Groundwork (priority high, status Working) +- **Target Release**: not set +- **Assignee**: Vladimir Arsov +- **Epic**: WP-1963 Modernize FE 2.0 Frontend Workflow Authentication +- **Relations**: blocked by PFM-ISSUE-34283 (release-flow consolidation, PR #183); relates to PFM-ISSUE-33676 (replace the shared GitHub user account in frontend workflows) +- **Suggested Branch**: `improvement/PFM-ISSUE-34282-Use-GITHUB_TOKEN-with-scoped-permissions-for` (exists; draft PR #189, based on the PR #183 branch) +- **Description**: + + > **Description** + > Switch `fe-tag.yml` / `fe-release.yml` to the built-in `GITHUB_TOKEN` for in-repo tag and release, scoped narrowly to the release/tag job. This follows the backend pattern and removes the shared user PAT from the tagging/release path. + > + > **Requirements** + > - Grant `GITHUB_TOKEN` **only on the release/tag job** (not workflow-wide), so build/test/install jobs that run third-party code do not inherit write scope. + > - Baseline permissions: `contents: write`, `checks: write`, `pull-requests: write`. + > - Confirm whether `issues: read` and `actions: write` are actually needed (current FE templates run `actions: read` and no `issues`) and drop any without a consumer. + > - Remove use of the shared user PAT for tagging/releasing. + > + > **Acceptance Criteria** + > - In-repo tag/release authenticates via `GITHUB_TOKEN` with least-privilege, job-scoped permissions. + > - The shared user PAT is no longer used for tagging/releasing. + > + > **Dependencies** + > Depends on the release-flow consolidation (applied to the already-consolidated workflow). Relates to PFM-ISSUE-33676. + + The ticket was written before #183 and names `fe-tag.yml` / `fe-release.yml`. After #183, the target is `fe-release-flow.yml` and its caller template. The user confirmed this scope. + +## Summary + +- **One remaining PAT use.** The shared user PAT is used for tagging/releasing in exactly one place: the `release` job's checkout, `token: ${{ secrets.GIT_USER_TOKEN }}` (`fe-release-flow.yml:121`). Checkout persists that credential into `.git/config`. Two things then use it implicitly: + - the artifacts tool's `git push origin ` (`artifacts-handler.ts:313`); + - the failure cleanup's `git ls-remote --exit-code` (`fe-release-flow.yml:176`). + + Nothing in the tool handles a token itself. The GitHub release is already created with `github.token` in the `github-release` job (`fe-release-flow.yml:198-222`). +- **The switch is small.** + - Drop `token:` from the release checkout. The default is `github.token`. + - Raise the `release` job from `contents: read` (`:110-111`) to `contents: write`. + - Remove the `GIT_USER_TOKEN` secret declaration (`fe-release-flow.yml:24-25`). + - The caller template already grants `contents: write` at workflow level and uses `secrets: inherit`. No consumer change is needed, so removing a declared secret is safe. +- **Permissions without a consumer.** Of the ticket's baseline, only `contents: write` has a consumer in the release flow. Nothing in `fe-release-flow.yml`, the nested `fe-install-deps` / `fe-build` / `fe-e2e` workflows or the composite actions calls the Checks, Pull Requests, Issues or Actions APIs. Re-checked on `87feb8e`. + - `checks: write`, `pull-requests: write`, `issues: read`, `actions: read` and `actions: write` all lack a consumer here. + - The four-scope block in the other FE templates is inherited boilerplate. The only real `pull-requests`/`issues` consumer in the FE workflows is the PR comment in `fe-pr-snapshot.yml:76-88`, which is not part of the release flow. + - Under "drop any without a consumer", the least-privilege answer is `contents: write` on the tag job, `contents: write` on the GitHub release job, and `contents: read` everywhere else. +- **Job-scoping is largely done already.** #183 gives every job its own `permissions:` block (`guard`, `install-deps`, `build`, `e2e` = `contents: read`; `github-release` = `contents: write`). The caller's `contents: write` is only a ceiling. What 34282 adds is moving `release` to write. + - The `release` job itself runs `npm ci` and the TypeScript artifacts tool (third-party code) in the same job that holds the write token. + - Today that job holds the broader PAT, so the switch reduces exposure. Write scope is still not fully isolated from third-party code (see Architecture Insights). +- **The order inside the `release` job is now publish → promote → tag** (new since the first version). A tag push that fails comes after `release-X.Y` was moved on every package. The cleanup then unpublishes the version, and the promoted packages lose `release-X.Y` until the next release (README Recovery, `README.md:94-99`). A token that cannot push therefore costs more than before. Two cases that only surface at the push: + - a missing `contents: write` on a nested job is **not** one of them: it fails at startup, before anything is published; + - a future `version/*` tag ruleset without a bypass for GitHub Actions **would** be one. +- **The tag-push trigger goes away.** A tag pushed with `GITHUB_TOKEN` does not trigger other workflows. + - That was the reason for the old two-run design, and why an earlier attempt was reverted (commits d6542fe/a416ad2, 2023-11). After #183 nothing needs that trigger. + - A leftover `fe-tag-pushed.yml` / `on_tag_pushed.yaml` in a migrated tree can then no longer double-publish. + - The README (`:54-59`) and the template header (`fe-release.yml:1-5`) already promise this for 34282 and must be updated. +- **Backend pattern** (`cplace-gh-workflows`, PAT removed in commit 18ea38f3, 2024-01-19): + - `GITHUB_TOKEN` is written to a credential store by `prepare-git-environment`, and the checkout uses `persist-credentials: false`. + - The `gh` CLI uses `GH_TOKEN: ${{ github.token }}`. + - The git identity is `github.actor` / `cplace@github.com`. + - GitHub Apps remain for cross-repo access and protected-branch pushes only. + - The backend does not declare job-level permissions on `publish.yml`; it relies on the caller's grant. The FE flow after #183 is already stricter than the backend. + +## Changes since the first version (69021ec → 87feb8e) + +| Area | Change | Effect on 34282 | +|---|---|---| +| `fe-release-flow.yml` guard (`:59-68`) | The grep ignores comment lines (`^[^#]*…`); a commented-out old caller no longer fails the guard. The comment now also names old `fe-tag.yml` callers (branch push), which would tag in parallel. | The guard keeps a purpose after 34282: an old `fe-tag.yml` caller would still tag in parallel with the PAT. Only the "a PAT-pushed tag re-fires a tag-push caller" part of its rationale goes away. | +| `fe-release-flow.yml` cleanup (`:163-186`) | `git ls-remote --exit-code` result split: 0 = tag pushed, 2 = not pushed (unpublish), anything else (auth, network) = error, nothing unpublished. | The cleanup reads the remote with the persisted checkout credential. With `GITHUB_TOKEN` (`contents: read` is enough to read) this keeps working. If the credential were missing, the step would now fail loudly instead of unpublishing a release whose tag may exist. | +| Artifacts tool: staging and promote (`artifacts-handler.ts:293-309`, `nx-project.ts:356-403`) | Release packages are published under `release-X.Y-pending`. A promote phase (`npm dist-tag add`/`rm` against JFrog) moves `release-X.Y` before the tag push. | No GitHub token involved (JFrog credentials only). It raises the cost of a failed tag push: see Summary. | +| Artifacts tool: `[branch-off]` with force (`artifacts-handler.ts:118-127`) | A forced dispatch on a `[branch-off]` tip ends with the warning "FORCE is ignored". | None. | +| Artifacts tool: version calculation (`utils.ts:198-223`) | `nextVersion(branch, previous)` extracted; behaviour unchanged. | None. | +| `fe-install-deps.yml` | The job-level `concurrency` (cancel superseded runs) was removed in #183; each caller decides. | It was not a consumer of `actions:` (`concurrency` needs no token scope). The consumer `push_main.yaml:9` comment ("actions: write … for cancel-workflow-action") in cplace-fe is stale. | +| `fe-main.yml` template (`:14-16`) | The `concurrency` group was removed: every push to main must publish its snapshot. The four-scope `permissions:` block (`:8-12`) is unchanged. | See section 3a: the main chain has no consumer for any scope beyond `contents: read`. | +| README | New: the publish → promote → tag order, the staging tag, the extended Recovery section, the concurrency table. Unchanged: the 34282 migration note (`:54-59`) and the secret list (`:84-88`). | Text to update moves to new lines (section 8). | + +## Detailed Findings + +### 1. Current authentication in the consolidated flow (`fe-release-flow.yml`) + +**Secret contract and top-level permissions** +- Declared secrets (`fe-release-flow.yml:15-31`): + - JFrog/npm: `JFROG_BASE64_TOKEN`, `JFROG_URL`, `JFROG_USER`, `DOT_NPMRC`. Out of scope; the JFrog secret split is a separate EPIC-1963 item. + - Shared user: `GIT_USER_TOKEN` (`:24-25`), `GIT_USER` (`:26-27`), `GIT_USER_EMAIL` (`:28-29`), all `required: true`. + - Optional: `PERCY_TOKEN` (`:30-31`). +- There is no workflow-level `permissions:`. Every job declares its own. + +**Per-job permissions and token use** + +| Job | Lines | `permissions` | Token use | +|---|---|---|---| +| `guard` | 38-68 | `contents: read` (`:40-41`) | Dispatch-ref check (`:43-52`). Sparse checkout of `.github/workflows`, default token, `persist-credentials: false` (`:54-57`). Fails if a non-comment line of any workflow references `fe-release.yml@` / `fe-tag.yml@` (`:62-68`). | +| `install-deps` | 70-78 | `contents: read` (`:72-73`) | Nested `fe-install-deps.yml@master`, default-token checkout, `DOT_NPMRC` only. | +| `build` | 80-87 | `contents: read` (`:82-83`) | Nested `fe-build.yml@master`, default-token checkout. | +| `e2e` | 89-99 | `contents: read` (`:92-93`) | Nested `fe-e2e.yml@master`, `PERCY_TOKEN`. | +| `release` | 101-196 | `contents: read` (`:110-111`) | **Checkout with `token: ${{ secrets.GIT_USER_TOKEN }}`** (`:117-121`, `fetch-depth: 0`), persisted. `npm ci` on cache miss (`:139-141`). `git config user.name/email` from `GIT_USER`/`GIT_USER_EMAIL` (`:143-149`). The artifacts action publishes, promotes, then tags and pushes (`:151-159`). The failure cleanup runs `git ls-remote --exit-code --tags origin` (`:163-186`, call at `:176`), then unpublishes (`:188-196`). | +| `github-release` | 198-222 | `contents: write` (`:203-204`) | No checkout. `GH_TOKEN: ${{ github.token }}` (`:208`). Runs `gh release view` (`:214`) / `gh release create --verify-tag --generate-notes` (`:218-222`). | + +**Why `contents: read` works today:** the PAT, not `GITHUB_TOKEN`, carries the tag push. After the switch the job must declare `contents: write`. A job-level block replaces whatever it would otherwise inherit. + +### 2. Git operations performed by the artifacts tool + +- `.github/actions/artifacts/action.yml` runs `printenv`, `npm ci`, then `npx ts-node tools/scripts/artifacts/main.ts`. It reads no GitHub token env var. `printenv` is harmless for the persisted checkout credential, because that is stored in `.git/config`, not in the environment. +- The release flow path is `tagAndPublishRelease` (`artifacts-handler.ts:225-320`): + - It computes the next version from the previous tag of the line (`Utils.nextVersion`, `:254`) and checks affected projects unless forced. + - It publishes all publishable projects under the staging dist-tag `release-X.Y-pending` (`:296-297`). + - Promote phase (`:302-309`): `NxProject.promote()` runs `npm dist-tag add @ release-X.Y` and `npm dist-tag rm release-X.Y-pending` against JFrog (`nx-project.ts:371-403`). + - Tag phase (`:311-313`): `git tag ${gitTag}`, which creates a **lightweight** tag, and `git push origin ${gitTag}`. + - It writes the `tag` / `previous_tag` / `is_latest` outputs. + - There is no commit, no branch push, and no REST or Octokit call. +- The version file for the cleanup is written to `$RUNNER_TEMP/fe-release-version` before publishing (`utils.ts:19`, `:366-372`). +- The legacy `bumpVersionForReleaseBranch` (`artifacts-handler.ts:203-223`, `git tag`/`git push` at `:211`/`:215`) is used only by the deprecated `fe-tag.yml` (`ONLY_BUMP_VERSION`, `fe-tag.yml:59`). +- Remote reads go through `git ls-remote --tags` in `utils.ts:228`. Affected detection (`npx nx show projects --affected`, `utils.ts:157`) needs full history (`fetch-depth: 0`) but no write access. +- `npm publish` / `npm unpublish` / `npm dist-tag` (`nx-project.ts:115`, `:276`, `:379`, `:393`) use JFrog credentials (`jfrog-credentials.ts:7-12`). This is out of scope. + +### 3. Permission consumers: confirm or drop + +| Scope | Ticket position | Consumer in the release flow chain | Consumer elsewhere in FE workflows | +|---|---|---|---| +| `contents: write` | baseline | Yes: tag push (`artifacts-handler.ts:313`), `gh release create` (`fe-release-flow.yml:222`) | deprecated `fe-tag.yml` (via PAT) | +| `contents: read` | — | checkouts in every job, `git ls-remote` | all | +| `checks: write` | baseline | **None.** No check-run or test-reporter step | None found. It appears only in the template boilerplate. | +| `pull-requests: write` | baseline | **None.** No PR comment or PR creation | `fe-pr-snapshot.yml:76-88` (`actions/github-script`, `issues.*Comment` on the PR). Not in the release chain. | +| `issues: read` | confirm | **None** | None | +| `actions: read` | (templates) | **None.** Cache and artifacts use the runtime token, not `GITHUB_TOKEN` | None. Since #183 removed the job-level `concurrency` from `fe-install-deps.yml`, nothing in the FE chain even looks related. | +| `actions: write` | confirm | **None.** No dispatch, cancel or cache-delete | None in this repo | + +The FE templates' four-scope block appears in `fe-check-upmerge.yml:7-11`, `fe-cleanup-snapshots.yml:7-11`, `fe-licenses.yml:8-12`, `fe-main.yml:8-12`, `fe-pr.yml:7-11`, `fe-pr-close.yml:8-12` and `fe-pr-snapshot.yml:8-12`. It is the probable origin of the ticket's baseline. The new `fe-release.yml` template (`:18-19`) already narrowed to `contents: write` only. + +### 3a. The main chain (`fe-main.yml` template) + +New in this refresh, because the live test plan runs the main CI. +- `fe-main.yml` grants the four-scope block at workflow level (`:8-12`). Its jobs `install-deps`, `e2e-tests`, `build`, `snapshot` call `fe-install-deps`, `fe-e2e`, `fe-build`, `fe-snapshot` `@master` **without** job-level `permissions:` (`:22-56`). Every job of the main chain therefore holds `contents: write`, `pull-requests: write`, `checks: write`, `actions: read`. That includes `npm ci`, the builds and the snapshot publish. +- None of those workflows or the composite actions calls a GitHub API (grep on `87feb8e`: no `github-script`, `gh`, `GH_TOKEN`, `github.token`, `issues.`, `checks`). `fe-snapshot.yml` only checks out (default token, `:26-29`) and publishes to JFrog (`:41-49`). **The main chain needs `contents: read` and nothing else.** +- This is the same "build/install jobs run third-party code with write scope" exposure the ticket names, but on the main CI rather than the tag/release path. It is not covered by the ticket's wording (see Open Questions). +- The consumer `clone-cplace-fe`/`cplace-fe` `push_main.yaml` already grants only `contents: read` and `actions: write`; the `actions: write` comment refers to the cancel action that no longer exists. + +### 4. Caller template and consumers + +- `.github/workflow-templates/fe/fe-release.yml`: + - Triggers on `push` to `release/*` and on `workflow_dispatch(force)` (`:7-16`). + - Grants `permissions: contents: write` at workflow level (`:18-19`). + - Uses a non-cancelling `concurrency` group `fe-release-${{ github.ref }}` (`:21-24`). + - Its single job calls `fe-release-flow.yml@master` with `secrets: inherit` (`:26-32`). + - The header comment (`:1-5`) says the flow "still pushes the tag with the PAT" and that "PFM-ISSUE-34282 ... removes the tag-push trigger for good". 34282 must update it. +- **The caller grant is a ceiling.** A called workflow's jobs can only narrow it; requesting a scope the caller didn't grant fails at validation, before any job starts. The backend has hit this (`cplace-gh-workflows/specs/2026-07-27_build-cache-key-output/plan.md:1081-1104`). Since 34282 needs only `contents: write`, the existing caller grant is enough. Adding `checks`/`pull-requests` to the flow's job would require changing every migrated caller, which is a further reason not to add unused scopes. +- **`secrets: inherit`** was chosen in #183 so that removing `GIT_USER_TOKEN` (34282) and `GIT_USER*` (34286) needs no caller edits (34283 design.md:236, :82-85). Inherited secrets the callee doesn't declare are simply not passed. +- **Unmigrated consumers** still use the old pair with explicit secrets and are unaffected: + - `cplace-2lforge-scores-fe/.github/workflows/fe-release.yml`: `write-all`, explicit `GIT_USER_TOKEN`/`GIT_USER`/`GIT_USER_EMAIL`, `@release/26.1`. + - `cplace-fe/.github/workflows/push_to_release.yaml`: four-scope block, `if: github.event.pusher.name != 'squad-fe'` at `:43`, explicit PAT, `fe-tag.yml@master`. + - Both keep working because 34282 leaves `fe-tag.yml` (`GIT_USER_TOKEN` at `:19`, checkout `token:` at `:37`) as is. The release lines 25.4-26.4 keep the old flow and the PAT until they branch off from a master that has the new flow (34283 design.md:297). + +### 5. Precedent in this repo: PFM-ISSUE-34285 + +Commit faa4771 (2026-10-07, #182) removed `GIT_USER_TOKEN` (declared `required: false`) from the `workflow_call.secrets` of `fe-snapshot.yml` (now `:12-18`, JFrog secrets only). Its checkout already used the default token, so the PAT was never needed there. The pattern was to drop the declaration and the `token:`, and rely on the default `github.token`. + +Note: `cplace-fe/.github/workflows/push_main.yaml:45-49` still passes `GIT_USER_TOKEN` explicitly to `fe-snapshot.yml@master`, which no longer declares it (see Open Questions). + +### 6. Backend pattern (`C:\rr\cplace-gh-workflows`) + +Not re-checked in this refresh (outside this repo, unchanged by #183). + +**Tag/release path.** `publish.yml` and `complete-build.yml`: +- Workflow env `GH_TOKEN: ${{ github.token }} # this variable is used by gh cli` (`publish.yml:34`, `complete-build.yml:111`). +- Checkout with `persist-credentials: false` and no `token:` (`publish.yml:49-53`). +- `prepare-git-environment` is called with `github_token: ${{ secrets.GITHUB_TOKEN }}` before publishing and again right before the tag push (`publish.yml:72-76`, `:87-91`). +- The action writes `https://x-access-token:${token}@github.com` to `~/.git-credentials`, sets `credential.helper store`, `user.email cplace@github.com` and `user.name ${github.actor}` (`.github/actions/prepare-git-environment/action.yml:46-60`). +- The tag push runs `git push --atomic origin "$tag"` with retries (`src/scripts/push_local_tag.sh:75`). +- The release is created with `gh release create --generate-notes` (`src/scripts/publish_github_release_notes.sh:36-49`). + +**Ordering.** Publish artifacts first, then tag push, then GitHub release. #183 has the same order, with the extra promote phase between publish and tag. + +**Permissions.** +- Neither `publish.yml` nor the build chain declares `permissions:`. The consumer caller supplies them. +- Job-level blocks appear only for PR/check writers, e.g. `test.yml:200-203` (`contents: read, checks: write, pull-requests: write`) and `quality-analysis.yml:50-53`. +- Job-level `contents: write` is used by `auto-pr-upmerge.yml:78-79` and `integration-e2e-orchestrator.yml:75-78`. + +**History.** The backend's PAT ("patch release user and token") was removed in `18ea38f3` (2024-01-19, Vladimir Arsov). It removed `.github/actions/patch-release-configure-git` and 3 lines each from `publish.yml` and `complete-build.yml`. Leftover: `publish_github_release_notes.sh:146` still runs `export GITHUB_TOKEN=$ENV_PATCH_RELEASE_TOKEN`, a CircleCI remnant that is unset in Actions. `gh` then uses `GH_TOKEN`. + +**Where Apps remain.** GitHub Apps (`actions/create-github-app-token`) are kept for: +- Cross-repo reads (`SVA_ACTIONS_READ_PRODUCT_*`). +- Pushes to protected release branches with bypass (`SVA_ACTIONS_UPMERGE_*`). +- Cross-repo PR comments (`SVA_ACTIONS_PR_WRITER_*`). +- Cross-repo dispatch and PR authoring that must trigger workflows (`SVA_CONTAINER_BUILD_BOT_*`). + +None of these applies to the FE in-repo tag and release. + +**Differences from the backend worth deciding on (not prescribing):** +- **Credential handling.** The backend writes a global credential store and checks out with `persist-credentials: false`. The FE flow relies on checkout's persisted credential. Both work with `GITHUB_TOKEN`. Persisting through checkout is the smaller change and keeps the 34285 precedent. +- **Git identity.** The backend uses `github.actor`/`cplace@github.com`. The FE flow uses the `GIT_USER`/`GIT_USER_EMAIL` secrets. For the release flow, the tag is lightweight (`git tag ${gitTag}`, `artifacts-handler.ts:312`), so it records no tagger or author and the identity is never used. Removing the "Configure git user" step and the `GIT_USER*` declarations is formally PFM-ISSUE-34286 scope. + +### 7. `GITHUB_TOKEN` limitations checked against the flow + +| Limitation | Affects the FE release flow? | +|---|---| +| Pushes made with `GITHUB_TOKEN` do not trigger `on: push` workflows | Intended. Nothing in the consolidated flow depends on a tag-push trigger (`fe-tag-pushed.yml` template removed in #183). Leftover tag callers in migrated trees become inert. | +| Cannot bypass branch protection | No branch or commit push; only a `refs/tags/version/*` push. | +| Tag rulesets | None exist today (cplace-fe has four branch rulesets only, 34283 research.md:225; `clone-cplace-fe` has none). A future `version/*` ruleset (34283 Q10) would need the GitHub Actions identity as a bypass actor instead of `squad-fe`. Because the push comes after the promote phase, such a rejection would cost `release-X.Y` on every package until the next release. | +| Single repository only | The flow only touches its own repo. Nested `uses:` references to `collaborationFactory/github-actions` are resolved by GitHub, not by the token. | +| `--verify-tag` on release creation | The tag exists before `github-release` runs (it needs `release`), so it is unaffected. | +| Re-runs | A re-run of `github-release` uses the run's own `github.token`. Idempotent via `gh release view` (`:214`). | +| Repo default token permissions | `clone-cplace-fe` has `default_workflow_permissions: read`; the explicit job-level blocks make the default irrelevant for the release flow. | + +### 8. Text that must change with the switch + +- `fe-release-flow.yml:24-25` (the `GIT_USER_TOKEN` declaration), `:110-111` (`contents: read` → `write`), `:121` (`token:`). +- `.github/workflow-templates/fe/fe-release.yml:1-5` header comment ("still pushes the tag with the PAT"). +- `README.md:54-59` (migration note: the PAT-pushed tag re-fires old callers; "PFM-ISSUE-34282 … removes the tag-push trigger for good"), `:86-88` (secrets list includes `GIT_USER_TOKEN`; caller needs `contents: write`), and possibly `:146` (GitHub release "Created with `GITHUB_TOKEN`", which then applies to the tag too). +- The `guard` job (`fe-release-flow.yml:59-68`): its comment names two risks. The tag-push-caller risk disappears once the tag isn't PAT-pushed. The `fe-tag.yml`-caller risk (tagging in parallel with the PAT) stays. Keep the job; re-word the comment and message if wanted. Not a correctness need. + +## Code References + +- `.github/workflows/fe-release-flow.yml:15-31` - workflow secret contract, including `GIT_USER_TOKEN` (`:24-25`) +- `.github/workflows/fe-release-flow.yml:38-68` - `guard` job (dispatch ref, old-caller check ignoring comments) +- `.github/workflows/fe-release-flow.yml:101-196` - `release` job: `contents: read` (`:110-111`), PAT checkout (`:117-121`), `npm ci` (`:139-141`), git identity (`:143-149`), publish+promote+tag (`:151-159`), cleanup check with `ls-remote --exit-code` (`:163-186`), unpublish (`:188-196`) +- `.github/workflows/fe-release-flow.yml:198-222` - `github-release` job, already `GITHUB_TOKEN` + `contents: write` +- `.github/workflow-templates/fe/fe-release.yml:1-32` - caller template: `contents: write`, concurrency, `secrets: inherit`, 34282 comment +- `.github/workflow-templates/fe/fe-main.yml:8-16` - four-scope block, no concurrency (main chain, section 3a) +- `.github/actions/artifacts/action.yml` - composite: `printenv`, `npm ci`, ts-node +- `tools/scripts/artifacts/artifacts-handler.ts:225-320` - `tagAndPublishRelease`; staging `:296`, promote `:302-309`, `git tag` / `git push origin` at `:312-313` +- `tools/scripts/artifacts/nx-project.ts:356-403` - `getTag()` (staging tag) and `promote()` (`npm dist-tag add/rm`) +- `tools/scripts/artifacts/artifacts-handler.ts:203-223` - legacy `bumpVersionForReleaseBranch` (deprecated `fe-tag.yml` only) +- `tools/scripts/artifacts/utils.ts:228` - `git ls-remote --tags`; `:366-372` version file for the cleanup +- `.github/workflows/fe-tag.yml:19,37,59` - deprecated tagger, still PAT-based; untouched by 34282 +- `.github/workflows/fe-snapshot.yml:12-18` - 34285 precedent (no `GIT_USER_TOKEN`) +- `.github/workflows/fe-pr-snapshot.yml:76-88` - only real `pull-requests`/`issues` write consumer in the FE workflows (not the release chain) +- `README.md:54-59`, `:84-88`, `:94-99`, `:146` - PAT/secret documentation, Recovery for a failed promote/tag push +- `cplace-gh-workflows/.github/workflows/publish.yml:34,49-53,72-76,87-91` - backend `GH_TOKEN`, checkout, `GITHUB_TOKEN` credential setup +- `cplace-gh-workflows/.github/actions/prepare-git-environment/action.yml:46-60` - backend credential store + identity +- `cplace-gh-workflows/src/scripts/push_local_tag.sh:75` - backend tag push +- `cplace-gh-workflows/src/scripts/publish_github_release_notes.sh:36-49,146` - backend `gh release create`; leftover `ENV_PATCH_RELEASE_TOKEN` export + +## Architecture Insights + +- **Job-scoped least privilege is already the structure.** The caller grants a ceiling (`contents: write`), and every job in `fe-release-flow.yml` narrows explicitly. 34282 changes a single job's scope rather than introducing the pattern. This is stricter than the backend, which leaves permissions entirely to the caller. The main chain (`fe-main.yml`) has no such narrowing (section 3a). +- **Write scope next to third-party code.** The `release` job restores `node_modules` from cache, runs `npm ci` (`:139-141`) and runs the artifacts tool (another `npm ci` plus ts-node) in the same job that pushes the tag. The persisted credential in `.git/config` is readable by that code. Switching from the PAT (broad, long-lived, cross-repo) to `GITHUB_TOKEN` (this repo only, `contents: write`, expires with the job) is a large reduction in exposure, but not full isolation. Fuller isolation would need one of: + - (a) checkout with `persist-credentials: false`, plus credentials injected only for the push. The push currently happens inside the TS tool, so it would have to move out of the tool or receive the token in env. The cleanup's `ls-remote` would need the same credential (read is enough). + - (b) moving the tag push into a separate job without `npm`. That conflicts with #183's "publish, promote, tag, unpublish on failure" design, which needs publish and tag in one job to decide cleanup (`:163-196`). + + This is a design decision, not a research finding. The ticket's wording ("build/test/install jobs ... do not inherit write scope") is met by the current job split. +- **The tag push is the last and most expensive failure point.** With the promote phase, a push failure leaves the version unpublished and `release-X.Y` removed from every promoted package. Anything that makes the token's push rights verifiable before publishing (for example a `git push --dry-run` of the tag ref early in the job; not verified whether GitHub checks push rights on a dry run) would move a rejection before the publish. This is a design option, not a requirement of the ticket. +- **The PAT's original reason is gone.** The PAT existed so the pushed tag would start the second run. #183 removed the second run, so the PAT has no remaining function in this flow. Also, `squad-fe` pusher guards in old consumer callers (`cplace-fe push_to_release.yaml:43`) become moot once tags are not pushed by `squad-fe`. Tags never retrigger a `push: branches` workflow anyway. +- **Secret-contract changes are decoupled from consumers** through `secrets: inherit`. The new flow can drop declarations freely. The deprecated reusables keep their contracts for explicit-secret callers. + +## Historical Context (from specs/) + +- `specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/research.md:57,254-255` - the two-run split exists only because a `GITHUB_TOKEN` tag push triggers nothing. The 2023 attempt (d6542fe) was reverted (a416ad2). Pushing the tag with `GITHUB_TOKEN` "would avoid the trigger entirely", which was deliberately left to 34282. +- `specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/design.md:40,294` - 34283 works "under the current auth": the PAT pushes the tag and only the release uses `GITHUB_TOKEN`. +- `.../design.md:66,82-85,228-236` - per-job permissions; `secrets: inherit` chosen so 34282 / 34286 / the JFrog split need no caller edits. +- `.../design.md:97,100-101` - out of scope / handed off: 34282 (GITHUB_TOKEN tag push), 34286 (retire `GIT_USER*`), 34284 (immutable releases), 34287 (pilot), Q10 (`version/*` tag ruleset, unowned). +- `.../clone-cplace-fe-live-tests.md` - the live-test environment in `collaborationFactory/clone-cplace-fe` (JFrog `cplace-npm-test`). Phase A (PAT tag push) passed A1–A12 on 2026-11-02/03 with retests on 2026-11-06; the A8 first run led to the staging tag; A9 documented cancelling as unsupported. Its Phase B sketch is superseded by this ticket's `live-test-plan.md`. +- `specs/2026-06-05_node24-workflow-migration/validation-log.md:33-41,71` - never test on real `release/*`; use `test/*` or throwaway lines. The FE flow has since been validated live in `clone-cplace-fe`. +- `specs/2026-06-05_node24-workflow-migration/plan.md:264` - `fe-pr-snapshot` PR comment already uses the default `github.token` via `actions/github-script` (the PR-decoration part of 33676). + +## Related Research + +- `specs/2026-10-12_PFM-ISSUE-34283_consolidate-fe-release-workflow/` (research, design, plan, live tests) - the base this ticket builds on +- `specs/2026-10-26_PFM-ISSUE-34282_github-token-scoped-permissions/live-test-plan.md` - the live test plan for this ticket +- `specs/2026-06-05_node24-workflow-migration/` - action pinning, concurrency origin, validation rules +- `C:\rr\cplace-gh-workflows\specs\2026-07-27_build-cache-key-output\plan.md:1081-1104` - caller permission ceiling failure mode (backend) +- `C:\rr\cplace-gh-workflows\specs\2026-09-25_PFM-TASK-8475_e2e-via-integration-pr\design.md:59-61,248` - `GITHUB_TOKEN` trigger limitations; when an App is required + +## Open Questions + +1. **Permission baseline vs. "drop any without a consumer".** No consumer for `checks: write` or `pull-requests: write` (or `issues`, `actions`) in the release flow. Should the release/tag job get `contents: write` only? The ticket lists `checks`/`pull-requests` as baseline, but its third requirement asks to drop unused scopes. Adding them would also require every migrated caller to grant them. +2. **Isolation of the write token inside the `release` job.** Is the PAT → job-scoped `GITHUB_TOKEN` reduction enough, or should the push credential be kept away from `npm ci` / the artifacts tool? Options: `persist-credentials: false` with a push-only credential (the cleanup's `ls-remote` needs a read credential too), or a separate push step outside the TS tool (conflicts with publish → promote → tag in one job). +3. **Git identity and `GIT_USER` / `GIT_USER_EMAIL`.** These are unused for a lightweight tag. Remove the "Configure git user" step and the declarations in 34282, or leave them for 34286 as planned? +4. **Credential style.** Persisted checkout credential (FE today, 34285 precedent) or the backend's `persist-credentials: false` + credential-store approach? The second implies a reusable action that this repo doesn't have. +5. **Caller template ceiling.** Keep `permissions: contents: write` at workflow level in the template, which is required as the ceiling for the release jobs, and update only the comments? Any template change only reaches consumers when they re-copy it. +6. **Guard job after the switch.** Keep it, and re-word its rationale: the tag-push-caller risk goes, the parallel-`fe-tag.yml` risk stays. +7. **Early push-rights check.** With publish → promote → tag, should the job verify it can push the tag before publishing (e.g. a dry-run push), so a rejection (a future tag ruleset) costs nothing? Needs a live check of what GitHub validates on a dry run. +8. **Main chain permissions (new).** The `fe-main.yml` template gives every main-CI job the four-scope block, but the chain needs only `contents: read` (section 3a). Narrowing it fits the ticket's intent but not its "tag and release" scope. Include in 34282, or leave to another EPIC-1963 item? +9. **Validation.** Covered by `live-test-plan.md` in `clone-cplace-fe` (release on `release/26.4`, main CI and forced release flow on `main`). +10. **Out of scope, observed:** `cplace-fe/.github/workflows/push_main.yaml:45-49` still passes `GIT_USER_TOKEN` explicitly to `fe-snapshot.yml@master`, which no longer declares it since 34285. GitHub may reject explicitly passed undeclared secrets. Worth checking that cplace-fe's main snapshot run still succeeds (separate from 34282).