Skip to content

feat(policy)!: split the pinned address into ip4 and ip6 - #227

Merged
abhisheksp merged 9 commits into
mainfrom
feature/policy/address-nat64-and-translated-spellings
Nov 2, 2026
Merged

abhisheksp merged 9 commits into
mainfrom
feature/policy/address-nat64-and-translated-spellings

Conversation

@abhisheksp

@abhisheksp abhisheksp commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Description

An operator can now write this, and could not before:

@id("no_nat64_translator")
forbid (principal, action == Box::Action::"net:connect", resource)
when { context.input has ip6 && context.input.ip6 like "64:ff9b::*" };

"Never route through this translator." It refuses 64:ff9b::5db8:d822 and leaves
93.184.216.34 alone — the same address, reached directly. On main the rule is unwritable at
any length, because the single address field folds a wrapped address down to the IPv4 address it
carries and throws the wire form away.

net:connect now carries two fields in place of that one:

Holds Absent when
ip4 the IPv4 address, as a dotted quad the destination is an IPv6 address whose wrapping Box does not read
ip6 the IPv6 address, compressed and lowercase the destination is IPv4

A wrapped destination carries both, so one rule can name the endpoint and another the route:
64:ff9b::5db8:d822 gives ip4 = "93.184.216.34" and ip6 = "64:ff9b::5db8:d822". Box reads the
IPv4-mapped, IPv4-compatible, IPv4-translated, 6to4, Teredo, and well-known NAT64 wrappings. It
extracts an IPv4 address and never synthesises an IPv6 one, because one IPv4 address has many IPv6
encodings and there is no single form to report.

There is no ip. A rule that reads it is refused at load, naming both replacements. That refusal is
Box's own check, not Cedar's: has ip is statically false, so strict validation short-circuits and
never typechecks what is behind the guard. Without the check, such a rule loads and enforces
nothing.

The cost

A dual-stack rule needs a guard per family. The metadata forbid goes from five lines to six and
gains a level of parentheses. It reads worse. What it buys is a rule that states which addresses it
matches.

ip4 is absent on a NAT64 prefix Box cannot recognise. RFC 6052 lets a network choose its own
prefix and Box takes none as configuration, so on such a network an ip4 rule does not fire, and
the destination must be pinned with ip6 or host. Absence is now the failure mode, in place of a
literal that loaded and sat inert. The split does not fix this.

A box whose history predates this change cannot read its own old events. Events already written
carry ip, a predicate on ip4 or ip6 does not match them, and one naming ip no longer loads.
There is no rewind, so a counting rule that spans the change starts its count again.

One IPv6 pattern raised in review still loads. ip6 like "::ffff:a9fe:*" misses the addresses
it looks aimed at, because a mapped address is spelled with a dotted quad — but
::ffff:a9fe:a9fe:0 is a real address it does match, so refusing it would be wrong. Documented
instead. The sibling case is refused now: the mapped form is exactly ::ffff: and a dotted quad,
so a pattern holding a quad anywhere else can match no wire form. That is the shape an operator
reaches for, because RFC 6052 writes a NAT64 address as 64:ff9b::169.254.169.254 and RFC 6145
writes a translated one as ::ffff:0: and a quad.

The guidance ships with the refusal

Four prose places still told a reader to write ip, so an agent that followed one wrote a policy
that fails to load. All four now name ip4 and ip6: the three crate AGENTS.md files, and the
policy-authoring skill. The decisions.md entry for the metadata floor named context.input.ip as
its mechanism, which was false after this change, so that sentence is rewritten in place under the
same anchor — the entry's answer did not move, only the attribute it names.

One thing is left: an operator's existing policy generate-schema output is stale. The runtime
never reads it, so nothing breaks; it misleads authoring.

Related Issues

None.

Type of Change

Breaking change

Testing

  • I ran the relevant suites (just check, or cargo test --workspace --all-features)
  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings

Linux x86_64: policy suite 485 passed with --all-features, 7 ignored,
no skipping line. Zero clippy warnings in crates/policy. fmt --check and
RUSTDOCFLAGS="-D warnings" cargo doc clean.

Test What it pins
a_translator_prefix_rule_forbids_the_wire_form_and_leaves_the_address_it_carries The rule at the top of this description, plus the addresses it must leave alone. A second test pins the same through the gateway.
a_rule_naming_the_removed_ip_attribute_refuses_validate_and_open A rule reading ip is refused by both entry points, and the refusal names both replacements. Six rule shapes are covered, including isInRange and set membership.
a_clause_per_address_family_loads The rule the refusal asks for loads, so the advice is actionable.
one_ipv4_literal_forbids_every_encoding_that_carries_it One ip4 literal still denies five encodings, so the split costs no coverage.
every_ipv6_encoding_of_an_ipv4_address_populates_both_attributes The dotted quad and the exact wire form, for nine encodings.
a_plain_ipv4_outcome_records_the_ipv4_attribute_and_no_ipv6_form Its probe names the IPv4-mapped spelling, so it fails if anything starts synthesising an IPv6 form.
a_connect_that_opened_records_both_address_attributes and its error-leg pair Both outcome legs carry both fields on the same terms as the request leg.
a_tool_rule_that_names_ip_is_a_tool_argument_and_loads The family gate, so a tool's own ip argument is untouched.
an_address_pattern_whose_literal_holds_a_character_no_address_holds_is_refused A case slip, a cross-family wildcard, and four spellings of a dotted quad that no wire form writes.
an_ipv6_pattern_that_can_reach_a_dotted_quad_loads The other direction of that rule, so it cannot start over-refusing a mapped pattern.
every_shipped_example_policy_loads Each rewritten example still loads.

Each mutation was applied, observed, then reverted.

Mutation Result
Restore the old fold, so ip6 discards the wire form Both translator-prefix tests fail
Short-circuit the removed-attribute check Its load test fails on the Ok arm — the rule loads, which is the evidence the check is load-bearing
Synthesise ::ffff:<v4> for an IPv4 destination The outcome test and two unit tests fail
Make ip4 stop extracting the carried address one_ipv4_literal_forbids_every_encoding_that_carries_it fails
Drop the address fields from the outcome arm All four connect_address_history tests fail
Return Sound for every wildcard pattern, or drop the family filter The two literal-spelling tests fail
Drop the dotted-quad rule, make it unconditional, then weaken it to a prefix test The refusal rows fail, then the loads test fails, then the longer-prefix rows fail

Not run. test-integ and test-workload/verdict did not execute: Linux containment supports
ARM64 only and this host is x86_64, so the harness refuses before any case starts. Both are
excluded from the workspace. I edited the policy text in po_14, po_17, and the jailbreak
policy, and loaded each through PolicyEngine::validate, so the load is proved and the runtime
refusal is not. CI must cover those and macOS, which was not compiled; the crate holds no
cfg(target_os) path. No test was deleted and none was marked #[ignore].

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

## Problem

Policy gets one spelling of a pinned destination address, so an IPv6 encoding of an IPv4
address reads as the IPv4 literal an operator writes. The fold covered the IPv4-mapped,
IPv4-compatible, 6to4, and Teredo encodings only. It missed the NAT64 well-known prefix
`64:ff9b::/96` and the IPv4-translated prefix `::ffff:0:0:0/96`.

An address in one of those two prefixes reached no fold arm, so `context.input.ip` carried
an IPv6 string. A `forbid` on `context.input.ip like "169.254.*"` did not match it. The
gateway then permitted the destination and opened the connection. The design guide says that
an IPv6 spelling of an IPv4 address becomes that IPv4 address, so the code did less than the
guide states.

The cost falls on the instance metadata address. Policy is the only check on a metadata
endpoint, and the gateway holds no built-in block, so an authored `forbid` is the only
control. A translator on the path is also necessary to reach a metadata service. This bounds
the reach, but it does not close the gap in authorization.

## Solution

`embedded_v4` gets one arm for each prefix. Both encodings hold the IPv4 address in the last
32 bits, so each arm matches the first six segments and uses the extraction that was already
there. The six arms are disjoint, so their order has no effect.

Two forms stay outside the fold, because no fixed prefix finds them. A network-specific
prefix is not well known, so no arm can know it. The local-use NAT64 prefix `64:ff9b:1::/48`
is reserved, but it holds the address in a different layout, and that layout permits four
more prefix lengths. An address under that prefix, such as `64:ff9b:1:a9fe:a9:fe00::`, is
still an IPv6 string to a rule. This is residual risk, and this commit does not change it.

Two more costs are now larger, and neither is new. The load does not hold an `ip` literal to
its canonical spelling, as it holds a host literal, so a rule that names an IPv6 encoding of
an IPv4 address is inert, with no refusal and no warning. And the fold feeds the live
decision and both history legs, so older events keep the IPv6 spelling. A temporal rule on
`ip` that spans this change counts two keys for one destination. History has no rewind.

No interface moves. `address` is a private module, and the action vocabulary, the attributes
a rule reads, and what `when temporal` observes are unchanged.

## Tests

`cargo test -p strands-box-policy --all-features`: 31 suites, 464 passed, 0 failed, 7
ignored. With default features: 298 passed, 0 failed, 5 ignored. `cargo clippy -p
strands-box-policy --all-targets`, with and without `--all-features`: no warning in
`crates/policy`. `cargo fmt --all --check` and `RUSTDOCFLAGS="-D warnings" cargo doc`: clean.

`address.rs::every_ipv6_encoding_of_an_ipv4_address_is_that_address` gets four entries: the
dotted and the hex spelling of each new prefix. Each new arm was removed in turn, and the
test failed on that arm's entry.

`address.rs::ipv6_is_compressed_and_lowercase` gets five addresses that keep the IPv6 form,
although their last 32 bits spell an IPv4 address. They hold each new arm to its `/96`. The
NAT64 arm was widened to `/32` and the translated arm to `/80`, and the test failed each
time.

`adapters/egress.rs::an_address_forbid_refuses_only_its_addresses` gets the two spellings.
This shows that an authored `forbid` on `context.input.ip` refuses them through the
interceptor. With both arms removed, the test failed on the NAT64 spelling.

`test-integ/tests/policy/po_14.rs` gets `LIT_NAT64` and `LIT_V4_TRANSLATED`, which keeps its
one literal for each fold arm, and its comment names the two encodings.

Not run: `po_14` did not execute. Linux containment supports ARM64 only, and this host is
x86_64, so the trampoline refuses before any case starts. Continuous integration must prove
that case. `test-integ` type-checks and formats clean, and its two clippy warnings are also
present without this change.
Comment thread crates/policy/src/address.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

The fold is correct for every address that reaches it. The new arms are held to their /96, and the forbid now refuses both spellings, through the interceptor and in po_14. The open issue is on the load side: an ip forbid an operator wrote against the IPv6 spelling becomes silently inert (see the inline comment, reproduced against main).

Assumptions and rules checked that held
  • Each arm folds only its /96. The five near addresses stay IPv6, and 64:ff9b:1::/48 is left out on purpose.
  • The arm order does not overlap the mapped and compatible arms ([0,0,0,0,0,0xffff] vs [0,0,0,0,0xffff,0]). :: and ::1 stay IPv6.
  • An unspecified suffix (64:ff9b::, ::ffff:0:0:0) folds to 0.0.0.0. At worst that refuses too much. It never permits too much.
  • The fold feeds dogwood.rs (request and outcome) and schema.rs through one address::canonical, so the fact has one owner.
  • docs/design/egress.md states the guarantee in general terms. No page lists the encodings, so no doc is stale.
  • No public API, action vocabulary, or record shape changes, so approval under crates/policy/AGENTS.md is not needed.
  • po_14 sends each literal raw through the native probe, so the refusal check matches the spelling that was sent.

Out of scope, for a possible follow-up: the vendored crates/shell/src/vfs_kernel.rs::is_ip_blocked floor lacks the same two prefixes. It also lacks 6to4 and Teredo for blocked IPv4.

The mutation table in the description is a strong piece of evidence for the arm bounds.

@github-actions

Copy link
Copy Markdown

Correction to my summary: the vendored is_ip_blocked does handle 6to4 and Teredo. It is missing only the NAT64 (64:ff9b::/96) and IPv4-translated (::ffff:0:0:0/96) prefixes. The rest of the summary stands.

## Problem

A decision reads one spelling of a pinned destination address. An IPv6 form that carries an
IPv4 address reads as that IPv4 address, and any other IPv6 address reads compressed and in
lowercase. The load held a host literal to its spelling, and it held an `ip` literal to none.
A rule that named any other spelling loaded, raised no finding, and matched nothing. A
`forbid` that matches nothing is a fail-open that passes review.

The commit before this one made the cost worse. It added the NAT64 well-known prefix and the
IPv4-translated prefix to the fold. On an IPv6-only host with DNS64, each IPv4 destination
arrives on `64:ff9b::/96`, so an operator reads `ip` in that form from the decision log and
writes a `forbid` against it. That `forbid` refused the connection before the fold held those
two prefixes. After it, the policy loads, `ip` carries the dotted quad, and the gateway opens
the connection. There is no refusal and no warning. The decision guide states that the load
refuses a rule that cannot fire, so the code did less than the page states, for this rule and
also for the four older encodings.

## Solution

`spelling::judge_address` holds an `ip` literal to `address::canonical`, which is the one
function that writes `context.input.ip`. The judge and the decision share one rule, as
`judge_host_literal` shares the gateway's own `normalize_host`. `Scope::checks` admits `ip`
beside `host` under the network family, and `input_attribute` admits the name, which is why no
`ip` literal was judged before.

The judge gives `Finding::Inert` in two cases. A literal that parses as an address and is not
its canonical form is refused, and the refusal names the form to write. A literal that parses
as no address is refused too: each string that `address::canonical` returns parses as an
address and is its own canonical form, so no pinned address equals such a literal. Its advice
names a port, a bracket, or `context.input.host`.

A `like` pattern is judged only when it holds no wildcard, where the pattern and `==` make the
same comparison. A pattern that holds a wildcard is not judged. `64:ff9b::5db8:*` matches the
form that `64:ff9b:0:0:0:5db8:1:2` reads as, and no arm folds that address, so no proof of
inertness is possible. A warning for a pattern whose first literal starts on a folded prefix
was rejected, because the finding would be a guess, and because a new `PolicyWarning` variant
is an interface change. A `when temporal` clause is not judged either, because history keeps
the spelling that each event was recorded with.

No type moves. `PolicyError::Spelling` keeps its variant and its message. The new startup
refusal is observable: a box that holds a working `ip` rule in an IPv6 form now refuses to
start, and the operator must write the form the refusal names. This is a breaking change for
that operator. It is still correct, because that rule stops protecting them as soon as the
fold holds its prefix, and a refusal that names the canonical form is better than silence.

`docs/user/policy.md` holds the refusal and the migration guidance, and it names the two
NAT64 forms that stay unfolded, for which an IPv6-form rule is the only rule that works.
`docs/design/policy.md` adds the class to the list of rule classes the load refuses.
`docs/design/egress.md` states the load check beside the fold, as its host paragraph already
does.

## Tests

`cargo test -p strands-box-policy --all-features`: 31 suites, 471 passed, 0 failed, 7 ignored,
and no `skipping` line. With default features: 31 suites, 305 passed, 0 failed, 5 ignored.
`cargo build`, `cargo clippy --all-targets` with and without `--all-features`, `cargo fmt --all
--check`, and `RUSTDOCFLAGS="-D warnings" cargo doc`: clean, and zero clippy warnings in
`crates/policy`.

`path_spelling.rs::an_ipv6_encoding_of_an_address_literal_is_refused_and_the_dotted_quad_forbids_the_connect`
is the end-to-end claim. It refuses the reviewer's rule at load, with the dotted quad in the
message, and it shows that the dotted-quad rule denies five encodings of that address through
`decide` and leaves another address to the permit.

`spelling.rs::an_address_literal_is_refused_with_the_spelling_a_decision_reads` holds each of
the six encodings and both IPv6 cases to their canonical form.
`a_canonical_address_literal_is_sound` holds ten spellings that a decision reads, which
includes the three unfolded addresses, so the judge refuses nothing an operator needs.
`an_address_literal_that_no_pinned_address_can_equal_is_refused` holds the port, the bracket,
and the generic advice, and it holds a bare IPv6 with one group too many to the generic advice
rather than to a port it does not carry. `an_address_pattern_is_judged_only_when_it_holds_no_wildcard`
holds three wildcard patterns to no finding and one wildcard-free pattern to a refusal.
`a_reversed_operand_and_a_set_membership_judge_the_address` and
`an_address_literal_under_no_action_is_refused_for_its_scope_and_not_its_spelling` hold the
other comparison shapes and the scope gate.
`shipped_examples.rs::every_shipped_example_policy_loads` holds each committed example policy.

Each mutation below was applied, observed, then reverted.

| Mutation | Result |
|---|---|
| Drop `ip` from `input_attribute` | The six literal and pattern tests fail |
| Drop `ip` from `Scope::checks` | The same tests fail |
| Delete the literal arm in `judge_literal` | Those tests and the end-to-end test fail |
| Make the parse failure `Finding::Sound` | The advice test fails |
| Drop the `canonical != literal` guard | The sound-literal test fails |
| Replace the pattern arm with `Finding::Sound` | The pattern test fails |
| Judge each pattern's first literal | The pattern test fails, and `every_shipped_example_policy_loads` fails on `like "169.254.*"` |
| Accept a bare IPv6 as an address with a port | The advice test fails on `2001:db8::1:2:3:4:5:6` |
| Delete the NAT64 fold arm | The end-to-end test fails, because the load accepts the IPv6 rule |

The last two rows are the ones that matter. The seventh shows that the wildcard restriction
carries weight, because a wider arm refuses a pattern that each shipped example holds.

**Not run.** `test-integ` did not run, and the workspace suite did not link: this host has 7 GB
free and the link exhausted the disk. `po_14` also cannot run here, because Linux containment
supports ARM64 only and this host is x86_64. Continuous integration must prove those cases. No
test was deleted and none was marked `#[ignore]`.
Comment thread docs/user/policy.md Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at d0cab7c)

The blocking finding from my last review is fixed. An ip literal is now held at load to the same address::canonical that writes context.input.ip, so the judge and the decision share one owner, as host does with normalize_host. The only open item is the non-blocking doc sentence in my inline comment.

Assumptions and rules checked that held
  • A non-canonical == literal, a set-membership entry, a reversed operand, or a wildcard-free like under net:*/http:* is refused with the canonical form. All four older encodings are covered too.
  • Every canonical spelling loads: IPv4, 0.0.0.0, ::, ::1, and the near-prefix addresses outside the /96. So the judge refuses nothing a decision can read.
  • An ip literal under a tool action stays Sound, and a rule with no action is refused for its scope only.
  • A wildcard pattern can't be proven inert, so it loads. Warning on it would add a PolicyWarning variant to the frozen façade, so leaving it is correct under crates/policy/AGENTS.md.
  • A when temporal clause uses input.ip: syntax, which the Cedar walk doesn't see. That matches how host is handled and is documented.
  • A policy that loaded yesterday and now refuses is the cost decisions.md accepts, and docs/user/policy.md tells the operator what to rewrite.
  • I ran the spelling unit tests (34 passed) and tests/path_spelling.rs (16 passed).

@github-actions

Copy link
Copy Markdown

Assessment: Approve (re-review at 51f6dcd)

Since d0cab7c, only docs/user/policy.md changed (+39 → +42). All code and test files have the same diff stats as before. The rewritten paragraph is now accurate, and it matches the interceptor probe from my last review. A forbid ... ip like "64:ff9b::*" lets [64:ff9b::a9fe:a9fe]:80 through because that address is on the /96, and refuses [64:ff9b::1:a9fe:a9fe]:80, which is outside it. The advice to "read such a pattern in both directions" also gives the right instruction for a permit with that pattern. No open findings remain. Every assumption listed in my previous summary still holds.

Comment thread docs/user/policy.md Resolved
## Problem

`context.input.ip` holds two different things. For an IPv4 destination it holds a dotted quad.
For an IPv6 destination it holds an IPv6 address, unless that address carries an IPv4 address in
a wrapping Box recognises, in which case a fold replaces it with the carried dotted quad. Three
costs follow.

An operator cannot tell from their own rule which addresses it will match, because the answer
depends on how the destination arrives.

A change to the fold silently changes what an existing rule matches. The two arms earlier on this
branch do exactly that: a rule written against the previous output of the fold stops covering the
prefix it was written for, with no refusal and no warning.

The fold is lossy. It discards the IPv6 wire form of a wrapped address, so no rule can name the
route a connection takes. `ip6 like "64:ff9b::*"` - never route through this translator - is
unwritable.

## Solution

`net:connect` carries `ip4` and `ip6`, and no `ip`. Each is optional and each needs its own `has`
guard.

`ip4` holds the IPv4 address, as a dotted quad. It is present for an IPv4 destination and for
an IPv6 destination that carries an IPv4 address: the extraction is deterministic given the
prefix, so one `ip4` literal covers the dotted quad and every encoding that carries it.
`ip6` holds the IPv6 address, compressed and in lowercase, as `Ipv6Addr::to_string` writes it. It
is present for every IPv6 destination. A wrapped destination carries both, so a rule can name the
endpoint and a rule can name the route.

A plain IPv4 destination carries no `ip6`, and Box never computes one, because one IPv4 address
has many IPv6 encodings and none of them is the address that was dialled. Where Box does not
recognise the wrapping - a network's own NAT64 prefix, or `64:ff9b:1::/48` - `ip4` is absent and
an `ip4` rule does not fire.

`address::embedded_v4` keeps every arm, including the two earlier on this branch, and stops
replacing a spelling. `address::attributes` is the one producer of both fields, and the Cedar
request mapping, the Dogwood request leg, and the Dogwood outcome leg each call it, so the
`::request`, `::response`, and `::error` legs cannot carry different sets.

The load refuses a network rule that reads `context.input.ip`, and the refusal names both
replacements. The refusal is not cosmetic: `context.input has ip` is statically false, so strict
validation never typechecks the comparison behind that guard and the rule would load and enforce
nothing. The check is gated on the network action family, so a tool's own `ip` argument still
loads.

Each literal is held to its own field's spelling: a literal of the other family is refused with
the field that holds it, and a non-canonical literal with the spelling a decision reads. A
wildcard pattern is not held to a whole address, because the addresses it admits cannot be
listed, but each piece between the wildcards is held to the characters its field holds, so an
uppercase pattern and a pattern of the other family are both refused. `like` is case-sensitive
and `ip6` is always lowercase, so that case is a silent fail-open otherwise.

Both earlier commits on this branch are repurposed rather than kept beside this change. Their
load check refused a non-canonical `ip` literal; `ip` now does not exist, so a stricter refusal
supersedes it. Shipping them separately would give an operator two different refusals for `ip`
in sequence, and would ship canonicalization for a field about to be deleted.

Rejected: `ip4` alone, which leaves a prefix rule unwritable and is the lossy behaviour this
replaces; and `ip6` alone, under which a rule on the IPv4 address misses every wrapped form,
which is the defect the fold was added to close.

The four example policies, `docs/user/security.md`, and the jailbreak policy each held IPv4
metadata, IPv6 metadata, and IPv6 link-local in one `ip` clause. Each is now a clause per family.
A dual-stack rule needs one `has` guard per family, so it is more verbose than one `ip` clause
was. That is the cost of the split.

`Request::Connect` keeps its `ip: Option<IpAddr>` field: it is what a policy enforcement point
supplies, not what a rule reads, and the split is in the projection.

## Tests

`cargo test -p strands-box-policy --all-features`: 31 suites, 484 passed, 0 failed, 7 ignored,
no `skipping:` line. Default features: 31 suites, 317 passed, 0 failed. `cargo clippy
-p strands-box-policy --all-targets`, with and without `--all-features`: 0 warnings in
`crates/policy`. `cargo fmt --all --check` clean. `RUSTDOCFLAGS="-D warnings" cargo doc` clean.
`cargo build --workspace --all-features --all-targets` succeeds.

`address.rs::every_ipv6_encoding_of_an_ipv4_address_populates_both_attributes` pins the dotted
quad and the exact wire form for nine encodings.
`a_plain_ipv4_destination_carries_no_ipv6_form` and `an_unrecognized_encoding_carries_no_ipv4_address`
pin each absence, and `only_the_attributes_an_address_carries_are_populated` pins the one producer.

`load_time_rule_checks.rs::a_rule_naming_the_removed_ip_attribute_refuses_validate_and_open` pins
the refusal through both `validate` and `open`, and `a_clause_per_address_family_loads` pins that
the rule the refusal asks for loads.
`spelling.rs::a_network_rule_that_names_the_removed_address_attribute_is_refused` pins six shapes
that name `ip`, and `a_tool_rule_that_names_ip_is_a_tool_argument_and_loads` pins the gate.

`spelling.rs::an_address_literal_of_the_other_family_is_refused_with_the_attribute_that_holds_it`,
`an_address_literal_is_refused_with_the_spelling_a_decision_reads`,
`a_canonical_address_literal_is_sound`, `an_address_literal_that_no_pinned_address_can_equal_is_refused`,
and `an_address_pattern_whose_literal_holds_a_character_no_address_holds_is_refused` pin the
literal and pattern judgements.

`connect_address_history.rs` probes both legs on both fields:
`a_connect_that_opened_records_both_address_attributes`,
`a_connect_that_did_not_open_records_both_address_attributes_on_its_error_leg`,
`the_request_and_the_outcome_record_one_set_of_attributes`, and
`a_plain_ipv4_outcome_records_the_ipv4_attribute_and_no_ipv6_form`, whose probe names the
IPv4-mapped spelling, so it fails if anything ever synthesises an IPv6 form.
`policy_egress_e2e.rs::the_pinned_address_reaches_history_as_the_connect_outcomes_ip4` pins the
same through the gateway.

`path_spelling.rs::a_translator_prefix_rule_forbids_the_wire_form_and_leaves_the_address_it_carries`
and `adapters::egress.rs::a_translator_prefix_forbid_refuses_the_wire_form_and_not_the_address_it_carries`
pin the rule the split makes writable. `one_ipv4_literal_forbids_every_encoding_that_carries_it`
pins that one `ip4` literal still denies five encodings.
`shipped_examples.rs::every_shipped_example_policy_loads` pins that each rewritten example loads.

Each mutation below was applied, observed, then reverted. Dropping `address_fields` from the
outcome arm failed all four `connect_address_history` tests. Restoring the old fold, so `ip6`
discards the wire form, failed both translator-prefix tests. Making `ip4` stop extracting the
carried address failed `one_ipv4_literal_forbids_every_encoding_that_carries_it`. Synthesising
`::ffff:<v4>` for an IPv4 destination failed
`a_plain_ipv4_outcome_records_the_ipv4_attribute_and_no_ipv6_form` and two unit tests.
Short-circuiting the removed-attribute check failed its load test on the `Ok` arm, which is the
evidence that the rule otherwise loads. Returning `Sound` for every wildcard pattern failed the
pattern-character test.

**Not run.** `test-integ` did not execute: Linux containment supports ARM64 only and this host is
x86_64, so the harness refuses before any case starts. `test-workload/verdict` did not execute.
Both are excluded from the workspace. Their policy text was edited, and each rewritten policy was
loaded through `PolicyEngine::validate` and type-checked, so the load is proved and the runtime
refusal is not. macOS was not compiled; the crate holds no `cfg(target_os)` path, so continuous
integration is the only proof. No test was deleted and none was marked `#[ignore]`.

**Still wrong, and not fixed here.** `docs/design/decisions.md` names `context.input.ip` as the
mechanism of the metadata forbid, and four crate `AGENTS.md` files name `ip` as the field to
forbid on. A code change writes no decision entry, and this change was told not to edit an
`AGENTS.md`, so both are reported rather than corrected.
@abhisheksp abhisheksp changed the title fix(policy): fold the NAT64 and translated spellings of an address feat(policy)!: split the pinned address into ip4 and ip6 Oct 30, 2026
@github-actions

Copy link
Copy Markdown

Important (non-blocking): The coding-agent guidance still tells agents to write the rule this change now refuses.
Example: crates/policy/AGENTS.md:115 says "refuse an address with a forbid on the string ip". crates/egress-gateway/AGENTS.md:43 and crates/box/AGENTS.md:296 name context.input.ip as the metadata forbid. An agent that follows any of them writes a policy that fails with the new reads context.input.ip, which no action carries error. The root AGENTS.md table says a crate AGENTS.md changes when "a frozen surface, a premise, or a gate moves". This change moves one: the readable-attribute vocabulary is frozen by crates/policy/AGENTS.md line 5. The commit message reports these lines and decisions.md:602 as left stale on purpose.
Suggestion: A maintainer could authorize the three one-line AGENTS.md edits (ip → ip4/ip6, one clause per family) in this PR, so the guidance and the refusal ship together. Changing the decisions.md:602 entry should go through /kd, as the root AGENTS.md requires.

Comment thread crates/policy/src/spelling.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review at d70b271)

This head swaps the ip fold for separate ip4 and ip6 fields, as @zastrowm asked. The redesign is sound. One function produces both fields for every leg, and both earlier embedding arms are kept. A rule that names ip is refused instead of loading inert. My two comments are both non-blocking: an ip6 pattern spelling that still loads but can never match, and stale AGENTS.md guidance.

Assumptions and rules checked that held
  • A rule naming ip is refused in every scope that can reach it: under net:*/http:* by the new check, with no action or across families by refuse_input_across_families, and in unless as well as when. A tool action's own ip still loads.
  • address::attributes is the only producer. The Cedar request, the Dogwood request leg, and the outcome leg all call it, and before resolution neither field is present, so the host-phase decision is unchanged.
  • An IPv4 dial carries ip4 only. Each of the six embeddings carries both fields, and 64:ff9b:1::/48 carries ip6 only, which the table in docs/user/policy.md documents.
  • A literal of the wrong family, a non-canonical literal, a port, brackets, and an uppercase or other-family pattern are each refused with the right field or spelling.
  • Changing a frozen surface: a maintainer asked for it in the review thread, the ! marker is set, and docs/user/policy.md ships in the same commit, as root AGENTS.md requires.
  • The shipped examples, the jailbreak policy, po_14, and po_17 all use one clause per family.
  • I ran cargo test -p strands-box-policy --all-features locally: every suite passed, with 7 ignored.

Separating the route from the endpoint makes the address rules much easier to audit.

zastrowm
zastrowm previously approved these changes Oct 30, 2026
Comment thread docs/user/policy.md Resolved
The address attribute is now `ip4` and `ip6`, but four prose places still told a reader to write `ip`. An agent that followed one of them wrote a policy that fails to load.
@abhisheksp

Copy link
Copy Markdown
Contributor Author

All three addressed in af87bc2. I verified each before acting.

The temporal ban was wrong, and you were right about why. I renamed ip to ip4/ip6 on that line without asking why the ban existed — it came from ip being an ipaddr that faulted in a temporal match, and both new fields are plain strings. connect_address_history.rs builds a predicate per leg per field and all four tests pass on this head, so the ban is gone rather than renamed. Lines 99 and 104 are fixed too.

The dotted-quad pattern gap is real and is now refused. I probed the renderer directly rather than trusting the reasoning: of the six wrappings, only the IPv4-mapped form renders with a dot — ::169.254.169.254 comes back as ::a9fe:a9fe. So judge_address_pattern refuses an ip6 pattern holding a . unless its first element is a literal starting ::ffff:, or it opens with a wildcard, where what the wildcard admits cannot be listed. The refusal points at the hexadecimal groups and at ip4.

I did not take the second half of your suggestion — requiring digits-and-dots or 0: after a leading ::ffff:. That would refuse ::ffff:a9fe:*, and ::ffff:a9fe:a9fe:0 is a real address it matches, because ffff lands in the fifth group there rather than the sixth. So that case stays unprovable and stays documented.

Tests: two rows added to an_address_pattern_whose_literal_holds_a_character_no_address_holds_is_refused (64:ff9b::169.254.* and ::169.254.*), and an_ipv6_pattern_that_can_reach_a_dotted_quad_loads guards the other direction with ::ffff:169.254.*, ::ffff:*.254, and *169.254.*. Mutated both ways: dropping the rule fails the refusal rows, and making mapped_quad always false fails the loads test. The refusal is documented in docs/user/policy.md, and as a refused class in docs/design/policy.md and docs/design/egress.md.

On dropping ip — done for the operator-facing pages and the agent guidance: the field table in actions.md, crates/policy/README.md, crates/policy/AGENTS.md, and the skill no longer mention it, and the before/after migration block in docs/user/policy.md is gone. The refusal message already carries that advice to whoever hits it, and the root AGENTS.md says a page carries no changelog, so the error is the better place for it.

Two deliberate exceptions, both on design pages rather than reference ones. docs/design/policy.md keeps it in the list of rule classes the load refuses, and docs/design/egress.md beside the fold — the root AGENTS.md table requires a load refusal to reach that page, and a security evaluator reading why the check is load-bearing needs to know what it refuses. Say the word if you want those two gone as well.

Gates: 485 passed / 0 failed / 7 ignored, no skipping line; 0 policy-owned clippy warnings; fmt clean.

zastrowm
zastrowm previously approved these changes Oct 30, 2026
@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review at af87bc2)

Both open threads from the last round are fixed. The authoring skill no longer bans temporal reads of ip4/ip6 and no longer lists ip, and NAT64 or IPv4-compatible dotted ip6 patterns are now refused. One case still gets through the new refusal (inline). It doesn't block the merge, but it does contradict the user doc.

Checked and held at this head
  • "Every ip6 pattern with a . and no ::ffff:/wildcard opening can't match." Holds. Ipv6Addr writes a dot only in the mapped form (::169.254.169.254 is written ::a9fe:a9fe).
  • Patterns that open with a wildcard (*169.254.*) still load. That's correct, because the wildcard can cover ::ffff.
  • SKILL.md:99, :104, and :338 are right now. The temporal reads they used to warn against are tested in connect_address_history.rs.
  • "There is no ip" has been removed from the operator-facing pages, the README, crates/policy/AGENTS.md, and the skill. It stays only on the two design pages that list load refusals, which is what the root AGENTS.md table requires.

Comment thread crates/policy/src/spelling.rs Resolved
The mapped form is exactly `::ffff:` and a dotted quad. The first check
tested the prefix alone, so a quad behind a longer prefix still loaded and
could never fire. RFC 6145 writes a translated address as `::ffff:0:` and
a quad, and the user page already said such a pattern is refused.
@abhisheksp

Copy link
Copy Markdown
Contributor Author

Fixed in 013a7f0, and you caught a mistake in my last reply as well as in the code.

I had conflated two cases. ::ffff:a9fe:* holds no ., so it never reaches the check and a stricter rule cannot refuse it — that part stands. But ::ffff:0:169.254.* does hold one, passed a prefix-only test, and can never match. I checked the renderer again: ::ffff:0:169.254.169.254 prints as ::ffff:0:a9fe:a9fe and ::ffff:a9fe:1.2.3.4 as ::ffff:a9fe:102:304. The mapped form is exactly ::ffff: and the quad, with nothing between.

So mapped_quad now requires everything after a leading ::ffff: to be digits, dots, or wildcards, in the first literal and in every later one. Your suggested predicate is what I implemented, give or take the spelling.

RFC 6145 is the part worth having in the docs, so I added it beside RFC 6052: an operator rewriting a translator rule can reach for either spelling, and both now refuse.

::ffff:0:169.254.* and ::ffff:a9fe:1.* are new refusal rows. The three load rows still pass, as you predicted. Mutating mapped_quad back to the prefix-only test fails the refusal rows, so the tightening is pinned and not just present.

The three pages that describe this refusal now say "anywhere but in ::ffff: and the quad" rather than "behind any prefix but ::ffff:", which is what docs/user/policy.md was overclaiming.

Gates: 485 passed / 0 failed / 7 ignored, no skipping line; 0 policy-owned clippy warnings; fmt clean.

@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review at 013a7f0)

The tightening I asked for last round is done: ::ffff:0:169.254.* and ::ffff:a9fe:1.* are now refused, and the tests pin it. One set of patterns that can match is now wrongly refused (inline). It doesn't block the merge, but it does reject a valid forbid with an error that isn't true.

Checked and held at this head
  • "An ip6 pattern with a . whose literals, after a leading ::ffff:, are all digits and dots can reach the mapped form." Holds. The mapped form is ::ffff: and the quad, with nothing in between.
  • "A pattern with any other character after ::ffff: can't match." Holds. I checked ::ffff:0:169.254.*, ::ffff:*:1.2.3.4, and ::ffff:a9fe:1.*.
  • The three load rows still load. These are ::ffff:169.254.*, ::ffff:*.254, and *169.254.*.
  • The docs/user/policy.md:669 wording matches the code, apart from the partial-prefix case in the inline comment.

Comment thread crates/policy/src/spelling.rs Resolved
…prefix

The last commit refused a pattern whose literal stops inside `::ffff:`,
such as `::*169.254.*`, and told the operator no address can match it.
The mapped form matches it, because the wildcard covers the rest of the
prefix. An over-refusal of a correct rule is worse than the gap it
replaced, because the error states the opposite of the truth.
@abhisheksp

Copy link
Copy Markdown
Contributor Author

Fixed in a746990. This one was my regression, and the direction matters: an over-refusal of a correct rule is worse than the gap it replaced, because the operator is told the opposite of the truth and cannot load a forbid that works.

A head that stops inside ::ffff: with a wildcard next is now treated like a leading wildcard — what that wildcard admits cannot be listed, so the judge proves nothing and the pattern loads. an_ipv6_pattern_that_can_reach_a_dotted_quad_loads gains ::*169.254.*, ::ff*169.254.*, ::ffff*.254, and ::ffff:0*169.254.*. Dropping the new arm fails that test.

::ffff:0*169.254.* is in there because it loaded before this commit for a different reason, and I wanted it pinned rather than incidental: ::ffff:0.169.254.5 is a real mapped address that the pattern matches.

docs/user/policy.md now says a pattern whose wildcard could cover the rest of ::ffff: is not refused, instead of naming only a leading wildcard.

Gates: 485 passed / 0 failed / 7 ignored, no skipping line; 0 policy-owned clippy warnings; fmt clean.

Three rounds on one wildcard heuristic is the signal, though. I have been fixing the case you demonstrate instead of deriving the rule, and the last two errors pointed in opposite directions — under-refusing, then over-refusing — which is what patching examples looks like. The rule was derivable from the renderer on the first round: the mapped form is ::ffff: and a quad, and any wildcard that can reach into that prefix makes the pattern unprovable.

Worth asking whether this heuristic belongs in the PR at all. It judges a wildcard pattern, which this page already documents as not held to a whole address, and the Sev-2 this PR closes does not depend on it. Reverting the three commits back to documenting the class is a defensible call, and I would rather you make it than have me keep tightening.

@github-actions

Copy link
Copy Markdown

Assessment: Comment (re-review at a746990). I have no new findings.

a746990 fixes the partial-prefix over-refusal. The ip6 dotted-quad check now refuses only patterns that provably can't match, and a wildcard that could reach into ::ffff: lets the pattern load. On your question about reverting, see my reply in the spelling.rs thread. I'd keep the check.

Checked and held at this head
  • A pattern whose first literal is a prefix of ::ffff: with a wildcard after it loads. Holds: ::*169.254.*, ::ff*169.254.*, ::ffff*.254, ::ffff:0*169.254.*. The last one matches ::ffff:0.169.254.5.
  • The refusal rows from earlier rounds are still refused. Holds: 64:ff9b::169.254.*, ::169.254.*, ::ffff:0:169.254.*, ::ffff:a9fe:1.*.
  • A first literal that is neither a prefix of ::ffff: nor starts with it can't match the mapped form. Holds, from reading the code. It can't line up with the mapped form's first characters.
  • cargo test -p strands-box-policy --all-features passes on this head, with no failures. Last round's summary said I had "checked" ::ffff:*:1.2.3.4. That came from reading the code, not from running it.

@abhisheksp

Copy link
Copy Markdown
Contributor Author

Additional manual verification on a local Mac (Apple silicon, macOS 26), with the PR branch built in release mode:

Updated examples. I ran all four updated examples (claude-code, codex-cli, pi, strands-sdk-agent) end to end against Bedrock. Each one loaded its rewritten policy.dw, completed a task through the box shell, and connected to the model only through model_connect.

The rewritten metadata_addresses rule at runtime. In the examples, default-deny already blocks everything except the model, so this rule never decides anything there. To exercise it, I copied it unchanged into a test policy whose only other rule permits every connection, then sent connections through the gateway:

  • Refused by metadata_addresses: 169.254.169.254, plus its IPv4-mapped, IPv4-compatible, 6to4 and well-known NAT64 encodings, fd00:ec2::254, fe80::1 and feb0::1.
  • Permitted: public IPv4 and IPv6 controls.
  • The no_nat64_translator rule from the description refused 64:ff9b::101:101 and permitted 1.1.1.1.
  • For hostnames, ip4 and ip6 are filled from the address the gateway resolved. A dual-stack name that was pinned over IPv6 was caught only by the ip6 clause, which is the per-family cost the description calls out.
  • Every row of the new ip4/ip6 table in docs/user/policy.md matches at runtime. That includes the documented gap: the local-use NAT64 prefix carries no ip4.

Load-time checks.

  • Main's version of the example policy, which still reads ip, is refused. The message names ip4 and ip6 as the replacements.
  • 22 rule spellings taken from the new docs behave as documented: 15 are refused with the stated message and 7 load.

Tests.

  • cargo test -p strands-box-policy --all-features: 485 passed, 0 failed, 7 ignored.
  • test-integ policy cases, including the edited po_14 and po_17, built with --features test-support: 9 of 9 pass on macOS.

Not covered. I couldn't test a hostname that resolves to a link-local address end to end, because the local DNS strips private answers. The IP-literal and public-hostname cases exercise the same path. I did not run the rest of test-integ, or the Linux leg.

The branch and main both changed the load checks in the policy engine.
Main added the refusal of a temporal predicate that names an action
group, and this branch added the refusal of the removed address
attribute. Both checks now run, with the group check first, as main
ordered it.
@abhisheksp

Copy link
Copy Markdown
Contributor Author

Merged main in at becbdc0 to clear the conflict. One file conflicted, crates/policy/src/dogwood.rs: main added the refusal of a temporal predicate that names an action group, and this branch added the refusal of the removed address attribute, in the same place. Both checks now run, with the group check first, in main's order. The staged path took the same treatment; main added the group check only to check_and_expand, so nothing else needed it.

I merged rather than rebased on purpose. A rebase needs a force-push, and this branch has four reviewed heads — AGENTS.md says not to rewrite history a reviewer saw. The pull request squashes on landing, so the merge commit does not reach main. Say the word if you would rather have a linear branch and accept losing the review trail.

Gates on the merged tree: policy 508 passed / 0 failed / 7 ignored with --all-features, no skipping line; 0 policy-owned clippy warnings; fmt clean; cargo build --workspace --all-features clean. No conflict remains against the newer main either.

One thing worth knowing for this PR specifically: the merge brings in the change that requires real Linux test execution in CI. My Testing section says test-integ and the containment suite did not run here, because this host is x86_64 and Linux containment is ARM64 only, and that CI had to cover them. CI can now actually run that half, so this head is the first one where that claim gets tested rather than deferred.

@abhisheksp
abhisheksp enabled auto-merge (squash) November 2, 2026 19:57
@abhisheksp
abhisheksp merged commit bcf4273 into main Nov 2, 2026
21 checks passed
@abhisheksp
abhisheksp deleted the feature/policy/address-nat64-and-translated-spellings branch November 2, 2026 20:43
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Assessment: Comment (re-review at becbdc0, merge of main). No new findings.

The only conflict was in crates/policy/src/dogwood.rs, and you resolved it correctly. Both load checks from the two sides still run, and the new reload API from main (#217) refuses everything this PR refuses.

Checked and held at this head
  • Every load path runs the ip refusal. Holds. check_against runs refuse_group_predicates, then refuse_removed_address_attribute, then refuse_input_across_families. refuse_input_reads_before_discovery (used by open_staged, discovery, and validate_staged_source) runs the ip check and then the family check. main added the group check only to check_against, so the staged path is right not to have it.
  • The new PolicyEngine::reload from main is covered. Holds. It goes through validate_canonical_policy_set, then check_and_expand, then check_against. I ran a temporary probe with a live engine (since removed). Reloading a context.input.ip rule is refused with the replacement guidance, and reloading ip6 like "64:ff9b::169.254.*" is refused with the dotted-quad message.
  • Nothing main brought in still reads ip. Holds. Outside the refusal tests, nothing in crates/, examples/, or test-integ/ reads context.input.ip.
  • Both legs of net:connect write the address fields through one function. Holds: request_fields and outcome_fields both call address_fields.
  • Merging rather than rebasing follows root AGENTS.md. Holds. Line 15 says not to rewrite history a reviewer saw, and rebasing is only allowed, not required.
  • cargo test -p strands-box-policy --all-features passes on the merged tree. 508 passed, 0 failed, 7 ignored.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants