Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Vela OIDC provider #1120

Merged
merged 43 commits into from
Jun 5, 2024
Merged

feat!: Vela OIDC provider #1120

merged 43 commits into from
Jun 5, 2024

Conversation

ecrupper
Copy link
Contributor

@ecrupper ecrupper commented May 3, 2024

go-vela/community#976

How it works

  1. Compiler generates VELA_ID_TOKEN_REQUEST_URL (nothing unique about it, just for convenience.. the path is /api/v1/repos/ORG/REPO/builds/BUILD/id_token).
  2. The worker will request the VELA_ID_TOKEN_REQUEST_TOKEN if the user specifies any value for the id_request YAML step tag. This request is secured by the MustBuildAccess() permissions check. The reason this token isn't generated at compile time is because part of the claims involve build_id, which isn't created during compilation due to potential errors.
  3. The token manager will generate an RSA key pair at start up. The private key is stored in memory, and the public key (converted to a JWK object) is stored in the database with the KID as the primary key. That KID is generated using UUID v7 whenever the key pair is generated.
  4. The Vela server router loads in an OpenID config and a JWKs endpoint. These are used to validate ID tokens signed by the token manager's private key.
  5. A user will request an ID token using the ID_TOKEN_REQUEST_TOKEN. This request must be made while the build is running, else it will be denied for security reasons.
  6. Key rotation involves dropping all inactive JWKs and setting all active JWKs to inactive. The inactive JWKs can still be used to validate already-signed tokens, but their corresponding private keys will not sign any new tokens. This is because the token manager will verify its private key in-memory is still OK to sign tokens. If not, it will generate a new pair.

Example

version: "1"

steps:
  - name: request token
    image: alpine:latest
    id_request: write  # becomes a claim in token `request`
    commands:
      - apk add curl
      - 'curl -H "Authorization: Bearer $VELA_ID_TOKEN_REQUEST_TOKEN" $VELA_ID_TOKEN_REQUEST_URL'

go.mod Outdated Show resolved Hide resolved
@ecrupper ecrupper marked this pull request as ready for review May 16, 2024 16:27
@ecrupper ecrupper requested a review from a team as a code owner May 16, 2024 16:27
cmd/vela-server/token.go Outdated Show resolved Hide resolved
cmd/vela-server/token.go Show resolved Hide resolved
database/resource.go Show resolved Hide resolved
Copy link

codecov bot commented May 16, 2024

Codecov Report

Attention: Patch coverage is 35.90504% with 216 lines in your changes missing coverage. Please review.

Project coverage is 67.27%. Comparing base (4f81558) to head (922ffd0).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1120      +/-   ##
==========================================
- Coverage   68.04%   67.27%   -0.78%     
==========================================
  Files         411      422      +11     
  Lines       13752    14083     +331     
==========================================
+ Hits         9358     9474     +116     
- Misses       3859     4064     +205     
- Partials      535      545      +10     
Files Coverage Δ
compiler/native/environment.go 85.82% <100.00%> (+0.11%) ⬆️
database/database.go 58.00% <ø> (ø)
database/jwk/create.go 100.00% <100.00%> (ø)
database/jwk/get.go 100.00% <100.00%> (ø)
database/jwk/opts.go 100.00% <100.00%> (ø)
database/jwk/table.go 100.00% <100.00%> (ø)
internal/token/parse.go 88.23% <100.00%> (ø)
api/build/token.go 0.00% <0.00%> (ø)
database/jwk/list.go 85.71% <85.71%> (ø)
database/resource.go 78.41% <75.00%> (-0.21%) ⬇️
... and 11 more

api/build/id_token.go Outdated Show resolved Hide resolved
database/testutils/api_resources.go Show resolved Hide resolved
database/testutils/api_resources.go Outdated Show resolved Hide resolved
database/jwk/get.go Show resolved Hide resolved
Copy link
Collaborator

@wass3r wass3r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spotted a couple of small-ish tings. looks good overall

api/admin/rotate_keys.go Outdated Show resolved Hide resolved
api/build/id_request_token.go Outdated Show resolved Hide resolved
api/build/id_request_token.go Outdated Show resolved Hide resolved
api/build/id_request_token.go Outdated Show resolved Hide resolved
api/build/id_request_token.go Outdated Show resolved Hide resolved
cmd/vela-server/main.go Outdated Show resolved Hide resolved
constants/table.go Show resolved Hide resolved
database/jwk/jwk.go Outdated Show resolved Hide resolved
database/testutils/api_resources.go Show resolved Hide resolved
router/router.go Show resolved Hide resolved
api/build/id_token.go Outdated Show resolved Hide resolved
api/build/id_token.go Show resolved Hide resolved
internal/token/mint.go Outdated Show resolved Hide resolved
@ecrupper ecrupper changed the title feat: Vela OIDC provider feat!: Vela OIDC provider Jun 5, 2024
@ecrupper ecrupper merged commit a0b14ae into main Jun 5, 2024
15 of 17 checks passed
@ecrupper ecrupper deleted the feat/oidc-provider branch June 5, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants