fix(auth): distinguish missing credentials from operational keyring failures (#1) [0xcFDa9f32d292661740a6d0B4c00867E34c05c56D] - #7
Open
meridianmindx wants to merge 1 commit into
Conversation
…ailures (condoraltidoi32#1) - Distinguish ErrNotFound from operational keyring daemon/system failures in authtoken package - Propagate operational errors up through config.AuthTokenForHost and factory.HttpClientFunc without swallowing or silent fallback - Surface clear, actionable troubleshooting diagnostics to stderr in RunApi when keyring fails - Comprehensive unit tests for authtoken, config resolution chain, factory, and API command
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1 — Differentiates missing credentials from operational keyring failures and prevents silent unauthenticated API requests in
gh api.Root Cause
Previously, operational errors from secret storage (such as locked keychain, disconnected D-Bus daemon, access denied) were treated equivalently to missing credentials (
ErrNotFound). Consequently,gh apiwould swallow the error, proceed with an unauthenticated request, and cause confusing downstream HTTP 404 or 403 rate-limit errors.Changes & Architecture
pkg/authtoken:ErrNotFoundfor absent credentials.KeyringOpErrorcontaining target host and underlying root cause.TokenFromKeyringonly returnsErrNotFoundwhen a secret is absent, while strictly propagating operational failures.internal/config:AuthTokenForHostevaluates resolution hierarchy:GH_TOKEN/GITHUB_TOKEN-> System Keyring ->hosts.yml.IsKeyringOpError), preventing silent fallback.pkg/cmd/factory&pkg/cmd/api:HttpClientFuncsurfaces operational failures.RunApicatches keyring errors, halts execution immediately with non-zero exit code, and writes actionable diagnostics tostderr(explaining root cause and suggestingGH_TOKENbypass).pkg/authtoken: missing token vs operational error tests.internal/config: resolution precedence, clean fallback, and error propagation tests.pkg/cmd/factory: factory HTTP client construction error handling.pkg/cmd/api: command execution, stderr output validation, unauthenticated public requests, and authenticated header injection.Verification
Payout Address
0xcFDa9f32d292661740a6d0B4c00867E34c05c56DFixes #1