# Onboard AWS

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


> Let Ringleader run workstation EC2 instances in your own AWS account, with a Terraform module or a CloudFormation stack and no access key.


Let Ringleader run your developers' workstations as EC2 instances in your own AWS account, on
your bill and inside your VPC, with a Terraform module or a CloudFormation stack. Ringleader
never holds a key to your account, and the role it signs in as never holds account admin.

## Prerequisites

- [Ringleader installed](https://docs-stg.ringleader.dev/install/), for the check at the end.
- Two values from Ringleader, which you received when your organization was set up: the issuer
  URL, written with no trailing slash, and your [organization](https://docs-stg.ringleader.dev/reference/resources/organization/)'s
  id, a UUID and never its name. If you do not have them, ask Ringleader.
  [Fix a sign-in that your cloud refuses](https://docs-stg.ringleader.dev/cloud-accounts/keyless-access/#fix-a-sign-in-that-your-cloud-refuses)
  says what to check if AWS rejects them.
- An AWS account to run the workstations in. Use an account that serves no other purpose.
  Workstations are billed to it, and everything Ringleader may do is limited to it. A
  dedicated account keeps the bill and the risk in one place.
- In that account, permission to create an IAM OIDC provider and an IAM role. You need it only
  for this setup, which you do once.
- The examples use the CloudAccount `my-aws-account` in the organization `acme`. Replace them
  with yours.

[Keyless cloud access](https://docs-stg.ringleader.dev/cloud-accounts/keyless-access/) explains why no key
changes hands. [AWS permissions and resources](https://docs-stg.ringleader.dev/reference/providers/aws-permissions/)
lists what the setup creates.

## Set up keyless access

Two paths do the same thing, so use the one your team already runs. Both live in
[github.com/ringleader-dev/cloud-onboarding](https://github.com/ringleader-dev/cloud-onboarding),
and both create the network for the workstations unless you turn it off. Both finish by
printing the values you send back.

An IAM OIDC provider requires a certificate thumbprint. Both paths fill it in from the live
certificate, so you never compute it by hand.


### CloudFormation


1. Clone the repository and go to the CloudFormation folder:

   ```bash
   git clone https://github.com/ringleader-dev/cloud-onboarding
   cd cloud-onboarding/aws/cloudformation
   ```

2. Run `deploy.sh` with your two values, your region and the addresses your engineers connect
   from. It deploys the stack and prints the values to send back.

   ```bash
   ISSUER_URL=https://oidc-app.ringleader.dev \
   ORG_UID=0192f5bf-af83-7178-8d0a-f1c7aea06bde \
   REGION=us-east-1 \
   CREATE_NETWORK=true \
   SSH_SOURCE_CIDR=203.0.113.0/24 \
     ./deploy.sh
   ```

`SSH_SOURCE_CIDR` adds an SSH rule of your own. [Cloud accounts and reachability](https://docs-stg.ringleader.dev/cloud-accounts/accounts-reachability/) says who can connect without it.



### Terraform


1. Clone the repository and go to the standalone example:

   ```bash
   git clone https://github.com/ringleader-dev/cloud-onboarding
   cd cloud-onboarding/aws/terraform/examples/standalone
   ```

2. Copy the example variables file:

   ```bash
   cp terraform.tfvars.example terraform.tfvars
   ```

3. In `terraform.tfvars`, set the two values above, your region and `ssh_source_ranges`, the
   addresses your engineers connect from.
4. Apply the module:

   ```bash
   terraform init && terraform apply
   ```

5. Print the values to send back:

   ```bash
   terraform output handoff
   ```

The module is reusable. You can reference it as a module source from your own configuration
instead of copying it. If you do, set `allowed_regions` to bound what Ringleader may do to
your regions. It is empty by default, so no region condition applies and the whole account is
the boundary.






## Send the values to your organization administrator

Send the printed values to whoever administers Ringleader for your organization, which may be
you. `terraform output handoff` prints them together, and `deploy.sh` prints them when it
finishes. [Values you hand back](https://docs-stg.ringleader.dev/reference/providers/aws-permissions/#values-you-hand-back)
says what each value is and where it lands.

Neither tool prints the IAM path for runtime identities, which let a workstation run as an IAM
role of its own. Runtime identities are on by default, and
[Setup switches](https://docs-stg.ringleader.dev/reference/providers/aws-permissions/#setup-switches) says how to
turn them off. If you keep them on, send the path too, with its slash at each end:
`/ringleader-workstations/` with Terraform, or `/ringleader/` with CloudFormation. If you set your
own path in `workstation_identity_path` or `WORKSTATION_IDENTITY_PATH`, send that one instead.

## Create the CloudAccount

As the administrator, create the CloudAccount from the role ARN you were sent, and from the IAM
path if you were sent one.

1. Save this as `my-aws-account.yaml`, with your organization, your role ARN and your IAM path:

   ```yaml
   apiVersion: core.ringleader.dev/v1
   kind: CloudAccount
   metadata:
     name: my-aws-account
   spec:
     org: acme
     provider: aws
     aws:
       # The IAM role in YOUR account that Ringleader assumes via
       # AssumeRoleWithWebIdentity. Its trust policy admits only your organization's
       # subject and audience. This one value is all AWS needs to sign in. AWS finds the
       # OIDC provider and the audience from the signed token itself.
       targetRoleArn: arn:aws:iam::123456789012:role/ringleader-workstations
       # The IAM path for runtime identities, exactly as you were sent it. This is the
       # Terraform default. Leave the line out if runtime identities are off.
       workstationIdentityPath: /ringleader-workstations/
   ```

2. Apply it:

   ```bash
   rl apply -f my-aws-account.yaml
   ```

Signing in needs only `aws.targetRoleArn`. Ringleader also needs `aws.workstationIdentityPath` to
give a workstation a [runtime identity](https://docs-stg.ringleader.dev/cloud-accounts/cloud-identities/runtime-identities/),
which a CloudIdentity declares in `spec.serviceAccount`. The
[CloudAccount](https://docs-stg.ringleader.dev/reference/resources/cloudaccount/#spec-fields) reference lists every
field in a table.

Then create a [CloudIdentity](https://docs-stg.ringleader.dev/reference/resources/cloudidentity/) with the region,
subnet and security groups you were sent, and a `cloudAccountRef` that names this CloudAccount.

## Choose the security group for workstations

If you created the network with egress control on, you have two security groups, and each
workstation gets one of them. As the administrator, name the group on the CloudIdentity, in
`providerConfig.aws.securityGroupIds`. [Security groups for workstations](https://docs-stg.ringleader.dev/reference/providers/aws-permissions/#security-groups-for-workstations)
shows what each group lets in and out.

1. For a workstation with no egress policy, name `security_group_id` (Terraform) or
   `SecurityGroupId` (CloudFormation).
2. For a workstation with an egress policy, name `inbound_only_security_group_id`
   (Terraform) or `InboundOnlySecurityGroupId` (CloudFormation).
3. Optional: to empty the VPC's default security group, which compliance checks such as
   AWS Security Hub's EC2.2 expect, set `restrict_default_security_group = true`
   (Terraform). With CloudFormation, run `RESTRICT_DEFAULT_SECURITY_GROUP=true ./deploy.sh`,
   which removes the rules after the stack deploys. Name one of the two groups on every
   workstation first, because a workstation that names none then has no outbound path.

<div class="callout callout-warning">
  <p class="callout-title">Leave the inbound-only group without an outbound rule</p>
  <div class="callout-body">
    The inbound-only group has no outbound rule on purpose. One rule of any kind there undoes
every egress policy in the VPC. The CloudFormation version carries a single placeholder rule
to <code>127.0.0.1/32</code>, which permits nothing. Leave it alone.
  </div>
</div>


[AWS security groups](https://docs-stg.ringleader.dev/workstations/providers/cloud/#aws-security-groups) says what the
default group must allow, and [Enforcement points](https://docs-stg.ringleader.dev/security/outbound/enforcement/)
says why a policy needs the second group.

## Check the setup

Confirm that Ringleader can use the identity before anyone creates a workstation. The check
starts once an administrator has created the CloudAccount and the CloudIdentity from the
values you sent back.

1. Wait for the CloudIdentity to be ready. Replace `aws` and `dev` with the CloudIdentity's
   name and namespace:

   ```bash
   rl cloudidentity wait aws -n dev --for Ready --timeout 2m
   ```

2. Read its status:

   ```bash
   rl cloudidentity get aws -n dev -o yaml     # status.valid: true
   ```

`status.valid: true` means Ringleader can use the identity. `false` means it cannot, and
`rl cloudidentity describe aws -n dev` says why.

## Optional: Revoke Ringleader's access

Delete the OIDC provider or the role, and Ringleader can get no new credentials. There are no
keys to hunt down. AWS keeps temporary credentials valid until they expire, so credentials
Ringleader already holds can keep working for up to an hour. If you never revoke, Ringleader keeps
the access you granted.

- In the AWS console, delete the OIDC provider or the role.
- With Terraform, run `terraform destroy`.
- With CloudFormation, delete the stack.

To also cut off the credentials Ringleader already holds, work in the IAM console before you run
Terraform or delete the stack:

1. Delete the OIDC provider, so Ringleader cannot sign in again.
2. Open the role and choose **Revoke active sessions** on its **Revoke sessions** tab.
   [Revoke IAM role temporary security credentials](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_revoke-sessions.html)
   says what that does.
3. Delete the role. Revoking added a policy to it that Terraform and CloudFormation do not know
   about, and deleting that policy on its own would let the old credentials work again.

Then run `terraform destroy` or delete the stack for the rest.

## Troubleshoot

**If `status.valid` is `false` or AWS turns Ringleader away,** compare what your account checks
against what was created. [Checks your account makes](https://docs-stg.ringleader.dev/reference/providers/aws-permissions/#checks-your-account-makes)
lists the three values. A mismatch in one of them is the usual cause, and a trailing slash on
the issuer is the usual mismatch. A wrong role ARN is the other usual cause.

**If a workstation refuses to start and the message names a security group,** the workstation
was given the first group but has an egress policy. Ringleader refuses to start a workstation
it would have to report as restricted while it can reach the whole internet. Give it the
inbound-only group instead.

**If a workstation that names no security group refuses to start,** your VPC's default group
has no outbound rule, or the workstation has an egress policy and the default group allows
outbound traffic. Give the workstation one of the two groups.

**If a workstation reports the `SSHAdmissionMissing` condition,** Ringleader could not create
its SSH security group. That happens with egress control turned off, or for a workstation in a
VPC the grant does not cover. A workstation reports `Ready` whether or not anything can reach
it, so it cannot confirm this for you. [Cloud accounts and reachability](https://docs-stg.ringleader.dev/cloud-accounts/accounts-reachability/)
explains the rule and your options.

**If an instance does not match its image,** check its instance type. The image aliases
resolve to x86-64 images, so an arm64 (Graviton) instance type will not match. See
[Values you hand back](https://docs-stg.ringleader.dev/reference/providers/aws-permissions/#values-you-hand-back).

## Next steps

- [Cloud accounts](https://docs-stg.ringleader.dev/cloud-accounts/) explains how the pieces fit, and the egress and storage switches that are on by default.
- [Cloud accounts and reachability](https://docs-stg.ringleader.dev/cloud-accounts/accounts-reachability/) explains who can connect to your workstations, public addresses and the NAT gateway.
- [Cloud runtime identities](https://docs-stg.ringleader.dev/cloud-accounts/cloud-identities/runtime-identities/) explains how to give a workstation an IAM role of its own.
- [Storage buckets](https://docs-stg.ringleader.dev/cloud-accounts/storage-buckets/) explains how to keep session transcripts and uploaded files in an S3 bucket in your account.
- [AWS permissions and resources](https://docs-stg.ringleader.dev/reference/providers/aws-permissions/) lists the resources, permissions and tables behind this setup.
- [Provider images and keys](https://docs-stg.ringleader.dev/reference/providers/images-keys/) lists the full `providerConfig.aws` field set.

