feat: add macOS keychain secret backend for profile refs#108
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds keychain://... secret reference support to the internal/secretref resolver so profile secret refs can be resolved via macOS Keychain (with a non-macOS stub backend), aligning with RFC 0011 / issue #88.
Changes:
- Register
keychaininNewDefaultResolver()alongsideenv. - Implement a Keychain backend with macOS
security-based lookup plus non-darwin stub behavior. - Add unit + opt-in darwin integration tests for keychain resolution and error mapping.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/secretref/secretref.go | Registers keychain in the default resolver. |
| internal/secretref/secretref_test.go | Keeps unsupported-scheme coverage independent of the new keychain backend. |
| internal/secretref/keychain_backend.go | Core keychain backend, path parsing, and error-kind mapping. |
| internal/secretref/keychain_backend_darwin.go | macOS implementation using security find-generic-password. |
| internal/secretref/keychain_backend_stub.go | Non-macOS stub that reports backend unavailable. |
| internal/secretref/keychain_backend_test.go | Unit tests for path parsing, success path, and typed error mapping. |
| internal/secretref/keychain_backend_integration_darwin_test.go | Opt-in integration test using security CLI to add/delete and resolve a real keychain item. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+23
to
+40
| add := exec.Command("security", "add-generic-password", "-U", "-s", service, "-a", account, "-w", secret) | ||
| if out, err := add.CombinedOutput(); err != nil { | ||
| t.Fatalf("add-generic-password failed: %v\n%s", err, out) | ||
| } | ||
| t.Cleanup(func() { | ||
| del := exec.Command("security", "delete-generic-password", "-s", service, "-a", account) | ||
| _, _ = del.CombinedOutput() | ||
| }) | ||
|
|
||
| b := NewKeychainBackend() | ||
| got, err := b.Resolve(context.Background(), Ref{ | ||
| Raw: "keychain://" + service + "/" + account, | ||
| Scheme: "keychain", | ||
| Path: service + "/" + account, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Resolve: %v", err) | ||
| } |
Comment on lines
102
to
+107
| // NewDefaultResolver builds the baseline resolver with env:// support. | ||
| func NewDefaultResolver() *Resolver { | ||
| return NewResolver(map[string]Backend{"env": NewEnvBackend(nil)}) | ||
| return NewResolver(map[string]Backend{ | ||
| "env": NewEnvBackend(nil), | ||
| "keychain": NewKeychainBackend(), | ||
| }) |
| } | ||
| return "", fmt.Errorf("security find-generic-password failed: %s", msg) | ||
| } | ||
| return strings.TrimSpace(string(out)), nil |
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.
Summary
keychain://...secret reference support.keychaininto the default secret resolver next toenv.What Changed
internal/secretref/keychain_backend.gointernal/secretref/keychain_backend_darwin.gointernal/secretref/keychain_backend_stub.gointernal/secretref/secretref.gonow includeskeychaininNewDefaultResolver()internal/secretref/keychain_backend_test.gointernal/secretref/keychain_backend_integration_darwin_test.goCLOUDSTIC_TEST_KEYCHAIN=1Notes
keychain://<service>/<account>parsing uses the last path segment as account and the preceding path as service.not_found,backend_unavailable,invalid_ref).Validation
go test ./internal/secretref -count=1go test ./...golangci-lint run ./...go test ./internal/secretref -run TestKeychainBackend_Integration -count=1 -vCLOUDSTIC_TEST_KEYCHAIN=1 go test ./internal/secretref -run TestKeychainBackend_Integration -count=1 -vTracking
rfcs/0011-profile-credential-storage-backends.md