Skip to content

Restructure authz chain - #4507

Merged
kcp-ci-bot merged 18 commits into
kcp-dev:mainfrom
ntnn:mpp
Nov 3, 2026
Merged

kcp-ci-bot merged 18 commits into
kcp-dev:mainfrom
ntnn:mpp

Conversation

@ntnn

@ntnn ntnn commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

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

IMPORTANT: The authorization chain has been restructured - it was possible to bypass checks for vital kcp functions via the authorization webhook. This has been remediated. Normal operation should be unaffected.

BREAKING: When a MaximalPermissionPolicy applies and does not allow a request, the MaximalPermissionPolicy authorizer now returns Deny instead of NoOpinion. Later authorizers, including the webhook, can no longer allow such a request.

BREAKING: --authorization-order now only selects and orders RBAC and Webhook (default RBAC,Webhook). AlwaysAllowGroups and AlwaysAllowPaths always run first. They can no longer be reordered, and leaving them out of the flag no longer disables them. Both names are still accepted in the flag, but they are ignored and will be removed in a future release. Use --authorization-always-allow-paths to control which paths are always allowed.

The synthetic system:kcp:initializer:* and system:kcp:terminator:* groups only grant access if they name an initializer or terminator registered in the LogicalCluster's status, and the cluster is in the matching phase.

The logical cluster admin identities (system:kcp:logical-cluster-admin and the external variant) skip authorization only for requests the bootstrap policy allows. Access they get through workspace-local or global RBAC now goes through the regular workspace access checks.

BREAKING: Authorizer names in audit annotations have changed. The authorizers have been sorted into four group: `bypass`, `pregate`, `grant` and `gate. Each authorizer is annotated with its group as prefix. The numbering has been removed.

01-requiredgroups → gate-requiredgroups
02-content → grant-content
03-systemcrd → gate-systemcrd
04-maxpermissionpolicy → gate-maxpermissionpolicy
05-bootstrap, 05-local, 05-global → grant-bootstrap, grant-local, grant-global

New names: grant-webhook, pregate-existence, bypass-logicalclustermanagement. Update any audit log tooling that matches on the old names.

@kcp-ci-bot kcp-ci-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the DCO. kind/bug Categorizes issue or PR as related to a bug. kind/chore Categorizes issue or PR as related to maintenance and other usually non-code changes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 29, 2026
@ntnn

ntnn commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

@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 mjudeikis-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread pkg/server/options/authorization.go Resolved
@kcp-ci-bot kcp-ci-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 29, 2026
@ntnn

ntnn commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

@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 mjudeikis-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@ntnn

ntnn commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

@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 mjudeikis-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@ntnn

ntnn commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

/hold

I want to make some changes

@kcp-ci-bot kcp-ci-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 29, 2026
@ntnn

ntnn commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

/retest
/unhold

Changed my mind. I think adding more changes here will be too much. I'll make follow ups later.

@kcp-ci-bot kcp-ci-bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 29, 2026
@ntnn

ntnn commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

@mjudeikis-bot review and use fable. don't re-review, actually go through every change again and reason about the placement of authorizers.

Comment on lines +61 to +64
// 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
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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 mjudeikis-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 /healthz or system identities.
  • Lifecycle-group allow: moved out of the content authorizer into the bypass group. It is now validated against Status.Initializers/Status.Terminators instead of phase only, and still skips deep SARs. It no longer passes through requiredgroups (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=access check 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 Deny is 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: ApplyTo on origin/main vs head; workspaceContentAuthorizer.Authorize in full; requiredGroupsAuthorizer.Authorize; SystemCRDAuthorizer; MaximalPermissionPolicyAuthorizer.Authorize and its constructor; DelegateAuthorization and the Decorator methods (decorator.go); deep_sar.go; pkg/server/filters/shardlevelpaths.go and shardpaths; the initializing/terminating VW group injection (build.go:324, build.go:310); the logicalcluster phase reconciler (when Deleting is entered); the proxy prefix stripping (pkg/proxy/options/authentication.go); the other users of HasLifecycleGroup, NewWorkspaceContentAuthorizer and NewRequiredGroupsAuthorizer (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. union of 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 getLogicalCluster closure 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 of ApplyTo for 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 vet of test/e2e/... could not complete here (module download of mockoidc/go-jose blocked). golangci-lint is not installed here; CI pull-kcp-lint is 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 on df1a086 and is being retested; I could not read its log, so I cannot say whether the failure relates to this change.

Comment thread pkg/server/options/authorization.go Resolved
Comment thread pkg/server/options/authorization.go Resolved
Comment thread pkg/server/options/authorization.go Resolved
Comment on lines -140 to -160
// 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
}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed because the initializer/terminator have a bypass that validates both the correct phase and that the request is for a valid initializer/terminator.

@ntnn

ntnn commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

/test pull-kcp-test-e2e-sharded

@ntnn

ntnn commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

/test pull-kcp-test-e2e

ntnn added 11 commits October 31, 2026 06:42
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]>
@kcp-ci-bot kcp-ci-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 31, 2026
@ntnn

ntnn commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

/retest

@kcp-ci-bot kcp-ci-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Nov 3, 2026
@mjudeikis

Copy link
Copy Markdown
Contributor

/lgtm
/approve

@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Nov 3, 2026
@kcp-ci-bot

Copy link
Copy Markdown
Contributor

LGTM label has been added.

DetailsGit tree hash: c8f983dcb4142d2529f05f3471e8d211b18f6439

@kcp-ci-bot

Copy link
Copy Markdown
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kcp-ci-bot kcp-ci-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 3, 2026
@mjudeikis

Copy link
Copy Markdown
Contributor

@mjudeikis-bot create an issue in kcp-operator and helm-charts repo for release 0.34 to make sure it is changed

@kcp-ci-bot
kcp-ci-bot merged commit 7c952f7 into kcp-dev:main Nov 3, 2026
19 checks passed
@mjudeikis

Copy link
Copy Markdown
Contributor

@mjudeikis-bot create an issue in kcp-operator and helm-charts repo for release 0.34 to make sure it is changed

@mjudeikis-bot

Copy link
Copy Markdown

Created tracking issues for the 0.34 release: kcp-dev/kcp-operator#313 and kcp-dev/helm-charts#249

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has signed the DCO. kind/bug Categorizes issue or PR as related to a bug. kind/chore Categorizes issue or PR as related to maintenance and other usually non-code changes. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants