
# Installing with infra-agent.md

`infra-agent.md` installs one private target: a CloudFormation stack, k3s from an offline bundle, and Agent Cloud's runner. An owner downloads it; your infra engineer or their agent runs it with AWS CLI access. Success is step 6 printing a `registered` line and the console turning **Healthy** within two minutes.

Download it from **Deployment targets** → the target's **Manage** → **Download infra-agent.md**. Each download carries a single-use registration code and voids unused codes. Treat the file as a secret until the target is Healthy, and download a new one rather than reusing an old copy.

## Ask your infra agent

```text
Here is infra-agent.md for our Agent Cloud target. Before deploying, read the CloudFormation template in
step 1 and list what it creates. Then run the steps in order from a shell with our AWS credentials, run
each step's Check, and stop if one fails. If anything fails, run the doctor in step 7 and show me its JSON.
Never pass the TLS private key as an SSM send-command parameter; use an interactive session for step 4.
```

You'll see the stack deploy, the node come `Online` in SSM, and the target turn **Healthy** in the console.

## Steps

You need:

- AWS CLI, `python3` and the Session Manager plugin;
- permission to deploy CloudFormation with `CAPABILITY_NAMED_IAM` and to use SSM;
- a wildcard certificate and key for `*.<internal domain>`, or an ACM certificate if the target has an internal ALB.

The runbook opens by setting `AWS_REGION`, `TARGET`, `CODE` and `STACK` (`agent-cloud-<target id>`). It then defines `on_node`, which runs a command on the node with `aws ssm send-command --document-name AWS-RunShellScript` and a 1800-second timeout.

| Step | What it does | Check that must pass |
|---|---|---|
| 1. Deploy the template | Writes `agent-cloud-target.json`, runs `aws cloudformation deploy --capabilities CAPABILITY_NAMED_IAM` tagged `agent.cloud/org` and `agent.cloud/target`, reads the `InstanceId` output into `NODE` | `aws ssm describe-instance-information … PingStatus` prints `Online`, within ten minutes |
| 2. Fetch the bundle | Downloads the bundle, the k3s binary and its airgap images into `/opt/agent-cloud` with the code | `sha256sum -c SHA256SUMS` ends with three `OK` lines |
| 3. Install k3s, offline | Runs `install-k3s.sh`: k3s `v1.35.9+k3s1`, then waits for the node and Traefik | Output ends with `k3s: node Ready` |
| 4. TLS certificate | Creates Secret `apps-tls` in namespace `agent-cloud` | `on_node "k3s kubectl -n agent-cloud get secret apps-tls"` lists it |
| 5. Runner and egress proxy | Applies `manifests/runner.yaml`, Secrets `runner-registration` and `registry-pull`, `manifests/egress.yaml`, `manifests/coredns-custom.yaml`; restarts CoreDNS; installs the doctor | Output ends with `deployment "runner" successfully rolled out` |
| 6. Registration | The runner registers itself with an STS proof | `on_node "k3s kubectl -n agent-cloud logs deploy/runner \| grep -m1 registered"` prints a line; console shows **Healthy** |
| 7. Doctor | Prints one JSON report | See [The doctor](/docs/targets/the-doctor.md) |

For step 4, `send-command` parameters persist in SSM's history and often its logs, so open an interactive session instead:

```bash
aws ssm start-session --target "$NODE"
```

Run `umask 077`, paste the certificate and key into `/tmp/tls.crt` and `/tmp/tls.key`, then run the runbook's three `kubectl` lines, which delete both files at the end. For a first try without a certificate, the runbook has a one-line `openssl` command that makes a self-signed one on the node; browsers will warn. The registration code does travel as an SSM parameter in steps 2 and 5. That's acceptable only because it's single-use and spent within minutes.

DNS: without an ALB, point `*.<internal domain>` at the node's private IP (the stack's `PrivateIp` output). With an internal ALB, your zone's owners add one CNAME per app to the `AlbDnsName` output; until then, call the ALB's name with a `Host:` header.

## How it works

Most options are settings of the target, entered when an owner adds it and rendered into its template. Only `CreateSsmEndpoints` and `InternetEgress` are deploy-time parameters, because an ALB's CIDR list can't be a CloudFormation parameter without a rule per entry. A target that sets no option renders the plain template.

The default node has no internet route, so Agent Cloud serves everything it installs. `GET /targets/<id>/bundle` is a small tar.gz with `VERSION`, `SHA256SUMS`, k3s's own `install.sh` at the pinned tag, `install-k3s.sh`, `doctor.sh` and the three manifests. The large pieces come from `/targets/<id>/bundle/k3s` and `/targets/<id>/bundle/k3s-images`, streamed from k3s's GitHub release with an `X-Agc-Sha256` header, and the sums are checked before anything runs. Every bundle URL checks the code without spending it; only registration spends it. The runner image is pulled from Agent Cloud's registry front, at first with the code as the password in `registry-pull`.

## Reference

### Parameters and target settings

| Kind | Name | Effect |
|---|---|---|
| Parameter | `CreateSsmEndpoints` | `true` (default in a VPC you own) creates the `ssm`, `ssmmessages`, `ec2messages` endpoints. Pass `false` if the VPC already has them with private DNS. |
| Parameter | `InternetEgress` | Only in a shared-VPC template. `true` (default) opens 443 from the node to the internet so SSM works through the NAT. |
| Console setting | Shared VPC | "Shared from another account (RAM)". `CreateSsmEndpoints` defaults to `false`; the runbook deploys with `--parameter-overrides CreateSsmEndpoints=false InternetEgress=true`. |
| Console setting | Internal ALB certificate | An ACM certificate ARN; the stack then owns an internal ALB that ends TLS with it. |
| Console setting | ALB sources | CIDRs, /8 to /32, never `0.0.0.0/0`, allowed to reach the internal ALB on 443. |
| Console setting | Host pattern | A DNS name with `{app}` exactly once, replacing `<app>.<domain>`. |
| Agent Cloud operator | Public ALB subnets, log days | An internet-facing ALB; only on a target with [edge sign-in](/docs/targets/your-idp-at-the-edge.md). Ask Agent Cloud. |

A shared VPC is the one case where the node gets internet egress, and the doctor's `internet_blocked` then reads `false`. App pods stay egress-only by NetworkPolicy either way. Pick it only when you can't create endpoints in the VPC.

### Optional resources

- **Internal ALB:** `AlbSecurityGroup`, `Alb` (scheme `internal`), `AlbTargetGroup` (HTTPS to the node's 443, health matcher `200-499`), `AlbListener` (HTTPS 443, `ELBSecurityPolicy-TLS13-1-2-2021-06`). The node's 443 then admits only the ALB's security group. Output: `AlbDnsName`.
- **Public ALB:** `PublicAlbSecurityGroup` (443 from anywhere, nothing else), `PublicAlb` in your public subnets, `PublicAlbListener` (default action: fixed 404), `PublicAlbHosts1…` rules forwarding only the target's hosts, `WebAcl` with `AWSManagedRulesAmazonIpReputationList`, `AWSManagedRulesAnonymousIpList`, `AWSManagedRulesCommonRuleSet`, `AWSManagedRulesKnownBadInputsRuleSet`, `AWSManagedRulesSQLiRuleSet` and `RatePerIp` (2,000 requests per IP per five minutes), and `AlbLogs`, an S3 bucket retained when the stack is deleted. `HostingProviderIPList`, `SizeRestrictions_BODY` and `RatePerIp` count rather than block. Outputs: `PublicAlbDnsName`, `PublicAlbListenerArn`, `PublicAlbSecurityGroupId`, `AlbLogsBucket`. Your DNS and TLS owners attach the wildcard certificate to the listener as an SNI certificate.

## Errors

These are HTTP answers from Agent Cloud to the node, not `agc` envelopes, so there's no exit code.

| code | exit | cause | fix |
|---|---|---|---|
| `target.code_refused` | n/a (HTTP 403) | The code is unknown, used, expired, or for another target | Download a fresh infra-agent.md and use its `CODE` |
| `target.bundle_unavailable` | n/a (HTTP 502) | Agent Cloud couldn't fetch a k3s piece, or k3s's install script didn't match its pinned sum | Try again in a minute; tell Agent Cloud if it persists |
| `target.register_refused` | n/a (HTTP 403) | Registration was refused; the message names the reason | Run the doctor and send its output to Agent Cloud; see [Registration and identity](/docs/targets/architecture-of-a-private-target.md#registration-and-identity) |

A failing example: step 2 with a code from an older download. The runbook's `curl -fsS` prints only `curl: (22) The requested URL returned error: 403`; the body it hides is:

```json
{"error":{"code":"target.code_refused","message":"The registration code is unknown, used or expired, or for another target.","fix":"Download a fresh infra-agent.md from the console."}}
```

Other failures print plain text: `k3s: node not Ready after 5 minutes` (run the doctor), and `doctor.sh is empty: the jsonpath was mangled by quoting; redo that line` (run the line again exactly as written). If `PingStatus` never reaches `Online`, the node can't reach SSM: check `CreateSsmEndpoints`, or `InternetEgress=true` in a shared VPC.

## Limits

- Registration code: single use, 24 hours.
- An ALB needs two or more subnets in two or more availability zones; the node goes in the first. Agent Cloud can't check zones without AWS credentials, so pick them yourself.
- Node sizes: see [Sizing and capacity](/docs/targets/sizing-and-capacity.md).

## Agent notes

- Don't re-run step 1 against an existing stack without a reviewed change set: it's a stack update and can replace the node ([stack policy](/docs/targets/manifests-and-updates.md#runner-self-upgrade-and-the-stack-update-policy)).
- Don't loop on step 6. If no `registered` line appears, run the doctor and read `runner_log`.
- With a public ALB, the template written in step 1 holds its resources (`PublicAlb`, `WebAcl`, `AlbLogs`); the runbook's prose describes the internal ALB, so list them from the template.
- To remove a target, follow [Removing a target](/docs/owners/deployment-targets.md#removing-a-target).

## Related

- [Architecture of a private target](/docs/targets/architecture-of-a-private-target.md)
- [Registration and identity](/docs/targets/architecture-of-a-private-target.md#registration-and-identity)
- [The doctor](/docs/targets/the-doctor.md)
- [Deployment targets (owner view)](/docs/owners/deployment-targets.md)

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