Follow-up API implementation - Allow users to customize their JWT sub claim (MVC)

Why are we doing this work

Allow users to customize their JWT sub claim (MVC) (#360592 - closed) added a project attribute to customize the JWT sub claim, and made it possible to change that attribute using the REST API. The attribute is exposed as ci_id_token_sub_claim_components.

However, ci_id_token_sub_claim_components isn't documented in the API docs.

Also, ci_id_token_sub_claim_components can't be changed alone.

NOTE: ci_id_token_sub_claim_components can only be set to specific values, and expanding this to other values is out of the scope of this issue.

Supported values:

  • project_path,ref_type,ref
  • project_path,ref,ref_type
  • project_path,ref
  • project_path,ref_type

This is intentional, and supporting any other value is beyond the scope of this follow-up issue.

Relevant links

  • #360592 (comment 2354169940)
  • #360592 (comment 2060395819)

Relevant source code:

  • https://gitlab.com/gitlab-org/gitlab/-/blob/30e17df70d91c1171b89a8576bfdb1b8b95ac3ae/lib/gitlab/ci/jwt_v2.rb#L38
  • https://gitlab.com/gitlab-org/gitlab/-/blob/ba543cede3416ec32aadf81c5c0ba7ea742e8ada/lib/api/helpers/projects_helpers.rb#L121-122
  • https://gitlab.com/gitlab-org/gitlab/-/blob/2474baab27740ac1eb05c5d70b708f026affcc02/lib/api/entities/project.rb#L122
  • https://gitlab.com/gitlab-org/gitlab/-/blob/2d2226b624dd7c6d61212e2780a4db1770ad6ca0/app/models/project_ci_cd_setting.rb#L21

Non-functional requirements

  • Documentation: update Edit the project (API docs).
  • Feature flag:
  • Performance:
  • Testing: add spec to ensure that the project var can be set alone

Implementation plan

  • Add ci_id_token_sub_claim_components to ProjectsHelpers.update_params_at_least_one_of.
  • Add specs to ensure that ci_id_token_sub_claim_components can be updated alone using the Projects REST API.
  • Add ci_id_token_sub_claim_components to Edit the project (API docs).

Verification steps

  • Change the ci_id_token_sub_claim_components of some project to a non-default value.

    curl -XPUT "https://gitlab.com/api/v4/projects/$PROJECT_ID" \
        -H "PRIVATE-TOKEN: $GITLAB_TOKEN" \
        -H 'Content-Type: application/json' \
        --data-binary "{\"ci_id_token_sub_claim_components\":[\"project_path\", \"ref\"]}"
  • Check documentation.

Edited Feb 21, 2025 by Fabien Catteau
Assignee Loading
Time tracking Loading