Skip to content

Harden LocalResource fromRef: cross-namespace reads use the provider's identity, not the author's #10

Closed

Description

@braghettos

Summary

LocalResource lets the CR author name any object in any namespace via spec.fromResource.fromRef, and the provider fetches it with its own ServiceAccount rather than the author's. The fetched object is serialised in full and committed to a git remote the same author chooses.

The effect is that namespaced create rights on one CRD confer cluster-wide read through the provider's identity, plus an egress path for the result. This is the classic confused-deputy shape.

Filing as hardening, not as a live exploit: this repository is public, private vulnerability reporting is not enabled on it, and there is no SECURITY.md. I have deliberately not included a ready-to-run manifest. Enabling private vulnerability reporting would be worth doing regardless of this issue.

Where

  • internal/controllers/localresource/localresource.go:352-364 — the GVR is built from spec.fromResource.fromRef.apiVersion + .resource, and when .namespace != "" it is used verbatim. There is no comparison against cr.GetNamespace() and no kind allow-list.
  • internal/controllers/localresource/localresource.go:365 — the Get uses e.dynamic, constructed at localresource.go:60 from dynamic.NewForConfigOrDie(mgr.GetConfig()). That is the provider's ServiceAccount, never the CR author.
  • helm/git-provider/templates/clusterrole.yaml:8-10 — that ServiceAccount holds apiGroups: ["*"], resources: ["*"], verbs: ["get"] cluster-wide.
  • internal/controllers/localresource/localresource.go:369 → internal/tools/localfs WriteK8sResource serialises the whole unstructured object with no field stripping, so Secret.data is included as-is.
  • The file is then copied, committed and pushed to spec.toRepo.url — a URL supplied by the same CR.

No SubjectAccessReview, impersonation, or allow-list exists anywhere in the repo (grep -rn "SubjectAccessReview|Impersonat|AuthorizationV1" returns nothing), and the CRD leaves fromRef.namespace free-form (required: [apiVersion, name, resource]).

Scope, stated fairly

Two things keep this from being a straightforward "anyone can read every Secret":

  1. It is the ClusterRole's stated intent. clusterrole.yaml:7 carries the comment "ClusterVisibilty, needed to get resource from references across namespaces". Cross-namespace reads are the feature; the gap is that nothing checks whether the author was entitled to the object.
  2. The same class already exists without fromRef. credentials.secretRef.namespace is required and free-form, Connect resolves it with the provider's client, and the resulting token is sent to the author-chosen toRepo.url. So "create on this CRD ⇒ reach a Secret the author cannot read" is already true. fromRef widens the blast radius from git credentials to every object in the cluster.

So the honest framing is: the CRD's trust model is "the author is trusted with the provider's identity" — the standard provider-runtime managed-resource posture — and that model should be made explicit and bounded rather than implicit.

Mitigating in Krateo specifically: the Blueprint Builder / builder-publish publish path only ever emits fromResource.fromString, never fromRef, so this is not reachable from portal-user content today. It needs a direct grant of create localresources.git.krateo.io, which is operator-level.

Options

  1. Namespace confinement by default — require fromRef.namespace == cr.Namespace unless an operator explicitly opts the installation into cross-namespace reads (a flag or a per-namespace allow-list). Preserves the documented use case, removes the default cliff.
  2. Authorize the author — SubjectAccessReview the CR's creator (from the annotation the reconciler records, or via impersonation) against the referenced GVR before the Get at line 365. Strictly correct, more machinery, and needs a trustworthy author identity.
  3. Narrow the ClusterRole — drop resources: ["*"] to the kinds this actually needs to read, and exclude secrets unless explicitly enabled. Cheapest, and independently worthwhile.
  4. Strip on serialise — never write Secret.data / stringData into a committed file. Narrow (only helps Secrets) but a good defence in depth given the destination is a git remote.

1 and 3 together would remove most of the risk without touching the feature.

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_01JumEqTGGJ2hf3vjE3xFQsv

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions