
# Manifests and updates

Agent Cloud never changes a private target's Kubernetes objects or CloudFormation stack itself. When objects fall behind, the target's row under **Deployment targets** says "Its Kubernetes objects are behind Agent Cloud's (version N of M)", and your infra team runs five steps on the node. Success is `"manifests_behind": false`.

The row lists what's missing and the commands, and the next heartbeat clears it. The runner [upgrades its own image](#runner-self-upgrade-and-the-stack-update-policy), but only a person changes its permissions and objects, so it can't escalate itself.

## Ask your infra agent

```text
Our Agent Cloud target's Kubernetes objects are behind (sha256 <sha256>). Over SSM, run infra-agent.md's
Update section through kubectl diff and show me the whole diff. After I approve, apply, reinstall the
doctor, wait a minute and run it.
```

You'll see the diff first; the console line clears within a minute of the apply.

## Steps

[infra-agent.md](/docs/targets/installing-with-infra-agent-md.md)'s Update section, with its `on_node` helper and the console's sha256:

```bash
on_node "sudo k3s kubectl -n agent-cloud get secret runner-token -o jsonpath='{.data.token}' | base64 -d | sed 's/^/authorization: Bearer /' | curl -fsS -H @- -o /tmp/manifests.yaml https://agent.cloud/runner/v1/manifests"
on_node "echo '<sha256 from the console>  /tmp/manifests.yaml' | sha256sum -c"
on_node "sudo k3s kubectl diff -f /tmp/manifests.yaml"
on_node "sudo k3s kubectl apply -f /tmp/manifests.yaml && rm /tmp/manifests.yaml"
on_node "sudo k3s kubectl -n agent-cloud get configmap agc-doctor -o jsonpath='{.data.doctor\.sh}' | sudo install -m 0755 /dev/stdin /opt/agent-cloud/doctor.sh"
on_node "test -s /opt/agent-cloud/doctor.sh && wc -c /opt/agent-cloud/doctor.sh"
```

| Step | Why |
|---|---|
| Fetch | The token goes from the node's Secret into `curl`, never onto a command line; owners can use **Download manifests.yaml** in **Manage** |
| Check | On `WARNING: 1 computed checksum did NOT match`, reload the console and refetch; never pipe the file straight into `kubectl apply` |
| Diff, apply | The diff shows every change, the doctor script included; apply is idempotent and immediate |

Wait a minute, then run the [doctor](/docs/targets/the-doctor.md); `manifests_behind` lags an apply by up to a minute, so don't re-apply.

## How it works

Every generated object carries a stamp. The runner reads it off its ClusterRole `agc-runner`, hashes the role's live rules, and sends both in each heartbeat (every 60 seconds). A target is behind when one differs from the bundle's:

| Compared | What it is |
|---|---|
| `agent.cloud/manifests-version` | A counter in Agent Cloud's code, one sentence per bump; 0 before stamping. Behind when lower |
| `agent.cloud/manifests-shape` | sha256 of this target's generated objects, the runner image as a placeholder, so a new image is never drift |
| The role's rules hash | A hand edit: "The runner's role was changed on the node: its rules differ from the ones Agent Cloud installs. Re-apply the manifests to put them back." |

Drift is a line under the target, never its state. While upgrades are held, served manifests carry the image the node reports, so an update can't get around the hold.

| Also | |
|---|---|
| `coredns-custom` | The runner's key was never in `kubectl`'s last-applied configuration, so apply, diff and shape skip it |
| Objects a newer bundle drops | Remove them with `kubectl delete` |
| `GET /runner/v1/manifests` | Runner token only: the objects as one YAML list, headers `x-agc-sha256` and `x-agc-manifests-version` |

## Runner self-upgrade and the stack update policy

The runner upgrades its own image, and nothing else, when a heartbeat offers one by digest, unless an owner holds upgrades. CloudFormation updates are never automatic; set the stack policy below first.

| Self-upgrade | |
|---|---|
| Offer | The heartbeat answer's current runner image, only as `<agent.cloud host>/runner@sha256:<64 hex>` |
| Taken when | It differs from what runs, the runner knows its digest, no task is in flight and it isn't stopping |
| Order | The egress proxy (cutting open tunnels; apps reconnect via their pools), then the runner (`Recreate`, `terminationGracePeriodSeconds: 600`), letting in-flight work finish |

**Holds.** An owner's **Hold upgrades** (undone by **Allow upgrades**) in the target's **Manage** panel shows "upgrades held" and is [logged](/docs/owners/activity-log.md). While held, the heartbeat names no image; a fetch before a held runner's first heartbeat is `target.image_unknown`.

**The stack policy.** A new stack takes the node's AMI from the SSM path `/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-6.1-x86_64`, which CloudFormation re-resolves on every update, so even unchanged template text can replace the node. Once an operator records them from the deployed stack, Agent Cloud pins the AMI (`node_ami`) and keeps the original tag key (`agent.cloud/org`, or `agent.cloud/team` before 7 Oct 2026, beside `agent.cloud/target`). The first update swapping path for literal shows the node "Replacement: Conditional"; the values match, so nothing is replaced. Before any update, set the policy `updatePolicy()` generates:

```json
{ "Statement": [
  { "Effect": "Allow", "Action": "Update:*", "Principal": "*", "Resource": "*" },
  { "Effect": "Deny", "Action": ["Update:Replace", "Update:Delete"], "Principal": "*", "Resource": "*" } ] }
```

```bash
aws cloudformation set-stack-policy --stack-name "$STACK" --stack-policy-body file://stack-policy.json
aws cloudformation create-change-set --stack-name "$STACK" --change-set-name review --template-body file://agent-cloud-target.json --capabilities CAPABILITY_NAMED_IAM
aws cloudformation describe-change-set --stack-name "$STACK" --change-set-name review
```

Execute the change set only if nothing unexpected reads `Replacement: True`. A change set can't carry a policy, so it stays on the stack. For an approved replacement or removal (retiring an ALB, rotating the node), that update's policy exempts only the named logical IDs, then the default returns:

```json
{ "Effect": "Deny", "Action": ["Update:Replace", "Update:Delete"], "Principal": "*", "NotResource": ["LogicalResourceId/Alb"] }
```

A rollback because the policy denied a replacement is the policy working: find out why, and allow only named IDs if intended. Never re-run step 1 of an old `infra-agent.md` against a live stack.

## The doctor

The doctor, `/opt/agent-cloud/doctor.sh` on the node, prints one redacted JSON report on the node's health. When an install step, update or release fails, run `on_node "/opt/agent-cloud/doctor.sh"` (not `agc doctor`) and send the whole report. Its checks, fields and fixes are on [The doctor](/docs/targets/the-doctor.md).

## The version matrix

Some product behavior needs a minimum manifests version; the target's row lists what yours lacks, and the doctor's `manifests_version` prints what the node has. The current customer series is version 9; a target with app storage or analytics egress counts one or two above it. Targets Agent Cloud runs itself count their own series, so a change only they need never asks you to re-apply.

| Version | Adds | Since |
|---|---|---|
| 0 | Objects from before stamping; deleting an app needs 1 | before 0.3.0 |
| 1 | The runner may delete app namespaces (only `app-<name>`, by admission policy) and read its role to report its manifests | 0.3.0 |
| 2 | The doctor ships with the manifests (`agc-doctor`), so an update refreshes it | 0.3.0 |
| 3 | App pods resolve granted connection hosts to the egress proxy; the runner keeps one `coredns-custom` key (`get`, `patch` on it) | after 0.3.0 |
| 4 | The egress proxy asks Agent Cloud, per app and host, whether to relay a connection or dial it inside the network | after 0.3.0 |
| 5 | The HTTP API gateway's namespace `agc-egress` and a service account that may read pods, for HTTP API connections | after 0.3.0 |
| 6 | The runner may cordon a node (`patch` on nodes); a customer target carries the rule and never uses it | after 0.3.0 |
| 7 | The [doctor](/docs/targets/the-doctor.md) reports `storage_isolated`, its storage isolation proof; app storage is offered only while a passing run stands | after 0.3.0 |
| 8 | Optional observability collectors on every node with separate short-lived ingest credentials; nothing is exported unless streams are turned on | after 0.3.0 |
| 9 | The runner may read pod metrics (`get`, `list` on pods in `metrics.k8s.io`) in each app's own namespace, so `agc status` shows each service's memory in use against its limit | after 0.3.0 |

k3s's version is pinned by sha256 and set at install.

## Related

- [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/manifests-and-updates: <what is wrong>" --body <file>` with the sentence quoted in the file. No code or app data is sent.
<!-- feedback:end -->
