Enforce namespace boundary in generator.apply() (backport)
Committed by realshuting
fix(gpol,mpol): enforce namespace boundary in generator.apply() (backport) (#16238)
Backport of GHSA-79gf-7frw-68m9 to release-1.18.
A NamespacedGeneratingPolicy or NamespacedMutatingPolicy could call
generator.apply("<arbitrary-namespace>", [...]) to instruct the
background controller to create resources in any namespace it has RBAC
on, bypassing the intended namespace isolation.
generator.Lib() now accepts the policy namespace. When non-empty, the
SDK wires a namespacedImpl that rejects, at evaluation time, any
generator.apply() call whose target namespace differs from the policy's
own namespace. Additionally, GenerateResources now rejects cluster-scoped
resources whenever a namespace is set, so a namespaced policy cannot emit
a cluster-scoped resource that would escape its namespace.
This backport pins github.com/kyverno/sdk to the old cel/libs layout
build that carries the fix (branch ghsa-79gf-7frw-68m9-compat). Unlike
the main branch, enforcement here is a runtime check inside the CEL
binding (the namespace argument cannot be removed from the signature),
so namespaced policies still compile successfully.
Fixes GHSA-79gf-7frw-68m9
Signed-off-by: realshuting <[email protected]>
Co-authored-by: Copilot <[email protected]>Editor assessment
This commit patches CVE-2026-54523. The content is strong: the body describes how a namespaced policy could call generator.apply on an arbitrary namespace to place resources anywhere the background controller held RBAC, then explains that generator.Lib now takes the policy namespace and wires a namespacedImpl rejecting mismatched targets at evaluation time, plus a guard against emitting cluster-scoped resources. It also explains why the backport differs from main - the namespace argument cannot be removed from the signature, so enforcement is a runtime check in the CEL binding - and pins the SDK build accordingly. The `gpol,mpol` scope is a comma-separated multi-scope header, which caps this otherwise excellent message.