Flows from relations
About 1167 words
Most flows come from relations the catalog already has: a Component consumes an API, an app depends on its database. This guide goes through each relation the plugin reads, which way the traffic goes, and which ports it gets. The examples come from docs/examples/prod.
All of these flows exist only while the policy's spec.catalogRules is true, the default. With it set to false, the policy has only the rule entities and each endpoint's own pods.
| Relation | Flow |
|---|---|
Component consumesApi API | to the API's providers' pods, if they run on the cluster; else to the API's cilium-dst; else to its providers' cilium-dst; else, for an API on the tailnet, to the Tailscale egress proxies |
endpoint dependsOn Resource on the cluster | to the Resource's pods |
endpoint dependsOn a gateway on the cluster | the other way: from the gateway's pods to the endpoint |
endpoint dependsOn anything outside the cluster | to its cilium-dst |
endpoint dependsOn Component on the cluster | none |
The web shop of the example uses all of them:
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: shop
title: Web shop
annotations:
backstage.io/kubernetes-namespace: shop
backstage.io/kubernetes-label-selector: app=shop
specht-labs.de/cilium-ports: tcp:8080
specht-labs.de/cilium-metrics-ports: tcp:9090
spec:
type: website
lifecycle: production
owner: group:shop
consumesApis: [orders-api, payments-api, billing-api, inventory-api]
dependsOn:
- resource:prod
- resource:shop-db
- resource:edge
- resource:assets-bucket
- component:ordersconsumesApi
A Component that consumes an API reaches the pods of every Component that provides it on the cluster. orders-api is provided by component:orders, which runs on the cluster, so the shop reaches the orders pods:
egress:
# to component:orders
# component:shop consumes api:orders-api
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: orders
app: orders
toPorts:
- ports:
- port: "9000"
protocol: TCPand allow-component-orders has the same flow as ingress. The port is the API's specht-labs.de/cilium-ports (9000 here). If the API has none, the provider's cilium-ports count; if neither has any, the flow is allowed on every port and the provider gets a warning. A Component that provides the API it consumes gets no flow to itself.
When no provider runs on the cluster, the API is somewhere else, and its specht-labs.de/cilium-dst says where. payments-api is a SaaS API, reached by name:
egress:
# to fqdn:api.payments.example.com
# component:shop consumes api:payments-api
- toFQDNs:
- matchName: api.payments.example.com
toPorts:
- ports:
- port: "443"
protocol: TCPIf the API has no cilium-dst, its providers' count. billing-api has none, but its provider, component:billing, runs in a data centre the shop reaches by address:
apiVersion: backstage.io/v1alpha1
kind: Component
metadata:
name: billing
annotations:
specht-labs.de/cilium-dst: cidr:203.0.113.0/24
specht-labs.de/cilium-ports: tcp:8443
spec:
type: service
lifecycle: production
owner: group:finance
providesApis: [billing-api]egress:
# to cidr:203.0.113.0/24
# component:shop consumes api:billing-api
- toCIDR:
- 203.0.113.0/24
toPorts:
- ports:
- port: "8443"
protocol: TCPAn API with none of these is not allowed, and the consumer gets a warning: consumes api:default/legacy-api, which doesn't run on resource:default/lab and has no specht-labs.de/cilium-dst: not allowed. External destinations covers cilium-dst in full, and Tailnet egress the last case, APIs on a Tailscale tailnet.
dependsOn a Resource
An endpoint that depends on a Resource with pods on the cluster (a database, a cache, a queue) reaches those pods, on the Resource's cilium-ports:
egress:
# to resource:shop-db
# component:shop depends on resource:shop-db
- toEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: shop
cnpg.io/cluster: shop-db
toPorts:
- ports:
- port: "5432"
protocol: TCPA Resource outside the cluster (a bucket, a managed database) is reached at its cilium-dst, on its cilium-ports:
egress:
# to fqdn:assets.s3.eu-central-1.amazonaws.com
# component:shop depends on resource:assets-bucket
- toFQDNs:
- matchName: assets.s3.eu-central-1.amazonaws.com
toPorts:
- ports:
- port: "443"
protocol: TCPThe same goes for a Component outside the cluster. Argo CD in the example depends on component:github, which has cilium-dst: fqdn:github.com, fqdn:api.github.com:
egress:
# to fqdn:github.com
# component:argocd depends on component:github
- toFQDNs:
- matchName: github.com
toPorts:
- ports:
- port: "443"
protocol: TCPA dependency without a cilium-dst and without pods on the cluster gives no flow. If it has backstage.io/kubernetes-namespace, it probably runs on the cluster but doesn't dependsOn its Resource, and the policy warns. Otherwise, if it's a Component or Resource, the policy notes it (info), in case it is reached over the network after all. A Resource that isn't reached over the network at all, such as a DNS zone its controller manages through the DNS provider's API, can say so with specht-labs.de/cilium-dst: none, and the note goes away.
dependsOn a gateway
A Resource of spec.type: gateway is the exception. An endpoint that depends on a gateway is exposed through it: the gateway's pods reach the endpoint, not the other way round. The shop depends on resource:edge:
apiVersion: backstage.io/v1alpha1
kind: Resource
metadata:
name: edge
title: Edge gateway
annotations:
backstage.io/kubernetes-namespace: gateways
backstage.io/kubernetes-label-selector: gateway.networking.k8s.io/gateway-name=edge
specht-labs.de/cilium-ports: tcp:10443
specht-labs.de/cilium-allow: entity:world
spec:
type: gateway
owner: group:platform
dependsOn: [resource:prod, component:envoy-gateway]So the shop's policy has an ingress from the gateway, on the shop's own cilium-ports:
ingress:
# from resource:edge
# component:shop is exposed through resource:edge
- fromEndpoints:
- matchLabels:
io.kubernetes.pod.namespace: gateways
gateway.networking.k8s.io/gateway-name: edge
toPorts:
- ports:
- port: "8080"
protocol: TCPand the gateway's policy the matching egress. The gateway's cilium-ports are the ports it listens on; cilium-allow: entity:world lets the internet reach it there. A gateway's own dependsOn (its controller, its load balancer) gives no flow at all: those are what the gateway is made of, not what it reaches. Why gateways run the other way explains the choice.
dependsOn a Component on the cluster
None. In Backstage, dependsOn between Components says that one needs the other to work, not that it opens connections to it; the shop above depends on component:orders and gets no flow from that. Use consumesApis for traffic between Components: it names the API, and the API carries the port.
What the comments say
Every rule in the rendered manifests carries a comment with the peer and the facts that allow it:
| Comment | Fact |
|---|---|
component:shop consumes api:orders-api | consumesApi |
component:shop depends on resource:shop-db | dependsOn |
component:shop is exposed through resource:edge | dependsOn a gateway |
allowed by resource:edge (specht-labs.de/cilium-allow) | cilium-allow |
component:prometheus scrapes its metrics (specht-labs.de/cilium-metrics-ports) | the metrics scraper |
rule cilium:cnpg-manages-instances | a rule entity |
its own pods | the endpoint's own pods (allowWithin) |
Flows to the same peer share one rule, with every fact listed under it and their ports merged.
