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

Authentication on Bitbucket DC fails - Redirects to bitbucket.org #722

Closed
augustocarvalho opened this issue Jun 3, 2022 · 8 comments
Closed
Labels
auth-issue An issue authenticating to a host bug A bug in Git Credential Manager

Comments

@augustocarvalho
Copy link

augustocarvalho commented Jun 3, 2022

Which version of GCM are you using?
2.0.696+4365b917da

Which Git host provider are you trying to connect to?
Bitbucket DC (On prem)

Expected behavior

I am trying to clone a repo from a Bitbucket DC on prem.
GMC detects that it is a bitbucket server (I see the right host with the trace and on my gitconfig it shows the provider = bitbucket)

But redirects the authentication to bitbucket.org:

Logs
10:46:46.972059 ...GitCommandBase.cs:48 trace: [ExecuteAsync]   protocol=https
10:46:46.972059 ...GitCommandBase.cs:48 trace: [ExecuteAsync]   host=mybitbucket_url
10:46:46.972059 ...GitCommandBase.cs:48 trace: [ExecuteAsync]   username=myusername
10:46:47.103677 ...oviderRegistry.cs:99 trace: [GetProviderAsync] Host provider override was set id='bitbucket'
10:46:47.103677 ...GitCommandBase.cs:50 trace: [ExecuteAsync] Host provider 'Bitbucket' was selected.
10:46:47.312195 ...tHostProvider.cs:103 trace: [GetStoredCredentials] Look for existing credentials under mybitbucket_url ...
10:46:47.713122 ...tHostProvider.cs:109 trace: [GetStoredCredentials] No stored credentials found
10:46:47.713122 ...tHostProvider.cs:126 trace: [GetRefreshedCredentials] Refresh credentials...
10:46:47.713122 ...tHostProvider.cs:131 trace: [GetRefreshedCredentials] Checking for refresh token...
10:46:47.713122 ...tHostProvider.cs:138 trace: [GetRefreshedCredentials] No stored refresh token found
10:46:47.713122 ...tHostProvider.cs:146 trace: [GetRefreshedCredentials] Prompt for credentials...
10:46:48.342977 ...enticationBase.cs:40 trace: [InvokeHelperAsync] Starting helper process: C:\Program Files\Git\mingw64\bin\Atlassian.Bitbucket.UI.exe userpass --username myusername
10:46:55.577219 ...tHostProvider.cs:167 trace: [GetRefreshedCredentials] Checking if two-factor requirements for credentials...
10:46:55.577219 ...tHostProvider.cs:376 trace: [RequiresTwoFactorAuthenticationAsync] Check if 2FA is required for credentials (myusername/********)...
10:46:55.593222 ...tbucketRestApi.cs:74 trace: [GetUserInformationAsync] HTTP: GET https://api.bitbucket.org/2.0/user
10:46:55.593222 ...pClientFactory.cs:58 trace: [CreateClient] Creating new HTTP client instance...
10:46:57.061702 ...pClientFactory.cs:97 trace: [CreateClient] Custom certificate verification has been enabled with certificate bundle at C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
10:46:57.517012 ...tbucketRestApi.cs:77 trace: [GetUserInformationAsync] HTTP: Response 401 [Unauthorized]

@augustocarvalho augustocarvalho added the auth-issue An issue authenticating to a host label Jun 3, 2022
@ldennington
Copy link
Contributor

@mminns - would you mind taking a look at this? Perhaps it'll be fixed with #607?

@ldennington ldennington added the bug A bug in Git Credential Manager label Jun 8, 2022
@mminns
Copy link
Contributor

mminns commented Jun 9, 2022

Morning @augustocarvalho

Could you post up your git config settings, please?

It looks like you have set credential.provider ?

If its at all possible would you be able to post your Bitbucket DC URL or at least a close copy showing the structure of the URL?

Thanks

@augustocarvalho
Copy link
Author

augustocarvalho commented Jun 9, 2022

Hi @mminns, thanks for looking into it.
I can only reproduce the Atlassian Dialog if I set the credential.helper=manager.core
otherwise it will first show the Windows credentials dialog.

When I first try to clone a repo from my Bitbucket server, it detects a bitbucket provider and configures my gitconfig:
credential.https://URL.provider=bitbucket

My Bitbucket DC URL is simple: https://git.mydomain.com

$ git config --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
core.fscache=true
core.symlinks=false
core.autocrlf=true
pull.rebase=false
init.defaultbranch=master
user.name=Augusto
user.email=[email protected]
difftool.sourcetree.cmd='' "$LOCAL" "$REMOTE"
mergetool.sourcetree.cmd=''
mergetool.sourcetree.trustexitcode=true
credential.helper=manager-core
credential.https://git.domain.com.provider=bitbucket

@mjcheetham
Copy link
Collaborator

I think the problem here is the BitbucketRestApi class always targets the Bitbucket Cloud API:

https://github.com/GitCredentialManager/git-credential-manager/blob/ac73bebcb950663ee269a09ebb13e872eea0b538/src/shared/Atlassian.Bitbucket/BitbucketRestApi.cs#L51

https://github.com/GitCredentialManager/git-credential-manager/blob/ac73bebcb950663ee269a09ebb13e872eea0b538/src/shared/Atlassian.Bitbucket/BitbucketRestApi.cs#L60-L63

It should probably be modified to take a targetUri or base API URL in each method to compute the correct API to call for Server/DC instances.

@mminns
Copy link
Contributor

mminns commented Jun 14, 2022

Finally have a little time to look into this

@mminns
Copy link
Contributor

mminns commented Jun 14, 2022

Ah I think it was this commit that broke it, prior to this the check for 2FA was ignored for Bitbucket Server/DC instances.

5a2cfd7#diff-2204d18f7d581ae182cb6a29ef9d7e6b3d850d32dffce2d889305eed1941cc64R124

I haven't yet worked out why I removed it.

It would suggest releases < v2.0.567 should work correctly.

@mminns
Copy link
Contributor

mminns commented Jun 14, 2022

See #743

mminns added a commit to mminns/Git-Credential-Manager that referenced this issue Jun 14, 2022
BitbucketHostProvider: fix runtime exceptions  when authentication requests for Bitbucket DC would incorrectly call a Bitbucket Cloud REST API

A bug was introduced in commit: 5a2cfd7. Prior to this only authentication requests for Bitbucket Cloud would try and automatically determine if 2FA was required by the current user by calling a Bitbucket Cloud REST API using user provided Basic Auth credentials

Commit: 5a2cfd7 removed checking of the current host was Bitbucket Cloud vs DC. This meant the check would be run for Bitbucket Cloud and DC regardless. It would fail for Bitbucket DC

The fix is more radical than simply re-instating the check on the type of Bitbucket host.From 1st March 2022 support for using a Bitbucket Cloud user's account password to access REST or Git HTTPS operations has been removed, https://atlassian.community/t5/x/x/ba-p/1948231. As such this automatic test to see if 2FA is required no longer works.

Therefore the check against the Bitbcuket Cloud REST API has been removed in its entirety
mminns added a commit to mminns/Git-Credential-Manager that referenced this issue Jun 15, 2022
BitbucketHostProvider: fix runtime exceptions  when authentication requests for Bitbucket DC would incorrectly call a Bitbucket Cloud REST API

A bug was introduced in commit: 5a2cfd7. Prior to this only authentication requests for Bitbucket Cloud would try and automatically determine if 2FA was required by the current user by calling a Bitbucket Cloud REST API using user provided Basic Auth credentials

Commit: 5a2cfd7 removed checking of the current host was Bitbucket Cloud vs DC. This meant the check would be run for Bitbucket Cloud and DC regardless. It would fail for Bitbucket DC

The fix is more radical than simply re-instating the check on the type of Bitbucket host. From 1st March 2022 support for using a Bitbucket Cloud user's account password to access REST or Git HTTPS operations has been removed, https://atlassian.community/t5/x/x/ba-p/1948231. As such this automatic test to see if 2FA is required no longer works.

Therefore the check against the Bitbucket Cloud REST API has been removed in its entirety
@augustocarvalho
Copy link
Author

Hi, thanks for the fix.
I can confirm that the new version works, the authentication is redirected to our Bitbucket instance.

$ git credential-manager-core --version
2.0.779+57cd9d4e50

$ git --version
git version 2.37.0.windows.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth-issue An issue authenticating to a host bug A bug in Git Credential Manager
Projects
None yet
Development

No branches or pull requests

4 participants