Repository navigation
Description
Problem
Checked on 2026-11-22 (main 6e497c2), in the vetting of PR #6721.
SandboxNetworkPolicy.to_k8s_network_policy(src/devops_cli/sandbox/models.py:489-520) writes one NetworkPolicy for each sandbox withpolicyTypes: [Ingress, Egress].- The network policy controller of the cluster does not keep the two directions of such a policy apart: an egress rule of the policy can admit traffic between two pods that it selects although its ingress rules deny it, and the reverse (fix(k8s): narrow the in-namespace egress of the object store #6707, fix(k8s): an in-namespace egress allow skips the ingress rules #6708). PR fix(k8s): split the network policies whose egress skips their ingress #6721 makes every policy of
k8s/single-type and adds a k8s check row, but the row does not read the policies that the sandbox code makes at run time. - The risk today is low: each policy selects only the pods of one sandbox, and its rules are empty, a namespace peer or whitelisted CIDRs. But the rule of the repository is that no policy has both types.
Proposed remedy
- Write two policies for each sandbox, one Ingress-only and one Egress-only, with the same pod selector and the same rules. Keep the deny-all of the isolated mode: an Ingress-only policy with no rules and an Egress-only policy with no rules.
- Write the tests first: each network mode gives two policies, each with one type, and the union of their rules equals the rules of today.
Acceptance criteria
-
uv run devops ci teston the sandbox tests passes, and no generated policy has both types.
Dependencies
Alternatives check of 2026-11-22: none.
Tool: none found.
Reason: Searches found only policy engines such as Kyverno, which validate, mutate or generate whole resources; none splits a dual-type NetworkPolicy into two single-type policies, so the fix stays in the sandbox code.
Lacks:
- No tool that emits an Ingress-only and an Egress-only policy pair
- No tool that keeps today's pod selector and rules in both copies
- No run-time check of policies the sandbox code builds
Proposed design
Problem statement
SandboxNetworkPolicy.to_k8s_network_policy writes one NetworkPolicy with both Ingress and Egress policy types. The cluster network policy controller can mix the two directions of such a policy. The change writes two single-type policies for each sandbox and keeps the current pod selector, rules and isolated-mode deny-all behavior.
Acceptance criteria
Requirement: One type for every sandbox policy
The sandbox network policy renderer SHALL return exactly two NetworkPolicy objects for each sandbox, one with policyTypes equal to ["Ingress"] and one with policyTypes equal to ["Egress"].
Scenario: Every network mode yields a single-type pair
- WHEN the renderer builds policies for each sandbox network mode
- THEN it returns two policies for each mode, and neither policy contains both Ingress and Egress in
policyTypes.
Requirement: Keep selector and directional rules
Each single-type policy MUST keep the original pod selector and only the rules of its direction.
Scenario: Rules stay with their direction
- WHEN the renderer splits a policy that has one ingress rule and one egress rule
- THEN the Ingress policy has the original
podSelectorand ingress rule, the Egress policy has the originalpodSelectorand egress rule, and the union of their rules equals the original rules.
Requirement: Isolated mode denies both directions
The isolated network mode SHALL render an Ingress-only policy with no ingress rules and an Egress-only policy with no egress rules.
Scenario: Isolated mode keeps deny-all
- WHEN the sandbox network mode is isolated
- THEN the renderer returns two policies with empty rule lists and one policy type each.
Requirement: Distinct policy names
The renderer MUST give the two policies different metadata.name values.
Scenario: Policy names do not collide
- WHEN the renderer builds the Ingress-only and Egress-only policies for one sandbox
- THEN the two
metadata.namevalues differ and each name matches the Kubernetes DNS subdomain pattern.
Existing Tool Considered
The alternatives check of 2026-11-22 returned none and named no tool; see the alternatives block in the issue body for the tools considered and the Lacks: list. The change therefore edits SandboxNetworkPolicy and its tests. Estimated cost to build, keep and fix that code: about 6,000 tokens and 2 hours.
Key questions
- How should the renderer expose the two policies?: Keep
SandboxNetworkPolicy.to_k8s_network_policyand change its return value to a tuple of two dictionaries: the Ingress-only policy first and the Egress-only policy second. Update each caller to write both objects. (best practice) [sources: src/devops_cli/sandbox/models.py:489-520]- Chosen: Return a tuple from the existing method. It keeps one code path and forces every caller to handle both policies.
- Rejected: Add a plural method and keep the singular method. It leaves a method that can still emit a dual-type policy.
- Rejected: Return a list of two dictionaries. A tuple fixes the pair size and makes the two directions explicit.
- How should the two policies get distinct Kubernetes names?: Append
-ingressto the original policy name for the Ingress-only policy and-egressfor the Egress-only policy. If the base name would exceed the Kubernetes limit, trim the base and keep the suffix. (best practice) [sources: src/devops_cli/sandbox/models.py:489-520]- Chosen: Suffix the original name with
-ingressand-egress. The names stay readable and stable for the same sandbox. - Rejected: Use a hash of the sandbox name and direction. It hides the sandbox name in kubectl output and gives no benefit here.
- Chosen: Suffix the original name with
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 22, 2026
Both concern the NetworkPolicy controller bypass, but #6708 reports the controller defect while this candidate changes the sandbox code to emit two single-type policies.devops-cli-service commentedon Nov 22, 2026
The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.
Searches (10)
Tools considered:
Searches run:
Sources:
devops-cli-service commentedon Nov 22, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
devops-cli-service commentedon Nov 25, 2026
Released in v0.218.2: https://github.com/dan-petty/devops-cli/releases/tag/v0.218.2
devops-cli-service commentedon Nov 25, 2026
Live since 2026-11-25 08:43 UTC