Skip to content

Conversation

@carole-lavillonniere
Copy link
Collaborator

@carole-lavillonniere carole-lavillonniere commented Feb 6, 2026

Switches to 99designs/keyring for automatic fallback to encrypted file storage when system keyring is unavailable.
The previous implementation using zalando/go-keyring would fail without a keyring service. This would have required a custom fallback implementation (more code to maintain).
99designs/keyring has low maintenance but is stable (keyring APIs rarely change).

Fallback Strategy

// Try system keyrings first (most secure)
ring, err := keyring.Open(config)
if err != nil {
    // Fall back to encrypted file storage
    config.AllowedBackends = []keyring.BackendType{keyring.FileBackend}
    ring, err = keyring.Open(config)
}
  1. First attempt tries default backends (system keyrings preferred)
  2. If system keyring fails or is broken, retry with FileBackend -> handles both "not available" and "partially broken" scenarios

Storage Locations

Using os.UserConfigDir() for OS-dependant paths:

  • Linux: ~/.config/localstack/
  • macOS: ~/Library/Application Support/localstack/
  • Windows: %APPDATA%\localstack\

@carole-lavillonniere carole-lavillonniere force-pushed the carole/drg-453 branch 5 times, most recently from d5e4223 to 24d9d64 Compare February 9, 2026 09:22
@carole-lavillonniere carole-lavillonniere marked this pull request as ready for review February 9, 2026 09:30
Copy link
Member

@silv-io silv-io left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me in general, just some minor comments.

Nice that we can use something with integrated file fallback 🚀


config := keyring.Config{
ServiceName: keyringService,
FileDir: filepath.Join(configDir, "localstack"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use configDir from internal/config.go
(guess will need to rename to ConfigDir)

configDir, _ := os.UserConfigDir()
config := keyring.Config{
ServiceName: "localstack",
FileDir: filepath.Join(configDir, "localstack"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here with the config path

Comment on lines +69 to +94

func keyringGet(service, user string) (string, error) {
key := fmt.Sprintf("%s/%s", service, user)
item, err := testKeyring.Get(key)
if err != nil {
return "", err
}
return string(item.Data), nil
}

func keyringSet(service, user, password string) error {
key := fmt.Sprintf("%s/%s", service, user)
return testKeyring.Set(keyring.Item{
Key: key,
Data: []byte(password),
})
}

func keyringDelete(service, user string) error {
key := fmt.Sprintf("%s/%s", service, user)
err := testKeyring.Remove(key)
if err == keyring.ErrKeyNotFound || os.IsNotExist(err) {
return nil
}
return err
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: with these it was a bit confusing to me in the other locations why it's suddenly keyringGet vs keyring.Get. Maybe we can call it testKeyringGet etc.?

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.

2 participants