# SonarQube delegate authentication to GitLab fail \[404 not found\]

**URL:** <https://community.sonarsource.com/t/sonarqube-delegate-authentication-to-gitlab-fail-404-not-found/59850>\
**Category:** SonarQube Server / Community Build\
**Tags:** sonarqube\
**Created:** [March 14, 2022, 12:46pm UTC](https://community.sonarsource.com/t/sonarqube-delegate-authentication-to-gitlab-fail-404-not-found/59850 "2022-03-14T12:46:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bastien.martin](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@bastien.martin](https://community.sonarsource.com/u/bastien.martin)\
**Post date:** [March 14, 2022, 12:46pm UTC](https://community.sonarsource.com/t/sonarqube-delegate-authentication-to-gitlab-fail-404-not-found/59850/1 "2022-03-14T12:46:57Z")

</div>

# Context

- Sonarqube: 9.2.4.50792 → https[://]sonar[.]dev[.]mycompany[.]com
- Gitlab: 13.4.3-ee → http[://]git[.]mycomany[.]com

# What I am trying to achieve:

I try to delegate SonarQube authentication to Gitlab Self-Hosted.

# What I’ve done:

Following the official SonarQube documentation ([Introduction to GitLab integration | SonarQube Server 2025.5 | Sonar Documentation](https://docs.sonarqube.org/latest/analysis/gitlab-integration/)), I’ve created a “[GitLab OAuth app](https://docs.sonarqube.org/latest/analysis/gitlab-integration/)”:

1. Went to [git.mycompany.com/admin/applications](http://git.mycompany.com/admin/applications)
2. New Application:
  - Name: SonarQube
  - Redirect URI: https[://]sonar[.]dev[.]mycompany[.]com/oauth2/callback/gitlab
  - Trusted: Checked
  - Confidential: Checked
  - Scopes: all checked, to be sure my issue was not an access issue. (I’ll tune it later)

3. I have copied both Application ID and Secret to use later.
4. Went to https[://]sonar[.]dev[.]mycompany[.]com/admin/settings?alm=gitlab&category=almintegration
5. GitLab Authentication:
  - Enabled: Yes, of course
  - GitLab URL: http[://]git[.]mycomany[.]com/users/auth/gitlab/callback
  - Application ID: The one given by GitLab during step 2
  - Secret: The one given by GitLab during step 2
  - Allow users to sign-up: Enabled
  - Synchronize user groups: Enabled

6. Disconnected to my admin account
7. The new Log in with GitLab is well shown:

 ![Log in with GitLab logo](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/2/9/2914733cc5ac717a1ba90f524567bab2ecec205b.png)

1. When I clicked on this new button, I was well redirected to my GitLab instance (URL: http[://]git[.]mycomany[.]com/users/sign\_in).

 ![GitLab Sign in](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/e/a/ea2f552c31fe4027820dad94644e2aea9a6c3d00.jpeg)

1. I was using my GitLab credentials then clicked on “Sign in”
2. I’ve got a GitLab 404 error page:

 ![GitLab Error 404](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/7/4/7479166e687211da728b73000d8ba4235f7c0f4b.jpeg)

The URL was:

```auto
http://git.mycomany.com/users/auth/gitlab/callback/oauth/authorize?response_type=code&client_id=<MY_APPLICATION_ID>&redirect_uri=http%3A%2F%2Fsonar.dev.mycompany.com%3A9000%2Foauth2%2Fcallback%2Fgitlab&scope=api&state=ai1rq82joi504ggv3nc1qa0h29

```

The redirect\_uri seems to be constructed with my sonar.properties informations (html\_encoded):

```auto
"http://" + sonar.web.host + ":" sonar.web.port + "oauth2/callback/gitlab"

```

# Investigation:

While I’m reproducing this error, I’m following (tail -f) some log files:

```auto
root@sonar.dev.mycompany.com: tail -f /var/log/httpd/*_log /var/log/message /home/sonar/sonarqube/logs/*.log

```

As expected, there is no information regarding the error 404 on GitLab. On my GitLab server :

```auto
root@git.mycompany.com: tail -f /var/log/httpd/*_log /var/log/message /var/log/gitlab/*/current

```

And a message appears:

```auto
==> /var/log/gitlab/gitlab-workhorse/current <==
{
   "correlation_id":"ZUVztnRFFe9",
   "duration_ms":62,
   "host":"git.mycompany.com",
   "level":"info",
   "method":"GET",
   "msg":"access",
   "proto":"HTTP/1.1",
   "referrer":"",
   "remote_addr":"127.0.0.1:0",
   "remote_ip":"127.0.0.1",
   "status":404,
   "system":"http",
   "time":"2022-01-19T18:06:47+01:00",
   "uri":"/users/auth/gitlab/callback/oauth/authorize?response_type=code\u0026client_id=<MY_APPLICATION_ID>\u0026redirect_uri=http%3A%2F%2Fsonar.dev.mycompany.com%3A9000%2Foauth2%2Fcallback%2Fgitlab\u0026scope=api\u0026state=16r2cvc196v4fj8k0rv7oprs6h",
   "user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62",
   "written_bytes":28281
}

```

Is there anyone who can help me?

**Note** : In the next days, I’ll try to do my install process using Sonarqube 9.3.0.51899 and keeping the same version of GitLab EE

**Note 2** : Same question on stackoverflow: [https://stackoverflow.com/questions/70774906/sonarqube-delegate-authentication-to-gitlab-fail-404-not-found](https://stackoverflow.com/questions/70774906/sonarqube-delegate-authentication-to-gitlab-fail-404-not-found)

---

<div class="post-metadata">

**Author:** ![ganncamp](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/ganncamp/32/1261_2.png) [@ganncamp](https://community.sonarsource.com/u/ganncamp)\
**Post date:** [March 16, 2022, 6:32pm UTC](https://community.sonarsource.com/t/sonarqube-delegate-authentication-to-gitlab-fail-404-not-found/59850/2 "2022-03-16T18:32:51Z")

</div>

Hi,

Welcome to the community & congrats on such a thorough post!

> [@bastien.martin](#):
>
> The redirect\_uri seems to be constructed with my sonar.properties informations (html\_encoded):
> 
> ```auto
> "http://" + sonar.web.host + ":" sonar.web.port + "oauth2/callback/gitlab"
> 
> ```

Yes, that’s going to be the default value. Have you set your Server base URL (Administration → Server base URL)?

&nbsp;  
Ann

---

<div class="post-metadata">

**Author:** ![bastien.martin](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@bastien.martin](https://community.sonarsource.com/u/bastien.martin)\
**Post date:** [March 17, 2022, 10:39am UTC](https://community.sonarsource.com/t/sonarqube-delegate-authentication-to-gitlab-fail-404-not-found/59850/3 "2022-03-17T10:39:14Z")

</div>

Hello Ann,

Thank you very much for your reply.

Indeed, the field “Server base URL” (sonar.core.serverBaseURL) was empty.  
I have added my sonar instance URL [https://sonar.dev.mycompany.com](https://sonar.dev.mycompany.com) then saved parameters.

BTW, I’ve updated my sonarqube version to 9.3.0.51899 following [the official doc](https://docs.sonarqube.org/latest/setup/upgrading/) part “Upgrading from the ZIP file”  
No update planned regarding our GitLab-EE (unfortunately).

I’ve tried again after clearing the cache and I’ve the same result.

First step, when I’m on SonarQube login page, I click on the “Log in with GitLab” button then get this on GitLab log file (/var/log/gitlab/gitlab-workhorse/current)

```auto
{
   "correlation_id":"Ou37QVnzY49",
   "duration_ms":8,
   "host":"git.mycompany.com",
   "level":"info",
   "method":"GET",
   "msg":"access",
   "proto":"HTTP/1.1",
   "referrer":"",
   "remote_addr":"127.0.0.1:0",
   "remote_ip":"127.0.0.1",
   "status":302,
   "system":"http",
   "time":"2022-03-17T11:21:55+01:00",
   "uri":"/users/auth/gitlab/callback/oauth/authorize?response_type=code\u0026client_id=<MY_CLIENT_ID>\u0026redirect_uri=https%3A%2F%2Fsonar.dev.mycompany.com%2Foauth2%2Fcallback%2Fgitlab\u0026scope=api\u0026state=sbm9qg9lkdpsmm7char48rc1vv",
   "user_agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
   "written_bytes":98
}

{
   "correlation_id":"oMdWoCFkR22",
   "duration_ms":20,
   "host":"git.mycompany.com",
   "level":"info",
   "method":"GET",
   "msg":"access",
   "proto":"HTTP/1.1",
   "referrer":"",
   "remote_addr":"127.0.0.1:0",
   "remote_ip":"127.0.0.1",
   "status":200,
   "system":"http",
   "time":"2022-03-17T11:21:55+01:00",
   "uri":"/users/sign_in",
   "user_agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
   "written_bytes":10945
}

```

My browser show the GitLab login page, as expected, the current URL is [http://git.mycompany.com/users/sign\_in](http://git.mycompany.com/users/sign_in)  
I log in to my gitlab account using my LDAP credentials, then click on the green “Sign in” button to get the following log messages.

```auto
{
   "correlation_id":"YjEKOaeeml8",
   "duration_ms":58,
   "host":"git.mycompany.com",
   "level":"info",
   "method":"POST",
   "msg":"access",
   "proto":"HTTP/1.1",
   "referrer":"http://git.mycompany.com/users/sign_in",
   "remote_addr":"127.0.0.1:0",
   "remote_ip":"127.0.0.1",
   "status":302,
   "system":"http",
   "time":"2022-03-17T11:25:37+01:00",
   "uri":"/users/auth/ldapmain/callback",
   "user_agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
   "written_bytes":354
}

{
   "correlation_id":"CP7EXOJhV16",
   "duration_ms":15,
   "host":"git.mycompany.com",
   "level":"info",
   "method":"GET",
   "msg":"access",
   "proto":"HTTP/1.1",
   "referrer":"http://git.mycompany.com/users/sign_in",
   "remote_addr":"127.0.0.1:0",
   "remote_ip":"127.0.0.1",
   "status":404,
   "system":"http",
   "time":"2022-03-17T11:25:37+01:00",
   "uri":"/users/auth/gitlab/callback/oauth/authorize?response_type=code\u0026client_id=<MY_CLIENT_ID>\u0026redirect_uri=https%3A%2F%2Fsonar.dev.mycompany.com%2Foauth2%2Fcallback%2Fgitlab\u0026scope=api\u0026state=a4q92mie48oe2df1f62qkh4r9p",
   "user_agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
   "written_bytes":28281
}

{
   "correlation_id":"hW4NhFCJLV6",
   "encoding":"gzip",
   "file":"/opt/gitlab/embedded/service/gitlab-rails/public/assets/illustrations/error-404-4ac0f2ed92ff27c0f80853181c4dceb1858dac25d9e744d6594f067d60a45b48.svg",
   "level":"info",
   "method":"GET",
   "msg":"Send static file",
   "time":"2022-03-17T11:25:37+01:00",
   "uri":"/assets/illustrations/error-404-4ac0f2ed92ff27c0f80853181c4dceb1858dac25d9e744d6594f067d60a45b48.svg"
}

{
   "correlation_id":"hW4NhFCJLV6",
   "duration_ms":0,
   "host":"git.mycompany.com",
   "level":"info",
   "method":"GET",
   "msg":"access",
   "proto":"HTTP/1.1",
   "referrer":"http://git.mycompany.com/users/auth/gitlab/callback/oauth/authorize?response_type=code\u0026client_id=<MY_CLIENT_ID>\u0026redirect_uri=https%3A%2F%2Fsonar.dev.mycompany.com%2Foauth2%2Fcallback%2Fgitlab\u0026scope=api\u0026state=a4q92mie48oe2df1f62qkh4r9p",
   "remote_addr":"127.0.0.1:0",
   "remote_ip":"127.0.0.1",
   "status":200,
   "system":"http",
   "time":"2022-03-17T11:25:37+01:00",
   "uri":"/assets/illustrations/error-404-4ac0f2ed92ff27c0f80853181c4dceb1858dac25d9e744d6594f067d60a45b48.svg",
   "user_agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
   "written_bytes":3788
}

```

My issue seems to be more GitLab side than SonarQube side, isn’t it ?

---

<div class="post-metadata">

**Author:** ![bastien.martin](https://avatars.discourse-cdn.com/v4/letter/b/ecc23a/32.png) [@bastien.martin](https://community.sonarsource.com/u/bastien.martin)\
**Post date:** [March 17, 2022, 12:21pm UTC](https://community.sonarsource.com/t/sonarqube-delegate-authentication-to-gitlab-fail-404-not-found/59850/4 "2022-03-17T12:21:23Z")

</div>

I’ve just tried again but with a local gitlab-ee 14.8.4 to check if the issue is linked to our old GitLab 13.4.3-ee version.

Unfortunately, I’ve reach the same 404 error page 😢
