Skip to content

🔒 fix(ci): add persist-credentials:false and scope token to push step - #852

Merged
castrojo merged 1 commit into
mainfrom
guide/ci-persist-credentials-hardening
May 24, 2026
Merged

🔒 fix(ci): add persist-credentials:false and scope token to push step#852
castrojo merged 1 commit into
mainfrom
guide/ci-persist-credentials-hardening

Conversation

@kubestellar-hive

Copy link
Copy Markdown
Contributor

What

Two workflows used actions/checkout with the default persist-credentials: true, leaving GITHUB_TOKEN stored in .git/config for the full job duration.

pdf.yml

  • Add persist-credentials: false to checkout.
  • No git push in this workflow; gh release upload uses GITHUB_TOKEN as an env var so nothing breaks.

monthly-reports.yml

  • Add persist-credentials: false to checkout.
  • Inject the remote URL with the token only in the push step:
    git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${{ github.repository }}"
    GH_TOKEN is already present in that step's env: block. The token is in .git/config only for the duration of the push, not exposed to the earlier npm run generate-report and downstream script steps.

Why

With persist-credentials: true (the default), any step that can read the filesystem — including npm run generate-report, node scripts/*, or a compromised node_modules transitive dep — can read .git/config and exfiltrate the GITHUB_TOKEN. Scoping to the push step removes that window.

Scope

Two workflow files, no application code changed.

Two workflows checked out with default persist-credentials:true,
leaving the GITHUB_TOKEN in .git/config for the entire job —
accessible to any subsequent step (npm scripts, curl, etc.).

pdf.yml:
  - Add persist-credentials: false to checkout.
    The workflow never does git ops; gh release upload uses
    the GITHUB_TOKEN env var directly so no credentials needed
    in .git/config at any point.

monthly-reports.yml:
  - Add persist-credentials: false to checkout.
  - Inject the remote URL with the token only in the 'Push branch
    and create PR' step via:
      git remote set-url origin https://x-access-token:${GH_TOKEN}@...
    Token is already present as GH_TOKEN env in that step.
    This is the minimum-exposure pattern: token in .git/config
    only for the duration of the push, not the entire job.

Signed-off-by: guide [bot] <guide-agent@projectbluefin.hive>
@kubestellar-hive kubestellar-hive Bot added the documentation Improvements or additions to documentation label May 24, 2026
@kubestellar-hive
kubestellar-hive Bot requested a review from castrojo as a code owner May 24, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant