
# Connections

A connection lets your organization's apps use Snowflake, DuckLake, Arrow Flight SQL, Redis, ClickHouse or your own HTTP API without anyone pasting a credential into them.
An owner adds it and decides which apps may read or write; agents ask with `agc connections request <name> --why "<reason>"`.

## Do it in the console

Only owners edit connections; builders see the page "View only".

1. In the left menu, open **Infrastructure**; the **Connections** tab opens.
2. Click **Add connection**, then **Add** on Snowflake, Flight SQL, DuckLake, HTTP API, Redis or ClickHouse.
3. Fill in **Name** and the kind's fields (see [Reference](#reference)), then click **Add**.
4. On the connection's page, under **Production read**, open **+ Add production read credential** (a token for Flight SQL), paste it, and click **Save credential**. Add **Production write** and **Local** the same way if you need them.
5. Under **Access**, set **Read requests**, **Write requests** and **Local · agc up**, then click **Save access rules**.

It's working when the connection's row shows **Ready** and the agent's `agc connections` lists the capability as `granted`. **Test connection** on the connection's page tries every saved credential again.

Requests that need an owner show under **Needs you** on **Connections** and on the connection's page. Answer with **Grant read** (or **Grant write**) or **Decline**. To grant before anyone asks, open **+ Grant an app** under **Apps with access**, pick the **App** and **Capability** (**Read**, or **Read and write**), and click **Grant**. **Revoke** on an app's row takes it away.

## Steps

The agent's side. `agc connections` lists each connection with its capability states (`granted`, `available`, `needs approval`, `pending`, `disabled`) and the variable names the app gets:

```bash
agc connections
agc connections request snowflake --why "weekly revenue chart reads ORDERS"
```

The app declares the need in `agentcloud.toml`, and `agc ship` refuses a release that names a capability the app wasn't granted:

```toml
[connection.snowflake]
access = "read"
```

## How it works

Which credential an app gets:

| Console name | Used by |
|---|---|
| **Production read** | Live apps and rehearsals with a read grant. |
| **Production write** | Live apps with a write grant (they get it in place of read). Without one, no app can be granted write. |
| **Local** | Local runs (mirrors, from `agc up` or `agc check`), when the **Local** rule says so. |

Credentials are stored encrypted and shown back only as a fingerprint. Each is tested when saved, and saved even if the test fails. Snowflake and DuckLake tests record whether the credential can write; DuckLake reports the catalog and the bucket separately. For Flight SQL, Agent Cloud reads access and expiry from the token's claims and marks the row "Not verified yet", so the app's own health check is the end-to-end test. The add form lists the addresses to allow in Snowflake's network policy or the DuckLake catalog.

The **Local · agc up** rule decides what reaches a developer's machine. **Production read credential (read-only)** saves a second credential: agc fetches it at each start without writing it to disk, and it's offered only while the production read credential tests read-only. Where the organization's default target is private, choosing it also needs "Agents on laptops really need &lt;name&gt;’s production data" ticked. Activity logs each fetch as "gave a laptop".

A grant covers one app, one capability and one connection. For an agent's request, **Allow at once** grants on the spot, **An owner approves** waits under **Needs you**, and **Don’t offer** refuses with `connection.disabled`. At Start an app, an owner's pick is granted when the app is created and a builder's pick becomes a request. Until a person approves a release, its rehearsal gets only credentials verified read-only, and the release's page lists what was held back.

An **HTTP API** connection holds one OAuth client and is called through an API gateway that adds it. Only apps on your organization's own targets can hold one, and no mirror gets it.

**Redis** and **ClickHouse** connections are the app's own store, granted as read and write, in one variable named after the connection (`redis` gives `REDIS_URL`). Each Redis rehearsal gets an empty Redis of its own; ClickHouse rehearsals use the **Copies** server, whose user production must refuse. Their page shows **Checks** instead of credentials: Agent Cloud tests on save, each target's runner checks from where apps run, and apps get the store once every check passes.

A DuckLake local run connects to the catalog from the developer's machine, so a catalog that allows only Agent Cloud's addresses refuses it. A Flight SQL connection **inside a target’s network** can be granted only to apps on that target.

**A mirror reads a target's lake with no VPN.** On your own target, a granted Flight SQL connection's local runs go through Agent Cloud: the target's runner runs each read query, and the lake's token never reaches the laptop.

## Reference

| Kind | Settings | Each credential |
|---|---|---|
| Snowflake | Account, warehouse, database | Role and user, plus a key pair (PKCS#8 PEM, optional passphrase) or an OAuth client (client id, secret, https token URL) |
| DuckLake | Catalog host, port (5432 by default), database; data path `s3://bucket/prefix/` or `gs://bucket/prefix/`; region for `s3://` | Postgres user and password, plus an HMAC key id and secret |
| Flight SQL | Host, port (443 by default), catalog; **on the internet** or **inside a target’s network**; optional root CA | Username (`token` by default) and token |
| Redis | **Production URL** (`rediss://host:6379/0`) | Optional user, and password |
| ClickHouse | **Production URL** and **Copies URL** (`https://host:8443/database`) | User and password for each |

| Rule | Choices | Default |
|---|---|---|
| **Read requests** | **Allow at once**, **An owner approves**, **Don’t offer** | Allow at once |
| **Write requests** | The same; disabled until a Production write credential exists | An owner approves |
| **Local · agc up** | **Sample data, nothing from &lt;name&gt;**; **Production read credential (read-only)**; **Local credential** | Sample data for Flight SQL, and for any kind when the organization has a default target; otherwise Local credential |

| You do | Effect |
|---|---|
| **Revoke** | The app loses the connection at its next release, local runs at their next start. Running processes keep their environment. |
| **Edit … credential** > paste > **Save credential** | The new credential reaches apps at their next release or local start. The old one stays valid at the provider: revoke it there too. |
| **Mark rotated** | Clears **Rotate these credentials at the provider**, shown when an agent that received the credentials for a local run has since lost access. |

A replaced Flight SQL token stays valid until it expires, unless the server's signing key is rotated.

## Errors

| Code | Exit | Cause | Fix |
|---|---|---|---|
| `connection.approval` | 10 | The request waits for an owner. | Grant or decline it under **Needs you**. |
| `connection.disabled` | 12 | The rule is **Don’t offer**, or no production credential exists for that capability. | Change the rule or add the credential. |
| `connection.not_granted` | 12 | `agc ship` found a `[connection.*]` the app isn't granted. | The agent requests it; an owner grants it. |
| `connection.not_found` | 12 | No connection by that name. | Run `agc connections`. |
| `connection.not_in_org` | 12 | The agent hasn't joined the app's organization. | Give the builder a prompt with a join code. |
| `connection.not_reachable` | 1 | The connection is inside another target's network. | Deploy the app to that target. |
| `connections.no_reason` | 2 | No name, or no `--why`. | Pass both. |

A write request on a connection with no write credential, exit 12:

```json
{
  "ok": false,
  "product": "agent.cloud",
  "command": "connections request",
  "error": {
    "retryable": false,
    "code": "connection.disabled",
    "message": "snowflake doesn’t offer write to apps (no production role for it yet).",
    "fix": "Ask an organization owner; the organization doesn’t offer that to apps.",
    "docs": "agc help connections"
  },
  "next": [{ "cmd": "agc connections", "why": "what the organization has made available, and how to ask" }]
}
```

## Limits

- A connection name is 1 to 40 characters: lowercase letters, digits and hyphens, starting with a letter. It prefixes the variables, so `lake` gives `LAKE_URI` and so on.
- A Flight SQL token's row warns from 14 days before it expires.
- For apps on a private target, a DuckLake catalog must listen on 5432; the page warns and names the affected apps when it doesn't.

## Agent notes

- Relay `data.approval.url` exactly as printed; asking again returns the same pending request. The owner finds it under **Needs you** at the top of **Connections**.
- A revoke reaches a local run only at its next `agc up`, worker restart or `agc exec`. A file-watcher reload (`node --watch`) keeps the old environment.

## Related

- [Connection variables](/docs/reference/app-runtime-contract.md#connection-variables)
- [Mirror vs production](/docs/concepts/mirror-vs-production.md)
- [Approvals](/docs/concepts/approvals.md)
- [Deployment targets](/docs/owners/deployment-targets.md)
- [Activity log](/docs/owners/activity-log.md)
- [Error code catalog](/docs/reference/error-code-catalog.md)

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