Skip to content

CI: root checks out with the default token; SHAPE_LEGS_TOKEN is used only to fetch the legs - #12

Merged
brettheap merged 1 commit into
mainfrom
fix/legs-token-scope
Sep 4, 2026
Merged

brettheap merged 1 commit into
mainfrom
fix/legs-token-scope

Conversation

@brettheap

@brettheap brettheap commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Lane: repo-shape

Observed on the first real use of the SHAPE_LEGS_TOKEN org secret (MedxSoft, runs 33821509948 and 33821512605 on MedxEHR and MedxGlass, workflow_dispatch on main): SHAPE_LEGS_TOKEN_SET: true, then actions/checkout@v4 itself failed: fatal: unable to access 'https://github.com/MedxSoft/MedxEHR/': The requested URL returned error: 403.

Cause: templates/assembly-root/.github/workflows/validate.yml set token: ${{ secrets.SHAPE_LEGS_TOKEN || github.token }} on the ROOT checkout, so a token scoped only to the leg repositories (the sensible scope for a contents-read token) broke the root checkout, and a mis-scoped or unapproved token broke the whole job instead of degrading. The root repository is always readable by the default github.token; only the legs need the secret.

Fix:

  1. actions/checkout now uses the DEFAULT github.token (no token: override), with submodules: false and persist-credentials: false.
  2. The guarded submodule step fetches the legs with SHAPE_LEGS_TOKEN when present, scoped to that step only, via git -c "url.https://x-access-token:${SHAPE_LEGS_TOKEN}@github.com/.insteadOf=https://github.com/" -c "[email protected]:" submodule update --init --recursive, with the secret passed via env: — never echoed, never in a printed URL — falling back to a plain git submodule update --init --recursive when the secret is absent. SSH-form ([email protected]:) leg URLs are handled by the second insteadOf.
  3. Existing semantics preserved: legs_available output, the warning naming the secret and leg URLs on failure, naming/manifest always run, validate-pins.py only when legs are available, and FAIL only when the secret is set but the fetch still failed — the failure message now says the token cannot read one of the LEG repositories (named from .gitmodules) and that the root checkout no longer depends on it.
  4. Job-level SHAPE_LEGS_TOKEN_SET env is unchanged. secrets stays out of every if:; actionlint stays green.
  5. Updated templates/assembly-root/README.md and README.md's SHAPE_LEGS_TOKEN paragraphs: the token needs Contents read on the LEG repositories only; the root is read with the workflow's default token.
  6. Added tests asserting the checkout step has no token: key and that the submodule step references SHAPE_LEGS_TOKEN via env: and uses insteadOf.

python3 -m pytest tests -q: 249 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T

Summary by Sourcery

Use the default workflow token for root checkouts and reserve SHAPE_LEGS_TOKEN for fetching leg repositories.

Bug Fixes:

  • Ensure the root repository checkout always uses the workflow’s default token, preventing legs-scoped credentials from breaking CI with authorization errors.
  • Authenticate private or internal leg submodules only during their guarded fetch step, while preserving graceful degradation when no legs token is configured.

Enhancements:

  • Keep root checkout credentials out of the local Git configuration and support both HTTPS and SSH leg repository URLs.
  • Clarify that SHAPE_LEGS_TOKEN requires read access only to leg repositories and improve failure diagnostics for inaccessible legs.

Documentation:

  • Update root and generated assembly documentation to describe the token’s leg-only scope and root checkout behavior.

Tests:

  • Add coverage confirming the root checkout has no token override and that leg authentication is step-scoped with URL rewriting.

…only to fetch the legs

The validate workflow's root checkout carried
token: ${{ secrets.SHAPE_LEGS_TOKEN || github.token }}, so a token scoped
only to the leg repositories (the sensible scope for a contents-read
token) broke the ROOT checkout, and a mis-scoped or unapproved token broke
the whole job instead of degrading. Observed on the first real use of the
secret (MedxSoft, runs 33821509948 / 33821512605 on MedxEHR / MedxGlass,
workflow_dispatch on main): SHAPE_LEGS_TOKEN_SET: true, then
actions/checkout@v4 itself failed with a 403 on the root repository, which
is always readable by the default github.token.

Fix: actions/checkout now uses the default github.token (no token:
override), with submodules: false and persist-credentials: false. The
guarded submodule-fetch step reads SHAPE_LEGS_TOKEN via its own env: and,
when present, rewrites both https://github.com/ and [email protected]: leg
URLs to an x-access-token form scoped to that step alone, falling back to
a plain git submodule update --init --recursive when the secret is
absent. legs_available, the warning naming the secret and leg URLs,
always-run naming/manifest, and validate-pins.py-only-when-available are
all unchanged. The only-failure-case message now says the token cannot
read one of the LEG repositories (named from .gitmodules) and that the
root checkout no longer depends on it. secrets stays out of every if:;
actionlint stays green.

Updated README.md and templates/assembly-root/README.md's SHAPE_LEGS_TOKEN
paragraphs accordingly, and added tests asserting the checkout step has no
token: key and that the submodule step references SHAPE_LEGS_TOKEN via
env: and uses insteadOf.

Lane: repo-shape
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_015WekBEXf55Xv64psGe5t3T
Copilot AI lite review requested due to automatic review settings September 4, 2026 00:29
@sourcery-ai

sourcery-ai Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR fixes CI failures caused by applying a legs-scoped SHAPE_LEGS_TOKEN to the root checkout by using the default workflow token for the root, authenticating submodules through a step-local Git URL rewrite for HTTPS and SSH URLs, preserving graceful validation behavior, and adding documentation and regression tests.

Sequence diagram for root checkout and authenticated leg fetching

sequenceDiagram
    participant Workflow
    participant RootRepo
    participant Git
    participant LegRepos

    Workflow->>RootRepo: actions/checkout@v4
    RootRepo-->>Workflow: Root files via github.token
    Workflow->>Git: git submodule update --init --recursive
    alt SHAPE_LEGS_TOKEN is present
        Git->>LegRepos: Fetch legs via HTTPS/SSH insteadOf rewrite
        LegRepos-->>Git: Leg contents
    else SHAPE_LEGS_TOKEN is absent
        Git->>LegRepos: Fetch legs without token
        LegRepos-->>Git: Public legs or fetch failure
    end
    Git-->>Workflow: legs_available result
Loading

Flow diagram for graceful leg-fetch validation

flowchart TD
    A[Checkout root with github.token] --> B[Fetch submodules best effort]
    B --> C{Legs available?}
    C -->|Yes| D[Run naming, manifest, and validate-pins.py checks]
    C -->|No| E[Run naming and manifest checks]
    E --> F[Skip validate-pins.py with warning]
    F --> G{SHAPE_LEGS_TOKEN_SET?}
    G -->|No| H[Degrade without failing]
    G -->|Yes| I[Fail with LEG repository access error]
Loading

File-Level Changes

Change Details Files
Decouple root checkout authentication from the legs-only secret.
  • Remove the checkout token override and keep submodules disabled.
  • Disable credential persistence so the root checkout cannot leak authentication into later Git operations.
  • Retain the default workflow token for reading the root repository.
templates/assembly-root/.github/workflows/validate.yml
Authenticate submodule fetching only when and where the legs require it.
  • Pass SHAPE_LEGS_TOKEN through the fetch step’s environment rather than checkout configuration.
  • Use scoped Git URL rewrites for both HTTPS and SSH GitHub submodule URLs.
  • Fall back to unauthenticated fetching when the secret is absent while preserving best-effort behavior.
templates/assembly-root/.github/workflows/validate.yml
Preserve validation outcomes while improving token-failure diagnostics.
  • Keep naming and manifest checks unconditional and run pin validation only when legs are available.
  • Fail only when a configured legs token cannot fetch the leg repositories.
  • Report the affected leg URLs and clarify that root checkout does not depend on the secret.
templates/assembly-root/.github/workflows/validate.yml
Update documentation and regression coverage for the revised credential model.
  • Document that SHAPE_LEGS_TOKEN requires Contents read access on legs only.
  • Add assertions for the default root checkout, step-scoped secret usage, URL rewrites, and fallback behavior.
  • Retain checks preventing secrets from appearing in step-level if conditions and adjust the README length allowance.
README.md
templates/assembly-root/README.md
tests/test_repo_hygiene.py
tests/test_scaffold_e2e.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

@brettheap
brettheap merged commit caa888d into main Sep 4, 2026
4 checks passed

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="templates/assembly-root/.github/workflows/validate.yml" line_range="72-76" />
<code_context>
         run: |
           set +e
-          git submodule update --init --recursive
+          if [ -n "$SHAPE_LEGS_TOKEN" ]; then
+            git \
+              -c "url.https://x-access-token:${SHAPE_LEGS_TOKEN}@github.com/.insteadOf=https://github.com/" \
+              -c "url.https://x-access-token:${SHAPE_LEGS_TOKEN}@github.com/[email protected]:" \
+              submodule update --init --recursive
+          else
+            git submodule update --init --recursive
</code_context>
<issue_to_address>
**issue (bug_risk):** When `.gitmodules` contains a relative leg URL such as `../Project-spec.git`, neither `insteadOf` rule matches it, so Git attempts the fetch without `SHAPE_LEGS_TOKEN`; private relative legs fail even though the token is configured and has access.

**Triggers:** When an adopted root uses relative submodule URLs and the leg repositories are private or internal.

**Suggested fix:** Resolve relative submodule URLs against the root repository's GitHub origin before applying the credential rewrite, or add a rewrite covering the resolved GitHub URL form.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and the workflow now injects a legs-scoped credential into Git URL rewrites, changing which repositories the CI job can authenticate to and potentially exposing or misusing that access if the rewrite or masking behavior is wrong. Reverting stops the behavior for future runs, but any credential exposure or private-leg access that occurred before the revert cannot be undone.

Blocking findings: templates/assembly-root/.github/workflows/validate.yml:76


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +72 to +76
if [ -n "$SHAPE_LEGS_TOKEN" ]; then
git \
-c "url.https://x-access-token:${SHAPE_LEGS_TOKEN}@github.com/.insteadOf=https://github.com/" \
-c "url.https://x-access-token:${SHAPE_LEGS_TOKEN}@github.com/[email protected]:" \
submodule update --init --recursive

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): When .gitmodules contains a relative leg URL such as ../Project-spec.git, neither insteadOf rule matches it, so Git attempts the fetch without SHAPE_LEGS_TOKEN; private relative legs fail even though the token is configured and has access.

Triggers: When an adopted root uses relative submodule URLs and the leg repositories are private or internal.

Suggested fix: Resolve relative submodule URLs against the root repository's GitHub origin before applying the credential rewrite, or add a rewrite covering the resolved GitHub URL form.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are minor but concrete correctness/clarity issues in the updated workflow comments/diagnostics and an e2e test name/docstring that should be corrected to avoid misleading future maintenance.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates the assembly-root CI template to ensure the root repository always checks out using the default workflow token, and scopes SHAPE_LEGS_TOKEN usage to the submodule (legs) fetch step only—preventing legs-scoped tokens from breaking the root checkout while preserving the existing “degrade when legs unavailable” behavior.

Changes:

  • Remove the token: override from the root actions/checkout@v4 step and disable credential persistence (persist-credentials: false).
  • Fetch leg submodules in a guarded step that conditionally uses SHAPE_LEGS_TOKEN via git -c url.<...>.insteadOf=<...> rewriting (HTTPS + SSH URL forms).
  • Update docs and tests to reflect/lock in the new token-scoping behavior and failure messaging.
File summaries
File Description
templates/assembly-root/.github/workflows/validate.yml Root checkout uses default token; legs token is step-scoped to submodule fetch; failure messaging updated to reference leg repos.
tests/test_scaffold_e2e.py Adds/adjusts assertions to enforce “no checkout token override” and step-scoped legs token usage.
README.md Clarifies that SHAPE_LEGS_TOKEN is for legs only and the root checkout never uses it.
templates/assembly-root/README.md Mirrors the updated CI/token-scoping guidance for scaffolded assembly roots.
tests/test_repo_hygiene.py Updates README line-cap justification and threshold after doc additions.
Review details

Suppressed comments (2)

templates/assembly-root/.github/workflows/validate.yml:135

  • git config --get-regexp '\.url$' exits 1 when there are no matches, and with Actions' default bash -e -o pipefail that would stop the step before it prints any URLs. Since this block is meant to provide diagnostics (and the step already exits 1 explicitly), make the URL listing resilient to missing/malformed .gitmodules entries.
          echo "::error::SHAPE_LEGS_TOKEN is configured but 'git submodule update --init --recursive' still failed. The root checkout does not use this token — it reads with the workflow's default token — so this means SHAPE_LEGS_TOKEN cannot read one or more of the following LEG repositories (wrong token scope, a missing contents:read grant, or a leg URL problem):"
          git config --file .gitmodules --get-regexp '\.url$' | while read -r _ url; do
            echo "::error::  $url"
          done

tests/test_scaffold_e2e.py:360

  • This test no longer asserts anything about the root checkout using SHAPE_LEGS_TOKEN (that behavior was removed and is now covered by test_the_ci_workflow_root_checkout_uses_the_default_token), so the function name and docstring are now misleading. Renaming it will make failures easier to interpret.
    fetch = _step_block(workflow, "id: submodules")
    assert "git submodule update --init --recursive" in fetch
    assert "legs_available=true" in fetch
    assert "legs_available=false" in fetch
    assert "SHAPE_LEGS_TOKEN" in fetch
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +57 to +61
# `SHAPE_LEGS_TOKEN` is scoped to THIS STEP alone via `env:` — never to
# the job, never onto the root checkout above — and is used only
# through a scoped `git -c url.<...>.insteadOf=<...>` rewrite, never
# echoed or interpolated into a URL that gets printed. Two rewrites
# cover both submodule URL forms an adopted repository may carry:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants