PDP-1182 fix: TruffleHog scan failure on private repos (persist-credentials hotfix)#44
PDP-1182 fix: TruffleHog scan failure on private repos (persist-credentials hotfix)#44GAdityaVarma wants to merge 2 commits into
Conversation
…t-credentials: false With persist-credentials: false, subsequent git fetch fails on private repos because no credentials are stored in .git/config. This fix temporarily configures the extraheader for the fetch step, then immediately removes it so credentials are not available when PR code is checked out in later steps. Fixes TruffleHog scan failure on private repos like MarkLogic-Builds.
There was a problem hiding this comment.
Pull request overview
Hotfix to restore TruffleHog scanning on private repositories while keeping actions/checkout hardened with persist-credentials: false, by temporarily injecting Git HTTP auth for the git fetch that retrieves PR head refs.
Changes:
- Adds a temporary
http.*.extraheaderAuthorization header usinggithub.tokento authenticate thegit fetch originstep on private repos. - Unsets the temporary git auth header after fetching PR head commits.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…er URL 1. Use git -c to pass auth header inline instead of config/unset. This avoids credentials persisting to .git/config entirely, even if the fetch fails or the step exits early. 2. Use github.server_url instead of hardcoded https://github.com for GHES compatibility. 3. Fix misleading comment: fetching PR head ref, not merge ref.
| # Fetch PR commits using GitHub's PR head ref (works for all PRs including forks) | ||
| # Using git -c to pass auth inline without persisting credentials to .git/config | ||
| git -c "http.${SERVER_URL}/.extraheader=${AUTH_HEADER}" \ | ||
| fetch origin +refs/pull/${{ github.event.pull_request.number }}/head:refs/remotes/origin/pr-head |
There was a problem hiding this comment.
The auth header is scoped to https://github.com/ (the trailing / creates a git URL prefix match), so credentials are sent to any URL under github.com for the duration of this command — broader than necessary.
Scope it to just the specific repository:
| fetch origin +refs/pull/${{ github.event.pull_request.number }}/head:refs/remotes/origin/pr-head | |
| git -c "http.${SERVER_URL}/${GITHUB_REPOSITORY}/.extraheader=${AUTH_HEADER}" \ |
GITHUB_REPOSITORY = marklogic/copyrighttest, so the key becomes http.https://github.com/marklogic/copyrighttest/.extraheader — credentials only sent to that repo, nothing else on the same host.
Additional review concerns (lines outside the diff)1.
|
|
Closing this PR as the issues are addressed in #45 |
Hotfix: Fixes TruffleHog scan failure on private repos introduced in PR #42.
Root Cause
PR #42 added
persist-credentials: falseto the checkout step intrufflehog-scan.yml. This is correct security hardening for public repos, but on private repos (likeMarkLogic-Builds), the subsequentgit fetch originstep fails because no credentials are stored in.git/configto authenticate with the private remote.Fix
Temporarily configure git's
http.extraheaderwith theGITHUB_TOKENfor the fetch step only, then immediately remove it:extraheaderwith base64-encodedx-access-token:$GH_TOKENgit fetch origin(now succeeds on private repos)extraheaderimmediately afterThis ensures:
persist-credentials: falseremains (hardened checkout)git fetchworks for both public and private reposImpact
Tested in private PR: https://github.com/marklogic/MarkLogic-Builds/pull/1371 looks good. test workflow with git -c auth pattern works on private repo.