Skip to content

Persist HTTP basic auth credentials for git operations after clone - #7144

Open
pujitha24 wants to merge 1 commit into
pipe-cd:masterfrom
pujitha24:auto/issue-6453
Open

Persist HTTP basic auth credentials for git operations after clone#7144
pujitha24 wants to merge 1 commit into
pipe-cd:masterfrom
pujitha24:auto/issue-6453

Conversation

@pujitha24

Copy link
Copy Markdown

What this PR does:

Persists the HTTP Basic-Auth header (built from the piped git username/password config) into the checked-out repository's git config, so that git operations run after the initial clone (pull, fetch, push, etc.) keep using the configured credentials.

Why we need it:

When a piped git repository is configured with username/password (a PAT) for HTTPS auth, pkg/git/client.go's Client.Clone() only passed the Authorization header as a one-off -c http.extraHeader=... flag to the git clone --mirror / git fetch commands used to populate its internal cache. That flag is never persisted, and the Repo object handed back to callers (a worktree checked out from the cache, with origin rewritten to the real HTTPS remote URL) carries no credentials at all. Components such as the event watcher (pkg/app/piped/eventwatcher) call repo.Pull() repeatedly on that same object over time; Pull/Push/MergeRemoteBranch/CheckoutPullRequest in pkg/git/repo.go issue git commands straight at the remote with no auth, so every one of them fails with fatal: could not read Username for 'https://github.com': No such device or address — reproducing exactly the error reported in the issue.

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

  • How are users affected by this change: Piped deployments configured with HTTPS username/password git auth (a common CI/CD PAT pattern) now keep working after the initial clone — previously, background git operations like the event watcher's periodic pull and re-clone would fail indefinitely with a credential error. Deployments using SSH auth are unaffected.
  • Is this breaking change: No
  • How to migrate (if breaking change): N/A

AI assistance: this change was drafted with Claude Code.

Fixes #6453

Motivation:
When a piped git repository is configured with HTTPS username/password
(PAT) authentication, pkg/git/client.go's Client.Clone() only passed
the Authorization header as a one-off `-c http.extraHeader=...` flag
to the `git clone --mirror` / `git fetch` commands used to populate
its internal repo cache. That flag is never persisted, so the Repo
object handed back to callers (a worktree checked out from the cache,
with origin rewritten to the real HTTPS remote URL) carries no
credentials at all. Components such as the event watcher call
repo.Pull() repeatedly on that same object over time, and Pull/Push/
MergeRemoteBranch/CheckoutPullRequest in pkg/git/repo.go issue git
commands straight at the remote with no auth args, so every one of
them fails with "fatal: could not read Username for
'https://github.com': No such device or address" -- reproducing
exactly the error from the report.

Approach:
After Client.Clone() checks out the destination repo, persist the
basic-auth header into that repo's git config via a new
repo.setHTTPAuthHeader method (`git config http.extraHeader <value>`),
so every later git command run in that directory picks up the
credentials automatically instead of relying on a one-off CLI flag.
repo.CopyToModify (used to make a scratch copy for committing and
pushing changes) does a plain local `git clone`, which doesn't carry
over custom config keys, so the header is propagated there too before
CopyToModify's initial fetch.

Validation:
Ran `go build ./...` (whole main module, passes) and
`go test ./pkg/git/...` (passes, including three new/extended tests:
TestClonePersistsHTTPAuthHeader, Test_setHTTPAuthHeader, and an
extended TestCopyToModify). Confirmed TestClonePersistsHTTPAuthHeader
fails against the pre-fix code: with the new persistence call
temporarily removed from Clone(), the test fails because
`git config --get http.extraHeader` finds nothing in the checked-out
repo; restoring the fix makes it pass again. This is a local git-config
assertion, not a live HTTPS clone against a real PAT-protected remote,
but it directly demonstrates the exact defect: credentials silently
dropped after the initial clone.

Report: pipe-cd#6453
Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com>
@pujitha24
pujitha24 requested a review from a team as a code owner August 10, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot clone GitHub repository with username/PAT

1 participant