Skip to content

Cloud Connector: support extra claims in JWT

Matthias Käppler requested to merge 442417-com-jwt-namespace-id into master

What does this MR do and why?

Add support for extra claims when minting Cloud Connector JWTs on gitlab.com.

Some features such as GOB require the addition of additional claims to be carried in the JWT, to be interpreted upstream.

The way this would be used is, for example:

cloud_connector = CloudConnector::AccessService.new

token = cloud_connector.access_token(
  scopes: ['scope1', 'scope2'],
  extra_claims: {
    gitlab_namespace_id: project.root_ancestor.id
  }
)

These extra_claims will only take hold for self-issued access tokens on gitlab.com.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Set GITLAB_SIMULATE_SAAS=1

  2. In rails console run:

    JWT.decode(CloudConnector::AccessService.new.access_token(scopes: [:test], extra_claims: { custom: 123 }), nil, false)
  3. It should print:

    => [{"jti"=>"7a4bf3e7-1148-4244-9eab-3cb1b99f1645", "aud"=>"gitlab-ai-gateway", "iss"=>"http://local.gitlab.test:3000", "iat"=>1709199788, "nbf"=>1709199783, "exp"=>1709203388, "gitlab_realm"=>"saas", "scopes"=>["test"], "custom"=>123},
     {"typ"=>"JWT", "alg"=>"RS256"}]

Related to #442417 (closed)

Edited by Matthias Käppler

Merge request reports