[v0.9.0] osxkeychain: fix regressions on get and list#361
Merged
thaJeztah merged 2 commits intodocker:masterfrom Feb 28, 2025
Merged
[v0.9.0] osxkeychain: fix regressions on get and list#361thaJeztah merged 2 commits intodocker:masterfrom
thaJeztah merged 2 commits intodocker:masterfrom
Conversation
Commit 4cdcdc2 replaced the in-tree Objective-C code with github.com/keybase/go-keychain and inadvertently introduced a new failure mode on the `List` operation - it now fails when the keychain is empty. Before: ``` $ ./bin/build/docker-credential-osxkeychain list {} ``` After: ``` $ ./bin/build/docker-credential-osxkeychain list credentials not found in native keychain ``` Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Commit 4cdcdc2 swapped consts `kSecProtocolTypeHTTPS` and `kSecProtocolTypeHTTP` with plain-text "https" and "http" strings. This is causing a regression where credentials stored with prior versions (< v0.9.0) can't be fetched anymore. Unfortunately we can't just revert back to using Objective-C consts, as these are unsigned integers that need to be converted into `CFStringRef` and then passed to an helper like `keychain.CFStringToString`. Although `keychain.CFStringToString` is exported, it takes a C type `C.CFStringRef` so it's not consumable from other packages due to Cgo restrictions: > Cgo translates C types into equivalent unexported Go types. Because > the translations are unexported, a Go package should not expose C > types in its exported API: a C type used in one Go package is > different from the same C type used in another. We could alternatively copy `keychain.CFStringToString` into the `osxkeychain` package, but this commit takes a simpler approach: just hardcode the value of `kSecProtocolTypeHTTPS` and `kSecProtocolTypeHTTP` as strings. (These consts are very unlikely to ever change since it'd break all existing consumers.) This is **NOT** handling backward compatibility with v0.9.0, since it was released only 12hrs ago. So this fix won't work with credentials created with v0.9.0. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #361 +/- ##
==========================================
+ Coverage 49.92% 50.15% +0.23%
==========================================
Files 13 13
Lines 653 650 -3
==========================================
Hits 326 326
+ Misses 281 279 -2
+ Partials 46 45 -1 ☔ View full report in Codecov by Sentry. |
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 I did
osxkeychain: list: do not error out when keychain is empty
Commit 4cdcdc2 replaced the in-tree Objective-C code with github.com/keybase/go-keychain and inadvertently introduced a new failure mode on the
Listoperation - it now fails when the keychain is empty.Before:
After:
osxkeychain: store: use Apple's proto consts
Commit 4cdcdc2 swapped consts
kSecProtocolTypeHTTPSandkSecProtocolTypeHTTPwith plain-text "https" and "http" strings.This is causing a regression where credentials stored with prior versions (< v0.9.0) can't be fetched anymore.
Unfortunately we can't just revert back to using Objective-C consts, as these are unsigned integers that need to be converted into
CFStringRefand then passed to an helper likekeychain.CFStringToString.Although
keychain.CFStringToStringis exported, it takes a C typeC.CFStringRefso it's not consumable from other packages due to Cgo restrictions:We could alternatively copy
keychain.CFStringToStringinto theosxkeychainpackage, but this commit takes a simpler approach: just hardcode the value ofkSecProtocolTypeHTTPSandkSecProtocolTypeHTTPas strings. (These consts are very unlikely to ever change since it'd break all existing consumers.)This is NOT handling backward compatibility with v0.9.0, since it was released only 12hrs ago. So this fix won't work with credentials created with v0.9.0.
- How to verify it
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)