Skip to content

fix(auth): allow OAuth login when no system keyring is available - #165

Open
Mohith26 wants to merge 1 commit into
gleanwork:mainfrom
Mohith26:fix/oauth-login-without-keyring
Open

Mohith26 wants to merge 1 commit into
gleanwork:mainfrom
Mohith26:fix/oauth-login-without-keyring

Conversation

@Mohith26

@Mohith26 Mohith26 commented Nov 3, 2026

Copy link
Copy Markdown

Fixes #157.

glean auth login calls config.ClearTokenFromStorage() before saving the OAuth tokens, and that function returned an error for any keyring failure other than ErrNotFound. In a devcontainer with no Secret Service daemon, the delete fails with The name org.freedesktop.secrets was not provided by any .service files, so login aborts even though the OAuth tokens themselves are written to a file and SaveConfig already falls back to file-only storage in the same situation.

Change: when the keyring delete fails, check whether the token can still be read from the keyring. If it can't, no keyring token can shadow the new OAuth credentials, so log it and go on to clear the token from ~/.glean/config.json. If a token is still readable but couldn't be deleted (for example a keychain that allows reads but denies the delete), it still returns the error, so the stale-token protection from persistLoginState stays in place.

Tests (in TestClearTokenFromStorage):

  • keyring fully unavailable (keyring.MockInitWithError with the error from the issue): token is saved to the file only, ClearTokenFromStorage succeeds, and the file token is cleared while the server URL is kept. This fails on main with the same error as the issue.
  • token readable but delete denied: still returns error clearing token from keyring.

Ran go test ./... (all packages pass), go vet on config and auth, gofmt, and go build. golangci-lint run (v2.15.0 locally) reports the same 6 pre-existing goconst findings in internal/config with and without this change; CI's pinned version may differ. I didn't run a real OAuth login in a keyring-less container, only the unit tests.

ClearTokenFromStorage returned an error for any keyring failure other than
ErrNotFound, so glean auth login failed in containers with no Secret Service
daemon. If the keyring can't be read either, no token there can shadow the
new credentials, so clear the config file and continue. It still fails when a
token is readable from the keyring but can't be deleted.

Fixes gleanwork#157
@Mohith26
Mohith26 requested a review from a team as a code owner November 3, 2026 01:22
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.

Unable to oauth if no system keyring

1 participant