Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use native keychain bindings if possible #7743

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

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
@cliAutomation cliAutomation added this to Needs review 🤔 in The GitHub CLI 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.

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
@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.

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
No open projects
The GitHub CLI
  
Needs review 🤔
Development

Successfully merging this pull request may close these issues.

Switch to native bindings for macOS Keychain
4 participants