Skip to content

Admin Token API: Revoke GitLab Session

What does this MR do and why?

This MR adds support for revocation of GitLab sessions to the Admin token API. In this case, revocation is done by deleting the session. This is consistent with the Revoke button in the User Settings > Active Sessions UI

Issue: #517699 (closed)

🛠️ with ❤️ at Siemens

Changelog: added

References

MR acceptance checklist

checklist

How to set up and validate locally

  1. Enable the feature flag with rails c:
Feature.enable(:api_admin_token_revoke)

You'll need to create a personal access token to access the token and get a _gitlab_session that you'd like to query:

  1. Create a personal access token with admin_mode and api capabilities. Preferences > Access Tokens > Add a new token

  2. You'll need a _gitlab_session. The easiest way to get this is to get a session from your browser. Navigate to your gdk, e.g. https://gdk.test:3443 and sign in. After signing in, there should be a session key and a value in your cookie store. In Firefox, open the developer console and go to Storage > Cookies. It's mostly the same in Chrome/Safari. This should get you a key: _gitlab_session_abc123 and a value: long-string-with-numbers. You need to join both: _gitlab_session_abc123=long-string-with-numbers. For comparison, on gitlab.com, the key would be just _gitlab_session=. However, in development mode, a unique key is added to the prefix (in the example, abc123).

  3. Now you can retrieve information about this token:

curl -k --request POST \
--url 'https://gdk.test:3443/api/v4/admin/token' \
--header 'Authorization: Bearer <Admin Token from Step 2.>' \
--header 'Content-Type: application/json' \
--data '{"token": "_gitlab_session_abc123=long-string-with-numbers"}'
  1. Now, revoke the token:
curl -k --request DELETE \
--url 'https://gdk.test:3443/api/v4/admin/token \       
--header 'Authorization: Bearer <Admin Token from Step 1.>' \
--header 'Content-Type: application/json' \
--data '{"token": "_gitlab_session_abc123=long-string-with-numbers"}'
  1. Query the token again - you should now see that the status changed to Not Found, as the session no longer exists. You can also verify this in User Settings > Active Sessions

Related to #517699 (closed)

Edited by Nicholas Wittstruck

Merge request reports

Loading