Skip to content

Store CLI token in OS system keychain#1190

Closed
michael-webster wants to merge 1 commit intomainfrom
feature/system-keychain-credentials
Closed

Store CLI token in OS system keychain#1190
michael-webster wants to merge 1 commit intomainfrom
feature/system-keychain-credentials

Conversation

@michael-webster
Copy link
Contributor

Summary

  • Adds github.com/zalando/go-keyring to store the API token in the OS keychain (macOS Keychain, Windows Credential Manager, Linux Secret Service) under the service name com.circleci.cli keyed by host URL
  • Existing tokens in ~/.circleci/cli.yml are silently migrated to the keychain on first LoadFromDisk call
  • Falls back transparently to the YAML token when the keychain is unavailable (CI/headless Linux); CIRCLECI_CLI_TOKEN env var still overrides everything
  • Other CircleCI-owned tools can retrieve the token with keyring.Get("com.circleci.cli", "https://circleci.com")

Test plan

  • go test ./settings/... passes (uses keyring.MockInit() in tests)
  • go build ./... passes
  • Manual: circleci setup → token appears in macOS Keychain Access under com.circleci.cli
  • Manual: ~/.circleci/cli.yml has blank token: field after setup
  • Manual: existing token in YAML is auto-migrated to keychain on next CLI run
  • Manual: CLI still authenticates correctly after migration (circleci whoami)

Uses github.com/zalando/go-keyring to store the API token in the OS
keychain (macOS Keychain, Windows Credential Manager, Linux Secret
Service) under the service name "com.circleci.cli" keyed by host URL.

Existing tokens in ~/.circleci/cli.yml are silently migrated to the
keychain on first load. Falls back to the YAML token when the keychain
is unavailable (CI/headless environments).
@michael-webster michael-webster changed the base branch from develop to main March 12, 2026 18:45
@michael-webster
Copy link
Contributor Author

Superseded by #1191 (correctly based on develop)

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.

1 participant