feat(auth): Add --save-to-file flag for explicit credential file fallback#654
feat(auth): Add --save-to-file flag for explicit credential file fallback#654mgajda wants to merge 2 commits intoUpCloudLtd:mainfrom
Conversation
…back - Add --save-to-file flag to account login command for explicit fallback - Create credentials file at ~/.config/upcloud/credentials with 0600 permissions - Load credentials from file automatically if present - Provide clear error messages with --save-to-file guidance when keyring fails - Detect WSL, SSH, and headless environments for better error context Fixes UpCloudLtd#643
|
This implementation extends the shared credentials support in upcloud-go-api with:
The credentials file support could be contributed to the upstream upcloud-go-api/credentials package so all UpCloud Go tools could benefit from it. This would:
Current architecture: User Input The shared credentials package provides the foundation, but lacks file-based storage which we've added specifically for the CLI to handle environments where keyring isn't available. |
| fs.BoolVar(&s.saveToFile, "save-to-file", false, | ||
| "Save token to credentials file (~/.config/upcloud/credentials) instead of keyring when keyring is unavailable") |
There was a problem hiding this comment.
Let's look into how similar tools handle this situation and find out if there are some common practices 👀
For example, GitHub CLI, which does authentication very nicely, seems to (based on documentation) fallback to saving the credentials to configuration file, but not sure if this requires using --insecure-storage flag or is the default when keyring access fails (gh auth login docs) 🤔
There was a problem hiding this comment.
I took example of AWS CLI, which uses a separate credentials and configuration files. This allows all to read configuration, but only the user can read credentials.
Saving without explicit override means defaulting to potentially insecure behaviour, which should be discouraged.
Summary
This PR addresses issue #643 by adding an explicit
--save-to-fileflag that allows users to save credentials to a file when the system keyring is unavailable.This PR replaces #653 with a more secure approach that requires explicit user consent for fallback to file storage.
Problem (Issue #643)
Users on WSL, ARM systems, and headless environments encounter keyring errors:
Currently, there's no fallback mechanism, forcing the user to use environment variable UPCLOUD_TOKEN and failing to save token on login.
Solution
--save-to-fileflag toaccount logincommand~/.config/upcloud/credentialswith 0600 permissions--save-to-fileoptionChanges
internal/config/credentials_file.go- Handles credential file operationsinternal/commands/account/login.go- Added--save-to-fileflaginternal/config/config.go- Load from credentials file before attempting keyringinternal/clierrors/missing_credentials.go- error messages with fallback guidanceSecurity Considerations
--save-to-fileflagUser Experience
Successful save with --save-to-file:
Keyring failure without flag:
Related