Skip to content

fix(sandbox): a public whitelist refuses an IPv6 CIDR entry as private #3776

Closed

Description

@dan-petty

Problem Description

A public whitelist entry that is an IPv6 CIDR fails the config. SandboxNetworkConfig(mode="public_whitelist", public_whitelist=["2606:4700::/48"]) raises Public whitelist entry '2606:4700::/48' (host '2606:4700::/48') cannot be private, loopback, or metadata. An IPv4 CIDR, such as 140.82.112.0/20, is accepted.

_validate_public_whitelist_item in src/devops_cli/sandbox/models.py gives the host of the entry to is_loopback_or_private_host. That function reads a CIDR string as a name that is not a public DNS name, and so it returns True. The CIDR branch of _resolve_public_host, which handles 2606:4700::/48 correctly, is not reachable through a validated config.

Reproduction Steps

  1. Run uv run devops sandbox network-policy --network-mode public_whitelist --public-whitelist 2606:4700::/48.
  2. Read the error.

Expected vs Actual Behavior

Expected: the command prints a NetworkPolicy with one ipBlock for 2606:4700::/48 on port 443, as for an IPv4 CIDR.

Actual: the command exits 1 and names the entry as private, loopback or metadata.

Environment Diagnostics

devops-cli 0.66.0, found while moving the sandbox tests to the edge fakes (#1335, #3749). Tests reach the CIDR branch with SandboxNetworkConfig.model_construct, which skips the validators.

Logs, Traces, or Terminal Output

Value error, Public whitelist entry '2606:4700::/48' (host '2606:4700::/48') cannot be private, loopback, or metadata.

Alternatives check of 2026-11-08: covers.
Tool: ipaddress (https://pypi.org/project/ipaddress), Python Software Foundation License, last activity 2019-10-18, not maintained.

Proposed design

Problem statement

A public whitelist entry that is an IPv6 CIDR fails config validation. The validator gives the CIDR string to is_loopback_or_private_host, which reads it as a name that is not public. The fix parses an IP literal first and refuses it only when it is metadata or non-public. A public IPv6 CIDR then gives one ipBlock on port 443, as a public IPv4 CIDR does.

Acceptance criteria

Requirement: Public IPv6 CIDR entry accepted

The public whitelist validator SHALL accept a public IPv6 CIDR entry.

Scenario: Public IPv6 CIDR

  • WHEN a caller builds SandboxNetworkConfig(mode="public_whitelist", public_whitelist=["2606:4700::/48"])
  • THEN the config is valid, and to_k8s_network_policy() gives exactly one egress rule whose to is ipBlock cidr 2606:4700::/48 and whose port is TCP 443, beside the kube-dns rule.

Requirement: Public IPv6 CIDR with host bits accepted

The public whitelist validator SHALL accept a public IPv6 CIDR entry whose host bits are set.

Scenario: Public IPv6 CIDR with host bits

  • WHEN a caller builds SandboxNetworkConfig(mode="public_whitelist", public_whitelist=["2606:4700::1/48"])
  • THEN the config is valid, and the policy's one whitelist egress rule has ipBlock cidr 2606:4700::/48 on TCP port 443.

Requirement: Public IPv6 address accepted

The public whitelist validator SHALL accept a public IPv6 address with no prefix length.

Scenario: Public IPv6 address

  • WHEN a caller builds SandboxNetworkConfig(mode="public_whitelist", public_whitelist=["2606:4700::1111"])
  • THEN the config is valid, and the policy's one whitelist egress rule has ipBlock cidr 2606:4700::1111/128 on TCP port 443.

Requirement: IPv6 CIDR through the command

The sandbox network-policy command MUST print the ipBlock of a public IPv6 CIDR entry and exit 0.

Scenario: Command with an IPv6 CIDR

  • WHEN the user runs uv run devops sandbox network-policy --network-mode public_whitelist --public-whitelist 2606:4700::/48
  • THEN the command exits 0 and its YAML output holds an egress rule with ipBlock cidr 2606:4700::/48 and TCP port 443.

Requirement: Non-public IPv6 entry refused

The public whitelist validator MUST refuse an IPv6 address or CIDR that is loopback, private, link-local or cloud metadata.

Scenario: Private IPv6 CIDR

  • WHEN public_whitelist holds fd00::/8, ::1/128, fe80::/10 or fd00:ec2::254
  • THEN SandboxNetworkConfig raises a pydantic.ValidationError (a ValueError) whose message names the entry and says it cannot be private, loopback, or metadata.

Requirement: IPv4 CIDR unchanged

The public whitelist validator SHALL keep accepting a public IPv4 CIDR entry.

Scenario: Public IPv4 CIDR

  • WHEN a caller builds SandboxNetworkConfig(mode="public_whitelist", public_whitelist=["140.82.112.0/20"])
  • THEN the config is valid, and the policy's one whitelist egress rule has ipBlock cidr 140.82.112.0/20 on TCP port 443.

Requirement: Name check makes no lookup

The public whitelist validator MUST refuse a non-public name without a DNS lookup.

Scenario: Non-public name

  • WHEN public_whitelist holds localhost and the dns fake records every lookup
  • THEN the config raises a pydantic.ValidationError (a ValueError) and the dns fake records no lookup.

Existing Tool Considered

The alternatives check names ipaddress (https://pypi.org/project/ipaddress), Python Software Foundation License, last activity 2019-10-18, not maintained. It parses an IPv4 or IPv6 address or CIDR and reports is_private, is_loopback, is_link_local and is_global, which is the check the validator needs. It lacks cloud-metadata classification (the repository's is_cloud_metadata_host must be called beside it), a config validator (the change to _validate_public_whitelist_item in src/devops_cli/sandbox/models.py is still required), and a DNS lookup (the name path stays on is_loopback_or_private_host and _resolve_public_dns). The maintained form of the same API is the standard library ipaddress module, which src/devops_cli/sandbox/models.py:5 already imports and CONTRIBUTING.md:19 names as the standard parser, so the change adds no dependency. It adds about ten lines to one validator and one helper and builds no replacement for the tool.

Key questions

  • Which check refuses the public IPv6 CIDR entry?: _validate_public_whitelist_item (src/devops_cli/sandbox/models.py:159) takes the host from _parse_whitelist_entry, which for 2606:4700::/48 is the CIDR string, and gives it to is_loopback_or_private_host (src/devops_cli/sandbox/models.py:166). That function normalizes the string as a host, then finds that ipaddress.ip_address cannot parse it (src/devops_cli/core/validation.py:390) and that is_public_dns_name rejects it (src/devops_cli/core/validation.py:395), so it returns true and the validator refuses the entry. _resolve_public_host (src/devops_cli/sandbox/models.py:274) parses the same string as an IPv6 network, but the validator stops the config before that branch runs. [sources: src/devops_cli/sandbox/models.py:159, src/devops_cli/sandbox/models.py:166, src/devops_cli/core/validation.py:390, src/devops_cli/core/validation.py:395, src/devops_cli/sandbox/models.py:274, openspec/changes/archive/2026-11-06-3749-sandbox-tests-on-fakes/proposal.md:59]
  • How does the validator classify an IP address or CIDR entry?: Parse the host with ipaddress.ip_network(host, strict=False) in one private helper that returns the network, or None when the host is a name. A predicate shared with _resolve_public_host refuses that network when is_cloud_metadata_host or is_non_public_ip holds. The validator calls is_loopback_or_private_host only for a name, so it keeps its no-lookup check; the builder calls _resolve_public_dns only for a name. Each caller raises its own message, so the existing 'cannot be private, loopback, or metadata' text stays. (best practice) [sources: src/devops_cli/sandbox/models.py:81, src/devops_cli/sandbox/models.py:159, src/devops_cli/sandbox/models.py:274, src/devops_cli/core/validation.py:350, CONTRIBUTING.md:15, CONTRIBUTING.md:19]
    • Chosen: One shared parse and one shared predicate. The validator and the builder refuse the same IP literals, each keeps its own message, and a later rule change needs one edit.
    • Rejected: Copy the metadata and non-public checks into the validator. Two copies of the same rule can drift apart.
    • Rejected: Call _resolve_public_host from the validator. It makes a DNS lookup for a name, and the validator must make no lookup.
  • Does the public whitelist validator make a DNS lookup for a name?: No. The validator calls is_loopback_or_private_host (src/devops_cli/sandbox/models.py:166) with no resolver: that function calls is_public_dns_name (src/devops_cli/core/validation.py:395), which reads the name only. The policy builder makes the one lookup of the name through _resolve_public_dns (src/devops_cli/sandbox/models.py:261), which calls vet_addresses at the public level and refuses a name with an answer that is not public. [sources: src/devops_cli/sandbox/models.py:166, src/devops_cli/core/validation.py:395, src/devops_cli/sandbox/models.py:261, openspec/changes/archive/2026-10-28-2431-sandbox-vet-addresses/proposal.md:12]
  • Which exception does a caller see when the validator refuses an entry?: A pydantic.ValidationError, which is a ValueError. validate_whitelists is a model_validator(mode="after") (src/devops_cli/sandbox/models.py:410), and pydantic reports a ValueError raised there as a ValidationError whose message is Value error, Public whitelist entry ... cannot be private, loopback, or metadata. The existing test catches it as a ValueError (tests/commands/test_sandbox_network_policy.py:155). The whitelist builders raise SandboxValidationError, also a ValueError, so a caller catches both in the same way. [sources: src/devops_cli/sandbox/models.py:410, src/devops_cli/sandbox/models.py:167, tests/commands/test_sandbox_network_policy.py:155, src/devops_cli/exceptions/sandbox.py:48]
  • Which exception should the validator raise for a refused entry?: Raise SandboxValidationError, which is a ValueError, so pydantic still reports it as a ValidationError and the command catches it as before. CONTRIBUTING.md forbids a bare built-in exception in domain logic, and _validate_local_whitelist_item already raises it (src/devops_cli/sandbox/models.py:192). (best practice) [sources: CONTRIBUTING.md:26, docs/SDLC.md:125, src/devops_cli/sandbox/models.py:192, src/devops_cli/exceptions/sandbox.py:48]
    • Chosen: Raise SandboxValidationError. It follows CONTRIBUTING.md:26 and docs/SDLC.md:125, and it is a ValueError, so pydantic and the command catch it as before.
    • Rejected: Raise a bare ValueError. CONTRIBUTING.md:26 forbids a bare built-in exception in domain logic.
  • Does is_non_public_ip keep 2606:4700::/48 public?: Yes. is_non_public_ip treats a range as non-public when it is not global, when either end is non-public, or when it overlaps a non-public block, and its docstring records that 2606:4700::/48 stays public (src/devops_cli/core/validation.py:366). The CHANGELOG records the same case (feat(telemetry): sandbox egress port scoping, collector lane & in-container trace context #702). [sources: src/devops_cli/core/validation.py:350, src/devops_cli/core/validation.py:366, CHANGELOG.md:2955]
  • Do the existing helpers refuse the non-public IPv6 cases?: Yes. is_cloud_metadata_host refuses a link-local network (src/devops_cli/core/validation.py:271) and the IPv6 metadata addresses in CONST_CLOUD_METADATA_IPV6, which holds fd00:ec2::254 (src/devops_cli/config/constants.py:2973); is_non_public_ip refuses a network that is not global, which covers fd00::/8, ::1/128 and fe80::/10 (src/devops_cli/core/validation.py:369). [sources: src/devops_cli/core/validation.py:271, src/devops_cli/core/validation.py:322, src/devops_cli/core/validation.py:369, src/devops_cli/config/constants.py:2973]
  • The alternatives check found that https://pypi.org/project/ipaddress covers this item. Adopt the tool, or keep the item and give the reason?: Keep the item and do not add the PyPI distribution. The maintained form of the same API is the standard library ipaddress module, which src/devops_cli/sandbox/models.py:5 already imports and CONTRIBUTING.md:19 names as the standard parser for an open domain. The PyPI distribution is the same module published separately, with last activity 2019-10-18 and no maintenance, and the project runs Python 3.14+ (CONTRIBUTING.md:36), so adopting it adds a dependency for no API. The change uses ipaddress.ip_network(host, strict=False) and the existing is_cloud_metadata_host and is_non_public_ip checks, and adds no dependency. (best practice) [sources: CONTRIBUTING.md:19, CONTRIBUTING.md:36, src/devops_cli/sandbox/models.py:5, src/devops_cli/core/validation.py:366, https://pypi.org/project/ipaddress]
    • Chosen: Standard library ipaddress module. It is maintained with CPython, already imported at src/devops_cli/sandbox/models.py:5, and CONTRIBUTING.md:19 names it as the standard parser for an open domain; it adds no dependency.
    • Rejected: PyPI ipaddress distribution. The alternatives check records last activity 2019-10-18 and no maintenance; it is the same module published for Python versions that lack it, so on Python 3.14+ it adds a dependency for no API.
    • Rejected: Home-made IPv6 classifier. CONTRIBUTING.md:19 requires a standard parser for an open domain such as IP addresses, and a home-made check is a finding.

Open questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/sandbox
    status/new
    value/medium
    effort/low
    on Nov 6, 2026
  2. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/sandbox. The (sandbox) scope of the title gives the scope.
    • Priority: P2-Medium. Blocks valid IPv6 CIDR entries in public whitelist mode, but IPv4 works as a workaround.
    • Value: Medium. Restores correct acceptance of public IPv6 CIDR ranges in the sandbox network policy output.
    • Effort: Low. The CIDR branch in _resolve_public_host already handles the case; the validator only needs to route CIDR strings to it instead of is_loopback_or_private_host.
    • Related: feat(cli): ipv6 egress cidr fix and deny-class property tests for sandbox policy #701, which asks for a different change. Both touch IPv6 CIDR handling in sandbox/models.py validators, but #701 adds broader IPv6 support and deny-class tests while the candidate fixes one specific misclassification in the validator.
  3. added
    priority/p2-medium
    on Nov 6, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 7, 2026
  5. devops-cli-service commented on Nov 7, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 72744a9 (see proposed design in issue body).

  6. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Alternatives check: covers

    Reason: The issue's own "Existing Tool Considered" section already names the standard library ipaddress module as the tool that covers the need: it parses an IPv6 CIDR or address and reports is_private, is_loopback and is_link_local, and the repository already uses it in _resolve_public_host, is_non_public_ip and is_cloud_metadata_host. The searches confirmed the ipaddress package exists as a published distribution of the same module, so no new library is needed and the fix is wiring the validator to the existing parse rather than adopting a new tool.

    Tool: ipaddress (https://pypi.org/project/ipaddress)

    • License: Python Software Foundation License
    • Last activity: 2019-10-18
    • Maintained: no

    Covers:

    • Parses an IPv6 CIDR such as 2606:4700::/48 and an IPv6 address such as 2606:4700::1111, with strict=False accepting a network with host bits
    • Reports is_private, is_loopback and is_link_local on an IPv4 or IPv6 network or address, which is the check the validator needs
    • Normalises a bare IPv6 address to a /128 network, which is the ipBlock cidr the acceptance criteria expect
    • Is already used in the repository's sandbox helpers, so the validator can share one IP-literal parse with _resolve_public_host

    Lacks:

    • Does not classify cloud metadata addresses itself; the repository's is_cloud_metadata_host helper must still be called alongside it
    • Is a parsing and classification library, not a config validator, so the change to _validate_public_whitelist_item in sandbox/models.py is still required
    • Makes no DNS lookup, so the name path must stay on is_loopback_or_private_host and _resolve_public_dns

    Tools considered:

    Searches run:

    • Python library validate IPv6 CIDR not private loopback link-local, results: 5
    • Python ipaddress module IPv6 network is_private is_loopback documentation, results: 5
    • docs.python.org 3 library ipaddress ip_network is_private, results: 5
    • ipaddress standard library ipv6 cidr parsing strict=False site:docs.python.org, results: 5
    • Python ipaddress documentation, results: 5
    • ipaddress.ip_network strict=False ipv6 network object python 3, results: 5
    • "ipaddress" backport of the Python 3.3 ipaddress module pypi, results: 5

    Sources:

    Checked on 2026-11-08. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    status/new
    and removed
    status/ready
    on Nov 8, 2026
  8. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

    Status set back to New at 54e5d46. Refine cannot set this item to Ready at 54e5d46 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

  9. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 14, 2026
  10. removed
    status/in-review
    on Nov 14, 2026
  11. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-14 15:02 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