Network policies
No component template ships a network policy. Policies are generated once the whole graph is known, from the links between components, so adding a link opens exactly the path it needs and removing it closes that path at the next build.
What is generated
After every component has rendered, the generator reads stack-metadata.yaml and writes:
| Output | What it holds |
|---|---|
networkpolicy/ | One policy file per rule, for each link in both directions — component to component, sub-component to component, component to sub-component and sub-component to sub-component |
networkpolicy-manifest.json | Every policy, plus the lists you check after a build: unresolved_links, fallback_to_any, cross_stack, cross_stack_outbound, cross_stack_unaddressed |
network-diagram.md | A diagram of every path, the components with internet access, and the links that could not be resolved |
Policies work at namespace level: a policy admits traffic from the source component's namespace to the target's namespace on the ports the link uses. Link types that carry no pod-to-pod traffic are registered as such and produce no policy.
Where the ports come from
| Order | Source |
|---|---|
| 1 | The port table for the link type (link-ports): the ports the link actually uses on its target |
| 2 | The target component's own port attributes — port, service_port, http_port or native_port, and the multi-line ports of image-based components, one name:port per line |
| 3 | The well-known port of the target's type |
A link the generator cannot resolve to a port is allowed on all ports between its two namespaces,
listed under unresolved_links and in the diagram, so it works and can be tightened, rather than
being silently blocked.
What a link cannot express
Some traffic is not a link: an admission webhook the API server calls, a metrics port a scraper reads, a component on the host network, an observer that reads every namespace, a component that needs the internet. These are registered per component type in two exception tables — one for each set below — and the generator applies them to the types present in the stack. A link whose traffic runs against its arrow is registered as a reverse flow.
Two sets
microsegmentation_level on the system's sections chooses one.
| Value | What is generated |
|---|---|
| empty or any value except the two below | The standard set: one policy per link, the exceptions, and internet egress on ports 80 and 443 for every namespace |
pci_dss_strict | The strict set: a default-deny baseline in every namespace, no blanket allow rules, no blanket internet egress, internet ingress only through the gateway |
none | No network policies |
The strict set has three destinations that no namespace rule can match: the cluster DNS (node-local
cache), the API server, and the nodes themselves (kubelet, node-exporter). Each is allowed by address
range from a stack configuration key: cluster_dns_cidr, control_plane_cidr, node_cidr. Until a
key is set, that rule allows its ports to any destination, the build log says so, and the manifest lists
it under fallback_to_any — so an assessor sees exactly what is open. Every declared link still works.
Across stacks
A link to a component of another stack is handled in both directions: a pod that connects out to another stack's address gets egress on that address's port, to the IP itself when the address is an IP; a link from another stack into this one through the gateway opens the gateway to the target. The full rules and the list of link types are in External stacks.
Applying them
| Delivery | How |
|---|---|
| kubectl | kubectl apply -f networkpolicy/ after the build. Applying never deletes a policy the generator stopped writing: delete it by hand |
| Argo CD | Turn on automate_networkpolicies on the Argo CD component (with gitops on, on an Argo CD that manages only its own cluster). A networkpolicy Application then syncs the folder, prunes what the design dropped, adopts policies already applied with kubectl, and retries without limit while a namespace another Application creates does not exist yet |
A component added to a running stack races its own policies: its namespace may appear after the
policy sync starts, and with the OPA policy network-policy-enforcement at deny its workloads are
refused until the policies exist. The retries resolve it; raise the component's Argo CD
argocd_sync_retry_limit for a new component.
Proving them
| Check | What it does |
|---|---|
| Network policy scan, light | Do the policies the links imply exist, in both directions? Missing and extra policies are named |
| Network policy scan, full | Real connection probes across every declared link, plus negative tests that a path which should be closed is closed |
OPA network-policy-enforcement | Refuses workloads in a namespace without a policy, and wide-open policies |
network-diagram.md | What is open and why, for a reviewer who does not run the scan |
A missing policy is never fixed by hand-writing one. It means a missing link, or a port the generator does not know: add the link, or register the port.