Skip to content

store/keychain: windows support#67

Merged
Benehiko merged 8 commits into
mainfrom
keychain-windows
Jun 30, 2025
Merged

store/keychain: windows support#67
Benehiko merged 8 commits into
mainfrom
keychain-windows

Conversation

@Benehiko

@Benehiko Benehiko commented Jun 30, 2025

Copy link
Copy Markdown
Member

Closes #51
Closes #52

This patch adds support for the Windows Credential Manager API. It uses the danieljoos/wincred library. All credentials stored by the Windows Credential Manager are encoded in UTF16 format - since most applications accessing the credential manager expect this format.

Relates to #16

Benehiko added 3 commits June 30, 2025 12:10
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>

This comment was marked as outdated.

Benehiko added 2 commits June 30, 2025 14:08
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
…d error

Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
@Benehiko Benehiko requested a review from Copilot June 30, 2025 12:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds support for the Windows Credential Manager API by introducing a dedicated keychain implementation for Windows, updating module dependencies, and enabling Windows tests in the workflow.

  • Introduces a new implementation in store/keychain/keychain_windows.go to manage credentials using the wincred library.
  • Updates go.mod to include the wincred dependency and bumps versions for related packages.
  • Uncomments and adjusts the Windows tests in the GitHub Actions workflow.

Reviewed Changes

Copilot reviewed 3 out of 24 changed files in this pull request and generated 1 comment.

File Description
store/keychain/keychain_windows.go Implements Windows support for handling credentials using the Windows Credential Manager API.
store/go.mod Adds the wincred dependency and updates versions for golang.org/x/sys and golang.org/x/text.
.github/workflows/keychain.yml Activates Windows-based tests by uncommenting and adjusting the workflow configuration.
Comments suppressed due to low confidence (1)

store/keychain/keychain_windows.go:156

  • [nitpick] Consider renaming the variable 'g' to a more descriptive name such as 'credential' to improve code clarity.
	g := wincred.NewGenericCredential(k.itemLabel(id))

Comment thread store/keychain/keychain_windows.go
@Benehiko Benehiko requested review from joe0BAB and wmluke June 30, 2025 12:48
@Benehiko Benehiko marked this pull request as ready for review June 30, 2025 12:48
Comment thread store/keychain/keychain_windows.go Outdated
if err != nil && !errors.Is(err, wincred.ErrElementNotFound) {
return mapWindowsCredentialError(err)
}
if g == nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For readability: could we change that to g == nil || errors.Is(err, winced.ErrElementNotFound)? (it probably doesn't change logic but makes reading the code easier)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

But also, should deleting a secret that doesn't exist return an error? 🤔

Regardless of the answer, is that consistent across all OS and can we add verifying that it's consistent to the unit tests that check across all OS?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What I meant is, can you add to keychain_test.go a test case that verifies deleting a non existing secret behaves the same across all implementations? We don't have that test right now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can add more tests, but i don't think it's consistent in terms of when it errors. e.g. on success it returns nil error, but if it does error it can be for various reasons.

I'll do that in a follow-up when refactoring the tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

simplified the if check - instead of querying first, I let the delete handle the ErrNotFound.

if err != nil && !errors.Is(err, wincred.ErrElementNotFound) {
return mapWindowsCredentialError(err)
}
return nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The answer above might affect this as well.

Comment thread store/keychain/keychain_windows.go

@joe0BAB joe0BAB left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM! Could we add the missing test in keychain_test.go to the TODO/issue that is going to improve those tests? I believe we already have that somewhere.

Benehiko added 2 commits June 30, 2025 16:47
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com>
@Benehiko Benehiko merged commit 918c7a0 into main Jun 30, 2025
22 checks passed
@Benehiko Benehiko deleted the keychain-windows branch June 30, 2025 14:54
@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.

Windows Keychain GHA CI PR Checks Windows Keychain Support OS keychain [macos, linux, windows]

3 participants