
# Your IdP at the edge

Edge sign-in puts your identity provider in front of a private target's apps. A gate on the node checks your portal's session and passes the app `x-agc-user-email` and `x-agc-user-name`. Apps opt in with `[auth] provider = "edge"`; anyone signed in to your portal then skips the sign-in page.

Pick this for internal tools on a private target. It's the least code in the app and keeps your provider's token away from it: the app gets who the person is, and signing out of an app ends only that app's session, never your portal's.

## Ask your infra agent

```text
We want our Agent Cloud target's apps to use our portal's sign-in. Collect, for Agent Cloud: a broker host
inside our session cookie's domain, the session cookie names, the HTTPS URL that returns who a session
belongs to (with the header, prefix and JSON paths for email and name), and the login URL. Don't send any
secret. After Agent Cloud confirms the config, check that the edge runs:
k3s kubectl -n agc-edge get deploy edge over SSM.
```

You'll end with a list of values to send to Agent Cloud, then a running `edge` Deployment in namespace `agc-edge`.

## Steps

1. **Send Agent Cloud the edge config** (the fields under Reference). An Agent Cloud operator sets it on the target. The broker host needs a DNS name pointing at the target like the apps', and a certificate the target serves.
2. **Wait one heartbeat.** The runner creates namespace `agc-edge` with a signing key made in the cluster (Secret `edge-key`, never sent anywhere), the `edge` Deployment from its own image, a NetworkPolicy, and an IngressRoute `broker` for your broker host.

   ```bash
   on_node "k3s kubectl -n agc-edge get deploy edge"
   ```
3. **If validation needs its own credential** (`validate.method = "POST"`), put it on the target yourself. It lives only in the Secret `agc-edge/edge-validate` (key `secret`); Agent Cloud never holds it. Agent Cloud's script does it through an SSM port forward, never in a command parameter, and restarts the edge:

   ```bash
   printf '%s' "$VALUE" | infra/scripts/edge-credential.sh i-0abc1234def567890 us-east-1
   ```

   Agent Cloud's operator supplies the script. It needs the AWS CLI with `session-manager-plugin`, and `kubectl`. Run it again to rotate.
4. **Opt apps in.** An app sets this in `agentcloud.toml`, or an owner makes "the target's sign-in" the default for new apps on General:

   ```toml
   [auth]
   provider = "edge"
   ```

   Webhook paths a sender reaches without signing in, like `"/api/slack/*"`, go in `[auth] public` (at most 20); the app verifies the sender itself ([The edge gate](/docs/build/the-edge-gate.md)).

## How it works

```mermaid
sequenceDiagram
  participant B as Browser
  participant G as Gate (app host)
  participant K as Broker (broker host)
  participant P as Your provider
  B->>G: GET https://camp-bookings.apps.example.test/
  G-->>B: 302 to broker /start, sets __Host-agc_edge_state
  B->>K: /start?app=&return=&state= (with your portal cookie)
  K->>P: validate the session (through the egress proxy)
  K-->>B: 302 to app /__agc/sso?code=
  B->>G: /__agc/sso: code redeemed, __Host-agc_edge set
  G-->>B: the app, with x-agc-user-email and x-agc-user-name
```

The gate sends a browser without an app session to the broker, which reads your cookie, asks your provider, and returns a one-time code the gate turns into an app session.

Only the broker ever reads your provider's cookie, and only on the broker host. That host sits inside your cookie domain; app hosts sit outside it. The broker tries each configured cookie in order until the provider names one. With none, or a refused one, it redirects to `login_url`. When your login can return to another host, it adds its own `/start` address under `login_return_param`. No page is shown at any step.

The code works once, for 60 seconds, for the one app it was minted for. It works only in the browser that started the sign-in, which holds the `state` nonce in `__Host-agc_edge_state` (compared in constant time). The app session is the app, the email, the name and an expiry, signed with the target's key, in `__Host-agc_edge` (HttpOnly, Secure, SameSite=Lax). Before the gate, a middleware empties any client-sent `x-agc-user-email` and `x-agc-user-name`, so an app can trust them.

The edge reaches your provider only through the egress proxy, under the reserved identity `agc-edge`. Agent Cloud lets that identity reach exactly the validation URL's host and port, through the relay. An app pod asking for the same host is refused. The validation host is added to the target's CoreDNS list so the edge resolves it to the proxy.

On an internet-facing target (a public ALB, which needs this config), every app is behind the gate whatever its manifest says, including its health path.

## Reference

| Field | Required | Meaning | Limits |
|---|---|---|---|
| `broker_host` | yes | Host inside your cookie domain; the only one that reads your cookie | DNS name |
| `cookies` | yes | Session cookie names, first found wins; `{name, field}` for POST validation | 1 or more, each up to 64 characters |
| `validate.url` | yes | Called to learn who a session belongs to | `https` only |
| `validate.method` | no | `GET` (default) or `POST` | |
| `validate.header`, `validate.prefix` | yes | GET: header = prefix + session. POST: header = prefix + the `edge-validate` secret | header name up to 64; prefix up to 64 |
| `validate.email`, `validate.name` | yes | Dotted paths in the JSON answer | up to 5 segments |
| `validate.id` | no | Dotted path to the provider's stable id for the person | up to 5 segments |
| `validate.organization` | no | `{path, value}`: accept a session only when the answer holds exactly this organization string, for a provider shared across organizations | value up to 128 characters |
| `login_url` | yes | Where a person without a session signs in | `https` only |
| `login_return_param` | no | Your login's parameter for where to come back to | up to 32 characters |
| `session_seconds` | no | App session life | 300 to 86400; default 8 hours |
| `cache_seconds` | no | How long one validation answer is reused | 0 to 3600; default 300 (a refusal at most 10 s) |
| `csp` | no | Content-Security-Policy on edge apps' responses | one line, up to 1000 characters |

Gate paths on every app host: `/__agc/sso` (the callback), `/__agc/sign-out` and `POST /auth/sign-out`. Sign-out ends only the app session: an app's fetch gets 401 `{"signed_out":true}`, and a page says your workspace session is still there.

## Errors

| code | exit | cause | fix |
|---|---|---|---|
| `ship.edge_unavailable` | 1 | `[auth] provider = "edge"` on an app whose target has no edge config | Remove `[auth] provider`, or ask the target's owner to have edge sign-in configured |
| `manifest.bad_auth` | 2 | `[auth] provider` isn't `"agent.cloud"`, `"edge"` or `"none"` | Fix the value |
| `auth.required` | n/a (HTTP 401) | A non-browser request without an app session | Sign in in a browser first; API clients get no redirect |

A failing example:

```json
{
  "ok": false,
  "product": "agent.cloud",
  "command": "ship",
  "error": {
    "retryable": false,
    "code": "ship.edge_unavailable",
    "message": "camp-bookings asks for its target's sign-in ([auth] provider = \"edge\"), but its target has none configured.",
    "fix": "Remove [auth] provider from agentcloud.toml and use agent.cloud sign-in, or ask the target’s owner to configure edge sign-in."
  },
  "next": [{ "cmd": "agc status", "why": "see the current state before retrying" }]
}
```

## Limits

- Code: 60 seconds, once. State nonce: 10 minutes.

## Agent notes

- Mirrors and rehearsals have no gate. `AGC_EDGE_DEV_USER` stands in on a mirror; in smoke flows, `SIGN IN <email>` sets the two headers on later steps.
- Don't build a session layer in an edge app. Trust the headers; Traefik is the only way into the pod.

## Related

- [The edge gate](/docs/build/the-edge-gate.md)
- [Choosing a sign-in shape](/docs/build/choosing-a-sign-in-shape.md)
- [Network and egress](/docs/targets/network-and-egress.md)
- [Deployment targets (owner view)](/docs/owners/deployment-targets.md)

<!-- feedback:start -->
---
Wrong, outdated or unclear? Run `agc feedback docs "targets/your-idp-at-the-edge: <what is wrong>" --body <file>` with the sentence quoted in the file. No code or app data is sent.
<!-- feedback:end -->
