Add e2e tests for webhook grants passing through authz gates
Context
PR https://github.com/kcp-dev/kcp/pull/4507 ("Restructure authz chain") splits the authorization chain in pkg/server/options/authorization.go (Authorization.ApplyTo) into three groups: bypass, grant and gate. The only new e2e coverage is TestMaximalPermissionPolicyWebhookEscalation. Nothing tests the other gates, so a later reorder of the blocks or a change to the gate decision handling would not fail any test.
Requested in https://github.com/kcp-dev/kcp/pull/4507#discussion_r4414986222 (follow-up to the review comment at https://github.com/kcp-dev/kcp/pull/4507#discussion_r4414865487).
What exists today
pkg/server/options/authorization.go: the final authorizer closure sits inline inApplyTo. It composes the bypass authorizers, the grant authorizers (RBAC, webhook) and the gates (gate-maxpermissionpolicy,gate-systemcrd,gate-requiredgroups).- The e2e suite only covers the maximal permission policy gate against a webhook grant.
What should be added
An e2e test (against a kcp server configured with an authorization webhook) proving that a webhook decision cannot get around the gates:
- A webhook
Allowfor a user not in the groups listed in the workspace's required-groups annotation ends in a Deny. - A webhook
Allowforupdate/patchonapiexports/statusandapibindings/status(apis.kcp.io) ends in a Deny. - A webhook
Denyshort-circuits before the gates (the gates are not consulted and the request is denied).
Optionally, extract the closure into a function, e.g. chainAuthorizer(bypass, preGate, grants, gates authorizer.Authorizer) authorizer.Authorizer, so the decision table can also be unit tested.
Checklist
- [ ] Look at how
TestMaximalPermissionPolicyWebhookEscalationsets up the webhook and reuse its helpers. - [ ] Add an e2e case: webhook Allow plus the required-groups annotation, user lacks the group, expect Forbidden.
- [ ] Add an e2e case: webhook Allow on
apiexports/statusandapibindings/status, expect Forbidden. - [ ] Add an e2e case: webhook Deny, expect Forbidden and that the gates do not change the outcome.
- [ ] (Optional) Extract the closure and add a table-driven unit test over (bypass, grants, gates) decisions.
Hi, I'd like to take this. My plan is to add the three e2e cases following TestMaximalPermissionPolicyWebhookEscalation's setup, and I'll skip the optional refactor unless you want it. Is #4507 merged or still changing?