Enrich Receiver resourceFilter with OIDC claims#1313
Merged
Conversation
Signed-off-by: Matheus Pimenta <matheuscscp@gmail.com>
resourceFilter with OIDC claims
Member
|
Why not send a json payload with what resources you want reconciled same as GAR works. The JWT role would stick to authorization only. |
Member
Author
|
Because any repo (any client) can craft a payload to trigger the other object. This feature allows the restriction to be enforced on the server side. It's a security feature. |
Member
Author
|
I'm filing a second PR on top of this one to introduce another feature that will simplify the setup even further, introducing even more authorization flexibility. See below, the setup after this PR, and then the setup after the second PR I'm currently working on (the second is much more powerful and readable). After this PR: apiVersion: notification.toolkit.fluxcd.io/v1
kind: Receiver
metadata:
name: flux-webhook-receiver
namespace: flux-system
spec:
type: generic-oidc
oidcProviders:
- issuerURL: https://token.actions.githubusercontent.com
validations:
- expression: >-
claims.job_workflow_ref.matches(r"^controlplaneio-fluxcd/d2-fleet/\.github/workflows/push-artifact\.yaml@<< inputs.artifactSubjectGitRef >>$")
|| claims.job_workflow_ref.matches(r"^controlplaneio-fluxcd/flux-appx/\.github/workflows/push-image\.yml@refs/(heads/main|pull/[0-9]+/merge)$")
message: "token job_workflow_ref is not an allowed d2-fleet/flux-appx workflow"
resourceFilter: >-
(claims.repository == 'controlplaneio-fluxcd/d2-fleet' && res.kind == 'OCIRepository') ||
(claims.repository == 'controlplaneio-fluxcd/flux-appx' && res.kind == 'ResourceSetInputProvider')
resources:
- apiVersion: source.toolkit.fluxcd.io/v1
kind: OCIRepository
name: flux-system
- apiVersion: fluxcd.controlplane.io/v1
kind: ResourceSetInputProvider
name: '*'
matchLabels:
preview: "true"After the second PR I'm working on: apiVersion: notification.toolkit.fluxcd.io/v1
kind: Receiver
metadata:
name: flux-webhook-receiver
namespace: flux-system
spec:
type: generic-oidc
oidcProviders:
- issuerURL: https://token.actions.githubusercontent.com
validations:
- expression: "claims.repository_owner == 'controlplaneio-fluxcd'"
message: "token is not from the controlplaneio-fluxcd org"
resources:
- apiVersion: source.toolkit.fluxcd.io/v1
kind: OCIRepository
name: flux-system
filter: 'claims.job_workflow_ref.matches(r"^controlplaneio-fluxcd/d2-fleet/\.github/workflows/push-artifact\.yaml@<< inputs.artifactSubjectGitRef >>$")'
- apiVersion: fluxcd.controlplane.io/v1
kind: ResourceSetInputProvider
name: '*'
matchLabels:
preview: "true"
filter: 'claims.job_workflow_ref.matches(r"^controlplaneio-fluxcd/flux-appx/\.github/workflows/push-image\.yml@refs/(heads/main|pull/[0-9]+/merge)$")' |
Member
|
The filter per resource kind looks great! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up for #1306
In my setup I have a single Receiver per namespace. In one of them (
flux-system) I have two use cases for Receiver:I want to allow each repo to trigger only the resources they need to trigger. They can't trigger resources they don't relate to.
Currently, to make the above possible, I have split the Receiver in two. Each Receiver has a strict OIDC validation that allows the repo to trigger only the respective resource it relates to.
If the OIDC claims were injected into the
.spec.resourceFiltercontext, the CEL expression would be more powerful, allowing me to keep a single Receiver per namespace like before (when I was usinggeneric-hmac).