Rule entities
About 812 words
Not all traffic is one entity using another's API. A probe checks many services; an operator talks to the instances it manages; a backup job reads a database it doesn't own. For those, write a kind: Cilium entity of spec.type: rule: one allow, with both ends and the ports. The examples come from docs/examples/prod.
A rule
The CloudNativePG operator polls each PostgreSQL instance it manages on port 8000. Neither consumesApi nor dependsOn describes that well, so a rule does:
apiVersion: specht-labs.de/v1alpha1
kind: Cilium
metadata:
name: cnpg-manages-instances
title: The CloudNativePG operator reaches its database instances
spec:
type: rule
target: cilium:prod
owner: group:platform
from: [component:cnpg-operator]
to: [resource:shop-db]
ports: [tcp:8000]The operator's policy gets the egress:
egress:
# to resource:shop-db
# rule cilium:cnpg-manages-instances
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: shop
cnpg.io/cluster: shop-db
toPorts:
- ports:
- port: "8000"
protocol: TCPand the database's policy the ingress:
ingress:
# from component:cnpg-operator
# rule cilium:cnpg-manages-instances
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: cnpg-system
app.kubernetes.io/name: cloudnative-pg
toPorts:
- ports:
- port: "8000"
protocol: TCPThe fields
| Field | Required | Meaning |
|---|---|---|
target | yes | the policy the rule belongs to: cilium:prod, or prod (the kind defaults to Cilium, the namespace to the rule's) |
owner | yes | the rule's owner, like any catalog entity's |
from | yes | the sources, at least one |
to | yes | the destinations, at least one |
ports | no | the ports, in the port syntax; every port if unset |
system | no | the System the rule is part of |
from and to take the peer syntax:
| Value | In from | In to |
|---|---|---|
component:x, resource:x | its pods | its pods, or its cilium-dst if it has no pods on the cluster |
api:x | the pods of its providers on the cluster | the same, or its cilium-dst |
entity:world, entity:remote-node, … | that Cilium entity | that Cilium entity |
cidr:… | those addresses | those addresses |
fqdn:… | not allowed | that DNS name |
* | every endpoint of the policy | every endpoint of the policy |
Every source is paired with every destination, and each pair is a flow. At least one end of each pair must be pods on the cluster: a rule from entity:world to cidr:192.0.2.0/24 says nothing Cilium could enforce here, and is an error. A pair whose two ends are the same endpoint is skipped.
Every endpoint
* stands for every endpoint of the policy. A rule like this one lets the blackbox exporter probe every workload on its health port:
spec:
type: rule
target: cilium:prod
owner: group:platform
from: [component:blackbox-exporter]
to: ['*']
ports: [tcp:8080]It renders one egress rule per endpoint on the exporter's side and one ingress rule on each endpoint, and it allows the port on every endpoint whether or not it listens there. The example catalog names the two services it really probes instead:
from: [component:blackbox-exporter]
to: [component:shop, component:orders]
ports: [tcp:8080]Ports
A rule's ports apply to all of its pairs. Without ports, the rule allows every port, and unlike a relation without ports it doesn't get a warning: a rule says what it means. Write two rules when two destinations need different ports.
Rules and the policy
- Rules apply whether the policy's
spec.catalogRulesis on or off. With it off, rules are the only flows besides each endpoint's own pods. - A rule whose
targetisn't a policy in the catalog renders nowhere. It's reported asspec.target: no Cilium policy cilium:staging: in every policy's Problems in the console, on the rule's own card, and inbackstage-cilium-render's output. - A name in
fromortothat isn't in the catalog is an error; an entity without pods on the cluster (and, into, withoutcilium-dst) is a warning. The rest of the rule still renders.
The catalog module checks a rule's shape when it processes it: from and to must be non-empty lists of valid peers, fqdn: only in to, ports valid ports. A rule that fails is refused by the catalog. Diagnostics has the messages.
On the entity page
A rule entity's page has a Network policy rule card: its sources, destinations and ports, its problems, and the flows it adds, with a link to the rule in the console. The catalog relates the rule to its policy (partOfPolicy) and to each catalog entity it names (appliesTo), so the rule also shows up among those entities' relations. Relations lists them.
Keep rules in the same protected location as the policy entity: a rule can open any path on the cluster. Restrict where policies come from explains how.
