Skip to content

Clear Git helper credentials on logout - #15152

Merged
BagToad merged 1 commit into
bagtoad/oauth-logout-revocationfrom
bagtoad/git-helper-logout-cleanup
Nov 24, 2026
Merged

BagToad merged 1 commit into
bagtoad/oauth-logout-revocationfrom
bagtoad/git-helper-logout-cleanup

Conversation

@BagToad

@BagToad BagToad commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Related to #13111. Builds on #15100 and carries the Git helper cleanup from @babakks's #13450.

Description

gh auth logout now clears saved HTTPS credentials for the selected host from Git credential helpers.

Login can store credentials in an external helper with git credential approve. Logout currently leaves that copy behind. This change calls git credential reject after local logout, using the existing shared updater.

Cleanup failures print a warning without failing logout. The parent PR's OAuth revocation, refresh-and-retry behavior, locking, and account selection are unchanged.

How did you test this change?

I ran the same command before and after this layer:

gh auth logout --hostname github.com --user monalisa

I used synthetic API responses, two accounts, an in-memory keyring, and a test-owned Git store helper. Both builds returned exit 0 and kept the other account signed in. Before, the helper retained the credential. After, it removed the credential for github.com and kept the control host's credential.

I also ran the changed build without Git on PATH. It printed the cleanup warning, returned exit 0, and still removed the selected local account.

The recording includes preparation, the real gh command and its output, and state checks for each case. No live authentication or OS keychain was used. Native osxkeychain and wincred behavior was not exercised.

git-helper-logout-cleanup.mp4

Open chapters and notes

Key points

  • Cleanup runs only after successful local logout, including --no-revoke.
  • Rejection is host-wide for HTTPS, matching login. It can remove another account's credential for the same host.
  • Git errors warn on stderr without changing a successful logout's exit status.

Notes for reviewers

Start with the logout flow. It reuses RejectExisting, so no new Git credential protocol handling is needed.

#13111 reports the retained helper credential. #13450 contains the original cleanup change. #15100 supplies the OAuth behavior below this layer.

Local validation

I used Go 1.27.4 and the repository-pinned golangci-lint v2.15.0 with isolated configuration.

go fix ./pkg/cmd/auth/logout
# Passed.
go test ./pkg/cmd/auth/logout ./pkg/cmd/auth/shared/gitcredentials
# Passed.
go test ./...
# Passed.
go test -race ./pkg/cmd/auth/logout ./pkg/cmd/auth/shared/gitcredentials
# Passed.
make
# Passed.
make lint
# Passed, 0 issues.

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @BagToad will read and reply directly.
  • An agent will draft replies and @username will read them before they are posted.
  • Nobody has explicitly committed to replying.

Reject cached HTTPS credentials for the selected host after local logout. Keep logout successful and print a warning when Git credential cleanup fails. Reuse the existing credential updater.

Co-authored-by: Babak K. Shandiz <[email protected]>
@BagToad
BagToad requested a review from a team as a code owner November 24, 2026 21:42
@BagToad
BagToad requested review from tidy-dev and a balanced review from Copilot and removed request for a team November 24, 2026 21:42
@BagToad
BagToad added this pull request to stack #15153 November 24, 2026 21:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the logout credential-cleanup change.

No open issues 🎉

What changed in this PR

This PR extends gh auth logout to remove saved HTTPS credentials from Git credential helpers, addressing the retained credentials reported in #13111 while preserving the parent PR’s OAuth revocation behavior.

Changes:

  • Reuses the shared credential updater after successful local logout, including with --no-revoke.
  • Documents host-wide cleanup and warns on stderr if cleanup fails without failing logout.
  • Adds tests for Git client wiring, host selection, cleanup ordering, and failure warnings.
File Description
pkg/​cmd/​auth/​logout/​logout.go Wires the Git client, performs helper cleanup, and documents warning behavior.
pkg/​cmd/​auth/​logout/​logout_test.go Adds credential-rejection stubs and checks cleanup behavior in interactive and non-interactive flows.

Review effort: Balanced

@BagToad
BagToad merged commit d298dbd into trunk Nov 24, 2026
25 of 26 checks passed
@BagToad
BagToad deleted the bagtoad/git-helper-logout-cleanup branch November 24, 2026 22:39
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.

3 participants