Skip to content

Gitlab duo provider is not working with Self Hosted instances. #8655

Closed

Description

@gaetan-puleo

Description

I am using Opencode with a self hosted gitlab instance.
I got an error when trying to send a message.

GitlabError: Failed to get direct access token: 403 Forbidden - {"Message":"403 Forbidden"}

I use the PAT method to login. (Even Gitlab show the token to be used recently).

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

macos sonoma 14.8.2

Terminal

kitty / iterm2

Activity

  1. github-actions commented on Jan 15, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if none of these address your specific case.

  2. gaetan-puleo commented on Jan 15, 2026

    @gaetan-puleo
    Author

    @vglafirov I created an issue for Gitlab instances

  3. vglafirov commented on Jan 15, 2026

    @vglafirov
    Contributor

    @gaetan-puleo Could you please provide GitLab version you are currently running?

  4. gaetan-puleo commented on Jan 15, 2026

    @gaetan-puleo
    Author
  5. NicFontana commented on Jan 15, 2026

    @NicFontana

    Same here on v18.7.1-ee

  6. vglafirov commented on Jan 15, 2026

    @vglafirov
    Contributor

    Thanks for posting the versions. They are relatively new, which is good. Could you please tell me if you use OAuth or PAT authentication? Could you please try both methods? If it's PAT, make sure it has API access, if PAT is old, try to create a new one and test it.

  7. gaetan-puleo commented on Jan 15, 2026

    @gaetan-puleo
    Author

    @vglafirov I created a PAT yesterday with API Access, but I couldn't use Oauth because OpenCode tried to log me in gitlab.com and not the self hosted instance. I'll try again

  8. gaetan-puleo commented on Jan 15, 2026

    @gaetan-puleo
    Author

    Same behavior using /connect and selecting gitlab duo (oauth method)

  9. gaetan-puleo commented on Jan 15, 2026

    @gaetan-puleo
    Author

    When using "opencode auth login" I can enter a gitlab instance URL. Ok we need to avoid using /connect when opencode is running.

  10. gaetan-puleo commented on Jan 15, 2026

    @gaetan-puleo
    Author

    "Client authentication failed due to unknown client, no client authentication included, or unsupported authentication method."

    I guess oauth is not possible with my instance

  11. vglafirov commented on Jan 15, 2026

    @vglafirov
    Contributor

    Yeah, for OAuth you might need to register your own application. I am currently investingating this. I will keep you posted.

  12. vglafirov commented on Jan 15, 2026

    @vglafirov
    Contributor

    Another question: Have you tried Duo-CLI ? Does this work for you? It doesn't mean we should not fix OpenCode, it's a part of debug process :) Trying to find the difference.

  13. gaetan-puleo commented on Jan 15, 2026

    @gaetan-puleo
    Author

    Another question: Have you tried Duo-CLI ? Does this work for you? It doesn't mean we should not fix OpenCode, it's a part of debug process :) Trying to find the difference.

    I just connected duo cli to the instance and try to send a message, it works and it can find my project @vglafirov

  14. 28 remaining items

  15. plutowang commented on Jan 19, 2026

    @plutowang

    I think I found the bug, it's not related to OpenCode it's related to AI Gateway: https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist/-/merge_requests/4288

    Let's see if it works once it's merged.

    Hi @vglafirov, I noticed that the MR has merged and the AI Gateway has released a new version. Here’s the link: https://gitlab.com/gitlab-org/modelops/applied-ml/code-suggestions/ai-assist/-/releases/v1.261.2. However, I tested opencode with GitLab Duo and it still complains with an error: “GitLabError: Anthropic API error: 403 {“detail”:”Gitlab instance uid mismatch”}”

  16. NicFontana commented on Jan 19, 2026

    @NicFontana

    I now get this error:

    GitLabError: Failed to get direct access token: 503 Service Unavailable - {"message":"Token creation failed"}
    
  17. J4NS-R commented on Jan 19, 2026

    @J4NS-R

    Hi all

    Thanks for everyone's input with the mob-debugging. Thanks to this thread I have reproducable steps to get opencode working with Duo in my organisation (on a self-hosted instance).

    Steps:

    • Enable Duo Agent Platform for the user/group/instance.
    • Ensure the following feature flags are enabled (root access required. No restart required)
      • Feature.enabled?(:agent_platform_claude_code)
      • Feature.enabled?(:third_party_agents_enabled)
    • Ensure your instance's personal access tokens have the prefix glpat- set (Admin > Settings > General > Account and limit > Access token prefix)
    • Create a new PAT with api and ai_features scopes.
    • Run opencode auth login in your terminal (do not use /connect command)
    • Select Duo, type in your instance URL and paste in your PAT.
    • I do not know why, but the following env vars must also be set (eg through direnv or .bashrc or export ...)
      • GITLAB_INSTANCE_URL=https://gitlab.example.com
      • GITLAB_TOKEN=glpat-xxxxx
    • Run opencode, use /models to select one of the models under Duo, and Bob's your uncle.

    Versions:

    • opencode 1.1.19
    • Gitlab v18.7.1-ee
  18. vglafirov commented on Jan 19, 2026

    @vglafirov
    Contributor

    I can confirm this it is working now. The fix has been merged, but not deployed until this EMEA morning, due to the change lock, preventing weekend deployments. Now it's been deployed and the issue with UID mismatch has gone. @J4NS-R Thanks for testing this.

    Enable Duo Agent Platform for the user/group/instance.
    Ensure the following feature flags are enabled (root access required. No restart required)
    Feature.enabled?(:agent_platform_claude_code)
    Feature.enabled?(:third_party_agents_enabled)

    I do not know why, but the following env vars must also be set (eg through direnv or .bashrc or export ...)
    GITLAB_INSTANCE_URL=https://gitlab.example.com

    These two things are required, indeed. The rest, you mention, is not necessary. Token with glpat- prefix will be created automatically on newer versions of GitLab (17+).

    You can also specify GITLAB_AI_GATEWAY_URL environment variable, in case you run your own AI Gateway.

  19. NicFontana commented on Jan 19, 2026

    @NicFontana

    Thanks a lot @J4NS-R, it is working now.

    On my side, the only thing missing was the opencode auth login part.

  20. vglafirov commented on Jan 19, 2026

    @vglafirov
    Contributor

    @rekram1-node This issue can be closed. It's working now. Updated documentation as follow-up MR

  21. vglafirov commented on Jan 19, 2026

    @vglafirov
    Contributor

    Thanks a lot @J4NS-R, it is working now.

    On my side, the only thing missing was the opencode auth login part.

    opencode auth login command does the same as /connect, stores PAT in auth.json file.

  22. Pipyakas commented on Jan 21, 2026

    @Pipyakas

    I tested opencode with GitLab Duo and it still complains with an error: “GitLabError: Anthropic API error: 403 {“detail”:”Gitlab instance uid mismatch”}”

    Im having this error too, GitLab v18.6.1-ee

  23. vglafirov commented on Jan 21, 2026

    @vglafirov
    Contributor

    @Pipyakas Please, go to the Admin area of your instance and execute a health check, GitLab Duo -> "Run health check", make sure everything is 🟢

  24. calebdw commented on Jan 21, 2026

    @calebdw

    There's still a few issues:

    1. When using /connect with PAT, the instance url is never asked for which presumably means it will default to gitlab.com instead of using the private instance url
    2. I do NOT want to have to set env vars---this defeats the whole purpose of entering the instance url and the PAT during opencode auth login
    3. allowing oauth to work with private instances would be great
  25. vglafirov commented on Jan 21, 2026

    @vglafirov
    Contributor

    @calebdw Interesting observation, thanks. I am always relying on environment variable, TBH, but you are right, instance URL can be stored in auth storage.I think this issue can be closed, since it's working now. Could you please create a dedicated issue for this usecase?

    Image

    cc: @rekram1-node

  26. rekram1-node commented on Jan 21, 2026

    @rekram1-node
    Collaborator

    Yeah we should have additional prompt for it

  27. vglafirov commented on Jan 22, 2026

    @vglafirov
    Contributor

    Okay, now I understand the problem. opencode auth login provides a dialog to specify the instance URL, but when you do /connect, opencode bypasses the auth plugin's prompts and goes directly to gitlab.com, unless you specified GITLAB_INSTANCE_URL environment variable. This needs to be added to Opencode codebase, not to auth plugins. @rekram1-node Do you want me to open an issue to implement this?

  28. gaetan-puleo commented on Jan 26, 2026

    @gaetan-puleo
    Author

    I close this issue, I don't have access to the endpoint.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions