feat(session): store session in macOS Keychain by default#248
Merged
Conversation
Add a sessionStore abstraction so session read/exists/delete go through a single seam, with two backends: a file (existing behaviour, used off macOS and when keychain is disabled) and the macOS login Keychain via the `security` CLI (no cgo, keeps the static binary). Keychain is the default on macOS; set `keychain: false` to opt out. An existing file session is migrated into the Keychain on first use and the file is removed; logout clears both. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
On macOS, the Telegram session is now stored in the login Keychain by default instead of a plaintext file in the config dir. Other platforms keep using the file backend, unchanged.
Why
The session string is the full auth credential. Keeping it as a
0600file in~/Library/Application Support/gotd/is weaker than the OS keystore. The Keychain is the native macOS secret store and needs no new dependency.How
sessionStoreabstraction (cmd/tg/session_store.go) — a single seam for read / exists / delete — with two backends:session.FileStorage, existing behaviour) — used off macOS and when disabled.cmd/tg/session_keychain_darwin.go) via thesecurityCLI. No cgo, so the static cross-compiled release binary is unaffected.app.go),logout(delete),accounts(existence).keychain: falsein the config (e.g. headless macOS). Non-darwin always uses a file.logoutclears both.gotd.session, account<label>.<kind>.<seed>— mirrors the on-disk filename scheme, so multi-account and user/bot never collide.Tests
session_store_test.go— default-on logic, account naming, file round-trip (cross-platform).session_keychain_darwin_test.go— argv builders, exit-44→ErrNotFoundmapping, and a real migration round-trip against the login Keychain (darwin-only; CI is Linux so it never runs there).go test -race ./...,go vet, andgofmtall clean.🤖 Generated with Claude Code