Token prefixes: Add support for CI/CD Job 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 CI/CD Job Tokens to the instance wide token prefix feature. It only supports JWT tokens, as the previous type will be deprecated.
Instance wide token prefix have been added with !179852 (merged)
The new prefix format is: #{instance_prefix}#{token_type_prefix}
. E.g. for CI/CD Job tokens
, we'd get: #{instance_prefix}-glcbt-
. By default, the prefix is empty. However, we can now customize the instance prefix to create a new prefix: mycompanyname-glcbt-
.
References
- Allow custom instance token prefix for all toke... (#388379)
- https://docs.gitlab.com/administration/settings/account_and_limit_settings/#instance-token-prefix
How to set up and validate locally
- Enable feature flag via
rails c
:
Feature.enable(:custom_prefix_for_all_token_types)
- Change the instance wide token prefix:
Admin area > General > Account and limit > Instance token prefix
, e.g. tomycustomprefix
- You can add a small
.gitlab-ci.yml
that echoes the beginning of the token and clones another repository, that the Job Token has access to. You can find a description for the fine grained permissions here. The following script will intentionally leak the beginning of the token, so don't use it outside of testing:
build:
script:
- echo "Full token - should be masked:" + ${CI_JOB_TOKEN}
- echo "Short token:" + ${CI_JOB_TOKEN:0:12}
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gdk.test:3443/<example-repository>
- You should see that the full token is masked, the short token starts with your instance prefix and
git clone
has been successful.
MR acceptance checklist
checklist
-
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