Restrict where policies come from
About 682 words
A network policy decides what reaches what on your cluster. Anyone who can get a kind: Cilium entity into your catalog can add a rule to it, and anyone who can edit a Component can change its flows. This guide limits where the kind may come from, and lists the other inputs worth guarding.
Allow the kind from one location
Catalog rules match an entity's origin location: the location that first discovered it. Register the directory that holds the policy and its rules as a location of its own, and allow Cilium for that location only:
# app-config.yaml
catalog:
rules:
# The kinds every location may hold. Cilium is not one of them.
- allow: [Component, System, API, Resource, Location, Group, User]
locations:
- type: url
target: https://github.com/acme/k8s-deployment/blob/main/cilium/policy/*.yaml
rules:
- allow: [Cilium]Then check two things:
- No global rule allows
Cilium. Acatalog.rulesentry withallow: [Cilium]lets every location register the kind. - No other location discovers the same files first: not a broader glob, not a
Locationentity, not a discovery provider that scans the repository. If one does, it becomes the origin, and its rules apply.
The catalog refuses a Cilium entity from any other location.
Protect the directory
The location rule is only as strong as the repository behind it. Treat cilium/policy/ like the manifests themselves: require reviews on it, for example with a CODEOWNERS entry for the team that owns the cluster, and protect the branch the location points at.
Know the other inputs
Cilium entities aren't the only thing that changes the manifests. These come from ordinary catalog entities, usually in many repositories:
| Input | What it can change |
|---|---|
dependsOn the cluster's Resource, with a namespace or selector | whether an entity is an endpoint at all |
backstage.io/kubernetes-namespace, -label-selector, specht-labs.de/cilium-selector, -namespaces | which pods an endpoint's policy selects, and so which pods get its allows |
consumesApis, dependsOn | flows from the entity to others |
specht-labs.de/cilium-allow | who reaches the entity, including entity:world |
specht-labs.de/cilium-dst on an API, Component or Resource | where every consumer of it may connect outside the cluster |
specht-labs.de/cilium-ports, -metrics-ports | the ports flows into the entity are allowed on |
specht-labs.de/tailnet-dst, -ports on an API | flows to the Tailscale egress proxies |
So someone who can edit a Component can, for example, give it cilium-selector: '*' and extend its allows to every pod in the namespace, or add cilium-allow: entity:world and open it to the internet. Someone who can edit an API that many Components consume can change where they all may connect.
If that's more trust than you want, there are two places to stop it:
- Review the pull request. With
flow: pullRequest, nothing reaches the cluster until someone merges Backstage's pull request. The diff shows every rule that changed, with the catalog fact behind it in the comment. - Turn
catalogRulesoff on the policy and write every flow as a rule entity in the protected directory. The relations and thecilium-allowand metrics annotations then give no flows; endpoints still come from the catalog, and their selectors still do.
Limit where Backstage writes
cilium.allowedRepos in app-config.yaml lists the only repositories Backstage writes manifests to. A policy entity can name any repository in spec.publish, but Backstage won't publish to one that isn't on the list. Keep it to the repository your GitOps tool applies, and give the GitHub App access to that repository only. Publish to GitHub has the permissions.
Who can read the policy
The backend reads the catalog with its own service credentials, so /api/cilium/overview contains every policy, whatever catalog permissions the user who asks has. Any user who can call Backstage's backend can read the rendered policies: every workload's selector, what it reaches, and which addresses outside the cluster are allowed. Keep that in mind before you install the frontend in a Backstage that people outside the platform team use.
