Skip to content

Admin Token API: Add support for revocation of Cluster Agent Tokens

What does this MR do and why?

This MR adds support for revocation of Cluster Agent Tokens to the Admin Token API.

🛠️ with ❤️ at Siemens

References

MR acceptance checklist

MR Checklist ( @nwittstruck)

How to set up and validate locally

  1. Enable the feature flag with rails c:
Feature.enable(:api_admin_token_revoke)
  1. You'll need to create two new tokens:
    1. A personal access token with admin_mode and api capabilities at: Preferences > Access tokens > Add new token
    2. A cluster agent token that you can query:
    • If you have configured the GDK with gitlab_k8s_agent enabled, you can create a new cluster token at Any Project > Operate > Kubernetes clusters > Connect a cluster. You can now register a new agent.
    • You can also create a new token with rails c. This assumes there is at least one project. This example uses the first project, feel free to choose any other project:
       agent = Clusters::Agent.new(name: 'test-agent', project: Project.first)
       agent.save
    
       token = Clusters::AgentToken.new(name: 'test-agent-token', agent: agent)
       # this will print the token:
       token.ensure_token
       # don't forget to save the token to be able to retrieve it:
       token.save
  2. Now you can retrieve information about this token and see that the status is active:
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": "glagent-token-from-step-2-2"}'
  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": "glagent-token-from-step-2-2"}'
  1. Query the token again - you should now see that the status has changed to revoked.

Related to #513537 (closed)

Edited by 🤖 GitLab Bot 🤖

Merge request reports

Loading