Git CodeCommit credentials keep ending up in Keychain Access on Mac OS X

Viewed 2396

After doing the following to set up my CodeCommit repo on AWS with git:

$ git config --global credential.helper '!aws codecommit credential-helper $@'
$ git config --global credential.UseHttpPath true

I can only make one commit before I have to go and delete it from Keychain Access like so:

enter image description here

which is super annoying. Anyone know how to prevent Mac OS X from adding this to keychain on each git push ?

2 Answers

Here are some options to avoid this disturbance with keychain:

  • Disable osxkeychain for git:

    $ nano /usr/local/git/etc/gitconfig
    # helper = osxkeychain <======== Comment out using #
    
  • Connect to CodeCommit using SSH instead of HTTPS. For more information, see For SSH Connections on Linux, macOS, or Unix [1].

  • Install a version of Git that does not use the keychain by default.

  • Consider a scripting solution for deleting the keychain item. To view a community-generated sample of a scripted solution, see Mac OS X Script to Periodically Delete Cached Credentials in the OS X Certificate Store in Product and Service Integrations [2].

  • In the Keychain Access utility, on the Access Control tab for git-codecommit.us-east-2.amazonaws.com, choose the Allow all applications to access this item (access to this item is not restricted) option. This prevents the pop-ups, but the credentials eventually expire (on average, this takes about 15 minutes) and you then see a 403 error message. When this happens, you must delete the keychain item to restore functionality.

Much more information on the above options in AWS Docs: [3]

[1] https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-ssh-unixes.html

[2] https://github.com/nicc777/macaws-codecommit-pwdel

[3] Troubleshooting the Credential Helper and HTTPS Connections to AWS CodeCommit - Git for macOS: I configured the credential helper successfully, but now I am denied access to my repository (403) - https://docs.aws.amazon.com/codecommit/latest/userguide/troubleshooting-ch.html#troubleshooting-macoshttps

For me this issue is occuring more because of the AWS SSO has short lived access keys, also when you need github for some projects and codecommit for others.

For me the solution was to configure git to use oskeychain for github, and not use it for codecommit..

# identify location of git config file with credential.helper**
git config -l --show-origin
   > file:/<path>/git-core/gitconfig    credential.helper=osxkeychain

# edit the file as root 
sudo vi <path-from-above>

# add github in the credential line so oskeychain not used for other sites
[credential "https://github.com"]
    helper = osxkeychain
Related