Rendered manifests
About 996 words
What the backend renders for one policy: a single YAML file of CiliumClusterwideNetworkPolicy documents (apiVersion: cilium.io/v2), separated by ---. The examples are from docs/examples/prod.
| Document | Count | Selects |
|---|---|---|
default-deny | one | every pod outside spec.defaultDeny.exclude |
allow-<kind>-[<namespace>-]<name> | one per endpoint with flows | the endpoint's pods |
allow-tailnet-egress-<namespace> | one per namespace with tailnet consumers | the Tailscale egress proxies of that namespace |
The documents come in that order, the endpoints' sorted by name. Without the cluster in the catalog, the file is empty.
The header
The file starts with a comment:
# Network policies for resource:prod, rendered by Backstage from
# cilium:prod and the catalog's relations. Change the catalog, not
# this file: each rule says which catalog fact it comes from.Labels and annotations
Every document has:
| Key | Value | |
|---|---|---|
| label | app.kubernetes.io/managed-by | backstage |
| annotation | specht-labs.de/cilium-policy | the policy entity, such as cilium:default/prod |
| annotation (endpoint policies only) | specht-labs.de/cilium-source | the endpoint's entity, such as component:default/shop |
The label lets you find, or prune, everything the plugin rendered: kubectl get ccnp -l app.kubernetes.io/managed-by=backstage.
default-deny
# Network policies for resource:prod, rendered by Backstage from
# cilium:prod and the catalog's relations. Change the catalog, not
# this file: each rule says which catalog fact it comes from.
apiVersion: cilium.io/v2
kind: CiliumClusterwideNetworkPolicy
metadata:
name: default-deny
labels:
app.kubernetes.io/managed-by: backstage
annotations:
specht-labs.de/cilium-policy: cilium:default/prod
spec:
description: "Default deny on resource:prod, outside kube-system: nothing reaches a pod, and a pod reaches nothing but the cluster DNS, unless a policy below allows it."
endpointSelector:
matchExpressions:
- key: io.kubernetes.pod.namespace
operator: NotIn
values:
- kube-system
enableDefaultDeny:
ingress: true
egress: true
ingress:
- {}
egress:
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: kube-system
k8s-app: kube-dns
toPorts:
- ports:
- port: "53"
protocol: UDP
- port: "53"
protocol: TCP
rules:
dns:
- matchPattern: "*"endpointSelector: every pod whoseio.kubernetes.pod.namespaceisn't excluded. Without exclusions,{}: every pod.enableDefaultDeny: {ingress: true, egress: true}: every selected pod is in default deny both ways.ingress: [{}]: one empty ingress rule, which allows nothing.egress: DNS to the cluster DNS (spec.dns, kube-dns by default) on port 53, UDP and TCP, through the DNS proxy withmatchPattern: "*". FQDN rules and the DNS proxy explains why.
The description names the cluster and the excluded namespaces.
allow-<kind>-<name>
One per endpoint, named after its entity: allow-, the kind, the entity's namespace if it isn't default, and the name, lowercased, with runs of anything but a-z, 0-9, . and - replaced by -, cut at 253 characters. An endpoint without any flow gets none, which only happens with allowWithin: false.
apiVersion: cilium.io/v2
kind: CiliumClusterwideNetworkPolicy
metadata:
name: allow-component-orders
labels:
app.kubernetes.io/managed-by: backstage
annotations:
specht-labs.de/cilium-source: component:default/orders
specht-labs.de/cilium-policy: cilium:default/prod
spec:
description: "orders (component:orders): what reaches it, and what it reaches."
endpointSelector:
matchLabels:
io.kubernetes.pod.namespace: orders
app: orders
enableDefaultDeny:
ingress: false
egress: false
ingress:
# from component:shop
# component:shop consumes api:orders-api
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: shop
app: shop
toPorts:
- ports:
- port: "9000"
protocol: TCP
# from component:prometheus
# component:prometheus scrapes its metrics (specht-labs.de/cilium-metrics-ports)
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: monitoring
app.kubernetes.io/name: prometheus
toPorts:
- ports:
- port: "9090"
protocol: TCP
# its own pods
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: orders
app: orders
# from component:blackbox-exporter
# rule cilium:blackbox-probes
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: monitoring
app.kubernetes.io/name: blackbox-exporter
toPorts:
- ports:
- port: "8080"
protocol: TCP
egress:
# its own pods
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: orders
app: ordersendpointSelector: the endpoint's pods. One namespace is amatchLabelsentry onio.kubernetes.pod.namespace; several are anInexpression; none, no namespace constraint.enableDefaultDeny: {ingress: false, egress: false}: this policy only allows. It never puts a pod into default deny or takes it out;default-denyalone decides that.ingress: one rule per peer that reaches the endpoint;egress: one per peer it reaches. A section without rules is left out.
Each rule has a comment: the peer (from component:shop, to fqdn:api.github.com, or its own pods), then each catalog fact that allows a flow to or from that peer, then every port: no specht-labs.de/cilium-ports if the rule has no ports and isn't the endpoint's own pods.
A rule's peer renders as:
| Peer | Ingress | Egress |
|---|---|---|
| an endpoint | fromEndpoints: [<its selector>] | toEndpoints: [<its selector>] |
entity: | fromEntities: [<name>] | toEntities: [<name>] |
cidr: | fromCIDR: [<range>] | toCIDR: [<range>] |
fqdn: | (never) | toFQDNs: [{matchName: <name>}], or matchPattern with a * |
| the tailnet | (never) | toEndpoints: [<the egress proxies' selector>] |
and its ports as toPorts: [{ports: [...]}], merged across the flows to that peer. Every port is no toPorts at all.
An endpoint in an excluded namespace gets Its namespace is left out of the default deny: this only allows. in its description, and, if it has fqdn: destinations, the DNS rule from default-deny as an egress rule of its own.
allow-tailnet-egress-<namespace>
One per namespace whose endpoints reach an API on the tailnet, when the policy has spec.tailnetEgress:
apiVersion: cilium.io/v2
kind: CiliumClusterwideNetworkPolicy
metadata:
name: allow-tailnet-egress-shop
labels:
app.kubernetes.io/managed-by: backstage
annotations:
specht-labs.de/cilium-policy: cilium:default/prod
spec:
description: "The Tailscale egress proxies of Services in shop: their consumers reach them on the way to the tailnet."
endpointSelector:
matchLabels:
io.kubernetes.pod.namespace: tailscale
tailscale.com/parent-resource-type: svc
tailscale.com/parent-resource-ns: shop
enableDefaultDeny:
ingress: false
egress: false
ingress:
# from component:shop, toward the tailnet
# component:shop consumes api:inventory-api (svc:inventory)
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: shop
app: shop
toPorts:
- ports:
- port: "443"
protocol: TCPIt selects the egress proxies (tailnetEgress.namespace and selector, plus consumerNamespaceLabel set to the namespace) and allows ingress from each consumer in that namespace, on the APIs' tailnet-ports. Consumers with more than one namespace don't get one. Tailnet egress has the details.
What it never renders
Kubernetes NetworkPolicy, namespaced CiliumNetworkPolicy, deny rules (ingressDeny, egressDeny), layer 7 rules other than the DNS rule, toServices, toGroups, node selectors and host policies.
