OAuth Introspect fails for authenticated user
Summary
Requesting verification of an OAuth User token results in a server error when the token is valid. An invalid token will be reported correctly.
Steps to reproduce
- Enable OmniAuth.
- Create a global Application integration client/secret.
- Authenticate a user with openid/oauth through other means (a Single Page Website)
- Generate a user_token.
- send the token to the GitLab introspection service for authentication.
What is the current bug behavior?
curl -F client_id=20b82ad6f9a4bb3e9c81ce17c35f27dd17be5722a3679ff6668a0b2075fe11af -F client_secret=6f73cf149c0554df9a79cd013fe09ece02073344a3524675f5a15f468df9beca -F token=b0568a139a25b742c3dd4611124ba831b35f5aac6956b0ff121b508d9221ec9 -X POST https://domain.com/git/oauth/introspect
Returns:
<!DOCTYPE html>
<html>
<head><SNIP>
<div class="container">
<h3>Whoops, something went wrong on our end.</h3>
<hr />
<p>Try refreshing the page, or going back and attempting the action again.</p>
<p>Please contact your GitLab administrator if this problem persists.</p>
<a href="javascript:history.back()" class="js-go-back go-back">Go back</a>
</div>
<script>
(function () {
var goBack = document.querySelector('.js-go-back');
if (history.length > 1) {
goBack.style.display = 'inline';
}
})();
</script>
</body>
</html>
Response for an unauthenticated user:
{"active":false}
What is the expected correct behavior?
{
"active": true,
"scope": "read write email",
"client_id": "J8NFmU4tJVgDxKaJFmXTWvaHO",
"username": "aaronpk",
"exp": 1437275311
}
Relevant logs and/or screenshots
Started POST "/git/oauth/introspect" for : at 2019-01-30 10:10:16 +0000
Processing by Doorkeeper::TokensController#introspect as */*
Parameters: {"client_id"=>"20b82a26f9a4bb3e9c81ce17c35f27dd17be5722a3679ff6668a0b2075fe11af", "client_secret"=>"[FILTERED]", "token"=>"[FILTERED]"}
Completed 500 Internal Server Error in 8ms
NoMethodError (undefined method `seconds' for nil:NilClass):
lib/gitlab/middleware/rails_queue_duration.rb:24:in `call'
lib/gitlab/metrics/rack_middleware.rb:17:in `block in call'
lib/gitlab/metrics/transaction.rb:55:in `run'
lib/gitlab/metrics/rack_middleware.rb:17:in `call'
lib/gitlab/middleware/multipart.rb:103:in `call'
lib/gitlab/request_profiler/middleware.rb:16:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:13:in `call'
lib/gitlab/middleware/correlation_id.rb:16:in `block in call'
lib/gitlab/correlation_id.rb:15:in `use_id'
lib/gitlab/middleware/correlation_id.rb:15:in `call'
lib/gitlab/middleware/read_only/controller.rb:40:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/request_context.rb:20:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:29:in `call'
lib/gitlab/middleware/release_env.rb:13:in `call'
==> /var/log/gitlab/gitlab-rails/production_json.log <==
{"method":"POST","path":"/git/oauth/introspect","format":"*/*","controller":"Doorkeeper::TokensController","action":"introspect","status":500,"error":"NoMethodError: undefined method `seconds' for nil:NilClass","duration":9.14,"view":0.0,"time":"2019-01-30T10:10:16.557Z","params":[{"key":"client_id","value":"20b82a26f9a4bb3e9c81ce17c35f27dd17be5722a3679ff6668a0b2075fe11af"},{"key":"client_secret","value":"[FILTERED]"},{"key":"token","value":"[FILTERED]"}],"remote_ip":null,"user_id":null,"username":null,"ua":null,"correlation_id":"1MkoUozJH8"}
Output of checks
(If you are reporting a bug on GitLab.com, write: This bug happens on GitLab.com)
Results of GitLab environment info
System information System: Current User: git Using RVM: no Ruby Version: 2.5.3p105 Gem Version: 2.7.6 Bundler Version:1.16.6 Rake Version: 12.3.2 Redis Version: 3.2.12 Git Version: 2.18.1 Sidekiq Version:5.2.3 Go Version: unknown
GitLab information Version: 11.7.0 Revision: 1d9280e1 Directory: /opt/gitlab/embedded/service/gitlab-rails DB Adapter: postgresql URL: https://ai.terma.com/git HTTP Clone URL: https://ai.terma.com/git/some-group/some-project.git SSH Clone URL: ssh://git@ai.terma.com:2222/some-group/some-project.git Using LDAP: yes Using Omniauth: yes Omniauth Providers:
GitLab Shell Version: 8.4.4 Repository storage paths:
- default: /var/opt/gitlab/git-data/repositories Hooks: /opt/gitlab/embedded/service/gitlab-shell/hooks 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 >= 8.4.4 ? ... OK (8.4.4) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Check GitLab API access: OK Redis available via internal API: OK
Access to /var/opt/gitlab/.ssh/authorized_keys: 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: ... Server: ldapmain LDAP authentication... Success LDAP users with access to your GitLab server (only showing the first 100 results) 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: ... 3/1 ... yes 7/2 ... yes 7/3 ... yes 7/4 ... yes 8/5 ... yes Redis version >= 2.8.0? ... yes Ruby version >= 2.3.5 ? ... yes (2.5.3) Git version >= 2.18.0 ? ... yes (2.18.1) Git user has default SSH configuration? ... yes Active users: ... 8
Checking GitLab App ... Finished
Checking GitLab subtasks ... Finished