> ## Documentation Index
> Fetch the complete documentation index at: https://ryvn.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Cloud connections

> How Ryvn acts in your cloud through an identity you create and control

A cloud connection is how Ryvn acts in your AWS account, Google Cloud project or Azure subscription. It goes through an
identity you create and control, and Ryvn stores no keys for it. Ryvn uses an environment's cloud connection to
provision, upgrade and deprovision that environment's infrastructure. In Ryvn's API and CLI, the connection is the
environment's access identity.

Each environment has its own cloud connection.

A cloud connection is separate from the agent's [infrastructure permissions](https://ryvn.ai/docs/provision/existing-cluster.md#infrastructure-permissions),
which the Ryvn agent uses from inside the cluster to run Terraform services. An
[audit export connection](https://ryvn.ai/docs/connections/audit-export.md) is another cloud connection: it uses the same mechanism to write
audit records to your bucket.

## How it works

Cloud connections use OIDC federation. Your cloud trusts your organization's Ryvn issuer and accepts tokens for one
subject, `access-identity:<id>`, where `<id>` is the access identity ID.

**1. Setup (once)**

You run the setup script from the dashboard. It creates the trust in your cloud: a trust for Ryvn's issuer and an
identity that only this subject can use. Running the script again updates the existing resources in place,
including the provisioning role's permissions on Google Cloud and Azure.

**2. Sign**

For each provisioning run, Ryvn signs an OIDC token with the subject `access-identity:<id>`. The token is valid for
at most 30 minutes.

**3. Verify**

Your cloud checks the token's issuer, audience and subject, then returns short-lived credentials for the identity the
script created.

**4. Expire**

The credentials expire on their own. You can revoke the connection at any time by deleting the identity.

## What an environment's setup script creates

The script names each resource with your Ryvn hub's resource prefix, shown as `<prefix>` below, and the first 8
characters of the access identity ID. The setup script shows the exact names. It is safe to run again.

> [tab] AWS
>
> * **IAM OIDC identity provider** for your organization's Ryvn issuer, with the audience `sts.amazonaws.com`. The
>   script creates it or reuses an existing one, so environments in the same account share it.
> * **IAM role** `<prefix>-provisioner-<first 8 of id>`, one per environment. Its trust policy allows
>   `sts:AssumeRoleWithWebIdentity` only when the token's subject is `access-identity:<id>`. The role holds the
>   provisioning permissions.
>
> The script refuses to change a role that belongs to another access identity. It prints the role ARN; nothing needs
> to be pasted back into Ryvn.

> [tab] Google Cloud
>
> * **Workload identity pool** `<prefix>-<organization id>` and **OIDC provider** `<prefix>-oidc` that trusts your
>   organization's Ryvn issuer. The script creates them or reuses them, so environments in the same project share them.
> * **Service account** `<prefix>-prov-<first 8 of id>`, one per environment, with the provisioning roles.
> * **Binding** of `roles/iam.workloadIdentityUser` on the service account for the exact subject
>   `access-identity:<id>` in the pool. No other subject can impersonate it.
>
> The script refuses to reuse a service account that belongs to another access identity, or a provider with the same
> name that trusts a different issuer. A different issuer means another Ryvn organization or hub uses that project;
> use another project.
>
> Whoever runs the script needs Service Usage Admin, Service Account Admin, Role Administrator and Project IAM Admin on
> the project. The script also reads, and when needed creates, restores or updates, the workload identity pool and
> provider, so it needs IAM Workload Identity Pool Admin. IAM Workload Identity Pool Viewer is enough only when an
> active pool and provider already match.
>
> The script prints the project number to paste into Ryvn.

> [tab] Azure
>
> * **Resource group** `<prefix>-provisioner`, created if it does not exist. Environments in the same subscription
>   share it.
> * **User-assigned managed identity** `<prefix>-provisioner-<first 8 of id>`, one per environment, tagged with its
>   access identity ID.
> * **Federated credential** `<prefix>-oidc-<first 8 of id>` on the managed identity. It trusts your organization's
>   Ryvn issuer for the subject `access-identity:<id>` and the audience `api://AzureADTokenExchange`.
> * **Custom role** `<prefix>-provisioner-<first 8 of id>-apply`, assigned to the managed identity on the subscription.
>
> The script refuses to reuse a managed identity that belongs to another access identity. It prints the managed
> identity's client ID to paste into Ryvn.

## Guarantees

* **No static keys.** Ryvn stores no access keys, service account keys or client secrets for the connection.
* **Scoped to one environment.** Your cloud accepts only the environment's own subject, `access-identity:<id>`.
* **Short-lived credentials.** Each provisioning run gets new credentials that expire on their own.
* **Revocable by you.** Deleting the environment's identity in your cloud stops Ryvn from getting new credentials.

## Revoke a cloud connection

Ryvn also uses the cloud connection to deprovision the environment. To delete an environment, deprovision it first, then
remove its identity.

`ryvn get teardown-script --access-identity-id <id>` prints a script that removes the identity. It checks that your CLI
targets the environment's saved account, project or subscription before it deletes anything. Get the script before you
delete the environment: it is no longer available afterwards.

To remove the identity by hand, sign in to the environment's account, project or subscription and delete it:

> [tab] AWS
>
> ```bash theme={null}
> aws iam delete-role --role-name <prefix>-provisioner-<first 8 of id>
> ```
>
> Run this with the AWS CLI signed in to the environment's account; every account uses the same role name. Detach or
> delete the role's policies first; IAM refuses to delete a role that still has them.

> [tab] Google Cloud
>
> ```bash theme={null}
> gcloud iam service-accounts delete \
>   <prefix>-prov-<first 8 of id>@example-project.iam.gserviceaccount.com \
>   --project=example-project
> ```

> [tab] Azure
>
> ```bash theme={null}
> az identity delete --subscription <subscription id> \
>   --resource-group <prefix>-provisioner --name <prefix>-provisioner-<first 8 of id>
> ```
>
> Deleting only the federated credential `<prefix>-oidc-<first 8 of id>` also revokes the connection. Do not delete
> the `<prefix>-provisioner` resource group: it removes every environment's managed identity in that subscription.

> [!WARNING]
>
> The IAM OIDC identity provider (AWS), the workload identity pool and provider (Google Cloud) and the
> `<prefix>-provisioner` resource group (Azure) are shared. Deleting them cuts off every environment in that account,
> project or subscription. If an audit export connection uses the same identity provider or pool, deleting it also
> stops audit export.

Credentials Ryvn already obtained stay valid until they expire. Ryvn cannot get new ones after you revoke the connection.
