Skip to content

GitLab: Ignore username from Git credential input when looking up and generating credentials #2270

Open

Description

@tjuchniewicz

Version

2.7.0.0

Operating system

Windows

OS version or distribution

Windows 11

Git hosting provider(s)

GitLab

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

Expected Behavior

The GitLab provider should:

  1. Completely ignore the username from Git's credential input with OAuth

Rationale

  • Using the input username can cause incorrect credential lookups and confusing authentication prompts

Actual behavior

Current Behavior

When Git passes a username in the credential request (e.g., username=test when remote.origin.url=https://test@repo.git), the GitLab provider:

  1. User runs git pull
  2. GCM checks for token for user test - token is missing (not in cache, that's OK)
  3. GCM asks user to login using browser
  4. GCM Stores token in cache with user oauth (not test)
  5. git pull is successful
  6. User runs git pull again
  7. GCM checks for token for user test - token is not found due to invalid user!
  8. GCM asks user again to login using browser

Logs

No response

Activity

  1. tjuchniewicz commented on Feb 20, 2026

    @tjuchniewicz
    Author

    Simple workaround is to remove user name from Git url. Not sure if it's worth to fix this issue. Maybe just add more logging to easily debug such issue.

  2. mjcheetham commented on Mar 12, 2026

    @mjcheetham
    Contributor

    Hello! This is expected behaviour. Git credential helpers should respect the username field when passed by Git. You'll also find this the case with the contrib helpers such as wincred or osxkeychain.

    Is there a reason why you're including a username (that is not the correct user) in the remote URL?

  3. tjuchniewicz commented on Mar 19, 2026

    @tjuchniewicz
    Author

    We migrated from the legacy repository to GitLab.
    In the legacy setup, users had to include a username in the repository URL. During migration, some users copied and pasted the old URL (changing host part only), not realizing that the embedded username is no longer valid in GitLab.

    If changing this behavior is not feasible, we should add trace-level logging to make this issue easier to diagnose.
    In my case, I had to add custom logs to the GCM source code, then compile and distribute a custom GCM build to identify the root cause.

    This is expected behaviour. Git credential helpers should respect the username field when passed by Git.

    But currently credential helper does it only partially, when storing token in cache, username is ignored and oauth is always used as username.

  4. elieux commented on Jun 29, 2026

    @elieux

    I checked the credentials saved for different providers and GitLab seems to be the only one totally ignoring the requested username when saving ("d..." in the screenshot is my username). To be clear, I'm using the correct username for the account that I'm using to log in through the browser.

    I also believe the use case for including usernames should be fairly obvious – I have both a personal account and a work account with a provider and some remotes should use one and some should use the other. Specifying the username in the remote URL has always been the way to do that, I think.

    Image
  5. becm commented on Jul 4, 2026

    @becm
    Contributor

    @elieux code for GitLab is locked to oauth2 for historic reasons.
    They actually checked the username value in Basic auth at some point in the past.

    I agree that it's better to adapt naming/lookup with multi-user support (as in other providers) instead of adding another opaque special condition to the GitLab code path.

  6. becm commented on Jul 4, 2026

    @becm
    Contributor

    As a mitigation for the multiple accounts per URL, it's still possible to use a credential.namespace.

    A fix for the other account distinction option in the GitLab provider should be a simple matter of copy&paste (and test).

    Sadly, getting rid of the oauth2 account name is not so trivial;
    GitLab provider distinguishes authentication modes by the account name.

    → Candidate for local expiry detection of structured token (#1837), so username restriction can be removed.
    Token content query not an option, GitLab also uses an opaque value.

  7. becm commented on Jul 4, 2026

    @becm
    Contributor

    @mjcheetham the username should be part of the stored credential, but is replaced/ignored in GitLab OAuth2 case.

    The GitLab provider misuses the account field for credential type metadata (trigger token expiry check).
    So it's in direct violation of the described behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    auth-issueAn issue authenticating to a hosthost:gitlabSpecific to the GitLab host provider

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions