
# Architecture of a private target

A private target runs your organization's apps on one EC2 node in a private subnet of your own AWS account. An owner adds it under **Deployment targets** and hands the generated `infra-agent.md` to your infra team; it's done when the badge reads **Healthy**. Agent Cloud never holds an AWS credential.

The default node rules allow HTTPS to `agent.cloud`, `relay.agent.cloud` and the VPC; a shared-VPC install can also allow internet HTTPS for SSM. Agents work as on Agent Cloud's own servers. Your VPC gets the running app, its inbound traffic and its network boundary; builds, the app's Postgres and approvals [stay on Agent Cloud](#what-lives-where).

## How it works

1. An owner adds the target (account, region, VPC, subnets, internal domain, node size; no credentials) and downloads `infra-agent.md`.
2. Your infra team runs it: one CloudFormation stack, k3s installed offline from Agent Cloud's bundle, your TLS certificate, then the runner and egress proxy.
3. The runner [registers](#registration-and-identity) by signing `sts:GetCallerIdentity` with the node's instance role.
4. It long-polls for its target's tasks (reserve, rehearse, release, scale, prune, remove) and sends a heartbeat every minute.
5. On `agc ship`, Agent Cloud builds, rehearses and gets approvals; your runner pulls the image and switches the app's route.

Inbound, people reach `https://<app>.<internal domain>` on 443 and Traefik routes by host; with an internal ALB, only the ALB's security group reaches the node. Outbound, a NetworkPolicy lets app pods reach only the egress proxy (TCP 5432 and 8443), their own app's pods and cluster DNS. The proxy carries Postgres and granted connections to the relay, and sign-in and email to Agent Cloud, routing by DNS and TLS SNI without reading the bytes ([Network and egress](/docs/targets/network-and-egress.md)).

## Registration and identity

At install step 6 the runner sends the runbook's registration code and an `sts:GetCallerIdentity` request signed by the node's instance role. Agent Cloud forwards it to AWS to learn the account and role. The code says which target, the signature where the runner runs, so a leaked runbook can't register a runner in another account. Success is `registered: target <id>` in the runner's log:

```bash
on_node "k3s kubectl -n agent-cloud logs deploy/runner | grep -m1 registered"
```

To register again after **Revoke runner** or with an expired code, run step 5 of a fresh `infra-agent.md`, then restart the runner, which reads the code only at start:

```bash
on_node "k3s kubectl -n agent-cloud rollout restart deploy/runner"
```

The runner reaches IMDSv2 over host networking, which [app pods can't](/docs/security/tenant-isolation.md#isolation-on-private-targets), and signs `POST /` to `sts.<region>.amazonaws.com` with the body `Action=GetCallerIdentity&Version=2011-06-15` and a signed `x-agc-target: <target id>` header, so a proof for one target can't be replayed for another. It sends code and proof to `POST /runner/v1/register` and gets a 60-minute `agcr_` token; one copied off the node is dead within the hour.

Agent Cloud checks the proof before forwarding it, so it can't be pointed elsewhere:

| Part | Must be |
|---|---|
| URL | `https://sts.amazonaws.com/` or `https://sts.<target region>.amazonaws.com/`, no port, path or query |
| Body, `x-agc-target` | Exactly the GetCallerIdentity body; the target's id, signed |
| Headers forwarded | Only `authorization`, `content-type`, `host`, `x-amz-date`, `x-amz-security-token`, `x-agc-target` |
| AWS's answer | `arn:aws:sts::<account>:assumed-role/<role>/…` with the target's account and the template's role, `agent-cloud-runner-<12 characters of the target id>` |

The code is spent in the transaction that creates the runner record; registering again revokes the previous runner. The runner renews every 40 minutes with a fresh proof from the same account and role. Since renewal needs a proof anyway, a token expired up to 7 days ago may still renew, so a node off overnight needs no new code. A restarted runner tries the saved `runner-token` first, then the code.

A runner token works only on its own routes under `/runner/v1/` and at the relay for its own target's apps; any other route answers 403 `auth.forbidden`. **Revoke runner**, in the target's **Manage** panel, makes every route that checks the token refuse it at once, renewal included.

## Reference

### What lives where

| Piece | Where it runs |
|---|---|
| App pods: web, worker, rehearsals, smoke checkers | Your node, namespace `app-<name>` |
| Runner and egress proxy | Your node, namespace `agent-cloud`, Agent Cloud's runner image by digest |
| Traefik | Your node, the copy bundled with k3s, serving your certificate |
| Images | Built by Agent Cloud, never in your account; pulled from the registry front `agent.cloud/v2/` with a one-hour token scoped to one app |
| The app's Postgres | Agent Cloud's account, reached only through the relay |
| Approvals, rehearsal results, receipts, console, sign-in, email | Agent Cloud |

### The AWS footprint

With no options set, the template creates only:

| Logical ID | What it is |
|---|---|
| `RunnerRole`, `RunnerProfile` | IAM role with only `AmazonSSMManagedInstanceCore` |
| `NodeSecurityGroup` | 443 in from the VPC CIDR; 443 out to Agent Cloud, the relay and the VPC |
| `SsmEndpoint`, `SsmmessagesEndpoint`, `Ec2messagesEndpoint`, `EndpointSecurityGroup` | SSM interface endpoints, skipped with `CreateSsmEndpoints=false` |
| `Node` | One Amazon Linux 2023 instance in the first private subnet, IMDSv2 required, hop limit 1, 100 GiB encrypted gp3 |

An internal ALB, a public ALB with a WAF, and shared-VPC settings are [optional](/docs/targets/installing-with-infra-agent-md.md).

### What the runner may do in your cluster

ClusterRole `agc-runner` covers namespaces, secrets, services, pods, deployments, NetworkPolicies and Traefik routes. The ValidatingAdmissionPolicy `agc-runner-namespaces` lets it delete only namespaces named `app-…`. Its Roles grant `get` on its own role and `get`/`patch` on the one ConfigMap `coredns-custom`, nothing else. It never changes its own permissions; a person applies [manifest updates](/docs/targets/manifests-and-updates.md).

### The runner's credentials

| Credential | Shape | Lifetime | Where it lives |
|---|---|---|---|
| Registration code | `agct_` plus 26 characters | Once, within 24 hours; a new runbook download voids an unused one | `infra-agent.md`, then Secret `agent-cloud/runner-registration`; stored hashed |
| Runner token | `agcr_` plus 32 characters | 60 minutes, renewed every 40 | Secret `agent-cloud/runner-token`, mounted by the egress proxy; stored hashed |
| Registry pull | Basic auth, user `agc` | The code until registration, then the runner token | Secret `agent-cloud/registry-pull` |

The runner token's routes under `/runner/v1/` are its target's tasks, task environments and claim renewals, heartbeat, renew, state, its own manifests and their version, and the egress check.

## Errors

Registration fails with HTTP 403 `target.register_refused` in the runner's log, never an `agc` exit code. Its `fix` always says to run the doctor; its `message` names the cause ([Error code catalog](/docs/reference/error-code-catalog.md)):

| `message` | Fix |
|---|---|
| "The registration code is unknown, used or expired." or "…was used a moment ago." | [Register again](#registration-and-identity) |
| "The proof comes from AWS account …, not …" | Deploy the stack in the target's account |
| "The proof comes from the role …, not …, the one the template creates." | Use the stack's `RunnerProfile` as the instance profile |
| "AWS STS refused the proof (HTTP …)." | Check the node's clock and role |
| `target.renew_refused`: "This runner was revoked." or "The proof comes from another role than the one that registered." | Register again |
| `auth.invalid` (HTTP 401): the token is unknown, revoked or long expired | Register again |

`agc db query --env prod` for an app here answers `target.private_data` (exit 12) unless an organization owner turned on "Agents may read this organization's apps' production databases" under General settings. With it on, a connected Builder or Read-only agent's query runs read-only on production as a `query` task your runner claims, reading through the relay like the app's pods ([Reading production safely](/docs/data/reading-production-safely.md)).

A refusal logs `/runner/v1/register: HTTP 403 {"error":…}`. With neither token nor code it logs `no runner token and no REGISTRATION_CODE: download a fresh infra-agent.md and run step 5 again`. `IMDSv2 token: HTTP …` or `the instance has no role` means it can't reach its role: check the instance profile.

## Limits

One node per target ([sizes](/docs/targets/sizing-and-capacity.md)) and one runner. Apps are internal by default; a public ALB exists only on a target that also has [your IdP at the edge](/docs/targets/your-idp-at-the-edge.md).

## Agent notes

- `agc status` shows the app's target with `internal: true` unless it uses a public ALB, and `mirrors: empty`: mirrors start from migrations and seed data.
- After **Revoke runner**, the token is refused at once, renewal included.

## Related

- [Installing with infra-agent.md](/docs/targets/installing-with-infra-agent-md.md)
- [Production data protection](/docs/security/production-data-protection.md)
- [Deployment targets (owner view)](/docs/owners/deployment-targets.md)
- [Where apps run](/docs/concepts/where-apps-run.md)

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