fulcio icon indicating copy to clipboard operation
fulcio copied to clipboard

Add support for GitLab tokens

Open dlorenc opened this issue 3 years ago • 15 comments

It looks like GitLab offers JWT tokens as well to CI jobs:

https://docs.gitlab.com/ee/ci/examples/authenticating-with-hashicorp-vault/#how-it-works

They're available as the CI_JOB_JWT environment variable, and the endpoint is https://gitlab.example.com/-/jwks.

It sounds like they don't support the audience field, which isn't great but should still be workable.

dlorenc avatar Nov 18 '21 13:11 dlorenc

cc @colek42

dlorenc avatar Nov 18 '21 13:11 dlorenc

It looks like this is a premium feature for GitLab as well.

colek42 avatar Nov 18 '21 15:11 colek42

Hmm, over here it says it might be in all job tiers: https://docs.gitlab.com/ee/ci/secrets/

dlorenc avatar Nov 18 '21 15:11 dlorenc

curl https://gitlab.com/.well-known/openid-configuration
{
  "issuer": "https://gitlab.com",
  "authorization_endpoint": "https://gitlab.com/oauth/authorize",
  "token_endpoint": "https://gitlab.com/oauth/token",
  "revocation_endpoint": "https://gitlab.com/oauth/revoke",
  "introspection_endpoint": "https://gitlab.com/oauth/introspect",
  "userinfo_endpoint": "https://gitlab.com/oauth/userinfo",
  "jwks_uri": "https://gitlab.com/oauth/discovery/keys",
  "scopes_supported": [
    "api",
    "read_user",
    "read_api",
    "read_repository",
    "write_repository",
    "read_registry",
    "write_registry",
    "sudo",
    "openid",
    "profile",
    "email"
  ],
  "response_types_supported": [
    "code",
    "token"
  ],
  "response_modes_supported": [
    "query",
    "fragment"
  ],
  "grant_types_supported": [
    "authorization_code",
    "implicit",
    "password",
    "client_credentials",
    "refresh_token"
  ],
  "token_endpoint_auth_methods_supported": [
    "client_secret_basic",
    "client_secret_post"
  ],
  "subject_types_supported": [
    "public"
  ],
  "id_token_signing_alg_values_supported": [
    "RS256"
  ],
  "claim_types_supported": [
    "normal"
  ],
  "claims_supported": [
    "iss",
    "sub",
    "aud",
    "exp",
    "iat",
    "sub_legacy",
    "name",
    "nickname",
    "email",
    "email_verified",
    "website",
    "profile",
    "picture",
    "groups",
    "groups_direct"
  ]
}

mattmoor avatar Nov 18 '21 15:11 mattmoor

It looks like it doesn't support configuring aud (e.g. to sigstore)

mattmoor avatar Nov 18 '21 15:11 mattmoor

It looks like it doesn't support configuring aud (e.g. to sigstore)

Yep, I think it's up to us to decide if that's too problematic to add support. We can use the gitlab audience here if we want to.

dlorenc avatar Nov 18 '21 15:11 dlorenc

That feels like a slippery slope. Once we allow it, it's hard to take back and ~every other piece of Vault OIDC documentation I've seen uses aud: vault. Github as precedent might help here.

mattmoor avatar Nov 18 '21 15:11 mattmoor

GitLab 14.6 looks to be shipping with an updated token -- CI_JOB_JWT_V2. See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72555. It doesn't look like aud is configurable though.

valdisrigdon avatar Dec 07 '21 20:12 valdisrigdon

Following along, it looks like customizable audiences isn't coming in 15.0 - https://gitlab.com/groups/gitlab-org/-/epics/7335

haydentherapper avatar Apr 13 '22 20:04 haydentherapper

Hi 👋 GitLab team member here. We're working on making the aud claim configurable via https://gitlab.com/gitlab-org/gitlab/-/issues/356986. Currently, this is scheduled for 15.2 which releases on June 22, but this is subject to change. I recommend following the issue for updates on progress.

Brcrwilliams avatar May 18 '22 10:05 Brcrwilliams

Amazing news!

dlorenc avatar May 18 '22 11:05 dlorenc

@dlorenc another GitLab team member here - this is a really exciting project so I'll be tracking as well as I'd love to get this working and show it off to the community. :smile:

olearycrew avatar May 23 '22 14:05 olearycrew

@Brcrwilliams and @olearycrew do you have some initial ideas for which claims from your OIDC token you might want to map into certificate extensions? You can see the claims that are mapped from Github Actions tokens here: https://github.com/sigstore/fulcio/blob/main/docs/oid-info.md

Mapping these OIDC claims to x509 extensions allows folks to write meaningful policy like

only run containers signed by the Fulcio with the Gitlab issuer and from project "foo/*"

Once we have that solidified, setting up Fulcio support for Gitlab tokens will be super straight forward and we'll all be doing keyless signing in Gitlab in no time :D

nsmith5 avatar May 26 '22 22:05 nsmith5

@nsmith5 Currently we provide several claims in this JWT which are documented under Connect to Cloud Services. I think these ones would be useful for policies:

  • namespace_id
  • namespace_path
  • project_id
  • project_path

These would allow you to assert that the image was signed by a specific project or organization (A namespace is a group).

Brcrwilliams avatar Jun 02 '22 16:06 Brcrwilliams

To be in sync with GitHub Actions-bound certificates, we'd also want to include information about the CI workflow that was run. I believe that's pipeline_id or pipeline_source.

haydentherapper avatar Jun 02 '22 17:06 haydentherapper