Repository navigation
Restructure authz chain - #4507
Conversation
|
@mjudeikis-bot review and use fable 5.1 be very careful about tracing the authorization paths and what changed for rbac-authorized users and webhook-authorized users. |
mjudeikis-bot
left a comment
There was a problem hiding this comment.
I traced the new bypass/grants/gates flow in ApplyTo against the requiredgroups, systemcrd, MPP and workspace-content authorizers. For both RBAC-granted and webhook-granted requests, the gates can only deny or pass through, and the lifecycle-group allow still goes through the gates. One compatibility break, below.
|
@mjudeikis-bot review and use fable 5.1 be very careful about tracing the authorization paths and what changed for rbac-authorized users and webhook-authorized users. |
mjudeikis-bot
left a comment
There was a problem hiding this comment.
Re-review: the earlier --authorization-order finding is resolved (AlwaysAllowGroups/AlwaysAllowPaths are accepted and ignored). No new issues found. Checked: the new lifecycle-group bypass, LC-existence pre-gate (shard-level /metrics, wildcard and LC-admin paths), and gate-Deny-only final decision for RBAC- and webhook-granted requests.
|
@mjudeikis-bot review and use fable. don't re-review, actually go through every change again and reason about the placement of authorizers. |
mjudeikis-bot
left a comment
There was a problem hiding this comment.
No issues found. Checked: every authorizer's placement in the new bypass / pre-gate / grant / gate flow in ApplyTo against the old chain (lifecycle-group allow, LogicalCluster existence, requiredgroups, systemcrd, MPP Deny-on-not-allowed, workspace-content access check, webhook-as-grant), the shared LogicalClusterGetter, the deep-SAR skips, and the legacy AlwaysAllow* order names (still accepted at this head). go test ./pkg/authorization ./pkg/server/options passes.
|
/hold I want to make some changes |
|
/retest Changed my mind. I think adding more changes here will be too much. I'll make follow ups later. |
|
@mjudeikis-bot review and use fable. don't re-review, actually go through every change again and reason about the placement of authorizers. |
| // Skip LC existence check for LC admin, which is used for creating LCs in the first place. | ||
| if rbacregistryvalidation.EffectiveGroups(ctx, attr.GetUser()).Has(bootstrap.SystemLogicalClusterAdmin) { | ||
| return authorizer.DecisionNoOpinion, "logical cluster admin access", nil | ||
| } |
There was a problem hiding this comment.
I really dislike these shortcuts. They will be addressed in a separate PR by adding a bypass for the LC admin identities.
This PR ist just big enough already.
mjudeikis-bot
left a comment
There was a problem hiding this comment.
No Critical or Warning defects found in the authorizer placement. Notes below. I re-traced every authorizer from scratch against origin/main, not against the earlier reviews.
Placement, per authorizer (old chain -> new chain)
- AlwaysAllowGroups/Paths: unchanged in the default order. They now run first regardless of
--authorization-order, and the legacy names are accepted as no-ops. This closes the case of a webhook placed first denying/healthzor system identities. - Lifecycle-group allow: moved out of the content authorizer into the bypass group. It is now validated against
Status.Initializers/Status.Terminatorsinstead of phase only, and still skips deep SARs. It no longer passes throughrequiredgroups(previously it was inside that chain, so a lifecycle identity without the required groups was denied). The VW already pre-authorized the request, and it still skips systemcrd/MPP exactly as before. This is a behaviour change worth a line in the docs. - LC existence: previously only in the content authorizer, so RBAC only (a webhook could answer for a missing workspace). It is now a pre-gate for RBAC and webhook alike. LC-admin, deep SAR, empty and
system:clusters are skipped. - RBAC (bootstrap, local, global) wrapped by the content authorizer: stays a grant. The
verb=accesscheck is still RBAC-only by design. - Webhook: now a grant. A webhook Deny is final. A webhook Allow goes through the gates.
- requiredgroups, systemcrd, MPP: moved from wrapping RBAC to gates after the grants. Walking the gate chain with a no-op innermost delegate: requiredgroups returns NoOpinion early (nil/empty cluster, LC not found) without delegating, so systemcrd/MPP are skipped only where the content authorizer already returned NoOpinion before. Deep SAR is skipped in requiredgroups and MPP. The new MPP
Denyis the fix for the reported escalation. - No gate returns Allow, because the innermost delegate is NoOpinion, so ignoring gate Allow in the final closure is safe today.
Not anchored
- None.
Checked
- Read beyond the diff:
ApplyToonorigin/mainvs head;workspaceContentAuthorizer.Authorizein full;requiredGroupsAuthorizer.Authorize;SystemCRDAuthorizer;MaximalPermissionPolicyAuthorizer.Authorizeand its constructor;DelegateAuthorizationand theDecoratormethods (decorator.go);deep_sar.go;pkg/server/filters/shardlevelpaths.goandshardpaths; the initializing/terminating VW group injection (build.go:324,build.go:310); the logicalcluster phase reconciler (whenDeletingis entered); the proxy prefix stripping (pkg/proxy/options/authentication.go); the other users ofHasLifecycleGroup,NewWorkspaceContentAuthorizerandNewRequiredGroupsAuthorizer(none left outside the changed files); the removed decorator keys (01-..05-), which nothing else references. - Correctness: the final closure returns a grant Deny, then a gate Deny, otherwise the grant decision. Errors from bypass, pre-gate, grants and gates are propagated and not swallowed. No gate returns Allow, so nothing is dropped.
unionof an empty grant list is NoOpinion, which is the correct result for a webhook-only or RBAC-less order. - Concurrency: the new closures hold no shared mutable state; the
getLogicalClusterclosure only reads informer listers. Not applicable beyond that. - kcp specifics: logical-cluster scoping is taken from
genericapirequest.ClusterFrom(ctx)in every new authorizer; local-then-global LC lookup is the same as before and is now one shared getter; deep SAR is skipped in lifecycle, existence, requiredgroups and MPP; no APIExport/APIBinding identity-hash, workspace type or VW path changes. - API/storage: no CRD, codegen or stored-format change. A CLI flag value change is handled by accepting the legacy names; the release note is
NONE, but the flag keeps working. - Security: lifecycle groups are only honoured when the group's name is registered on the LC and the phase matches; stricter than before. A webhook can no longer bypass requiredgroups, the system CRD status protection or the MPP. No credential reaches an error string; the decorators anonymise reasons as before.
- Tests: unit tests added for the lifecycle and existence authorizers and the updated content authorizer; e2e added for the MPP escalation (
TestMaximalPermissionPolicyWebhookEscalation), legacy order names, and the pre-gate. I did not find a test that covers the final closure ofApplyTofor a webhook-granted request hitting requiredgroups or the systemcrd gate (see the comment on the closure). - Commands:
go build ./pkg/... ./cmd/...OK;go vet ./pkg/authorization/... ./pkg/server/options/...OK;go test ./pkg/authorization/... ./pkg/server/options/...pass.go vetoftest/e2e/...could not complete here (module download ofmockoidc/go-joseblocked).golangci-lintis not installed here; CIpull-kcp-lintis green on this head. - e2e: not run locally (needs a kcp server and webhook processes). CI on this head is green apart from
pull-kcp-test-e2e-sharded, which failed ondf1a086and is being retested; I could not read its log, so I cannot say whether the failure relates to this change.
| // Lifecycle synthetic groups (system:kcp:initializer:*, system:kcp:terminator:*) | ||
| // are injected by the initializing/terminating VW content proxies *after* they | ||
| // have evaluated the request against the WorkspaceType's | ||
| // initializer/terminator permissions. They cannot be self-asserted because the | ||
| // front-proxy drops them on ingress. Their presence is the authoritative | ||
| // "pre-authorized by VW" marker — delegating further would re-run RBAC against | ||
| // the caller's identity, which by design has no in-workspace permissions, so | ||
| // allow directly here. | ||
| // | ||
| // Only honor the synthetic group when the workspace is actually in a lifecycle | ||
| // phase (Initializing/Terminating/Deleting). For Ready workspaces a leftover | ||
| // lifecycle group on the caller must not grant unconditional access. | ||
| if HasLifecycleGroup(attr.GetUser().GetGroups()) { | ||
| switch logicalCluster.Status.Phase { | ||
| case corev1alpha1.LogicalClusterPhaseInitializing, | ||
| corev1alpha1.LogicalClusterPhaseTerminating, | ||
| corev1alpha1.LogicalClusterPhaseDeleting: | ||
| return authorizer.DecisionAllow, "lifecycle VW pre-authorized access", nil | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Removed because the initializer/terminator have a bypass that validates both the correct phase and that the request is for a valid initializer/terminator.
5e518ea to
3f9520f
Compare
|
/test pull-kcp-test-e2e-sharded |
|
/test pull-kcp-test-e2e |
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
Signed-off-by: Nelo-T. Wallus <[email protected]> Signed-off-by: Nelo-T. Wallus <[email protected]>
|
/retest |
|
/lgtm |
|
LGTM label has been added. DetailsGit tree hash: c8f983dcb4142d2529f05f3471e8d211b18f6439 |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: mjudeikis The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
@mjudeikis-bot create an issue in kcp-operator and helm-charts repo for release 0.34 to make sure it is changed |
|
@mjudeikis-bot create an issue in kcp-operator and helm-charts repo for release 0.34 to make sure it is changed |
|
Created tracking issues for the 0.34 release: kcp-dev/kcp-operator#313 and kcp-dev/helm-charts#249 |
Summary
@BergCyrill reported that it might be possible that an authz webhook can bypass the maximal permission policy determined by a provider.
https://kubernetes.slack.com/archives/C021U8WSAFK/p1793117295299859
I validates this in the new added test
TestMaximalPermissionPolicyWebhookEscalation.While fixing that I noticed that our authz chain had a few problem with an authz webhook being able to grant access to resources and verbs that the rbac chain explicitly prohibits. E.g. the required groups or the protection for the APIExport/-Binding status of
apis.kcp.io.I think this was partially by design because the webhook is a distinct authorization mechanism and e.g. checking the access verb for a user only authorized through the webhook in the first place makes less sense because rbac is distinct form webhook.
However the required groups authorizer does make sense to apply to both rbac and webhook.
Further it has been possible for users to configure the webhook to be evaluated first, which could deny before the always allow paths/group are consulted, breaking e.g. access for kcp system identities.
So instead I reordered everything into three distinct groups: bypass, grant and gate. They are documented in the authorization chain.
What Type of PR Is This?
/kind bug
/kind chore
Related Issue(s)
Fixes #
Release Notes