Skip to main content

Module network_policy_controller

Module network_policy_controller 

Source
Expand description

NetworkPolicyController — the PRODUCER NetworkPolicyEnforcer never had.

★ THE GAP THIS CLOSES. network_policy.rs shipped a typed rule model, a trait, a FakeNetworkPolicyEnforcer and a CiliumNetworkPolicyAdapter, all tested — and nothing anywhere constructed a rule from a real NetworkPolicy object or called upsert. Measured 2026-08-30:

$ grep -rn 'NetworkPolicyEnforcer' --include=*.rs . | grep -v network_policy.rs
engenho-controllers/src/lib.rs:136:   (the re-export)

Zero consumers. That is instance #8 of “type + backend + no producer” in this codebase, and it is the most dangerous one so far: every other instance was a missing feature, while this one is a POLICY OBJECT THAT APPLIES SUCCESSFULLY AND RESTRICTS NOTHING. An operator writes a default-deny policy, kubectl says created, and every packet still flows.

★ TWO SEPARATE JOBS, DELIBERATELY NOT COLLAPSED.

  1. Translate + install. spec → NetworkPolicyRules → the enforcer. This is the feature.
  2. Say which one happened. If the enforcer’s PolicyDatapath is Computed — the darwin topology, where there is no kernel to install a filter into — the policy is annotated and an event is emitted saying the traffic is unrestricted.

Job 2 is not decoration and it does not wait for job 1 to be perfect. A computed-only policy is indistinguishable from an enforced one by every kubectl command there is, so the only thing standing between an operator and a false sense of containment is this annotation.

★ WHY “ALLOW FROM ANYWHERE” IS ENCODED AS 0.0.0.0/0 AND NOT AS AN EMPTY PEER LIST. Upstream’s from: [] (absent) means allow all, while a policyType naming a direction with no rules at all means deny all. NetworkPolicyRule already fixes empty allowed_peers to mean deny, so the two cases would collapse onto the same value and the permissive one would silently become a deny — or, read the other way, a deny would become permissive. Rendering allow-all as an explicit IpBlock { cidr: "0.0.0.0/0" } keeps them distinct without widening the rule type, and it is what every real enforcer emits for that case anyway.

Structs§

NetworkPolicyController
Translates every NetworkPolicy into enforcer rules, installs them, and records whether they are actually enforced.

Constants§

ALLOW_ALL_CIDR
Upstream’s allow-all CIDR. See the module header for why allow-all is encoded this way rather than as an empty peer list.
ENFORCEMENT_ANNOTATION
The annotation carrying the enforcement verdict, so the distinction is machine-queryable (kubectl get netpol -o json) and not only visible in an event that ages out.

Functions§

already_annotated
Whether the policy already carries the right verdict.
annotated
The policy with the enforcement verdict annotated.
effective_policy_types
The policyTypes a NetworkPolicy is effectively subject to.
enforcement_value
The annotation value for a datapath verdict.
not_enforced_message
The message an operator reads when a policy restricts nothing.
policy_prefix
The prefix every rule of one policy shares. Used to reap on delete.
rule_id
The stable id of one translated rule.
translate
Translate one NetworkPolicy object into flat enforcer rules.