fix: validate agent-supplied AllowedIPs in coordinator (backport #26144) by f0ssel · Pull Request #26295 · coder/coder · GitHub
Skip to content

fix: validate agent-supplied AllowedIPs in coordinator (backport #26144)#26295

Merged
f0ssel merged 1 commit into
release/2.29from
backport-26144-2.29
Jun 12, 2026
Merged

fix: validate agent-supplied AllowedIPs in coordinator (backport #26144)#26295
f0ssel merged 1 commit into
release/2.29from
backport-26144-2.29

Conversation

@f0ssel

@f0ssel f0ssel commented Jun 11, 2026

Copy link
Copy Markdown
Member

Backport of #26144 (commit 9b351c3) to release/2.29.

Validates agent-supplied AllowedIPs in the coordinator the same way node addresses are validated, preventing an agent from advertising routes for IPs it does not own.

Cherry-pick was clean; tailnet coordinator tests pass on this branch.


This PR was generated by a Coder Agent on behalf of @f0ssel.

`AgentCoordinateeAuth.Authorize` validated every prefix in
`upd.Node.Addresses` (each must be a `/128` derived from the
authenticating agent's own UUID) but applied no equivalent check to
`upd.Node.AllowedIps`. Because `AllowedIPs` are installed verbatim into
the WireGuard peer config (`tailnet/configmaps.go`) and WireGuard
routing is driven by `AllowedIPs`, a malicious agent could advertise a
victim agent's `/128` and become an eligible route for that IP. With
`ServerTailnet` tunneling to many agents and routing by destination IP,
this could let an attacker intercept sessions intended for the victim
workspace.

This applies the same UUID-derivation validation to `AllowedIps` that
already guards `Addresses`, extracted into a shared
`authorizeNodePrefixes` helper. The check is the single chokepoint used
by both the in-memory coordinator (`tailnet/coordinator.go`) and the
Postgres coordinator (`enterprise/tailnet/connio.go`), so one fix covers
both. Legitimate agents are unaffected: an agent's `AllowedIPs` is a
clone of its `Addresses` (`tailnet/node.go`), which are already
UUID-derived `/128`s.

Fixes PLAT-264 (SEC-89): https://linear.app/codercom/issue/PLAT-264

<details>
<summary>Implementation notes and decision log</summary>

### Root cause

Asymmetric validation in `tailnet/tunnel.go`: `Addresses` were bound to
the agent's UUID, but `AllowedIps` were trusted as-is and propagated
into the WireGuard peer config, which drives routing.

### Why the fix is safe for legitimate agents

- `tailnet/node.go` builds the node with `AllowedIPs:
slices.Clone(u.addresses)`, identical to `Addresses`.
- `agent/agent.go` sets those addresses to
`TailscaleServicePrefix.PrefixFromUUID(agentID)` and
`CoderServicePrefix.PrefixFromUUID(agentID)` (both `/128`,
UUID-derived).
- The existing `Addresses` check already accepts exactly those prefixes
plus the legacy workspace agent IP, so identical validation of
`AllowedIPs` passes for real traffic and only rejects forged prefixes.

### Coverage: one method, both coordinators

`AgentCoordinateeAuth.Authorize` is the shared auth path. A failed
`Authorize` is wrapped as `AuthorizationError{Wrapped: err}` and closes
the agent's response stream.

### Tests

- `tailnet/tunnel_internal_test.go`: fast unit tests on `Authorize`
(valid AllowedIPs accepted; foreign `/128` rejected with
`InvalidNodeAddressError`; wrong-bits rejected with
`InvalidAddressBitsError`).
- `tailnet/coordinator_test.go`: in-memory coordinator closes the agent
stream on a forged `AllowedIp`.
- `enterprise/tailnet/pgcoord_test.go`: same regression for the Postgres
coordinator.

Verified the regression tests fail when the new `AllowedIps` check is
disabled, then pass with it enabled. Local validation: targeted tests
(in-memory, internal, and Postgres-backed enterprise), plus `make
pre-commit` (gen/fmt/lint/build) passing.

</details>

> Generated by Coder Agents on behalf of @f0ssel.

(cherry picked from commit 9b351c3)
@f0ssel f0ssel changed the title fix(tailnet): validate agent-supplied AllowedIPs in coordinator (backport #26144) fix: validate agent-supplied AllowedIPs in coordinator (backport #26144) Jun 11, 2026
@f0ssel f0ssel merged commit 9181b84 into release/2.29 Jun 12, 2026
62 of 67 checks passed
@f0ssel f0ssel deleted the backport-26144-2.29 branch June 12, 2026 00:16
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants