Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@YorikSar
Copy link

Switch from github.com/zalando/go-keyring to github.com/99designs/keyring that uses native bindings on macOS and Windows.

Originally suggested in #7023 (comment)
Fixes #7123

cc @mislav who opened the issue and @reegnz who originally suggested this library.

@YorikSar YorikSar requested a review from a team as a code owner July 24, 2023 12:11
@YorikSar YorikSar requested review from vilmibm and removed request for a team July 24, 2023 12:11
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Jul 24, 2023
YorikSar added a commit to YorikSar/dotfiles that referenced this pull request Jul 24, 2023
Using patch to make access to Keychain more secure, see
cli/cli#7743
@YorikSar YorikSar force-pushed the native-keyring branch 3 times, most recently from 36ff598 to d10a0de Compare August 7, 2023 22:17
@YorikSar
Copy link
Author

YorikSar commented Aug 7, 2023

To address the concern raised by @samcoe in #7123 (comment) that user would have to re-authenticate to switch to the new library, I've added the code that detects token stored by old library and uses it to fetch it properly and overwrite it with plain token with the new library. This should address issue on the macOS.
In my testing I found out that old library reads plain token just fine, so both old and new versions will work with both formats. There is no such difference in the way the token is stored on other platforms, so there should be no compatibility issues now.

@YorikSar
Copy link
Author

YorikSar commented Aug 7, 2023

Note that user will still have to authorise access to the keychain item for the new binary after switch and on each subsequent upgrade of gh, but that is an expected behaviour on macOS.

@reegnz
Copy link

reegnz commented Aug 8, 2023

AFAIK the trusting of the binary for each release only has to be done if you don't sign your binaries. If you're releasing signed binaries, it's enough to trust developer once.

@reegnz
Copy link

reegnz commented Aug 8, 2023

See docs for how aws-vault does it (they're the guys responsible for the lib you're using): https://github.com/99designs/aws-vault/blob/e22aea12b03e8ce036e9af87dda9303806fa2a9e/README.md#development

Alternatively, on ARM macs if you distribute via homebrew, kegs are automatically codesigned on installation.

@YorikSar
Copy link
Author

YorikSar commented Aug 8, 2023

@reegnz Looks like release binaries are already signed here:

- name: Configure macOS signing
if: inputs.environment == 'production'
env:
APPLE_DEVELOPER_ID: ${{ vars.APPLE_DEVELOPER_ID }}
APPLE_APPLICATION_CERT: ${{ secrets.APPLE_APPLICATION_CERT }}
APPLE_APPLICATION_CERT_PASSWORD: ${{ secrets.APPLE_APPLICATION_CERT_PASSWORD }}
run: |
keychain="$RUNNER_TEMP/buildagent.keychain"
keychain_password="password1"
security create-keychain -p "$keychain_password" "$keychain"
security default-keychain -s "$keychain"
security unlock-keychain -p "$keychain_password" "$keychain"
base64 -D <<<"$APPLE_APPLICATION_CERT" > "$RUNNER_TEMP/cert.p12"
security import "$RUNNER_TEMP/cert.p12" -k "$keychain" -P "$APPLE_APPLICATION_CERT_PASSWORD" -T /usr/bin/codesign
security set-key-partition-list -S "apple-tool:,apple:,codesign:" -s -k "$keychain_password" "$keychain"
rm "$RUNNER_TEMP/cert.p12"

I'm installing gh via Nix, so that's probably why I'm getting confirmation dialogs from Keychain on each binary update. I'm also fine with it.

@williammartin williammartin requested review from williammartin and removed request for vilmibm September 11, 2023 15:56
@samcoe samcoe self-assigned this Oct 4, 2023
@samcoe
Copy link
Contributor

samcoe commented Oct 11, 2023

@YorikSar Apologies for letting this PR languish in review limbo for so long. Just wanted to give you a bit of a status update from our end. We are still interested in moving to the 99designs/keyring library, but at the moment the team is focused on bring multi-account support to gh which will cause code changes down to the keyring level. In order to reduce risk and accidentally introduce conflicting code we are going to revisit this work once multi-account work has shipped. Do you have any issue with leaving this PR open for awhile longer? Would you have interest in updating this PR to be compatible with the multi-account work once it has shipped?

@YorikSar
Copy link
Author

I use this patch myself since I’ve published it (I’ve overridden it in my dotfiles), so there is little detriment to myself from having this PR hanging. I’m fine with rebasing it when needed since I will have to rebase it anyway when I want to update my gh, which didn’t happen so far.
I honestly don’t see much downside in switching libraries early since the change is rather compatible with both old and new ways.

@samcoe
Copy link
Contributor

samcoe commented Oct 11, 2023

I honestly don’t see much downside in switching libraries early since the change is rather compatible with both old and new ways.

This is something I will bring up with the team to see how we feel about getting this in first.

@reegnz
Copy link

reegnz commented Dec 9, 2023

@samcoe any updates?

@samcoe
Copy link
Contributor

samcoe commented Dec 11, 2023

@reegnz No updates on this right now. As we just shipped multi-account this is unblocked now, but with holidays coming up it is unlikely that this work gets prioritized before then.

@samcoe samcoe removed the blocked label Dec 11, 2023
@samcoe samcoe removed their assignment Jan 10, 2024
@YorikSar YorikSar force-pushed the native-keyring branch 2 times, most recently from cd07328 to 7a55107 Compare May 20, 2024 14:07
YorikSar added a commit to YorikSar/dotfiles that referenced this pull request May 20, 2024
cli/cli#7743 is still in limbo, so keep dragging
the patch along.
@YorikSar
Copy link
Author

I've updated patch for the latest trunk. Still using it for myself, appears to be working just fine :)

@samcoe or @williammartin Any chance you could approve workflows on this PR so that I can see if any tests are broken on all the systems?

Switch from github.com/zalando/go-keyring to github.com/99designs/keyring
that uses native bindings on macOS and Windows.

On darwin, github.com/zalando/go-keyring encodes secret data in hex or
base64, adding a prefix indicating that. If new library returns this
prefix, convert the secret to plain data to keep using existing token
and not require reauthentication.

Originally suggested in cli#7023 (comment)
Fixes cli#7123
YorikSar added a commit to YorikSar/dotfiles that referenced this pull request Nov 5, 2024
cli/cli#7743 is still in limbo, so keep dragging
the patch along.
@YorikSar
Copy link
Author

YorikSar commented Nov 5, 2024

@samcoe Almost a year passed since last message, I keep bumping this patch. Any idea if I could get a review any time soon?

@BagToad
Copy link
Member

BagToad commented Nov 25, 2024

Hey @YorikSar πŸ‘‹

Apologies for the delay on this one - we've been very busy with other competing priorities the last few months. I bumped this with the team - @williammartin opened 99designs/keyring#138 to investigate our concerns about the maintenance status of that module. We have some other questions about this PR, but it seems like we wanted to investigate this maintenance status first.

Note that @samcoe has left GitHub, so we don't receive notifications when they are @ mentioned.

joshlreese added a commit to datum-cloud/datumctl that referenced this pull request Dec 29, 2024
Two new auth subcommands have been added:

- activate-api-token: Accepts an API token either via stdin or a secure prompt and saves it in the OS keyring. This token will be used to obtain a token compatible with Datum Cloud infrastructure APIs when no service account credentials are located.
- logout: Removes an activated token from the OS keyring.

Future work will likely come to clean up keyring access when we implement token caching.

We may also want to keep an eye on cli/cli#7743 to follow suit if a keyring library switch is made.
@BagToad
Copy link
Member

BagToad commented Feb 1, 2025

πŸ‘‹ Hey @YorikSar. I discussed this with the team, and we are going to close this PR for now because of the maintenance concern that we brought up in 99designs/keyring#138 😞 ; we have not heard back from the maintainers on that package.

I'll invite more discussion and suggestions from anyone interested in #7123 πŸ™

@BagToad BagToad closed this Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch to native bindings for macOS Keychain

5 participants