From catalog to policy
About 1025 words
This page follows a policy from the YAML in your repositories to the manifests in a pull request: who checks what, when, and why the work is split the way it is.
In the catalog: shapes and relations
The catalog module registers kind: Cilium with the catalog. When the catalog processes a Cilium entity, the module checks its shape: that spec.type is policy or rule, that required fields are there, that namespaces and label selectors parse, that a rule's peers and ports parse and that a DNS name isn't a source. A malformed entity fails processing with a message that names each problem, and the catalog doesn't take that version of it.
It doesn't check what the entity refers to. Whether the cluster's Resource exists, or a rule's component:x has pods on the cluster, depends on other entities that may not be processed yet, or live in another repository. Those checks wait until the whole catalog is in view.
The module also emits relations: from each Cilium entity to its owner and system, from a policy to its cluster, from a rule to its policy and to the catalog entities it names, each with its reverse. That's what puts a policy on its cluster's page and a rule on the pages of what it allows. Relations lists them.
The annotations on Components, APIs and Resources aren't checked by the catalog at all; they're ordinary annotations to it. The backend reads them.
In the backend: one pass over the catalog
The backend plugin asks the catalog for every Cilium entity, Component, API and Resource. It fetches only the fields it reads: kind, name, namespace, title, description, annotations, spec and relations. It does this with its own service credentials, at most once a minute for the console, and fresh for each publishing run.
Then, for each policy in order of name:
- Find the cluster. The Resource
spec.clusternames. Without it the policy has an error and nothing else renders. - Collect the endpoints. Every Component and Resource with a
dependsOnrelation to the cluster and a namespace or selector. Their annotations are parsed here: namespaces, selectors, ports, metrics ports. An endpoint whose namespace or selector doesn't parse is dropped, with an error. - Make the flows. With
catalogRuleson:consumesApi,dependsOn,cilium-allowon endpoints and on APIs they provide, and the metrics scraper. Then each endpoint's own pods (withallowWithinon), and the rule entities whosespec.targetis this policy. Each flow records why it exists and where its ports come from. - Check ports. Every endpoint reached without ports by a flow from the relations gets a warning.
- Render. The
default-denypolicy, then oneallow-<kind>-<name>policy per endpoint with flows, sorted by name, then oneallow-tailnet-egress-<namespace>policy per namespace whose endpoints reach the tailnet. Flows to the same peer in the same direction become one rule, their ports merged and every reason in the comment.
A rule entity whose spec.target isn't a policy belongs to none; it's reported on its own, as an orphan.
Both ends of every flow
Cilium checks a connection twice: as egress where it leaves, and as ingress where it arrives. Under the default deny, both must be allowed. So every flow between two endpoints renders twice, from one catalog fact: the shop's consumesApis: [orders-api] becomes an egress rule in allow-component-shop and an ingress rule in allow-component-orders. A flow to or from something outside the cluster renders once, on the endpoint's side.
That's also why the plugin renders clusterwide policies: a flow between two namespaces needs a rule in each, and one policy per endpoint, named after the catalog entity, keeps each rule next to the pods it applies to.
One default deny, many allows
Only default-deny turns default deny on (enableDefaultDeny: {ingress: true, egress: true}). Every other policy sets both to false: it adds allows, and never changes whether a pod is in default deny. Three things follow:
- Whether a pod is enforced depends on one selector,
default-deny's, which is every pod outsidespec.defaultDeny.exclude. - An endpoint in an excluded namespace still gets its allows rendered. They change nothing while the namespace is open, and they're ready when it isn't. Excluded namespaces has more.
- Deleting
default-denyopens the cluster without touching anything else, which is the emergency exit in Turn on the default deny.
Problems don't block the console, errors block publishing
The console renders a policy whatever its problems. A relation the plugin can't use gives no flow and a warning; a malformed annotation is ignored with an error. You see the policy as it would be, and the list of what's missing.
Publishing is stricter: a policy with an error isn't published. An error means the catalog says something the plugin couldn't read, so the manifests may not be what anyone meant, and under a default deny that's a dropped connection. Warnings and notes don't stop it. The pull request lists them.
Publishing
The publishing task runs every hour. For each policy with spec.publish whose repository cilium.allowedRepos lists, and without errors, it compares the rendered manifests with the file in the repository and, if they differ, updates the pull request or pushes. Publish to GitHub covers both flows.
The plugin never talks to the cluster. What Cilium enforces is whatever your GitOps tool last applied from the repository.
