Token prefixes: Add support for cluster agent tokens
-
Please check this box if this contribution uses AI-generated content (including content generated by GitLab Duo features) as outlined in the GitLab DCO & CLA. As a benefit of being a GitLab Community Contributor, you receive complimentary access to GitLab Duo.
What does this MR do and why?
This MR adds support for instance wide token prefixes to cluster agent tokens.
Instance wide token prefixes have been added with !179852 (merged)
The new prefix format is: #{instance_prefix}-#{token_type_prefix}. E.g. for Cluster agent tokens, we'd get: #{instance_prefix}-glagent-. By default, this is the current token prefix glagent-. However, we can now customize the instance prefix to create a new prefix: mycompanyname-glagent-.
With this custom prefix, it is easier to identify leaked tokens, because we can now skip all leaked tokens that start with glagent. Now, we only need to look at tokens starting with mycompanyname-glagent-.
References
How to set up and validate locally
- Enable feature flag via
rails c:
Feature.enable(:custom_prefix_for_all_token_types)
- Create a new cluster agent token.
- If you have configured the GDK with
gitlab_k8s_agentenabled, you can create a new cluster token atAny Project > 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 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
- Now, change the instance wide token prefix:
Admin area > General > Account and limit > Instance token prefix, e.g. tomycustomprefix - Now create a new token - you should now see the prefix in the token.
MR acceptance checklist
MR Checklist ( @nwittstruck)
-
Changelog entry added, if necessary -
Documentation created/updated via this MR -
Documentation reviewed by technical writer or follow-up review issue created -
Tests added for this feature/bug -
Tested in all supported browsers -
Conforms to the code review guidelines -
Conforms to the merge request performance guidelines -
Conforms to the style guides -
Conforms to the javascript style guides -
Conforms to the database guides
Related to #388379
Edited by Nicholas Wittstruck