Skip to content

gitlab omniauth + oauth2 report "You need to sign in or sign up before continuing."

Summary

I am configuring my Gitlab instance with Omniauth to use a Keycloak server as an Oauth2 provider after inputing username/pwd on keycloak and redirect back to gitlab. the git lab UI show "You need to sign in or sign up before continuing."

Steps to reproduce

  1. edit the gitlab.rb
 gitlab_rails['omniauth_allow_single_sign_on'] = ['saml','oauth2']
 gitlab_rails['omniauth_block_auto_created_users'] = false
 {
     'name' => 'oauth2',
     'app_id' => 'gitlab_oauth',
     'app_secret' => '82a3292f-0715-4728-a0bb-36f7a988e47a',
     'args' => {
             'client_options': {
                'site' => 'https://keycloak.willy.com:8443',
                'user_info_url' => '/auth/realms/pangu/protocol/openid-connect/userinfo',
                'authorize_url' => '/auth/realms/pangu/protocol/openid-connect/auth',
                'token' => '/auth/realms/test/protocol/openid-connect/token'
                },
             'user_response_structure':{
                attribue: { nickname: 'preferred_username'},
                id_path:'preferred_username'
                },
             'name': 'oauth',
             'strategy_class': 'OmniAuth::Strategies::OAuth2Generic',
             'redirect_url': 'https://gitlab.willy.com/users/auth/oauth2_generic/callback'
                        }

   }
  1. I can see the oauth button on the index. click it, the page will redirect to keycloak
  2. input user credential on keycloak. click login
  3. the web will redirect back to gitlab
  4. UI show: You need to sign in or sign up before continuing.
  5. the production log:
Redirected to https://gitlab.willy.com/users/sign_in
Filter chain halted as :redirect_unlogged_user rendered or redirected
Completed 302 Found in 27ms (ActiveRecord: 0.7ms | Elasticsearch: 0.0ms)
Started GET "/users/sign_in" for 172.16.106.91 at 2020-01-14 10:37:08 +0000
Processing by SessionsController#new as HTML
Completed 200 OK in 647ms (Views: 275.4ms | ActiveRecord: 17.4ms | Elasticsearch: 0.0ms)
Started POST "/users/auth/oauth" for 172.16.106.91 at 2020-01-14 10:37:13 +0000
Processing by Gitlab::RequestForgeryProtection::Controller#index as HTML
  Parameters: {"authenticity_token"=>"[FILTERED]"}
Completed 200 OK in 1ms (ActiveRecord: 0.0ms | Elasticsearch: 0.0ms)
Started GET "/-/metrics" for 127.0.0.1 at 2020-01-14 10:37:17 +0000
Processing by MetricsController#index as HTML
Completed 200 OK in 6ms (Views: 0.4ms | ActiveRecord: 0.0ms | Elasticsearch: 0.0ms)
Started GET "/users/auth/oauth2_generic/callback?state=d5834a26d8c58d1d68a0e193e885c6919c632ddb7b974e06&session_state=767c9018-8f8d-4bf6-a8d0-64546e3b308c&code=[FILTERED]" for 172.16.106.91 at 2020-01-14 10:37:20 +0000
Processing by ApplicationController#route_not_found as HTML
  Parameters: {"state"=>"d5834a26d8c58d1d68a0e193e885c6919c632ddb7b974e06", "session_state"=>"767c9018-8f8d-4bf6-a8d0-64546e3b308c", "code"=>"[FILTERED]", "unmatched_route"=>"users/auth/oauth2_generic/callback"}
Redirected to https://gitlab.willy.com/users/sign_in
Completed 302 Found in 270ms (ActiveRecord: 0.0ms | Elasticsearch: 0.0ms)
Started GET "/users/sign_in" for 172.16.106.91 at 2020-01-14 10:37:20 +0000
Processing by SessionsController#new as HTML
Completed 200 OK in 29ms (Views: 19.5ms | ActiveRecord: 1.3ms | Elasticsearch: 0.0ms)

What is the current bug behavior?

UI show: You need to sign in or sign up before continuing. the production log:

Redirected to https://gitlab.willy.com/users/sign_in
Filter chain halted as :redirect_unlogged_user rendered or redirected
Completed 302 Found in 27ms (ActiveRecord: 0.7ms | Elasticsearch: 0.0ms)
Started GET "/users/sign_in" for 172.16.106.91 at 2020-01-14 10:37:08 +0000
Processing by SessionsController#new as HTML
Completed 200 OK in 647ms (Views: 275.4ms | ActiveRecord: 17.4ms | Elasticsearch: 0.0ms)
Started POST "/users/auth/oauth" for 172.16.106.91 at 2020-01-14 10:37:13 +0000
Processing by Gitlab::RequestForgeryProtection::Controller#index as HTML
  Parameters: {"authenticity_token"=>"[FILTERED]"}
Completed 200 OK in 1ms (ActiveRecord: 0.0ms | Elasticsearch: 0.0ms)
Started GET "/-/metrics" for 127.0.0.1 at 2020-01-14 10:37:17 +0000
Processing by MetricsController#index as HTML
Completed 200 OK in 6ms (Views: 0.4ms | ActiveRecord: 0.0ms | Elasticsearch: 0.0ms)
Started GET "/users/auth/oauth2_generic/callback?state=d5834a26d8c58d1d68a0e193e885c6919c632ddb7b974e06&session_state=767c9018-8f8d-4bf6-a8d0-64546e3b308c&code=[FILTERED]" for 172.16.106.91 at 2020-01-14 10:37:20 +0000
Processing by ApplicationController#route_not_found as HTML
  Parameters: {"state"=>"d5834a26d8c58d1d68a0e193e885c6919c632ddb7b974e06", "session_state"=>"767c9018-8f8d-4bf6-a8d0-64546e3b308c", "code"=>"[FILTERED]", "unmatched_route"=>"users/auth/oauth2_generic/callback"}
Redirected to https://gitlab.willy.com/users/sign_in
Completed 302 Found in 270ms (ActiveRecord: 0.0ms | Elasticsearch: 0.0ms)
Started GET "/users/sign_in" for 172.16.106.91 at 2020-01-14 10:37:20 +0000
Processing by SessionsController#new as HTML
Completed 200 OK in 29ms (Views: 19.5ms | ActiveRecord: 1.3ms | Elasticsearch: 0.0ms)

What is the expected correct behavior?

gitlab login with keycloak account

Results of GitLab environment info

Expand for output related to GitLab environment info
System information
System:
Proxy:          no
Current User:   git
Using RVM:      no
Ruby Version:   2.6.3p62
Gem Version:    2.7.9
Bundler Version:1.17.3
Rake Version:   12.3.3
Redis Version:  3.2.12
Git Version:    2.24.1
Sidekiq Version:5.2.7
Go Version:     unknown

GitLab information Version: 12.6.3-ee Revision: 461e0ee8310 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: PostgreSQL DB Version: 10.9 URL: https://gitlab.willy.com HTTP Clone URL: https://gitlab.willy.com/some-group/some-project.git SSH Clone URL: git@gitlab.willy.com:some-group/some-project.git Elasticsearch: no Geo: no Using LDAP: no Using Omniauth: yes Omniauth Providers: openid_connect, oauth2

GitLab Shell Version: 10.3.0 Repository storage paths:

  • default: /var/opt/gitlab/git-data/repositories GitLab Shell path: /opt/gitlab/embedded/service/gitlab-shell Git: /opt/gitlab/embedded/bin/git

Results of GitLab application Check

Expand for output related to the GitLab application check
Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version >= 10.3.0 ? ... OK (10.3.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... yes Number of Sidekiq processes ... 1

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Git configured correctly? ... yes Database config exists? ... yes All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... skipped (no tmp uploads folder yet) Init script exists? ... skipped (omnibus-gitlab has no init script) Init script up-to-date? ... skipped (omnibus-gitlab has no init script) Projects have namespace: ... can't check, you have no projects Redis version >= 2.8.0? ... yes Ruby version >= 2.5.3 ? ... yes (2.6.3) Git version >= 2.22.0 ? ... yes (2.24.1) Git user has default SSH configuration? ... yes Active users: ... 2 Is authorized keys file accessible? ... yes Elasticsearch version 5.6 - 6.x? ... skipped (elasticsearch is disabled)

Checking GitLab App ... Finished

Checking GitLab subtasks ... Finished

~bug /lable

Edited by 🤖 GitLab Bot 🤖