Repository navigation
Description
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
- Run
uv run devops sandbox network-policy --network-mode public_whitelist --public-whitelist 2606:4700::/48. - 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 whosetoisipBlockcidr2606:4700::/48and 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
ipBlockcidr2606:4700::/48on 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
ipBlockcidr2606:4700::1111/128on 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
ipBlockcidr2606:4700::/48and 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_whitelistholdsfd00::/8,::1/128,fe80::/10orfd00:ec2::254 - THEN
SandboxNetworkConfigraises apydantic.ValidationError(aValueError) 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
ipBlockcidr140.82.112.0/20on 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_whitelistholdslocalhostand thednsfake records every lookup - THEN the config raises a
pydantic.ValidationError(aValueError) and thednsfake 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 for2606:4700::/48is the CIDR string, and gives it tois_loopback_or_private_host(src/devops_cli/sandbox/models.py:166). That function normalizes the string as a host, then finds thatipaddress.ip_addresscannot parse it (src/devops_cli/core/validation.py:390) and thatis_public_dns_namerejects 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, orNonewhen the host is a name. A predicate shared with_resolve_public_hostrefuses that network whenis_cloud_metadata_hostoris_non_public_ipholds. The validator callsis_loopback_or_private_hostonly for a name, so it keeps its no-lookup check; the builder calls_resolve_public_dnsonly 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_hostfrom 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 callsis_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 callsvet_addressesat 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 aValueError.validate_whitelistsis amodel_validator(mode="after")(src/devops_cli/sandbox/models.py:410), and pydantic reports aValueErrorraised there as aValidationErrorwhose message isValue error, Public whitelist entry ... cannot be private, loopback, or metadata.The existing test catches it as aValueError(tests/commands/test_sandbox_network_policy.py:155). The whitelist builders raiseSandboxValidationError, also aValueError, 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 aValueError, so pydantic still reports it as aValidationErrorand the command catches it as before.CONTRIBUTING.mdforbids a bare built-in exception in domain logic, and_validate_local_whitelist_itemalready 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 followsCONTRIBUTING.md:26anddocs/SDLC.md:125, and it is aValueError, so pydantic and the command catch it as before. - Rejected: Raise a bare
ValueError.CONTRIBUTING.md:26forbids a bare built-in exception in domain logic.
- Chosen: Raise
- Does
is_non_public_ipkeep2606:4700::/48public?: Yes.is_non_public_iptreats 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 that2606:4700::/48stays 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_hostrefuses a link-local network (src/devops_cli/core/validation.py:271) and the IPv6 metadata addresses inCONST_CLOUD_METADATA_IPV6, which holdsfd00:ec2::254(src/devops_cli/config/constants.py:2973);is_non_public_iprefuses a network that is not global, which coversfd00::/8,::1/128andfe80::/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
ipaddressmodule, whichsrc/devops_cli/sandbox/models.py:5already imports andCONTRIBUTING.md:19names 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 usesipaddress.ip_network(host, strict=False)and the existingis_cloud_metadata_hostandis_non_public_ipchecks, 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
ipaddressmodule. It is maintained with CPython, already imported atsrc/devops_cli/sandbox/models.py:5, andCONTRIBUTING.md:19names it as the standard parser for an open domain; it adds no dependency. - Rejected: PyPI
ipaddressdistribution. 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:19requires a standard parser for an open domain such as IP addresses, and a home-made check is a finding.
- Chosen: Standard library
Open questions
- The alternatives check found that https://pypi.org/project/ipaddress covers this item. Adopt the tool, or keep the item and give the reason. (a person decides)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 6, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
fixprefix of the title gives the type.(sandbox)scope of the title gives the scope.Blocks valid IPv6 CIDR entries in public whitelist mode, but IPv4 works as a workaround.Restores correct acceptance of public IPv6 CIDR ranges in the sandbox network policy output.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.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.devops-cli-service commentedon Nov 7, 2026
Status set to Ready at 72744a9 (see proposed design in issue body).
devops-cli-service commentedon Nov 8, 2026
Alternatives check: covers
Reason: The issue's own "Existing Tool Considered" section already names the standard library
ipaddressmodule 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_ipandis_cloud_metadata_host. The searches confirmed theipaddresspackage 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)
Covers:
Lacks:
Tools considered:
Searches run:
Sources:
Checked on 2026-11-08. A person decides what this means for the item. The check changes no label and closes no issue.
devops-cli-service commentedon Nov 8, 2026
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.
devops-cli-service commentedon Nov 14, 2026
Released in v0.138.0: https://github.com/dan-petty/devops-cli/releases/tag/v0.138.0
devops-cli-service commentedon Nov 14, 2026
Live since 2026-11-14 15:02 UTC