Skip to content

fix(sandbox): give each sandbox NetworkPolicy one type #6726

Done

Description

@dan-petty

Problem

Checked on 2026-11-22 (main 6e497c2), in the vetting of PR #6721.

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 test on 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 podSelector and ingress rule, the Egress policy has the original podSelector and 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.name values 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_policy and 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 -ingress to the original policy name for the Ingress-only policy and -egress for 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 -ingress and -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.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. dan-petty commented on Nov 22, 2026

    @dan-petty
    OwnerAuthor
  2. added
    type/bug
    source/agent
    status/new
    value/medium
    effort/low
    scope/sandbox
    priority/p2-medium
    on Nov 22, 2026
  3. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    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:

    • python library generate Kubernetes NetworkPolicy ingress egress rules, results: 5
    • tool split Kubernetes NetworkPolicy with both Ingress and Egress into two policies, results: 5
    • netpol-analyzer np-guard network policy analysis tool, results: 5
    • Kyverno policy validate NetworkPolicy policyTypes single Ingress or Egress, results: 5
    • kubernetes network policy generator, results: 5
    • netpol-analyzer github, results: 5
    • Kyverno, results: 5
    • kube-linter networkpolicy checks, results: 5
    • np-guard netpol-analyzer, results: 5
    • NetworkPolicy ingress egress policyTypes validation, results: 5

    Sources:

  4. added
    status/ready
    and removed
    status/new
    on Nov 22, 2026
  5. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  6. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 25, 2026
  7. removed
    status/in-review
    on Nov 25, 2026
  8. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-25 08:43 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/sandboxsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions