# Cloud runtime identities

> For the complete documentation index, see [llms.txt](https://docs-stg.ringleader.dev/llms.txt).


> A runtime identity is the cloud identity a workstation runs as, and it decides what the software on the workstation can do in your cloud.


A **runtime identity** is the cloud identity that a cloud workstation runs as. Whatever that identity can do in
your cloud, the software on the workstation can do too, including any AI coding agent. It is separate from the
identity Ringleader signs in with to build the workstation. A CloudIdentity declares a runtime identity in
`spec.serviceAccount`.

## Runtime identity

Without `spec.serviceAccount`, an Azure or AWS workstation starts with no attached service account or managed
identity. Nothing inside it can act as any cloud identity. Google Cloud differs, as
[the next section](#runtime-identities-by-cloud) says.

With `spec.serviceAccount`, Ringleader provisions a dedicated identity, grants it exactly the roles you
declare, and attaches it to the workstation. That identity is a service account on Google Cloud, a
user-assigned managed identity on Azure, or an IAM role and its instance profile on AWS. An agent working in
the workstation then holds its own scoped, revocable identity, never the operator's.

The identities are selected and not merged, so the CloudIdentity that declares `serviceAccount` must also
carry the full credential path and placement. Otherwise a workstation that matched it would win an
identity with no way to create a VM at all.

## Runtime identities by cloud

### Runtime identities on Google Cloud

Declaring `serviceAccount` is supported on Google Cloud.

A cloud workstation must present a Google-signed instance-identity assertion to come up. Google issues that
assertion only for a VM that has a service account attached. When you declare none, Ringleader creates a
service account named `rl-box-noroles`, which holds no roles, and attaches it. The software on the
workstation can then act as nothing in your project.

Whether the workstation can start depends only on Google's signature and the instance's identity claims
(project, zone, instance name). It never looks at the service account's IAM roles, so an account with no roles
works exactly like any other.

<div class="callout callout-warning">
  <p class="callout-title">The project&rsquo;s default service account is a fallback</p>
  <div class="callout-body">
    If your project refuses to let Ringleader create <code>rl-box-noroles</code>, Ringleader attaches the project&rsquo;s
default Compute Engine service account instead. The workstation&rsquo;s status says so. That account holds
whatever roles the project gave it. In many projects, especially older ones, it has the Editor role, which can
change almost anything in the project. Check in the console under IAM. Look for the account ending in
<code>compute@developer.gserviceaccount.com</code>.
  </div>
</div>


### Runtime identities on Microsoft Azure

By default a workstation has no Azure identity of its own. Nothing running on it, including an AI coding
agent, can touch anything in your subscription. That is the safe default, and there is nothing to narrow.

Declaring `serviceAccount` is supported on Azure. Ringleader then creates a user-assigned managed identity
and assigns roles to it. Templating `accountId` per user shares one identity across that user's
workstations, so one person's workstations can read one storage account and nobody else's can.

### Runtime identities on AWS

By default a workstation has no AWS identity of its own. Nothing running on it, including an AI coding agent,
can touch anything in your account. That is the safe default, and there is nothing to narrow.

Declaring `serviceAccount` is supported on AWS. Ringleader then creates an IAM role and an instance profile
of the same name, attaches the managed policies you list in `roles`, and puts the profile on the workstation.
Each `roles` entry names a managed policy by its ARN in the `aws` partition, with no `resource`.
Ringleader creates the role under the IAM path that your onboarding setup granted, so the CloudAccount
must name that path in `spec.aws.workstationIdentityPath`. With `autoCreate: false`, Ringleader adopts
a role and profile you created under that path instead.

You can also create the IAM role and its instance profile yourself, under the same IAM path, because
Ringleader can pass only roles under it. Whoever administers Ringleader then names the profile in
`overrideProviderConfig.aws.iamInstanceProfile` on the CloudIdentity, and Ringleader attaches it without
creating it. One CloudIdentity cannot declare both `serviceAccount` and `iamInstanceProfile`. A
workstation's own author cannot name a profile, and Ringleader refuses a workstation write that carries
`iamInstanceProfile`.

## Permissions for runtime identities

Creating an identity and binding roles to it takes real permissions in your cloud account. Your account must be
onboarded with them. They are on by default.

- **Google Cloud:** the power to create and delete service accounts, and to bind roles to them on the project.
  The role that binds roles, `roles/resourcemanager.projectIamAdmin`, can grant any role in the project to
  anyone, including `roles/owner`. No narrower permission exists, because the ability to set roles on a
  project is the ability to set any role. Attaching an account that Ringleader did not create needs only
  `roles/iam.serviceAccountUser`. [Runtime identity roles](https://docs-stg.ringleader.dev/reference/providers/gcp-permissions/#runtime-identity-roles)
  lists the roles.
- **Microsoft Azure:** the power to manage managed identities and to write role assignments, two things the
  built-in Contributor role cannot do. Both are limited to your one resource group, but they are still the
  power to hand out access inside it.
- **AWS:** the power to create and delete IAM roles and instance profiles under one IAM path, to attach any
  managed policy to those roles, and to pass them to EC2 with `iam:PassRole`. Nothing limits which policy,
  `AdministratorAccess` included, so this can reach anything in the account.
  [AWS permissions and resources](https://docs-stg.ringleader.dev/reference/providers/aws-permissions/#setup-switches)
  lists the actions and the path.

In an account dedicated to Ringleader workstations, leave them on. That is why onboarding asks for a
dedicated account. In a shared account, turn them off when you apply the onboarding setup, as
[Turn off runtime identities](#turn-off-runtime-identities) says. The permission tables are in
[Google Cloud permissions and resources](https://docs-stg.ringleader.dev/reference/providers/gcp-permissions/),
[Microsoft Azure permissions and resources](https://docs-stg.ringleader.dev/reference/providers/azure-permissions/) and
[AWS permissions and resources](https://docs-stg.ringleader.dev/reference/providers/aws-permissions/).

## Declared roles

Ringleader keeps the declared `roles` as an exact set. A role you remove from the spec is revoked in the
cloud on the next update cycle. Templating `accountId` with `${shortHash:creatorUserId}` gives each user their
own runtime identity, shared across that user's workstations.

On Google Cloud, Ringleader binds roles at project scope today. A role entry with a non-empty `resource` is
not yet bound, and the resulting `CloudServiceAccount`'s status reports it instead of applying it silently.
Scope the role itself until per-resource bindings land, for example with a custom project role over just the
resources you mean. Azure honors `resource` as an ARM scope id.

## Runtime identity records

Ringleader records each runtime identity in a `CloudServiceAccount`. [CloudServiceAccount](https://docs-stg.ringleader.dev/reference/resources/cloudserviceaccount/) says what the record holds and what happens when two CloudIdentities declare the same identity.

Changing the runtime identity of a running Google Cloud workstation takes a stop. Google Compute
Engine allows attaching or swapping a VM's service account only while the instance is stopped. Ringleader
applies the change through an automatic stop, apply and start cycle, so expect a brief restart.

## Run Google Cloud workstations as a service account you create

To name the account yourself, declare it in `spec.serviceAccount`. This identity uses a service account that
your own infrastructure-as-code creates with no role bindings:

```yaml
spec:
  provider: gcp
  cloudAccountRef: acme-gcp
  defaultProviderConfig:
    gcp:
      project: acme-dev
      zone: us-east4-c
  serviceAccount:
    accountId: rl-ws-default   # a service account with NO role bindings
    roles: []                  # least privilege: Ringleader binds nothing
    autoCreate: false          # your IaC pre-creates the zero-role SA; Ringleader ADOPTS it
    autoDelete: false          # Ringleader never deletes your SA
```

With `autoCreate: false`, Ringleader only adopts the account. A missing account fails the workstation
loudly, instead of Ringleader creating one without the grants it exists to carry. Set `autoCreate: true` if you
would rather Ringleader create the account. That needs the same onboarding permissions as any other
provisioned identity. Either way the account holds no roles, so the workstation starts yet reaches nothing.

Attaching an account that Ringleader did not create needs only `roles/iam.serviceAccountUser`, which the
onboarding setup grants whether or not runtime identities are on.

## Give each user their own runtime identity

Write a CloudIdentity with a higher `priority` than your default, a selector for the workstations that
opt in, and a `serviceAccount` block. This one gives each user a service account that can read one bucket:

```yaml
apiVersion: core.ringleader.dev/v1
kind: CloudIdentity
metadata:
  name: gcp-bucket-read-only
  namespace: dev
spec:
  provider: gcp
  priority: 100
  selector:
    matchLabels:
      ws-bucket: read-only
  cloudAccountRef: acme-gcp
  defaultProviderConfig:
    gcp:
      project: acme-dev
      zone: us-east4-c
      machineType: c4-standard-4
  serviceAccount:
    accountId: ws-ro-${shortHash:creatorUserId}     # one identity per user
    displayName: "Workstation bucket read-only (per user)"
    roles:
      - role: projects/acme-dev/roles/wsBucketReadOnly
```

A workstation opts in by carrying the label:

```yaml
metadata:
  labels:
    ws-bucket: read-only
spec:
  requirements: [provider:gcp]
```

The `autoCreate` and `autoDelete` fields default to `true`. The [CloudIdentity](https://docs-stg.ringleader.dev/reference/resources/cloudidentity/)
reference lists every `serviceAccount` field.

## Turn off runtime identities

Turn off runtime identities when you onboard a cloud account that holds anything besides Ringleader
workstations. Set the option when you apply the onboarding setup:

| Cloud | Setting |
|---|---|
| Google Cloud | `enable_workstation_identities = false` (Terraform) or `WORKSTATION_IDENTITIES=0 ./onboard.sh` (gcloud) |
| Microsoft Azure | `enable_workstation_identities = false` (Terraform) or `WORKSTATION_IDENTITIES=0 ./deploy.sh` (ARM) |
| AWS | `enable_workstation_identities = false` (Terraform) or the `EnableWorkstationIdentities` stack parameter (CloudFormation) |

After that, a CloudIdentity that declares a runtime identity refuses with a permission error, rather than
quietly starting a workstation with no identity. On Google Cloud and Azure, a workstation that asks for its
own identity fails with a `403` error. An AWS workstation that names an instance profile fails to launch.
Nothing else changes.

## Next steps

- [Placement delegation](https://docs-stg.ringleader.dev/cloud-accounts/cloud-identities/placement-delegation/):
  nobody sets a runtime identity on a workstation, and why.
- [Identity selection and workstation defaults](https://docs-stg.ringleader.dev/cloud-accounts/cloud-identities/selection-defaults/):
  why the CloudIdentity that declares a runtime identity needs its own credential path.

