# Onboard Google Cloud

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


> Give Ringleader keyless access to run workstation VMs in one of your Google Cloud projects, with the gcloud CLI or Terraform.


Give Ringleader keyless access to run workstation VMs in one of your
Google Cloud projects, with the gcloud CLI or Terraform. You want this when your
developers' workstations should run on your bill and inside your network.

## Prerequisites

- [Ringleader installed](https://docs-stg.ringleader.dev/install/), for the `rl` commands in the last tasks.
- Two values from Ringleader, which you receive when your organization is 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 us.
  [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 Google rejects them.
- A Google Cloud project to put the workstations in. We recommend a new, empty project used
  for nothing else. Workstations are billed to it and everything Ringleader may do is
  limited to it. A dedicated project keeps the bill and the risk in one place.
- Permission in that project to manage service accounts and IAM: Owner, or Project IAM
  Admin plus Service Account Admin. You need it only for this setup, which you do once.
- For the CloudAccount step, organization administrator access to your Ringleader
  organization.
- The examples use the project `my-company-dev-workstations` and the CloudAccount
  `my-gcp-account`. Replace them with yours.

[Cloud accounts](https://docs-stg.ringleader.dev/cloud-accounts/) says what a CloudAccount is and what
Ringleader does with your project.

## Set up keyless access

Run one script or one Terraform module in your project. It creates a service account for
Ringleader and tells Google to accept Ringleader's tokens for it without a password or a
key. [Google Cloud permissions and resources](https://docs-stg.ringleader.dev/reference/providers/gcp-permissions/)
lists everything it creates. Both live in
[github.com/ringleader-dev/cloud-onboarding](https://github.com/ringleader-dev/cloud-onboarding)
and both finish by printing the values you send back.


### gcloud


The scripts are safe to run again if something goes wrong partway.

1. Clone the repository and change to the gcloud directory:

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

2. Set your project and the two values from Ringleader:

   ```bash
   export PROJECT=my-company-dev-workstations
   export ISSUER_URL='https://oidc-app.ringleader.dev'
   export ORG_UID='0192f5bf-af83-7178-8d0a-f1c7aea06bde'
   ```

3. Run the onboarding script. It prints the values to send back to Ringleader:

   ```bash
   ./onboard.sh
   ```

4. Optional: if you don't already have a network for the workstations, create one. Set
   `SSH_RANGES` to where your engineers connect from, for an SSH rule of your own:

   ```bash
   REGION=us-central1 SSH_RANGES=203.0.113.0/24 ./network-landing-pad.sh
   ```

[Cloud accounts and reachability](https://docs-stg.ringleader.dev/cloud-accounts/accounts-reachability/)
says what the SSH rule does.



### Terraform


The module is reusable. If you prefer, reference it as a module source from your own
configuration rather than copying it.

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

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

2. Copy the example variables file:

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

3. In `terraform.tfvars`, set your project id, the two values from Ringleader 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 to Ringleader:

   ```bash
   terraform output handoff
   ```

To turn off a feature that is on by default, such as egress control or artifact storage,
set its switch when you apply. [Setup switches](https://docs-stg.ringleader.dev/reference/providers/gcp-permissions/#setup-switches)
lists them.






## Send the values to your organization administrator

Send these four values to whoever administers Ringleader for your organization, which may
be you:

- the target service account email
- the workload identity provider, as its resource name
- the project id
- the subnetwork self-link, only if you created a network

[Values you hand back](https://docs-stg.ringleader.dev/reference/providers/gcp-permissions/#values-you-hand-back)
says where each one goes.

## Create the CloudAccount

As an organization administrator, write the target service account and the workload
identity provider from your values into a [CloudAccount](https://docs-stg.ringleader.dev/reference/resources/cloudaccount/).

1. Save this as `my-gcp-account.yaml`:

   ```yaml
   apiVersion: core.ringleader.dev/v1
   kind: CloudAccount
   metadata:
     name: my-gcp-account
   spec:
     org: acme
     provider: gcp
     gcp:
       targetServiceAccount: ringleader-workstations@my-company-dev-workstations.iam.gserviceaccount.com
       workloadIdentityProvider: projects/123456789/locations/global/workloadIdentityPools/ringleader/providers/oidc
   ```

2. Apply it before the CloudIdentity that references it. A multi-document `apply` orders
   them for you:

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

3. List the accounts to confirm it exists:

   ```bash
   rl cloudaccount get
   ```

[CloudAccount](https://docs-stg.ringleader.dev/reference/resources/cloudaccount/) lists every field. Create the
CloudIdentity from the project id and, if you created a network, the subnetwork
self-link, as [CloudIdentity](https://docs-stg.ringleader.dev/reference/resources/cloudidentity/) describes.

## Check the setup

Check both halves: your project, then Ringleader's use of it. Do both before anyone
creates a workstation.

1. In `cloud-onboarding/gcp/gcloud`, run the check script. It checks everything in steps 2 to 4
   for you:

   ```bash
   ./verify.sh
   ```

2. Optional: check by hand that the service account's roles are exactly the ones on
   [Roles](https://docs-stg.ringleader.dev/reference/providers/gcp-permissions/#roles):

   ```bash
   gcloud projects get-iam-policy <project> \
     --flatten='bindings[].members' \
     --filter="bindings.members:ringleader-workstations@<project>.iam.gserviceaccount.com" \
     --format='table(bindings.role)'
   ```

3. Optional: check that the provider accepts only Ringleader's tokens, for your
   organization, for Google Cloud:

   ```bash
   gcloud iam workload-identity-pools providers describe oidc \
     --project <project> --location global --workload-identity-pool ringleader \
     --format='yaml(oidc.issuerUri, oidc.allowedAudiences, attributeCondition)'
   ```

4. Optional: check that your organization alone may use the service account, written
   `principal://`, not `principalSet://`:

   ```bash
   gcloud iam service-accounts get-iam-policy \
     ringleader-workstations@<project>.iam.gserviceaccount.com --project <project>
   ```

5. After an administrator has created the CloudAccount and CloudIdentity, wait for the
   CloudIdentity to be ready. Replace `gcp` and `dev` with its name and namespace:

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

6. Read its status:

   ```bash
   rl cloudidentity get gcp -n dev -o yaml
   ```

   `status.valid: true` means Ringleader can use the identity.

## Optional: Revoke Ringleader's access

Delete the pool and Ringleader loses access the moment it is gone. There are no keys to
hunt down. Skipping this leaves Ringleader's access in place.


### gcloud


In `cloud-onboarding/gcp/gcloud`, run the revoke script. It deletes the pool and keeps the
service account. Add `FULL=1` to delete the service account too:

```bash
./revoke.sh
FULL=1 ./revoke.sh
```



### Terraform


In the directory you applied from, run:

```bash
terraform destroy
```

<div class="callout callout-note">
  <p class="callout-title">A deleted pool is soft-deleted for 30 days</p>
  <div class="callout-body">
    Workload identity pool ids stay reserved after deletion. If you revoke and
re-onboard within that window, undelete the pool rather than creating it again:
<code>gcloud iam workload-identity-pools undelete ringleader --location global</code>. The
scripts already handle this.
  </div>
</div>







## Troubleshoot

**If Google turns Ringleader away,** compare the three values your project checks against
what was created. A mismatch in one of them is the usual cause, and a trailing slash on the
issuer is the usual mismatch. [Checks your project makes](https://docs-stg.ringleader.dev/reference/providers/gcp-permissions/#checks-your-project-makes)
lists the three, and [Keyless cloud access](https://docs-stg.ringleader.dev/cloud-accounts/keyless-access/)
says what each means.

**If you built this into your own Terraform instead of using the module,** check who may use
the `ringleader-workstations` service account, in the console or with the command in step 4 of [Check the setup](#check-the-setup).
If you see `principalSet://…/workloadIdentityPools/<pool>/*`, that is a wildcard that would
let anyone the pool accepts use your service account. It should be `principal://…/subject/org:<org-id>`
for your organization alone.

**If `status.valid` is `false`,** Ringleader cannot use the identity. Run
`rl cloudidentity describe gcp -n dev` to see why. The usual causes are a wrong workload
identity provider name or a wrong service-account email.

**If creating the first workstation fails with a `403` error,** the service account may be
missing `roles/iam.serviceAccountUser`. Compare its roles with
[Roles](https://docs-stg.ringleader.dev/reference/providers/gcp-permissions/#roles).

## Next steps

- [Cloud accounts](https://docs-stg.ringleader.dev/cloud-accounts/) explains what a CloudAccount is and what Ringleader does with your project.
- [Cloud accounts and reachability](https://docs-stg.ringleader.dev/cloud-accounts/accounts-reachability/) explains how you reach your workstations, and who may.
- [Cloud runtime identities](https://docs-stg.ringleader.dev/cloud-accounts/cloud-identities/runtime-identities/) explains what the workstations themselves can do in your project.
- [Storage buckets](https://docs-stg.ringleader.dev/cloud-accounts/storage-buckets/) explains how to keep session transcripts and uploaded files in your project.

