Set up
In order for Cloud Capture to reach into your Google Cloud project, to discover your Cloud Run services and jobs and your Google Kubernetes Engine (GKE) clusters, you need to grant permission to Kosli to do so. This requires a service account in your project that Cloud Capture can impersonate through workload identity federation; the service account, and the workload identity pool that guards it, exist within your own project. To simplify this process, Kosli has created a Terraform configuration that creates that service account, the read-only roles Cloud Capture needs, and a workload identity pool that accepts only the Kosli-side role created for your organization. If you would rather create these resources yourself, see Permissions and security for the service account, workload identity pool, and roles that Cloud Capture needs.1
Download the Terraform configuration
Infrastructure Manager reads a configuration from a local directory, so download the published file into an empty directory:You also need two values from Kosli: the Kosli AWS account ID, and the name of the Kosli-side IAM role for your organization. The configuration isn’t pre-filled with them. In your organization’s Settings, go to Cloud Capture, open Google Cloud, and select Register account; the first step of the form shows both.
2
Deploy with Infrastructure Manager
Deploy the configuration once in each project that holds Cloud Run services or jobs, or GKE clusters, you want Cloud Capture to snapshot. Run the following from the directory containing the configuration:Infrastructure Manager runs Terraform as the service account you name, so that service account needs permission to enable APIs and to create workload identity pools, service accounts, custom roles, and project IAM bindings.
3
Read the two outputs
Kosli needs two values to connect to your project. The configuration emits both as Terraform outputs:
kosli_capture_provider: the full resource name of the workload identity providerkosli_capture_service_account: the email of the service account Cloud Capture impersonates
4
Register the project
Accounts can only be registered while Cloud Capture is enabled. When you have deployed the configuration, continue the registration form: enter the project ID, the workload identity provider name, and the service account email, and choose the regions and services to scan. Cloud Run is selected for a new project. GKE is not selected, so select it if you want clusters snapshotted.Cloud Capture never connects to a GKE cluster. It lists the project’s clusters and reads their pods from Google’s Cloud Asset Inventory, so a private cluster is snapshotted like any other and nothing is installed in it. Cloud Asset Inventory can be a few minutes behind a cluster, so a pod that lives for less time than that may never be seen.Cloud Capture scans every five minutes unless you choose another frequency, and picks up a registered project the next time it runs - you should see environments and snapshots appearing within a few minutes.
Excluding resources
Exclude resources by label. In your organization’s Settings, go to Cloud Capture, open Google Cloud, and add the label to the Skip tags panel in the Google Cloud defaults. Key and value must both match the resource’s label exactly.- A Cloud Run service or job is skipped on its own, and the region’s Cloud Run environment in Kosli is made up of the services and jobs that remain.
- A GKE cluster is skipped with everything in it. The label is read on the cluster; labels on workloads inside it are not read.
gcp list of skip_tags; see Using the API.
Permissions and security
For the model that is common to every cloud, see Cloud Capture security. Kosli publishes a Terraform configuration, for use with Infrastructure Manager, that creates everything Cloud Capture needs to snapshot Cloud Run and Google Kubernetes Engine (GKE). Infrastructure Manager runs Terraform as a managed service inside your project, so there is no state file or Terraform install for you to manage. Deploy the configuration once in each project you want Cloud Capture to snapshot. The current version,v0.2.0, is published at
https://kosli-cloud-capture-templates.s3.eu-central-1.amazonaws.com/gcp/v0.2.0/main.tf, and what
this page describes is taken from it. Everything it creates is yours, in your project.
Cloud Capture runs in AWS and reaches your project through
Workload Identity Federation. Cloud
Capture exchanges its own short-lived AWS credentials for a short-lived Google token, then
impersonates a service account that you create. No service account key is ever created or shared.
Your workload identity pool makes two checks before it issues a token:
- It accepts only credentials issued by the Kosli AWS account in which Cloud Capture runs.
- Within that account, it accepts only the Kosli-side IAM role dedicated to your organization. Every Cloud Capture job runs under the role for the organization it is working for. A job for another Kosli tenant presents a different role name, so your pool refuses it, even if that tenant gave Kosli your provider and service account details instead of their own.
What the configuration creates
The configuration takes three inputs, none of which has a default:
project_id, and the two values
Kosli supplies, kosli_aws_account_id and kosli_role_name. It emits two outputs,
kosli_capture_provider and kosli_capture_service_account, which you enter when you register the
project; see Set up.
Permissions granted to the service account
All of the grants are read-only, and all are on the project.
Worth knowing for a security review of GKE:
- Cloud Capture never calls a cluster’s Kubernetes API. No Kubernetes RBAC objects are created inside your clusters, nothing is installed in them, and Cloud Capture needs no network access to any cluster control plane, so a private cluster is snapshotted like any other.
- The GKE role is custom because Google’s predefined roles are wider:
roles/cloudasset.viewerwould list every asset type in the project, including Kubernetes Secrets. - The role cannot be made narrower than every pod in the project, because Cloud Asset Inventory filters by neither cluster nor namespace. A pod’s record holds its images, commands, arguments, labels, annotations, and any environment variables written into the spec in plain text. A value taken from a Kubernetes Secret appears as a reference and not as the secret.
- A project inside a VPC Service Controls perimeter that restricts the Cloud Asset, Kubernetes Engine, or Cloud Run API needs an ingress rule that admits the service account, because Cloud Capture calls from outside the perimeter.
The configuration in full
main.tf, version v0.2.0
main.tf, version v0.2.0