Skip to content

store/keychain: fix macOS GetAll secrets#47

Merged
Benehiko merged 1 commit into
mainfrom
keychain-fix-darwin-list
Jun 26, 2025
Merged

store/keychain: fix macOS GetAll secrets#47
Benehiko merged 1 commit into
mainfrom
keychain-fix-darwin-list

Conversation

@Benehiko
Copy link
Copy Markdown
Member

@Benehiko Benehiko commented Jun 26, 2025

Related #53

This patch fixes the macOS GetAll function. It explicitly removes the ReturnData attribute from the newKeychainItem function which was preventing the use of MatchLimitAll attribute.

According to the Apple documentation
https://developer.apple.com/documentation/security/secitemcopymatching(_:_:)#Discussion you cannot use the ReturnData with MatchLimiteAll attribute - due to how the Apple keychain works with item data retrieval. It prompts the user per item retrieved. In cases where many items can exist under the application service group and service name it will prompt the user for each one.

The macOS keychain items are stored with AccessibleAfterFirstUnlock and an item can be marked as "don't ask again". In this case the user would only be required to unlock the item once.

Thinking of the future consequences for this - in the case of the secrets engine querying for many items from the keychain, macOS users might become overwhelmed with many prompts.

Reading the documentation it seems like some of our only options would be to lower the security requirements of items. Perhaps by omitting the user presence requirement with an AccessibleAfterFirstUnlock. https://developer.apple.com/documentation/security/secaccesscontrolcreatewithflags(_:_:_:_:)

Once the binary implementing this library is signed, it would also reduce the number of prompts a user is shown.

@Benehiko Benehiko requested a review from Copilot June 26, 2025 08:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the macOS GetAll implementation by removing the default ReturnData flag to allow bulk queries, introducing a helper for per-item data retrieval, and refactoring CRUD methods to add validation and separate data fetching.

  • Remove SetReturnData(true) from newKeychainItem and add getItemWithData for fetching the secret’s data.
  • Refactor Get, Delete, GetAll, and Save to validate IDs, use string-based constructors, and fetch data correctly.
  • Update GetAll to parse account IDs and call getItemWithData per item, avoiding per-item prompts during bulk lookup.
Comments suppressed due to low confidence (1)

store/keychain/keychain_darwin.go:109

  • [nitpick] The variable name i is ambiguous in this context; consider renaming it to something like itemResult or dataResult for clarity.
		i, err := getItemWithData(id.String(), k)

Comment thread store/keychain/keychain_darwin.go
Comment thread store/keychain/keychain_darwin.go
Comment thread store/keychain/keychain_darwin.go
Comment thread store/keychain/keychain_darwin.go Outdated
Copy link
Copy Markdown
Collaborator

@joe0BAB joe0BAB left a comment

Choose a reason for hiding this comment

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

LGTM! (just small non-blocking nit)

This patch fixes the macOS GetAll function. It explicitly removes the
`ReturnData` attribute from the `newKeychainItem` function which was
preventing the use of `MatchLimitAll` attribute.

According to the Apple documentation
https://developer.apple.com/documentation/security/secitemcopymatching(_:_:)#Discussion
you cannot use the `ReturnData` with `MatchLimiteAll` attribute - due to
how the Apple keychain works with item data retrieval. It prompts the
user per item retrieved. In cases where many items can exist under the
application service group and service name it will prompt the user for
each one.

The macOS keychain items are stored with `AccessibleAfterFirstUnlock`
and an item can be marked as "don't ask again". In this case the user
would only be required to unlock the item once.

Thinking of the future consequences for this - in the case of the
secrets engine querying for many items from the keychain, macOS users
might become overwhelmed with many prompts.

Reading the documentation it seems like some of our only options would
be to lower the security requirements of items. Perhaps by omitting the
user presence requirement with an `AccessibleAfterFirstUnlock`.
https://developer.apple.com/documentation/security/secaccesscontrolcreatewithflags(_:_:_:_:)

Once the binary implementing this library is signed, it would also reduce
the number of prompts a user is shown.

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
@Benehiko Benehiko force-pushed the keychain-fix-darwin-list branch from 55fcde2 to 5f74bfe Compare June 26, 2025 08:30
@Benehiko Benehiko merged commit 3ac7bbc into main Jun 26, 2025
13 checks passed
@Benehiko Benehiko deleted the keychain-fix-darwin-list branch June 26, 2025 08:33
@Benehiko Benehiko linked an issue Jul 2, 2025 that may be closed by this pull request
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.

Support OS keychain [macos, linux, windows]

3 participants