Skip to content

Agent Mesh

docs: egress destinations, HTTP grants and the request facts

Antonio Ojea913e86890ba8
diff --git a/site/content/docs/concepts/authorization.md b/site/content/docs/concepts/authorization.md
index e698e18e..15a73683 100644
--- a/site/content/docs/concepts/authorization.md
+++ b/site/content/docs/concepts/authorization.md
@@ -113,7 +113,10 @@ Biscuit authorizer and adds the following, in this order:
1. **The request**: `service("mcp", "calculator")` for the requested
service, and `connection_peer_id(P)` from the authenticated connection.
If the caller named an agent, the agent claim is added together with the
- check that the caller's own token grants that agent namespace.
+ check that the caller's own token grants that agent namespace. When the
+ node handles the request as HTTP it adds `method("GET")` and
+ `path("/v1/models")`, the path as the backend will see it; for a
+ destination outside the mesh it adds `host(...)` and `port(...)`.
2. **The baseline checks**: `client_peer_id($id), connection_peer_id($id)`
(the token belongs to the peer that presents it), and the expiration
check against the current time.
@@ -128,7 +131,9 @@ Biscuit authorizer and adds the following, in this order:
5. **The baseline policies**: `allow if service($t,$n), granted_service_exact($t,$n)`
and the equivalent policies for sets, prefixes, suffixes, per-type and
global wildcards, plus the target check
- `allow_network_target(...) or target_unrestricted(true)`.
+ `allow_network_target(...) or target_unrestricted(true)`, and the rules
+ that turn an [HTTP grant](../../reference/policy/#http-grants) into a
+ service grant when the request's method and path match it.
6. **The synced mesh policy rules** described above.
Biscuit evaluates every `check` and requires all of them to pass. It then
@@ -142,6 +147,35 @@ Before any of this, the connection itself is gated. A peer on the ban list is
dropped at the transport layer, and a peer whose credential does not verify
under a trusted signing key cannot name a service at all.
+## Why a caller cannot forge a fact
+
+Two kinds of fact meet in the authorizer. The facts in the credential's
+authority block were written and signed by the control plane: roles,
+grants, labels, the peer the token is bound to. The facts about the request
+(`service`, `method`, `path`, `host`, `port`, `agent`, `connection_peer_id`,
+`time`) are added by the node that received the request, from what arrived
+on the wire. A caller writes neither. It cannot change the authority block
+without breaking the signature, and it cannot put a fact into the request
+set because the node computes that set itself.
+
+Biscuit does let a holder append a block to a token. That is how a token is
+attenuated: a holder can add a check that narrows what the token does. The
+facts of an appended block are visible only to that block's own checks and
+never to the authorizer's policies, so an appended `role("admin")` grants
+nothing. `internal/identity`'s
+`TestAttenuationBlockFactsAreInvisibleToTheAuthorizer` pins this, and nodes
+refuse an inbound token that carries appended blocks at all.
+
+This is what lets the policy grow without a schema change. A requirement
+that needs a new dimension is a new fact or a new rule, written in the same
+language that the existing grants compile to. A role's `custom_datalog` can
+mint `tier("contractor")` into every holder's credential, a node's
+`attenuation` can then say `deny if tier("contractor"), method($m), !($m == "GET")`,
+and neither `PolicyRole` nor any wire message changed. The structured fields
+(`allowed_services`, `allowed_agents`, `http`, ...) are the common cases,
+compiled to Datalog by the control plane; `custom_datalog` and
+`attenuation` are the same engine written by hand.
+
## Local rules
The `attenuation` block in `sam-node.yaml` gives the hosting node the final
@@ -212,3 +246,6 @@ the namespace belongs to the node's role and not to the agent. The
name.
- [Node configuration reference](../../reference/node-config/): the
`attenuation`, `labels` and `egress` blocks.
+- [Reaching services outside the mesh](../../guides/egress-destinations/):
+ the node as a policy enforcement point for an application's outbound
+ HTTP calls.
diff --git a/site/content/docs/guides/egress-destinations.md b/site/content/docs/guides/egress-destinations.md
new file mode 100644
index 00000000..ad330a73
--- /dev/null
+++ b/site/content/docs/guides/egress-destinations.md
@@ -0,0 +1,193 @@
+---
+title: "Reaching services outside the mesh"
+linkTitle: "Egress destinations"
+weight: 3
+---
+
+An agentic application calls APIs that are not on the mesh: a source
+forge, a ticketing system, an internal REST service, a model provider. This
+guide puts a `sam-node` in front of such a destination as a policy
+enforcement point. The application changes one base URL. The admin writes
+one policy document. The node decides every request on the method, the
+path and the caller, holds the credential the destination needs, and keeps
+it out of the application.
+
+You need a control plane you administer, one enrolled node that will serve
+the destination, and the credential the destination expects (an API token)
+available to that node's host as a file.
+
+## What the admin writes
+
+Everything is in the mesh policy. The `egress` section names the
+destination, the credential and the nodes that serve it. A role narrows who
+may call it and how.
+
+```json
+{
+ "roles": [
+ {
+ "name": "sam:role:node",
+ "allowed_services": ["system://sam.catalog"],
+ "allowed_targets": ["*"]
+ },
+ {
+ "name": "pep",
+ "allowed_targets": ["*"]
+ },
+ {
+ "name": "contractor",
+ "allowed_services": ["egress://api.github.com"],
+ "allowed_targets": ["*"],
+ "http": [
+ { "service": "egress://api.github.com", "methods": ["GET"], "paths": ["/repos/acme/*"] }
+ ]
+ }
+ ],
+ "bindings": [
+ { "role": "sam:role:node", "members": ["group:platform", "group:external"] },
+ { "role": "pep", "members": ["group:platform"] },
+ { "role": "contractor", "members": ["group:external"] }
+ ],
+ "egress": [
+ { "name": "api.github.com", "credential": "github-eu", "served_by": ["pep"] }
+ ]
+}
+```
+
+- `egress[].name` is the destination hostname. It is the service name in
+ grants (`egress://api.github.com`) and the name a caller looks up.
+- `egress[].credential` is a name, never a value. The serving node reads
+ the file `/etc/sam/secrets/github-eu` (or under `--secrets-dir`) and
+ presents its content as `Authorization: Bearer <content>`; `user:pass`
+ is sent as HTTP Basic. Whatever puts secrets in files on the host, a
+ Kubernetes Secret volume, a vault agent, a secrets-store CSI driver,
+ delivers it; the control plane never sees it.
+- `egress[].served_by` selects the serving nodes by role or by attested
+ label (`site=eu`). The control plane grants the destination to those
+ nodes, so a serving node authorizes local requests on its own credential.
+- `roles[].http` narrows a grant to methods and paths. Here a contractor may
+ `GET` under `/repos/acme/` and nothing else. The other fields of a role
+ are unchanged; see the [policy reference](../../reference/policy/).
+
+Post it:
+
+```bash
+curl -sS -X POST "$CONTROL_PLANE/policies" \
+ -H "Authorization: Bearer $(cat admin-token)" \
+ -H 'Content-Type: application/json' \
+ --data @policy.json
+```
+
+## What the node does
+
+Nothing in `sam-node.yaml` changes, and `type: egress` is refused there. A
+node holding the `pep` role pulls its assignments from the control plane on
+the same schedule as the mesh policy, and sooner when the policy changes.
+For each destination that selects it, the node registers the service,
+announces `egress://api.github.com` on the mesh, and checks that the named
+credential is readable. Its log shows:
+
+```text
+[Egress] Serving egress://api.github.com -> https://api.github.com (assigned by the control plane)
+[Egress] Assignments: 1 assigned, 1 registered, 0 unchanged, 0 withdrawn, 0 refused
+```
+
+A destination whose credential is not in the secrets directory is refused
+and logged; the node keeps serving the others. When the admin removes a
+destination or its `served_by` no longer selects the node, the node
+withdraws the service on its next sync. Every sync that changes or refuses
+something logs the summary line above; the control plane, for its part,
+warns when a posted destination selects no enrolled node at all.
+
+## What the application does
+
+The application on the serving node's host is configured with the node's
+API as the base URL of the destination and the node's API token as its
+bearer, in the place it would hold a provider key:
+
+```bash
+export GITHUB_API_URL=http://127.0.0.1:8080/egress/api.github.com
+export GITHUB_TOKEN=$(cat /etc/sam/api-token)
+```
+
+A request then travels like this:
+
+```text
+app GET /egress/api.github.com/repos/acme/dubbing/pulls?state=open
+ Authorization: Bearer <api token>
+node accepts the API token; drops it
+ facts: service("egress","api.github.com") method("GET")
+ path("/repos/acme/dubbing/pulls") host("api.github.com") port(443)
+ authorizes on its own credential, with its attenuation
+ GET https://api.github.com/repos/acme/dubbing/pulls?state=open
+ Authorization: Bearer <content of /etc/sam/secrets/github-eu>
+```
+
+The destination sees the node's credential and none of the application's
+headers (`Authorization`, `Cookie`, `X-*`). A `403` is a policy decision; a
+`404` is a destination this node was not assigned. Both carry
+`Proxy-Status: sam-node; error=...`, so your client can tell them from an
+answer the destination sent.
+
+Every decision, allowed or denied, is one `Audit Traceability` line in the
+node's log with the peer, the role, the agent, the method, the path, the
+host and the port policy saw, and the decision. That line is the audit
+trail of the PEP; the destination's own logs see only the node.
+
+The node's `/metrics` endpoint counts the same events, so you can alert
+without reading logs:
+
+| Metric | Labels | Counts |
+|---|---|---|
+| `sam_node_egress_decisions_total` | `destination`, `outcome` | requests for a destination, by outcome: `allow`, `deny`, `not_assigned` (the node does not serve that name) and `credential_unavailable` (the credential file could not be read when the request arrived) |
+| `sam_node_egress_assignments_total` | `outcome` | assignments applied from the control plane: `registered`, `withdrawn` and `refused` |
+
+`sam_node_services_registered{type="egress"}` is the number of destinations
+the node serves right now. A `refused` assignment or a `credential_unavailable`
+decision means the platform did not deliver a credential the policy names.
+
+A client that names the agent it acts for sends `X-Sam-Agent`. The claim is
+checked against the node's `allowed_agents` grant and reaches policy as
+`agent()`, as it does on every other path.
+
+## What another mesh member does
+
+A member whose role grants `egress://api.github.com` reaches the same
+destination through its own node, which finds the serving node by name:
+
+```bash
+curl -sS -H "X-Sam-Authentication: Bearer $TOKEN" \
+ "http://127.0.0.1:8080/sam/$PEP_PEER_ID/egress/api.github.com/repos/acme/dubbing/pulls"
+```
+
+The serving node evaluates the member's credential. With the policy above a
+member in `group:external` gets `204` on that request, `403` on a `POST` to
+the same path, and `403` on `GET /user`.
+
+## Narrowing on the node
+
+The serving node's operator can refuse what the mesh policy allows, in
+`sam-node.yaml`. The request facts are available there. The dialect has no
+`!=`; a negation is `!`:
+
+```yaml
+attenuation:
+ policies:
+ - 'deny if path($p), $p.starts_with("/repos/acme/vault/");'
+ - 'deny if group("external"), method($m), !($m == "GET");'
+ - 'deny if port($p), !($p == 443);'
+```
+
+## Limits
+
+- The node is the HTTP origin. A method and path decision needs the request
+ in the clear, which is the case here because the application talks plain
+ HTTP to the node. A tunnel the node opens without terminating HTTP carries
+ `method("CONNECT")` and an empty path, so a grant narrowed to methods or
+ paths denies it.
+- The path is a prefix under the destination. A client that follows
+ absolute URLs returned by the destination (a `Link` header, a URL in a
+ body) leaves the node. Use a client that takes a base URL, or point it
+ back at the prefix.
+- One destination is one hostname. A wildcard destination and a destination
+ reached by `CONNECT` from a sandbox are not part of this release.
diff --git a/site/content/docs/reference/control-plane.md b/site/content/docs/reference/control-plane.md
index d2da9b0f..9efe2000 100644
--- a/site/content/docs/reference/control-plane.md
+++ b/site/content/docs/reference/control-plane.md
@@ -76,6 +76,7 @@ names. Every instant in a response (`expire_time` and the like) is a
| `POST /refresh` | `TokenRefreshRequest`, current credential as `Authorization: Bearer <base64>` | Exchange a credential for a new one. Refuses a replayed (superseded) credential, a banned node, an expired session, and a credential signed by a retired key unless the node has `autonomous_recovery`. |
| `POST /routers/lease` | `RouterLeaseRequest` (credential, addresses, telemetry) | Register or renew a router lease. Requires `role("sam:role:router")`. Announced addresses must end in the router's own peer ID. |
| `GET /policies` | credential as `Authorization: Bearer <base64>` | The mesh policy as `PolicyConfigGetResponse`: the Datalog rules a member adds to its authorizer, one per entry. Operators read the document at `GET /admin/policy`. |
+| `GET /egress` | credential as `Authorization: Bearer <base64>` | `EgressAssignmentsResponse`: the [egress destinations](../policy/#egress-destinations) whose `served_by` selects the calling node, by its roles or labels. A node registers and serves what it receives here. |
| `POST /nodes/catalog` | `NodeCatalogReport`, credential as bearer | A node's report of the services it publishes, for the console. Display only. Never used for authorization. |
### Admin
diff --git a/site/content/docs/reference/node-api.md b/site/content/docs/reference/node-api.md
index 77a235c6..09f54102 100644
--- a/site/content/docs/reference/node-api.md
+++ b/site/content/docs/reference/node-api.md
@@ -35,6 +35,7 @@ proxy path does not accept it there.
| `POST /v1/chat/completions`, `POST /v1/completions` | token | OpenAI-compatible inference, routed to a provider of the requested model. |
| `GET /sam/service/discover` | token | Discover services on the mesh. |
| `ANY /sam/{peer-id}/{type}/{name}[/{path}]` | token | Reverse proxy to one service on one peer. |
+| `ANY /egress/{destination}[/{path}]` | token | A destination outside the mesh that this node serves, for local clients. See [Egress](#egress). |
| `GET /sam/identity` | token, socket or mTLS only | This node's credential and the key it verifies under. |
| `GET /sam/peer/{peer-id}/evidence` | token, socket or mTLS only | A peer's credential as this node last verified it. |
| `GET /debug/*` | token | Operator diagnostics. These answer even when the mesh is unreachable. |
@@ -205,6 +206,46 @@ here because nothing on this path forwards that header. Streaming responses
are passed through. One provider can also be addressed directly, at
`/sam/<peer-id>/inference/<name>/v1/chat/completions`.
+## Egress
+
+`/egress/<destination>/<path>` reaches a destination outside the mesh that
+the control plane assigned to this node (an entry of the
+[egress section](../policy/#egress-destinations) of the mesh policy whose
+`served_by` selects it). The node is the HTTP origin: it authorizes the
+request on its own credential, with the request's method and path and the
+destination's host and port as facts, forwards it to the destination's
+`target_url` with the credential the policy names, and returns the answer.
+
+```bash
+curl -s --unix-socket $SOCK "http://localhost/egress/api.github.com/repos/acme/dubbing/pulls?state=open"
+```
+
+An application that takes a base URL for the API it calls points it at the
+node, `http://127.0.0.1:8080/egress/api.github.com`, and sends the API
+token as its bearer, the way it would send a provider key. The node accepts
+the token in `Authorization` on this path and never forwards that header:
+the destination sees the node's credential and none of the client's
+headers. A client may name the agent it acts for in `X-Sam-Agent`; the
+claim is checked against the node's `allowed_agents` grant and is visible
+to policy as `agent()`.
+
+`403` is a policy decision: the node's role lacks the destination, an
+`http` narrowing excludes the method or path, or the node's `attenuation`
+refuses the request. `404` is a destination the control plane did not
+assign to this node. Both carry a `Proxy-Status` header (RFC 9209) naming
+the node as the source, `sam-node; error=http_request_denied` or
+`error=destination_not_found`, so a client can tell them from a `403` or
+`404` the destination itself sent, which carries none. A destination whose
+credential file went missing after registration answers `502` with
+`error=proxy_configuration_error`. The same destination is reachable from
+another mesh member at `/sam/<peer-id>/egress/<destination>/<path>` on that
+member's node, authorized on the member's credential.
+
+The path is a prefix under the destination, so a client that follows
+absolute URLs returned by the destination (a `Link` header, a URL in a
+body) leaves the node. Point it back at the prefix, or use a client that
+takes a base URL.
+
## Identity evidence
`GET /sam/identity` returns the node's credential (base64), the control
diff --git a/site/content/docs/reference/node-config.md b/site/content/docs/reference/node-config.md
index 94e7e3f3..d818d2c6 100644
--- a/site/content/docs/reference/node-config.md
+++ b/site/content/docs/reference/node-config.md
@@ -76,7 +76,7 @@ A list. Each entry has these keys:
| Key | Required | Meaning |
|---|---|---|
-| `type` | yes | `mcp`, `inference` or `a2a`. |
+| `type` | yes | `mcp`, `inference` or `a2a`. `egress` is refused here: a destination outside the mesh is assigned to nodes by the control plane, in the [egress section](../policy/#egress-destinations) of the mesh policy. |
| `name` | yes | Unique on this node. DNS-style labels separated by dots (`db-reader`, `build.runner`). Policy grants refer to `type://name`. |
| `description` | no | Shown in discovery results and in the console. |
| `target_url` | `mcp`: this or `command`; `inference` and `a2a`: yes | Backend URL that the node proxies to. Embedded credentials (`http://user:pass@`) are refused. |
@@ -99,9 +99,10 @@ Before a service is advertised, the node probes the backend
(`--backend-probe-timeout`, 2 seconds). A backend that does not answer is
not advertised, and the log records this.
-Services exist only through this file. There is no runtime API that adds a
-service. An agent with access to the node's API therefore cannot point the
-mesh at a new backend.
+Services exist only through this file and through the control plane's
+egress assignments. There is no runtime API that adds a service. An agent
+with access to the node's API therefore cannot point the mesh at a new
+backend.
## `attenuation`
@@ -129,6 +130,11 @@ Facts available:
| `granted_service_*`, `granted_target_*`, `granted_agent_*` | The caller's grants. |
| `target_fact($name, $value)` | This node's own identity facts, for target matching. |
| `agent($id)` | The agent the caller says it acts for, when present. |
+| `method($m)`, `path($p)` | The request, when it is HTTP: the method as received and the path as the backend sees it. On a tunnel, `CONNECT` and an empty path. Absent on a stream that carries no HTTP request. |
+| `host($h)`, `port($n)` | The destination of a request for an egress destination. |
+
+The dialect has no `!=`; write a negation with `!`, as in
+`deny if method($m), !($m == "GET")`.
The mobile app has the same three lists in its settings, with the same
syntax and the same errors.
diff --git a/site/content/docs/reference/policy.md b/site/content/docs/reference/policy.md
index 11157ad9..0e7669a4 100644
--- a/site/content/docs/reference/policy.md
+++ b/site/content/docs/reference/policy.md
@@ -6,10 +6,11 @@ aliases:
- /docs/development/policy/
---
-The mesh policy is one document held by the control plane: a list of roles
-and a list of bindings. It is posted as JSON (protojson of `PolicyConfig` in
-`api/sam.proto`) to `POST /policies`, read back from `GET /admin/policy`,
-edited in the console, or given to `sam-one --policy-file` for first boot.
+The mesh policy is one document held by the control plane: a list of roles,
+a list of bindings and a list of egress destinations. It is posted as JSON
+(protojson of `PolicyConfig` in `api/sam.proto`) to `POST /policies`, read
+back from `GET /admin/policy`, edited in the console, or given to
+`sam-one --policy-file` for first boot.
```json
{
@@ -25,11 +26,23 @@ edited in the console, or given to `sam-one --policy-file` for first boot.
"allowed_targets": ["group:dev-nodes", "node:12D3KooWSpecialNode"],
"allowed_agents": ["*.dev.acme.example"],
"custom_datalog": ["tier(\"standard\");"]
+ },
+ {
+ "name": "contractor",
+ "allowed_services": ["egress://api.github.com"],
+ "allowed_targets": ["*"],
+ "http": [
+ { "service": "egress://api.github.com", "methods": ["GET"], "paths": ["/repos/acme/*"] }
+ ]
}
],
"bindings": [
{ "role": "sam:role:node", "members": ["group:engineering", "user:system:serviceaccount:sam-nodes:calc-mcp-sam-node"] },
- { "role": "developer", "members": ["group:engineering"] }
+ { "role": "developer", "members": ["group:engineering"] },
+ { "role": "contractor", "members": ["group:external"] }
+ ],
+ "egress": [
+ { "name": "api.github.com", "credential": "github-eu", "served_by": ["site=eu"] }
]
}
```
@@ -48,11 +61,16 @@ notice.
| `allowed_labels` | list of label patterns | Labels that a node holding this role may declare at enrollment. If absent, no labels may be declared. |
| `allowed_agents` | list of agent patterns | Agent identifiers that a node holding this role may claim to act for. If absent, no agent may be named. |
| `custom_datalog` | list of Datalog statements | Facts are minted into the credentials of holders. Rules are distributed to nodes and applied when a holder is verified. |
+| `http` | list of HTTP grants | Narrows an `allowed_services` entry to HTTP methods and paths. See [HTTP grants](#http-grants). |
### Service patterns
-`type://name`, where `type` is `mcp`, `inference`, `a2a` or `system`, and
-`name` consists of dot-separated DNS-style labels.
+`type://name`, where `type` is `mcp`, `inference`, `a2a`, `egress` or
+`system`, and `name` consists of dot-separated DNS-style labels. For
+`egress` the name is the hostname of a destination outside the mesh, written
+lowercase, with no scheme, port or path: `egress://api.github.com/v3` is
+rejected, because the path belongs in the role's `http` entry. See
+[Egress destinations](#egress-destinations).
| Pattern | Compiles to | Matches |
|---|---|---|
@@ -98,6 +116,76 @@ agents it hosts.
| `key=*` | any value for that key |
| `*` | any label |
+### HTTP grants
+
+An entry of `http` narrows one `allowed_services` entry of the same role to
+HTTP methods and paths. The service must be written exactly as it appears in
+`allowed_services`; at least one of `methods` and `paths` must be set.
+
+| Field | Meaning |
+|---|---|
+| `service` | The `allowed_services` entry this narrows. |
+| `methods` | Methods the holder may use, uppercase, such as `GET`. Empty means any method. |
+| `paths` | Paths the holder may request, as the backend sees them. `/user` matches that path only; `/v2/public/*` matches every path under the prefix. Empty means any path. |
+
+```json
+{ "service": "egress://api.github.com", "methods": ["GET", "HEAD"], "paths": ["/repos/acme/*", "/user"] }
+```
+
+The control plane compiles the entry into facts in the holder's credential
+and withholds the plain service grant for that entry:
+
+```datalog
+http_granted_service_exact("egress", "api.github.com")
+granted_method("egress", "api.github.com", ["GET", "HEAD"])
+granted_path_prefix("egress", "api.github.com", "/repos/acme/")
+granted_path_exact("egress", "api.github.com", ["/user"])
+```
+
+Baseline rules on every node derive `granted_service_exact("egress",
+"api.github.com")` from these facts only when the request's `method()` and
+`path()` facts satisfy them. The ordinary allow policies then decide as they
+do for any grant. The rules are positive, so a request that carries no HTTP
+method (a tunnel, a non-HTTP stream) derives nothing and a narrowed grant
+denies it. A role that holds the same service plainly, through another
+entry or another role, is not narrowed: grants are a union.
+
+A node built before this field existed has no derivation rules, so it denies
+a narrowed grant entirely rather than treating it as unrestricted.
+
+## Egress destinations
+
+An entry of `egress` is a destination outside the mesh that selected nodes
+serve as `egress://<name>`. The admin writes it once; each selected node
+receives it at `GET /egress`, registers the service, announces it on the DHT
+and forwards requests to it. Nodes hold no egress configuration of their
+own, and `type: egress` in `sam-node.yaml` is refused.
+
+| Field | Meaning |
+|---|---|
+| `name` | The destination hostname, lowercase, without a port or a path. It is the service name in grants (`egress://<name>`) and in the `service()` fact. One hostname; no wildcard. |
+| `target_url` | Where the serving node forwards requests. Optional; `https://<name>` when empty. `http` or `https`, no credential, no query. |
+| `credential` | Name of the credential the serving node presents to the destination. The node reads the file `<--secrets-dir>/<credential>` (default `/etc/sam/secrets`): `TOKEN` is sent as `Authorization: Bearer TOKEN`, `user:pass` as HTTP Basic. The file is read on every request, so a rotation by the platform applies at once. The value never travels through the control plane. |
+| `served_by` | Role names or `key=value` labels selecting the serving nodes. A node matches when any entry names one of its roles or attested labels. |
+
+The control plane renders one rule per `served_by` entry into the mesh
+policy, `granted_service_exact("egress", "api.github.com") <- role("pep")`
+or `<- label("site", "eu")`, so a serving node authorizes a local request
+with its own credential. Every other caller needs `egress://<name>` on its
+own role. A destination that names a credential the platform did not deliver
+to a node is refused by that node at registration and logged; the other
+destinations are still served.
+
+On an egress request the destination node injects `host()` and `port()`
+next to `method()` and `path()`, and the destination sees the node's
+credential only: the caller's `Authorization`, `Cookie`, `X-Sam-*` and
+`X-Forwarded-*` headers are removed. See [Node API](../node-api/#egress)
+for how a local client reaches a destination.
+
+The control plane warns in its log when a posted destination selects no
+enrolled node, since a selector with a typo is valid in form and would
+otherwise surface only as `404` at the callers.
+
Keys match `[a-zA-Z0-9_.-]{1,63}`. Values are up to 255 characters with no
`,`, `=` or control characters. Every label that a node declares must be
permitted by a role it holds, or enrollment fails. Manual approval of a
@@ -163,7 +251,9 @@ and removals within the credential TTL.
At the destination node, in this order:
1. Facts for the request: `service($type, $name)`, `connection_peer_id($id)`,
- `time($now)`, and `agent($id)` if a claim was made.
+ `time($now)`, and `agent($id)` if a claim was made. On an HTTP request,
+ `method($m)` and `path($p)`; on a request for an egress destination,
+ `host($h)` and `port($n)`.
2. Checks that always apply: `client_peer_id($id), connection_peer_id($id)`,
`time($t), expiration($e), $t <= $e`, and `agent_authorized(true)` when an
agent was named.
@@ -171,7 +261,8 @@ At the destination node, in this order:
4. The node's `attenuation` rules, checks and policies.
5. Baseline policies: `allow if service($t,$n), granted_service_exact($t,$n)`
and the set, prefix, suffix, per-type and global variants; the check
- `allow_network_target($f,$v) or target_unrestricted(true)`.
+ `allow_network_target($f,$v) or target_unrestricted(true)`; the rules that
+ derive a service grant from an [HTTP grant](#http-grants).
6. The synced mesh policy rules.
All checks must hold, and the first matching policy decides. Without a
@@ -202,10 +293,30 @@ statements.
| `granted_service_exact`, `_set`, `_prefix`, `_suffix`, `_all`, `_all_types` | type, name/set/pattern | control plane and node rules |
| `granted_target_exact`, `_set`, `_prefix`, `_suffix`, `_all`, `_all_facts` | fact, value/set/pattern | control plane and node rules |
| `granted_agent_exact`, `_set`, `_prefix`, `_suffix`, `_all` | pattern | control plane and node rules |
+| `http_granted_service_exact`, `_prefix`, `_suffix`, `_all`, `_all_types` | type, name/pattern | control plane and node rules, for an `http` entry |
+| `granted_method`, `granted_method_any` | type, key, set | control plane and node rules, for an `http` entry |
+| `granted_path_exact`, `granted_path_prefix`, `granted_path_any` | type, key, set/prefix | control plane and node rules, for an `http` entry |
| `service` | type, name | destination node, per request |
| `connection_peer_id` | peer ID | destination node, per request |
| `time` | date | destination node, per request |
| `agent` | identifier | destination node, from the caller's claim |
+| `method` | string | destination node, on an HTTP request: the method as received; `CONNECT` on a tunnel |
+| `path` | string | destination node, on an HTTP request: the path as the backend sees it, leading slash, no query; empty on a tunnel |
+| `host` | hostname | destination node, on an egress request |
+| `port` | integer | destination node, on an egress request |
| `target_fact` | fact, value | destination node, from its own credential |
| `allow_network_target` | fact, value | derived by baseline rules |
| `agent_authorized` | | derived by baseline rules |
+| `http_method_ok`, `http_path_ok` | type, key | derived by baseline rules |
+
+A node's `attenuation` can refer to the request facts. The Datalog dialect
+has no `!=`; a negation is written with `!`:
+
+```yaml
+attenuation:
+ policies:
+ - 'deny if method($m), !($m == "GET");'
+ - 'deny if path($p), $p.starts_with("/admin/");'
+ - 'deny if port($p), !($p == 443);'
+ - 'deny if host("payroll.internal.example.com");'
+```
diff --git a/site/content/docs/reference/sam-node.md b/site/content/docs/reference/sam-node.md
index 24a30041..ad0d5f9b 100644
--- a/site/content/docs/reference/sam-node.md
+++ b/site/content/docs/reference/sam-node.md
@@ -112,6 +112,7 @@ enroll.
| `--discovery-concurrency` | `10` | Concurrent catalog fetches during discovery. |
| `--dht-provider-addr-ttl`, `--dht-max-record-age` | library defaults | DHT record lifetimes. |
| `--backend-probe-timeout` | `2s` | How long a service backend may take to answer before the node declines to advertise it. Raise it for subprocesses that start slowly. |
+| `--secrets-dir` | `/etc/sam/secrets` | Directory holding the credentials that the control plane's [egress destinations](../policy/#egress-destinations) name, one file per credential name. The platform puts the files there; the node reads a file on every request to the destination. |
| `--control-plane-sync-interval` | `15m` | How often signing keys, the ban set, router addresses and the mesh policy are pulled from the control plane. Keep it well below the control plane's `--key-grace-period`; raise it on large meshes. |
| `--key-grace-period` | `24h` | How long a rotated-out control plane key is still accepted for verifying peers. |
| `--monitor-bootstrap` | `2m` | Delay before the router-connection monitor starts. |