git-ecosystem / git-ecosystem/git-credential-manager

Bitbucket DC reports `Must specify at least on AuthenticationModes` and falls back to cli input

Open
#1,460 8 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auth-issue bug host:bitbucket
Dominant language
C#
Stars
9.3k
Forks
2.9k
Avg merge
7d 1h
Merged PRs (30d)
14

Description

Version

2.3.2

Operating system

Windows

OS version or distribution

Windows 10 x64

Git hosting provider(s)

Bitbucket Server/DC

Other hosting provider

No response

(Azure DevOps only) What format is your remote URL?

None

Can you access the remote repository directly in the browser?

Yes, I can access the repository

Expected behavior

I expected the UI to pop up and prompt me for my username + token

Actual behavior

A fatal message is displayed Must specify at least one AuthenticationModes and then a CLI prompt asks for username and password.

Logs

The issue is that BitbucketHelper.GetBaseUri doesn't consider that Bitbucket DC could be proxied behind a path. For example, https://<host>/bitbucket. The method drops the needed path and causes 404 errors in the following API requests.
Then DataCenter.BitbucketRestApi.GetAuthenticationMethodsAsync and DataCenter.BitbucketRestApi.IsOAthInstalledAsync swallow the 404 errors and 0 Authentication modes are returned.

A quick fix would be to have DataCenter.BitbucketRestApi.GetAuthenticationMethodsAsync raise an exception on a 404 and the fallback logic in
BitbucketHostProvider.GetSupportedAuthenticationsModesAsync should kick in and i would expect everything to work.

git clone <host>/bitbucket/scm/<projectkey>/<repo>.git sfsf
Cloning into 'sfsf'...
16:39:04.620409 ...\Application.cs:95   trace: [RunInternalAsync] Version: 2.0.935.18315
16:39:04.636742 ...\Application.cs:96   trace: [RunInternalAsync] Runtime: .NET Framework 4.0.30319.42000
16:39:04.636742 ...\Application.cs:97   trace: [RunInternalAsync] Platform: Windows (x86-64)
16:39:04.636742 ...\Application.cs:98   trace: [RunInternalAsync] OSVersion: 10.0 (build 19045)
16:39:04.636742 ...\Application.cs:99   trace: [RunInternalAsync] AppPath: C:\Program Files\Git\mingw64\bin\git-credential-manager
16:39:04.636742 ...\Application.cs:100  trace: [RunInternalAsync] InstallDir: C:\Program Files\Git\mingw64\bin\
16:39:04.636742 ...\Application.cs:101  trace: [RunInternalAsync] Arguments: get
16:39:04.666881 ...GitCommandBase.cs:33 trace: [ExecuteAsync] Start 'get' command...
16:39:04.676790 ...GitCommandBase.cs:47 trace: [ExecuteAsync] Detecting host provider for input:
16:39:04.676790 ...GitCommandBase.cs:48 trace: [ExecuteAsync]   protocol=https
16:39:04.676790 ...GitCommandBase.cs:48 trace: [ExecuteAsync]   host=<host>
16:39:04.716857 ...oviderRegistry.cs:99 trace: [GetProviderAsync] Host provider override was set id='bitbucket'
16:39:04.726785 ...GitCommandBase.cs:50 trace: [ExecuteAsync] Host provider 'Bitbucket' was selected.
16:39:04.811054 ...tHostProvider.cs:277 trace: [GetSupportedAuthenticationModesAsync] <host>/ is Bitbucket DC - checking for supported authentication schemes...
16:39:04.821049 ...bucketRestApi.cs:100 trace: [GetAuthenticationMethodsAsync] HTTP: GET <host>/rest/authconfig/1.0/login-options
16:39:04.821049 ...pClientFactory.cs:58 trace: [CreateClient] Creating new HTTP client instance...
16:39:05.441305 ...pClientFactory.cs:97 trace: [CreateClient] Custom certificate verification has been enabled with certificate bundle at C:/Program Files/Git/mingw64/etc/ssl/certs/ca-bundle.crt
16:39:05.821410 ...bucketRestApi.cs:103 trace: [GetAuthenticationMethodsAsync] HTTP: Response 404 [NotFound]
16:39:05.821410 ...tbucketRestApi.cs:77 trace: [IsOAuthInstalledAsync] HTTP: GET <host>/rest/oauth2/1.0/client
16:39:06.071414 ...tbucketRestApi.cs:80 trace: [IsOAuthInstalledAsync] HTTP: Response 404 [NotFound]
16:39:06.071414 ...tHostProvider.cs:296 trace: [GetSupportedAuthenticationModesAsync] Bitbucket DC/Server instance supports authentication schemes: None
16:39:06.191234 ...tHostProvider.cs:103 trace: [GetStoredCredentials] Look for existing credentials under <host> ...
16:39:06.370031 ...tHostProvider.cs:109 trace: [GetStoredCredentials] No stored credentials found
16:39:06.370031 ...tHostProvider.cs:126 trace: [GetRefreshedCredentials] Refresh credentials...
16:39:06.370031 ...tHostProvider.cs:132 trace: [GetRefreshedCredentials] Checking for refresh token...
16:39:06.370031 ...tHostProvider.cs:139 trace: [GetRefreshedCredentials] No stored refresh token found
16:39:06.370031 ...tHostProvider.cs:143 trace: [GetRefreshedCredentials] Prompt for credentials...
fatal: Must specify at least one AuthenticationModes
Parameter name: modes
   at Atlassian.Bitbucket.BitbucketAuthentication.<GetCredentialsAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Atlassian.Bitbucket.BitbucketHostProvider.<GetRefreshedCredentials>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Atlassian.Bitbucket.BitbucketHostProvider.<GetCredentialAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at GitCredentialManager.Commands.GetCommand.<ExecuteInternalAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at GitCredentialManager.Commands.GitCommandBase.<ExecuteAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Invocation.CommandHandler.<GetExitCodeAsync>d__70.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.<InvokeAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<<UseVersionOption>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()
Username for '<host>':

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with BitbucketHelper.GetBaseUri to trace how a Bitbucket Server/DC URL with a path is converted into API requests. Review DataCenter.BitbucketRestApi.GetAuthenticationMethodsAsync, IsOAuthInstalledAsync, and BitbucketHostProvider.GetSupportedAuthenticationModesAsync. Done means proxied Bitbucket DC URLs retain their path and authentication modes no longer fall through to the empty-mode CLI prompt.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, git
Domain
authentication, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.