Skip to content

auth status misreports an inaccessible keyring as an invalid token #14171

Open

Description

@aimkiray

Describe the bug

When gh runs in an environment without access to the user's graphical session (for example, a system daemon on macOS), reading the auth token from the keyring fails with a permission error. gh auth status then reports "The token in default is invalid" and suggests re-authenticating — but re-authenticating can never succeed, because the token also cannot be stored in the keyring from that environment.

Affected version

gh version 2.97.0 (2026-07-31)

Steps to reproduce the behavior

  1. Log in to gh normally so the token is stored in the macOS keyring.
  2. Run gh auth status from a context without access to the user's graphical session (e.g. a launchd system daemon, where launchctl managername reports System).
  3. Observe the misleading error.

Expected vs actual behavior

Expected: gh auth status should report that the keyring is inaccessible and suggest a workaround that works in that environment (e.g. set GH_TOKEN or use gh auth login --insecure-storage).

Actual: it reports "The token in default is invalid" and suggests re-authenticating, which cannot succeed.

Logs

github.com
  X Failed to log in to github.com account aimkiray (default)
  - Active account: true
  - The token in default is invalid.
  - To re-authenticate, run: gh auth login -h github.com
  - To forget about this account, run: gh auth logout -h github.com -u aimkiray

Activity

  1. added
    gh-auth
    bug
    priority-3
    on Aug 28, 2026
  2. RRXXZZYY commented on Sep 1, 2026

    @RRXXZZYY

    @cli/code-reviewers, I'd like to work on this if the proposed scope is welcome.

    I traced the misleading output to the token lookup path: credential-store errors are discarded by ActiveToken, so auth status later tries to validate an empty token and renders the generic invalid-token message.

    Proposed acceptance criteria:

    1. When a configured account's credential-store lookup fails with an error other than "not found", gh auth status reports that the credential store is inaccessible rather than saying the token is invalid.
    2. The output suggests usable alternatives for that environment, including GH_TOKEN and gh auth login --insecure-storage.
    3. No token-validation request is made when credential retrieval itself failed.
    4. Existing behavior for a genuinely missing or rejected token remains unchanged.
    5. Unit tests cover the credential-store error path and the existing invalid-token path.

    Could you confirm the acceptance criteria and add help wanted if this is suitable for an external contribution? I will not open a PR before then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buggh-authpriority-3stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions