Getting intermittent authentication problem with BitBucket Server while doing git clone or git pull.

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: サーバーと Data Center のみ。この記事は、サーバーおよび Data Center プラットフォームのアトラシアン製品にのみ適用されます。

要約

While trying to clone a repository, there is an authentication failed response 2-3 times without getting prompted for the credentials.

git clone https://bitbucket.testing.com/scm/~test/test-demo.git
Cloning into 'test-demo'
fatal: Authentication failed for 'https://bitbucket.testing.com/scm/~test/test-demo.git/'

After that, it is prompted to enter the credentials and the clone works fine.

環境

Bitbucket Server/ Data Center version 7.6 + and above

診断

The atlassian-bitbucket.log, shows similar log entries for the authorization failure.

2022-06-10 11:25:18,498 INFO  [http-nio-7990-exec-925] @KXZGRTx685x337794699x2 54.93.107.158,127.0.0.1 "GET /scm/~test/test-demo.git/info/refs HTTP/1.1" c.a.c.m.a.ApplicationServiceGeneric Invalid credentials for user TestUser in directory mydirectory (262145), aborting

Once the git debug logging is enabled, we can see similar lines for the event of the failure.

15:15:07.021513 run-command.c:666       trace: run_command: 'git credential-store get'
15:15:07.024304 git.c:455               trace: built-in: git credential-store get
15:15:07.024664 http.c:756              == Info: Couldn't find host bitbucket.testing.com in the .netrc file; using defaults

If you want to compare, you can see the below entries when the try is successful. 

15:18:27.440380 run-command.c:666       trace: run_command: 'git credential-store get'
15:18:27.442953 git.c:455               trace: built-in: git credential-store get
Username for 'https://bitbucket.testing.com': TestUser
Password for 'https://TestUser@bitbucket.testing.com': 
15:18:34.966706 http.c:756              == Info: Couldn't find host bitbucket.testing.com in the .netrc file; using defaults

原因

Here the git-credential store is the reason for the failure. Once a password gets stored in it, it remains there and those credentials are used for the user authentication for git operations. There could be password policies set in the organization that will force you to change your passwords in a couple of months. But since the wrong password is already stored in the git-credential store, you will be getting the authentication error.

ソリューション

Unset the git the credential helper using the below command before running a git pull/clone. This should be a one time activity. 

git config --unset credential.helper

If this doesn't fix the issue, try unsetting it globally using the below command.

git config --global --unset credential.helper

The people who have used the credential.helper tend to miss the convenience of it and will need to enable it again with the correct password. (smile)  You can run the below command for that before you run any git command.

git config credential.helper store
最終更新日 2022 年 9 月 15 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.