Skip to content

identity: one authorizer assembly for every policy enforcement point - #839

Merged
aojea merged 3 commits into
google:mainfrom
aojea:authorizer-consolidation
Nov 1, 2026
Merged

aojea merged 3 commits into
google:mainfrom
aojea:authorizer-consolidation

Conversation

@aojea

@aojea aojea commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #838 (merged). Rebased onto main at c5562280. Three commits: the authorizer consolidation, the two review items on the merged ingress code (bounded ingress dial; api.HasDotSegment as the single dot-segment check, backslash-aware), and a scrub of test identities to example.com personas.

Summary

The node's in-mesh verifier (verifyBiscuitTokenWithRules), the node's external ingress handler, and the control plane's /sts/token each assembled their Datalog authorizer by hand: service fact, HTTP and egress facts, replay binding, target facts and check, local attenuation, baseline policies and rules, mesh rules — three copies. They matched by discipline, not by construction, and one divergence had already crept in: the ingress path took an EnforceTargetCheck knob and skipped BaselineTargetCheck when the node had no identity, where the in-mesh path always added it.

identity.AuthorizeMeshRequest(authorizer, MeshRequest, MeshPolicy) is now the only place a mesh authorizer is assembled.

  • MeshRequest says what the request is: service(); method()/path() only when HasHTTP; host()/port() only when HasEgress; connection_peer_id() + BaselineReplayCheck only when ConnectionPeer is set; target_unrestricted only when Unrestricted. Every absent field means "not present" and fails closed.
  • MeshPolicy says what the PEP adds: its own target facts, local attenuation, synced mesh rules.
  • Always added, no knob: BaselineTargetCheck, baseline policies/rules/HTTP rules, expiration().
  • MeshRequest.TaskRequest() derives the TaskAuthorizationRule context from the same value.

Callers

PEP Change
Node in-mesh (internal/node/middleware.go) ~90 lines of inline assembly and injectIdentityFacts replaced by MeshRequest{ConnectionPeer, Unrestricted: Local, …} + n.meshPolicy()
Node ingress (internal/node/ingress.go) same n.meshPolicy(); EnforceTargetCheck removed, target check now unconditional
Router edge (internal/router/ingress.go) IngressEvalParams keeps its fields and delegates to the shared assembly
Control plane /sts/token (internal/controlplane/sts.go) MeshRequest{egress, Unrestricted, ConnectionPeer: clientPeer}; stsDestinationRules as LocalRules

Production code is net +27 lines (+305/−278); the rest is tests and docs.

Tests

  • TestAuthorizeMeshRequest — 11 table cases pinning what each MeshRequest field contributes and that each fails closed when absent (HTTP-narrowed grant on a bare stream, node-scoped grant without provider target facts, replay from a different connection peer, border bearer without connection peer, local deny).
  • TestIngressEvalParamsMatchMeshRequest — runs the ingress evaluator and the shared assembly on identical inputs and requires the same decision: the structural "no leak between paths" guard.

Docs

  • external-ingress.md: new section "Ingress is for callers without a sidecar" — an agent on the mesh calls peers through its sidecar; the ingress URL is neither a second route for it nor one that accepts its node credential; same policy on both paths, no privilege by path choice.
  • security-architecture.md: "One authorizer assembly for every PEP".

Validation

On the rebased branch: make, go vet, make lint (0 findings), -race unit tests for api, identity, node, router, controlplane, envoy, standalone, and the full tests/integration suite serially (all pass).

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces external HTTP ingress capabilities to the Agent Mesh router and node, allowing services to be exposed externally via edge (zero-trust, Biscuit-verified) or passthrough modes. It implements the /mesh/ingress/1.0.0 protocol, adds ingress routing and rate-limiting to the router, and integrates these features into the standalone server, database storage, and Helm charts. Feedback on the changes highlights two high-severity security issues: a potential Denial of Service vulnerability due to a missing timeout in the router's stream dialer, and a potential Path Traversal vulnerability on Windows hosts in the path normalization logic.

Comment on lines +137 to +150
DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
peerStr := addr
if h, _, err := net.SplitHostPort(addr); err == nil {
peerStr = h
}
pid, err := peer.Decode(peerStr)
if err != nil {
return nil, fmt.Errorf("invalid target peer %q: %w", peerStr, err)
}
if r.gated == nil {
return nil, errors.New("router host is not initialized")
}
return gostream.Dial(network.WithAllowLimitedConn(ctx, "ingress"), r.gated, pid, api.IngressProtocolID)
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The DialContext function in http.Transport does not enforce a timeout when calling gostream.Dial. Since standard incoming HTTP requests do not have a default context deadline, an unresponsive peer or hung stream negotiation could cause the connection attempt to block indefinitely. This can lead to goroutine leaks and potential denial of service. Enforce a timeout using context.WithTimeout with ingressDialTimeout.

Suggested change
DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
peerStr := addr
if h, _, err := net.SplitHostPort(addr); err == nil {
peerStr = h
}
pid, err := peer.Decode(peerStr)
if err != nil {
return nil, fmt.Errorf("invalid target peer %q: %w", peerStr, err)
}
if r.gated == nil {
return nil, errors.New("router host is not initialized")
}
return gostream.Dial(network.WithAllowLimitedConn(ctx, "ingress"), r.gated, pid, api.IngressProtocolID)
},
DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
peerStr := addr
if h, _, err := net.SplitHostPort(addr); err == nil {
peerStr = h
}
pid, err := peer.Decode(peerStr)
if err != nil {
return nil, fmt.Errorf("invalid target peer %q: %w", peerStr, err)
}
if r.gated == nil {
return nil, errors.New("router host is not initialized")
}
dialCtx, cancel := context.WithTimeout(ctx, ingressDialTimeout)
defer cancel()
return gostream.Dial(network.WithAllowLimitedConn(dialCtx, "ingress"), r.gated, pid, api.IngressProtocolID)
},

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ae660d4: the dial is bounded by ingressDialTimeout (same bound the provider handshake before it already had); the stream outlives the dial context.

Comment thread internal/router/ingress.go Outdated
Comment on lines +952 to +959
func hasDotSegment(p string) bool {
for _, seg := range strings.Split(p, "/") {
if seg == "." || seg == ".." {
return true
}
}
return false
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

security-high high

The hasDotSegment function only splits the path on forward slashes (/). If the backend service is running on a Windows host, backslashes (\) may be interpreted as path separators. An attacker could bypass the dot-segment check by sending percent-encoded backslashes (e.g., %5C..%5C), potentially leading to directory traversal. Normalize backslashes to forward slashes before checking for dot segments.

Suggested change
func hasDotSegment(p string) bool {
for _, seg := range strings.Split(p, "/") {
if seg == "." || seg == ".." {
return true
}
}
return false
}
func hasDotSegment(p string) bool {
normalized := strings.ReplaceAll(p, "\\", "/")
for _, seg := range strings.Split(normalized, "/") {
if seg == "." || seg == ".." {
return true
}
}
return false
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in ae660d4, and consolidated: hasDotSegment existed in both the router and the node; api.HasDotSegment is now the single copy, normalizes \ before splitting, and both binaries call it. TestHasDotSegment gained the backslash cases.

The node's in-mesh verifier, the node's external ingress handler and the
control plane's /sts/token each assembled their Datalog authorizer by hand:
the service fact, the HTTP and egress facts, the replay binding, the target
facts and check, the local attenuation, the baseline policies and rules and
the mesh rules, in three copies. They matched, but nothing made them match:
a rule added to one path reached the others only if someone remembered.
One difference had already crept in. The ingress path took an
EnforceTargetCheck knob and left BaselineTargetCheck out when the node had
no identity, where the in-mesh path always added it and admitted only an
unrestricted grant.

identity.AuthorizeMeshRequest is now the only place the authorizer is
assembled. MeshRequest says what the request is: the service, the HTTP line
when there is one, the egress destination when there is one, the connection
peer when there is a libp2p stream to bind client_peer_id to, and whether
targets are unrestricted (a local caller, or the control plane with no
provider credential). MeshPolicy says what the enforcement point adds: its
own target facts, its local attenuation and the synced mesh rules.
BaselineTargetCheck, the baseline policies and rules and expiration() are
always added, so a path cannot leave them out, and every absent field means
not present, never unrestricted. MeshRequest.TaskRequest derives the
TaskAuthorizationRule context from the same value.

The node builds MeshPolicy once (meshPolicy) for both its verifier and its
ingress handler; injectIdentityFacts goes, the target facts come from
TargetFactsFromBiscuit as on the router. IngressEvalParams keeps its fields
and loses EnforceTargetCheck. The STS egress check keeps its destination
rules as the PEP's local rules and the policy rules as mesh rules.

TestAuthorizeMeshRequest fixes what each MeshRequest field contributes and
that each fails closed when absent: an HTTP-narrowed grant on a bare stream,
a node-scoped grant on a provider without target facts, a connection peer
other than client_peer_id. TestIngressEvalParamsMatchMeshRequest runs the
ingress evaluator and the shared assembly on the same credential, service
and policy and requires the same decision. The guide now says that an agent
on the mesh calls peers through its sidecar and that the ingress URL is
neither a second route for it nor one that takes its node credential; the
security architecture describes the single assembly.
@aojea
aojea force-pushed the authorizer-consolidation branch from 0bbf7ef to 4a9e80f Compare November 1, 2026 10:34
@aojea
aojea marked this pull request as ready for review November 1, 2026 10:34
aojea added 2 commits November 1, 2026 10:42
…separator

The router's ingress transport dialed the provider on the inbound request's
context, which carries no deadline: a provider that accepted the connection
and then never finished stream negotiation held the goroutine for as long
as the client waited. The dial is now bounded by ingressDialTimeout, as the
provider handshake before it already was; the stream outlives that context.

hasDotSegment existed twice, in the router and in the node, and both split
on "/" only. A path segment reaches the backend percent-encoded, so a
backend on a platform that treats "\" as "/" would resolve "..\" as a
traversal the check never saw. api.HasDotSegment is now the one copy, it
normalizes backslashes before splitting, and both binaries call it.
Test identities used a real domain and real first names. They are now the
alice, bob, carol and dave personas at example.com, like the rest of the
suite. No assertion changes meaning: the one negative case keyed on a
different local part, not on the domain.
@aojea
aojea merged commit a9acd90 into google:main Nov 1, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant