diff --git a/administration/cloud_capture/getting_started.md b/administration/cloud_capture/getting_started.md index 3328ebe..579601f 100644 --- a/administration/cloud_capture/getting_started.md +++ b/administration/cloud_capture/getting_started.md @@ -13,39 +13,63 @@ Cloud Capture is a managed service that runs on Kosli's infrastructure and conne ## Overview -Getting started with Cloud Capture involves two steps. Each step has instructions for AWS and for GCP. +Getting started with Cloud Capture involves two steps. Each step has instructions for AWS, Azure and Google Cloud. Azure and Google Cloud are in early access, so their pages appear in your settings only once Kosli has enabled them for your organization. - In order for Cloud Capture to reach into your AWS cloud, to discover your ECS clusters and Lambdas, you need to grant permission to Kosli to do so. This requires the creation of an IAM role that Kosli can assume; the role will exist within your AWS account. + In order for Cloud Capture to reach into your AWS cloud, to discover your ECS clusters, Lambdas and S3 buckets, you need to grant permission to Kosli to do so. This requires the creation of an IAM role that Kosli can assume; the role will exist within your AWS account. To simplify this process, Kosli has created a CloudFormation template that contains a role with the minimum set of permissions needed by Cloud Capture. The role can be assumed by Kosli and is protected by an external Id; each organization within Kosli has its own external Id. The CloudFormation template can be downloaded from the Settings page for your organization within the Kosli UI. If you would rather create the role yourself, see [Cloud Capture Security](/administration/cloud_capture/security) for the trust policy and the full set of permissions the role needs. The CloudFormation template can be deployed within an AWS account, or can be attached to an AWS Organizational Unit (OU) as a StackSet; this latter option ensures the correct IAM permissions are rolled out to all AWS accounts within the OU. + + The template's **S3 buckets** parameter is empty by default, and the role can then read no object in any bucket. Leave it empty unless you want S3 buckets snapshotted; see [Capturing S3 buckets](#capturing-s3-buckets). - - - This setup describes Google Kubernetes Engine (GKE), which is planned. Cloud Run is in early access; contact Kosli's Customer Success team for its setup. - + + Nothing is deployed in Azure. Cloud Capture reads a subscription as a Kosli application registered in Microsoft Entra, which you consent to in your tenant and then grant read access on each subscription. + + + + In your organization's **Settings**, go to **Cloud Capture**, open **Azure** and select **Register account**. Follow the **Consent in Azure** link as a Global Administrator of your tenant. Consenting creates the application's service principal in your tenant; it has no access until you grant it some in the next step. + + + The registration form shows three Azure CLI commands with your values filled in. Run them as an owner of the subscription: + + ```bash + az role assignment create --assignee "" --role Reader --scope "/subscriptions/" + az role assignment create --assignee "" --role AcrPull --scope "/subscriptions/" + az tag update --resource-id "/subscriptions/" --operation Merge --tags kosli-external-id="" + ``` - In order for Cloud Capture to reach into your GCP project, to discover your 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. + `Reader` lets Cloud Capture list the App Service sites and read tags, and `AcrPull` lets it fingerprint their container images. The `kosli-external-id` tag is how Cloud Capture checks the subscription is yours to read: it refuses to list a subscription whose tag does not carry your organization's external ID. + + + + + 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, a custom role holding the minimum set of permissions needed by Cloud Capture, and a workload identity pool that accepts only the Kosli-side role created for your organization. + 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 [Cloud Capture Security](/administration/cloud_capture/security) for the service account, workload identity pool and custom role that Cloud Capture needs. + If you would rather create these resources yourself, see [Cloud Capture Security](/administration/cloud_capture/security) for the service account, workload identity pool and roles that Cloud Capture needs. - Download the Terraform configuration from the Settings page for your organization within the Kosli UI. + 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. Copy them from the Cloud Capture section of your organization's Settings page in the Kosli UI. + ```bash + mkdir kosli-capture && cd kosli-capture + curl --fail --remote-name \ + https://kosli-cloud-capture-templates.s3.eu-central-1.amazonaws.com/gcp/v0.2.0/main.tf + ``` + + 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. - Deploy the configuration once in each project that holds GKE clusters you want Cloud Capture to snapshot. Run the following from the directory containing the configuration: + 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: ```bash gcloud infra-manager deployments apply \ @@ -57,13 +81,13 @@ Getting started with Cloud Capture involves two steps. Each step has instruction 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. - + 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 provider - `kosli_capture_service_account`: the email of the service account Cloud Capture impersonates - After the deployment completes, register them with Kosli through the Kosli API's cloud accounts endpoint. You can read them at any time from the deployment's latest revision: + You enter both when you register the project. You can read them at any time from the deployment's latest revision: ```bash gcloud infra-manager revisions describe \ @@ -72,8 +96,6 @@ Getting started with Cloud Capture involves two steps. Each step has instruction --format='value(latestRevision)')" \ --format='yaml(applyResults.outputs)' ``` - - {/* TODO: Link to the cloud accounts endpoint in the API reference, and show the call, once it is published. */} @@ -86,12 +108,23 @@ Getting started with Cloud Capture involves two steps. Each step has instruction To check environment names, or to exclude resources, before any snapshots are recorded, switch on [Dry run](#dry-run) and add [skip tags](#excluding-resources) now, before you register accounts. - Kosli is not notified when you create or delete the stack, so you then register each account yourself. Accounts can only be registered while Cloud Capture is enabled. Open your organization's **Settings**, go to **Cloud Capture**, select **Register account**, and enter the ARN of the role the stack created. If you deploy the template as a StackSet, register every account in the OU, including accounts that join it later. If you delete a stack, also remove its account from the **Registered accounts** table; until you do, scans of that account fail because the role no longer exists. + Kosli is not notified when you create or delete the stack, so you then register each account yourself. Accounts can only be registered while Cloud Capture is enabled. Open your organization's **Settings**, go to **Cloud Capture**, open **AWS**, select **Register account**, and enter the ARN of the role the stack created. Choose the services to scan in the account: ECS and Lambda are selected for a new account, and S3 is not, because it needs the extra steps in [Capturing S3 buckets](#capturing-s3-buckets). If you deploy the template as a StackSet, register every account in the OU, including accounts that join it later. If you delete a stack, also remove its account from the **Registered accounts** table; until you do, scans of that account fail because the role no longer exists. Cloud Capture scans every five minutes unless you [choose another frequency](#scan-frequency), and picks up a registered account the next time it runs - you should see environments and snapshots appearing within a few minutes. - - When you have deployed the configuration and registered the workload identity provider name and service account email with Kosli, you can activate Cloud Capture within the Kosli user-interface. Cloud Capture scans every five minutes unless you [choose another frequency](#scan-frequency), and once you have enabled it, Cloud Capture will pick up your environment the next time it runs - you should see environments and snapshots appearing within a few minutes. + + Accounts can only be registered while Cloud Capture is enabled. When you have consented to the application, granted it access and tagged the subscription, enter the **Tenant ID** and **Subscription ID** in the same registration form and save it. Register each subscription you want scanned. + + Azure has no regions to choose: Cloud Capture scans the whole subscription and reports each resource group that holds running container-based web apps into its own environment. + + Cloud Capture scans every five minutes unless you [choose another frequency](#scan-frequency), and picks up a registered subscription the next time it runs - you should see environments and snapshots appearing within a few minutes. + + + 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](#scan-frequency), and picks up a registered project the next time it runs - you should see environments and snapshots appearing within a few minutes. @@ -102,7 +135,7 @@ Getting started with Cloud Capture involves two steps. Each step has instruction -If there are resources you do not want Cloud Capture to snapshot, such as a test cluster or a service a vendor runs in your account, exclude them by tag. You choose the tags: in your organization's **Settings**, under **Cloud Capture**, the **Skip tags** panel takes any number of key and value pairs, and Cloud Capture skips every resource that carries one of them. +If there are resources you do not want Cloud Capture to snapshot, such as a test cluster or a service a vendor runs in your account, exclude them by tag. You choose the tags: in your organization's **Settings**, go to **Cloud Capture**, open **AWS** and edit the AWS defaults. The **Skip tags** panel there takes any number of key and value pairs, and Cloud Capture skips every resource that carries one of them. 1. Tag the resource in AWS, with any key and value you like. For example, to tag an ECS cluster and a Lambda function with `kosli-capture=false`: @@ -121,12 +154,12 @@ If there are resources you do not want Cloud Capture to snapshot, such as a test How the tags are matched: - A resource is skipped when any one of its tags equals any one of the skip tags, key and value both, exactly as AWS stores them. Tags are case-sensitive, so `Env=test` does not match `env=test`. A key on its own does not match: to skip both `env=test` and `env=staging`, add both. -- The tag is read on the resource Cloud Capture snapshots. An ECS cluster is skipped with everything in it, its services and tasks included; tags on a service or a task definition are not read. A Lambda function is skipped on its own, and the region's Lambda environment in Kosli is made up of the functions that remain. -- The change takes effect on the next scan. A Kosli environment that was already being captured keeps its last snapshot and receives no new ones; nothing is deleted. Remove the tag, or the skip tag, and the next run picks the resource up again. +- The tag is read on the resource Cloud Capture snapshots. An ECS cluster is skipped with everything in it, its services and tasks included; tags on a service or a task definition are not read. A Lambda function is skipped on its own, and the region's Lambda environment in Kosli is made up of the functions that remain. An S3 bucket is only ever snapshotted when it carries an [S3 opt-in tag](#capturing-s3-buckets); a bucket that carries an opt-in tag and a skip tag is skipped. +- The change takes effect on the next scan. A Kosli environment that was already being captured keeps its last snapshot and receives no new ones; nothing is deleted. Remove the skip tag from the resource, and the next run picks it up again. - Skip tags, like the other Cloud Capture settings, can only be changed while Cloud Capture is enabled. - The IAM role created by the CloudFormation template already grants the permissions needed to read tags, `ecs:DescribeClusters` and `lambda:ListTags`, so no change to the role is needed. -Skip tags can also be set through the API, as part of the organization's Cloud Capture settings. The settings PUT replaces every setting, not only the one you are changing, so start from what is stored: read the current configuration, take the `enabled`, `default_regions`, `scan_interval_minutes`, `skip_tags`, `dry_run` and `environment_name_template` values from its `settings` object, add your tags to `skip_tags`, and send those fields back. A field you leave out is reset: `dry_run` to `false`, and `environment_name_template` to the [default template](#environment-names). The response leaves out `environment_name_template` while your organization uses the default, so leave it out of the PUT in that case too. Sending the example below as it stands would also set your default regions, scan interval and dry run to the values shown, and your environment names to the default. +Skip tags can also be set through the API, as part of the organization's Cloud Capture settings. The settings PUT replaces every setting, not only the one you are changing, so start from what is stored: read the current configuration, take the `enabled`, `default_regions`, `scan_interval_minutes`, `skip_tags`, `opt_in_tags`, `dry_run` and `environment_name_template` values from its `settings` object, add your tags to `skip_tags`, and send those fields back. A field you leave out is reset: `dry_run` to `false`, `environment_name_template` to the [default template](#environment-names), and `skip_tags` and `opt_in_tags` to none, which stops your S3 buckets being captured. The response leaves out `environment_name_template` while your organization uses the default, so leave it out of the PUT in that case too. Sending the example below as it stands would also set your default regions, scan interval, S3 opt-in tags and dry run to the values shown, and your environment names to the default. ```bash curl "https://app.kosli.com/api/v2/cloud-capture/" \ @@ -140,16 +173,71 @@ curl -X PUT "https://app.kosli.com/api/v2/cloud-capture//settings" \ "default_regions": {"aws": ["eu-west-1"]}, "scan_interval_minutes": 5, "skip_tags": {"aws": [{"key": "kosli-capture", "value": "false"}]}, + "opt_in_tags": {"aws": [{"key": "kosli-capture-s3", "value": "true"}]}, "dry_run": false }' ``` - + + +Exclude resources by tagging the resource group that holds them. In your organization's **Settings**, go to **Cloud Capture**, open **Azure** and add the tag to the **Skip tags** panel in the Azure defaults. Cloud Capture skips every resource group that carries one of the tags, with all of the web apps in it; tags on an individual web app are not read. -Excluding resources by label is coming with GCP support. +Key and value must both match the resource group's tag exactly. Through the API, the tags are the `azure` list of `skip_tags`. + + + +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. + +Through the API, the labels are the `gcp` list of `skip_tags`. +## Capturing S3 buckets + +Cloud Capture reports the content of an S3 bucket as one artifact, whose fingerprint is calculated from the SHA256 checksums S3 stores for the bucket's objects. No object is downloaded, with one exception: a `.kosli_ignore` file at the root of the bucket, if there is one, which lists keys to leave out. + +S3 is opt-in, bucket by bucket. An account usually holds many buckets you would not want reported, such as CloudTrail and load balancer access logs, and a snapshot makes one request to AWS for every object in the bucket on every scan, which AWS bills to your account. So a bucket is snapshotted only when all of the following are true. + + + + Deploy version `v0.2.0` or later of the CloudFormation template, or update your existing stack to it, and list the buckets in its **S3 buckets** parameter (`S3BucketNames`): a comma-separated list of bucket names in lowercase, with no spaces. A name may use `*` and `?` as wildcards, for example `acme-releases-*`. + + This is the permission. The role can list and read objects in the buckets you name and in no others. See [Cloud Capture Security](/administration/cloud_capture/security) for exactly what it grants. + + + In your organization's **Settings**, go to **Cloud Capture**, open **AWS** and edit the AWS defaults. In the **S3 opt-in tags** panel, beneath **Skip tags**, add a key and a value, for example `kosli-capture-s3` and `true`, and save. + + Until you set an opt-in tag, no bucket is captured. + + + ```bash + aws s3api put-bucket-tagging \ + --bucket acme-releases \ + --tagging 'TagSet=[{Key=kosli-capture-s3,Value=true}]' + ``` + + `put-bucket-tagging` replaces all of a bucket's tags, so include the tags the bucket already carries. Key and value must both match the opt-in tag exactly; tags are case-sensitive. + + + In the **Registered accounts** table, edit the account and select **s3** among its services. + + + +What to expect: + +- **Each bucket is its own environment**, of type S3, named by your [environment name template](#environment-names) with the bucket name as `{resource}`. +- **A bucket needs both the tag and the permission.** A bucket that carries the opt-in tag but is not named in the stack fails its snapshot on every scan, with an access denied error. A bucket that is named in the stack but not tagged is left alone. +- **Skipping wins.** A bucket that carries an opt-in tag and a [skip tag](#excluding-resources) is not captured. +- **Only objects with a SHA256 checksum are fingerprinted.** S3 stores a full-object SHA256 checksum only when the upload asks for one, for example with `aws s3api put-object --checksum-algorithm SHA256`. An object without one, or one uploaded in several parts, is left out of the fingerprint, as if the bucket did not hold it. The fingerprint therefore matches an artifact you attested from the bucket's whole content only once every object carries the checksum, and a bucket where no object does is reported as holding no artifact. +- **Buckets encrypted with a KMS key are not supported.** The role is granted no KMS permission, so a bucket whose objects use SSE-KMS fails its snapshot. S3's default encryption, SSE-S3, needs nothing more. +- **Large buckets cost more and can time out.** A snapshot is one request per object, on every scan. At the default five minute frequency, a bucket of 100,000 objects is about 29 million requests a day. A bucket of more than roughly 100,000 objects may not finish in the time a snapshot is given, and then fails. Consider a longer [scan frequency](#scan-frequency) if you capture large buckets; it applies to everything Cloud Capture scans for you. +- **A newly tagged bucket is picked up on a later scan**, once AWS reports the tag. Removing the tag, or the opt-in tag from your settings, stops new snapshots; the environment keeps its last snapshot and nothing is deleted. + +Through the API, the tags are `opt_in_tags` on the same settings resource as the [skip tags](#excluding-resources), with the same shape. The settings PUT replaces every setting, so a PUT that leaves `opt_in_tags` out removes them, and your buckets stop being captured. + ## Scan frequency Cloud Capture scans your registered accounts every five minutes unless you choose otherwise. The frequency is a setting of your Kosli organization, so it applies to every account and region Cloud Capture scans for you. @@ -164,25 +252,25 @@ Through the API, the frequency is `scan_interval_minutes` on the same settings r Cloud Capture names each environment it reports into from a template. The default template is `{account_id}-{region}-{service}-{resource}`, so an ECS cluster named `app` in account `123456789012` and region `eu-central-1` reports into `123456789012-eu-central-1-ecs-app`. If a name matches an environment that already exists in your organization, Cloud Capture reports into that environment. This lets you name environments so you can tell accounts apart, or send snapshots into environments you already have. -To change the template, open your organization's **Settings**, go to **Cloud Capture**, and under **Environment names** select **Edit**. As you type, the page previews the names the template gives an example ECS cluster and a region's Lambda functions. Select **Save** to store it, or **Use the default** and then **Save** to go back to the default template. Like the other Cloud Capture settings, the template can only be changed while Cloud Capture is enabled. Resources are named with the new template from the next scan. +To change the template, open your organization's **Settings**, go to **Cloud Capture**, and under **Environment names** select **Edit**. As you type, the page previews the names the template gives example resources. Select **Save** to store it, or **Use the default** and then **Save** to go back to the default template. Like the other Cloud Capture settings, the template can only be changed while Cloud Capture is enabled. Resources are named with the new template from the next scan. A template is text with any of these placeholders: | Placeholder | Value | |-------------|-------| -| `{cloud}` | The cloud provider, for example `aws`. | -| `{account_id}` | The cloud account ID. | +| `{cloud}` | The cloud provider: `aws`, `azure` or `gcp`. | +| `{account_id}` | The cloud account ID: an AWS account ID, an Azure subscription ID or a Google Cloud project ID. | | `{account_name}` | The name you gave the account, for example `staging`. Empty for an account with no name. See [Account names](#account-names). | | `{account}` | The account's name where it has one, and its account ID where it does not. | -| `{region}` | The region, for example `eu-central-1`. | -| `{service}` | The service, for example `ecs` or `lambda`. | -| `{resource}` | The resource's own name, such as the ECS cluster name. | +| `{region}` | The region, for example `eu-central-1`. Empty on Azure, which is scanned a subscription at a time. | +| `{service}` | The service: `ecs`, `lambda` or `s3` on AWS, `apps` on Azure, `cloud-run` or `gke` on Google Cloud. | +| `{resource}` | The resource's own name: the ECS cluster, S3 bucket, Azure resource group or GKE cluster. | | `{tag:Key}` | The value of the resource's tag `Key`. For example, `aws-{tag:Env}` names a cluster tagged `Env=prod` as `aws-prod`. | How a template is rendered: - The text between placeholders can only hold letters, digits, `.`, `_` and `-`, and a template must start with a letter, a digit or a placeholder. Placeholder names are case-sensitive and take no formatting. -- A region's Lambda functions are captured together as one resource, so `{resource}` and every `{tag:Key}` are empty for them. An empty placeholder removes the separator before it: with the default template, a region's Lambda functions report into `123456789012-eu-central-1-lambda`. +- A region's Lambda functions are captured together as one resource, and so are a region's Cloud Run services and jobs, so `{resource}` and every `{tag:Key}` are empty for them. An empty placeholder removes the separator before it: with the default template, a region's Lambda functions report into `123456789012-eu-central-1-lambda`. - `{account_name}` is empty for an account with no name, and that account is still captured. When the empty placeholder starts the template, it removes the separator after it instead, so `{account_name}-{service}-{resource}` names a cluster `app` in an unnamed account `ecs-app`. With `{account}-{resource}`, a cluster named `payments` reports into `staging-payments` in an account named `staging`, and into `222222222222-payments` in account `222222222222` with no name. - Tag keys are case-sensitive, as AWS stores them, so `{tag:env}` does not read a tag named `Env`. A key may contain colons and spaces, as in `{tag:aws:cloudformation:stack-name}`. - A resource that does not carry a tag the template names is not captured, and the scan reports it as failed. So is a resource whose rendered name Kosli does not accept, for example because a tag value contains a space. A tag that is present with an empty value renders empty. diff --git a/administration/cloud_capture/overview.md b/administration/cloud_capture/overview.md index aad82f9..74ebd9f 100644 --- a/administration/cloud_capture/overview.md +++ b/administration/cloud_capture/overview.md @@ -29,10 +29,10 @@ Cloud Capture connects to your cloud accounts using permissions that you manage. |---|---|---|---| | AWS | Amazon ECS | Beta | One environment per cluster | | AWS | AWS Lambda | Beta | One environment per region, covering its functions | +| AWS | Amazon S3 | Beta | One environment per bucket, for the buckets you opt in by tag | | Azure | Azure App Service | Early access | One environment per resource group, covering its running container-based web apps | | Google Cloud | Cloud Run | Early access | One environment per project and region, covering its services and jobs | -| AWS | Amazon S3 | Planned | | -| Google Cloud | Google Kubernetes Engine (GKE) | Planned | | +| Google Cloud | Google Kubernetes Engine (GKE) | Early access | One environment per cluster | | Azure | Azure Kubernetes Service (AKS) | Planned | | Kosli's Customer Success team enables Cloud Capture for your organization. You then set it up yourself from your organization's Settings page, as described in [Getting started](/administration/cloud_capture/getting_started). @@ -48,7 +48,8 @@ Kosli's Customer Success team enables Cloud Capture for your organization. You t The security of your cloud infrastructure is the primary driver behind the internal architecture of Cloud Capture. You grant a read-only identity in your cloud account, protected by a trust condition that only Kosli can satisfy: an external ID on AWS, which acts as a shared secret between Kosli and -you, and a workload identity pool on Google Cloud. On Kosli's side, each Cloud Capture job runs under a role +you, a workload identity pool on Google Cloud, and on Azure an application you consent to and a tag +on your subscription that carries the same external ID. On Kosli's side, each Cloud Capture job runs under a role scoped to your organization alone, so a worker running for another tenant cannot reach your cloud account. Cloud Capture holds no tenant data; snapshots go straight to Kosli through the same ingest path as your existing pipelines. See [Cloud Capture Security](/administration/cloud_capture/security) @@ -60,11 +61,13 @@ Cloud Capture has been designed to operate with no on-going support from you. O ## Finding resources -Cloud Capture finds all [supported resources](#supported-platforms) within your cloud accounts, and determines which Kosli environment should hold the snapshots. Cloud Capture will create physical environments for you inside Kosli. You choose how those environments are named; see [Environment names](/administration/cloud_capture/getting_started#environment-names). +Cloud Capture finds the [supported resources](#supported-platforms) within your cloud accounts, in the services you select for each account, and determines which Kosli environment should hold the snapshots. Cloud Capture will create physical environments for you inside Kosli. You choose how those environments are named; see [Environment names](/administration/cloud_capture/getting_started#environment-names). You can keep a resource out of Cloud Capture by tagging it with any tag you have listed in your Cloud Capture settings; see [Excluding resources](/administration/cloud_capture/getting_started#excluding-resources). -As your cloud environment evolves, such as the addition of new AWS ECS clusters or the retirement of existing Lambdas, Cloud Capture automatically detects the changes. Because Cloud Capture creates physical environments as needed, when your infrastructure changes, Kosli will keep up. No changes to the configuration created during the initial setup are required. +Amazon S3 works the other way round. A bucket is snapshotted only when you opt it in, by tagging it with one of the S3 opt-in tags in your Cloud Capture settings, because a snapshot makes one request to AWS for every object in the bucket and most buckets hold data you would not want reported; see [Capturing S3 buckets](/administration/cloud_capture/getting_started#capturing-s3-buckets). + +As your cloud environment evolves, such as the addition of new AWS ECS clusters or GKE clusters, or the retirement of existing Lambdas, Cloud Capture automatically detects the changes. Because Cloud Capture creates physical environments as needed, when your infrastructure changes, Kosli will keep up. No changes to the configuration created during the initial setup are required. ## Multiple cloud accounts @@ -72,4 +75,4 @@ Cloud Capture can operate across multiple regions and cloud accounts, such as AW ## Operation -When Cloud Capture runs against one of your cloud accounts, it starts by gaining temporary credentials for the role you have created. It then uses these credentials to find resources to snapshot, such as all of your AWS ECS clusters or your Google Cloud Run services. For each resource it identifies, Cloud Capture generates a snapshot within Kosli. +When Cloud Capture runs against one of your cloud accounts, it starts by gaining temporary credentials for the identity you have granted it. It then uses these credentials to find resources to snapshot, such as all of your AWS ECS clusters or your Google Cloud Run services. For each resource it identifies, Cloud Capture generates a snapshot within Kosli. diff --git a/administration/cloud_capture/security.md b/administration/cloud_capture/security.md index 43ba3bb..c6c054c 100644 --- a/administration/cloud_capture/security.md +++ b/administration/cloud_capture/security.md @@ -11,11 +11,13 @@ Cloud Capture is still in active development. Its capabilities and configuration ## Cloud Capture permissions -The Cloud Capture managed service uses the public cloud APIs to extract information about your cloud environments. In order to do this, you need to provide Kosli with an identity in your cloud account that Kosli can use to call these APIs. The identity is created and managed by you. It must be protected by a trust condition that allows only Kosli to use it, and it must hold the read-only permissions Kosli needs to find and snapshot your resources. +The Cloud Capture managed service uses the public cloud APIs to extract information about your cloud environments. In order to do this, you need to provide Kosli with an identity in your cloud account that Kosli can use to call these APIs. The identity is created and managed by you. It must be protected by a trust condition that allows only Kosli to use it, and it must hold the read-only permissions Kosli needs to find and snapshot your resources. On Azure the identity is a Kosli application that you consent to and grant access; on AWS and Google Cloud it is a role or service account you create. -Kosli publishes a CloudFormation template, for use in AWS, showing the permissions needed. The template is publicly accessible and can be used directly within an `aws cloudformation create-stack` call. The current version, `aws/v0`, is published at `https://kosli-cloud-capture-templates.s3.eu-central-1.amazonaws.com/aws/v0/kosli-cloud-capture-access-role.yaml`, and the permissions shown on this page are taken from it. +Kosli publishes a CloudFormation template, for use in AWS, showing the permissions needed. The template is publicly accessible and can be used directly within an `aws cloudformation create-stack` call. The current version, `v0.2.0`, is published at `https://kosli-cloud-capture-templates.s3.eu-central-1.amazonaws.com/aws/v0.2.0/kosli-cloud-capture-access-role.yaml`, and the permissions shown on this page are taken from it. A published version is never changed; a change to the permissions is a new version, and reaches a role you have deployed only when you update your stack. + +Version `v0.2.0` adds one optional parameter to the earlier template, **S3 buckets** (`S3BucketNames`), for [capturing S3 buckets](/administration/cloud_capture/getting_started#capturing-s3-buckets). Left empty, the default, the role is the same as the one the earlier template created: it can read no object and no object key in any bucket. A role created from the earlier template keeps working for ECS and Lambda. If you wish to build an IAM role for Cloud Capture without using our published CloudFormation template, the permissions needed are those shown below. The role must contain an Assume Role policy that allows the Kosli account to access the resources, and must include an externalId. Both of these values are supplied by Kosli and cannot be derived; you cannot construct the trust policy without them. Whichever way you create the role, then register the account with the role's ARN, as described in [Getting started](/administration/cloud_capture/getting_started). @@ -24,12 +26,12 @@ If you wish to build an IAM role for Cloud Capture without using our published C The IAM role defined within the CloudFormation template includes an "assume role" policy granting permission from Kosli. This appears as: ```yaml - KosliCaptureAccessRole: + KosliCloudCaptureAccessRole: Type: AWS::IAM::Role Properties: RoleName: !Ref RoleName Description: >- - Read-only access for Cloud Capture SDLC compliance evidence collection. + Read-only access for Kosli Cloud Capture evidence collection. Managed by CloudFormation; do not edit in place. MaxSessionDuration: 3600 AssumeRolePolicyDocument: @@ -52,9 +54,12 @@ The IAM role defined within the Cloudformation template includes a number of IAM ```yaml Statement: - # How Capture finds what to snapshot. Discovery lists the ECS + # How Cloud Capture finds what to snapshot. Discovery lists the ECS # clusters in the account and reads each cluster's tags from the - # same DescribeClusters call. + # same DescribeClusters call; a cluster carrying the exclusion + # tag is skipped and everything else is snapshotted. Without + # ListClusters and DescribeClusters a role created from this + # template cannot run discovery at all. # # Worth knowing for a security review: these are inventory calls # and none of them returns application data. DescribeTaskDefinition @@ -81,6 +86,9 @@ Statement: - ecs:ListTasks Resource: "*" + # Lambda is the next snapshot target after ECS. Granted here so + # that adding it needs no change to a role you have already + # reviewed and deployed; read-only, like everything above. - Sid: LambdaInventory Effect: Allow Action: @@ -92,8 +100,10 @@ Statement: - lambda:ListVersionsByFunction Resource: "*" - # Bucket-level settings only. Cloud Capture does not snapshot S3 - # buckets yet; see the supported platforms on the overview page. + # Which buckets exist in a region, and bucket-level metadata, + # for every bucket; no object key and no object. Cloud Capture + # lists the buckets of a region to confirm the ones the tagging + # API named (see S3FindBucketsByTag below) are there. - Sid: S3BucketMetadataOnly Effect: Allow Action: @@ -107,15 +117,116 @@ Statement: - s3:ListAllMyBuckets Resource: "*" + # How Cloud Capture finds the buckets to snapshot; not granted + # when S3BucketNames is empty. A bucket is snapshotted only when + # it carries one of the S3 opt-in tags you set in Kosli, so + # Cloud Capture asks the Resource Groups Tagging API for the + # buckets carrying one, in place of reading the tags of every + # bucket in the account one by one on every scan. + # + # Worth knowing for a security review: AWS cannot scope this + # permission to S3 or to particular resources. It lets the role + # read the tag keys and values of every taggable resource in + # the account, whatever its service. Cloud Capture asks for + # resources of type s3:bucket carrying your opt-in tags, and + # for nothing else. Tags are metadata, but if yours hold + # anything you would not show Kosli, leave S3BucketNames empty. + - !If + - SnapshotsS3Buckets + - Sid: S3FindBucketsByTag + Effect: Allow + Action: + - tag:GetResources + Resource: "*" + - !Ref AWS::NoValue + + # What an S3 snapshot reads, in the buckets named in + # S3BucketNames and no others; neither statement exists when + # that parameter is empty. A snapshot records the fingerprint of + # a bucket's content: Cloud Capture lists the object keys, then + # reads the SHA256 checksum S3 stores for each object with a + # HeadObject request, which returns the object's metadata and no + # content. + # + # Worth knowing for a security review: AWS has no permission for + # reading an object's checksum alone. HeadObject is authorised by + # s3:GetObject, the permission that also authorises downloading + # the object, so this role is able to read the content of every + # object in the buckets you name. Cloud Capture downloads one + # object only, and only if it exists: a `.kosli_ignore` file at + # the root of the bucket, which lists the keys to leave out of + # the fingerprint. Name only the buckets you want snapshotted. + # + # No KMS permission is granted, so objects encrypted with a KMS + # key (SSE-KMS) cannot be read and their bucket's snapshot + # fails. Objects under S3's default encryption (SSE-S3) need + # nothing more than this. + # + # The ARNs are built from the list by joining it: for + # `a,b` the first is arn:aws:s3:::a and arn:aws:s3:::b, and the + # second arn:aws:s3:::a/* and arn:aws:s3:::b/*. + - !If + - SnapshotsS3Buckets + - Sid: S3ListObjectKeysInNamedBuckets + Effect: Allow + Action: + - s3:ListBucket + Resource: !Split + - "," + - !Join + - "" + - - "arn:aws:s3:::" + - !Join [",arn:aws:s3:::", !Ref S3BucketNames] + - !Ref AWS::NoValue + + - !If + - SnapshotsS3Buckets + - Sid: S3ReadObjectChecksumsInNamedBuckets + Effect: Allow + Action: + - s3:GetObject + Resource: !Split + - "," + - !Join + - "" + - - "arn:aws:s3:::" + - !Join ["/*,arn:aws:s3:::", !Ref S3BucketNames] + - "/*" + - !Ref AWS::NoValue + # The explicit denies below are redundant given the allow-list # above, but they are here so that a security reviewer can # verify the boundary without having to reason about IAM # defaults, and so that any future widening of this policy cannot # accidentally grant data-plane access. - - Sid: NeverReadObjectData + # + # s3:GetObject is denied everywhere except in the buckets named + # in S3BucketNames, and everywhere when none is named. + - !If + - SnapshotsS3Buckets + - Sid: NeverReadObjectDataOutsideNamedBuckets + Effect: Deny + Action: + - s3:GetObject + NotResource: !Split + - "," + - !Join + - "" + - - "arn:aws:s3:::" + - !Join ["/*,arn:aws:s3:::", !Ref S3BucketNames] + - "/*" + - Sid: NeverReadObjectData + Effect: Deny + Action: + - s3:GetObject + Resource: "*" + + # Every other way to read an object, its earlier versions, its + # ACL or its tags is denied in every bucket, named or not: a + # snapshot needs none of them. + - Sid: NeverReadObjectVersionsAclsOrTags Effect: Deny Action: - - s3:GetObject - s3:GetObjectAcl - s3:GetObjectAttributes - s3:GetObjectTagging @@ -129,6 +240,9 @@ Statement: # lambda:GetFunction returns a pre-signed URL to the deployment # package. That is source-code access, so it is denied outright. + # GetLayerVersion does the same for a layer's package, and it is + # also the IAM action behind the GetLayerVersionByArn API call, + # so both routes to a layer's code are denied here. - Sid: NeverDownloadFunctionCode Effect: Deny Action: @@ -137,19 +251,50 @@ Statement: Resource: "*" ``` +### What capturing S3 buckets grants + +The S3 statements above exist only when you name buckets in the **S3 buckets** parameter. Three things are worth knowing for a security review: + +- **The role can read the content of every object in the buckets you name.** Cloud Capture reads the SHA256 checksum S3 stores for each object with a `HeadObject` request, which returns metadata and no content. AWS has no permission for reading a checksum alone: `HeadObject` is authorized by `s3:GetObject`, the permission that also authorizes a download. Cloud Capture downloads one object only, a `.kosli_ignore` file at the root of a bucket if there is one. Reads of object versions, ACLs, tags and attributes stay denied in every bucket, and `s3:GetObject` stays denied in every bucket you did not name. +- **The role can read the tags of every taggable resource in the account.** Cloud Capture finds the buckets that carry one of your S3 opt-in tags by asking the Resource Groups Tagging API (`tag:GetResources`), which avoids reading the tags of every bucket one by one on every scan. AWS cannot scope that permission to S3 or to particular resources. Cloud Capture asks only for resources of type `s3:bucket` that carry an opt-in tag. +- **No KMS permission is granted.** Objects encrypted with a KMS key (SSE-KMS) cannot be read, and their bucket's snapshot fails. + +A name in the parameter may use `*` and `?` as wildcards, as an IAM resource may. A bare `*` names every bucket in the account. Naming a bucket is a permission, not a selection: Cloud Capture snapshots a bucket only when it also carries one of your S3 opt-in tags. + - + - -This setup describes Google Kubernetes Engine (GKE), which is planned. Cloud Run is in early access; contact Kosli's Customer Success team for its setup. - +Azure support is in early access. + +Nothing is deployed in your Azure tenant. Kosli registers one multi-tenant application in Microsoft Entra, and Cloud Capture reads your subscription as that application. The application's credentials are Kosli's own and never leave Kosli. Access is granted in three steps, each of which you control: + +1. **Consent.** A Global Administrator of your tenant consents to the Kosli application, which creates its service principal in your tenant. Consent alone grants no access to any subscription. +2. **Role assignments.** You assign the application two built-in roles on each subscription you want scanned: + + | Role | What Cloud Capture uses it for | + |---|---| + | `Reader` | Listing the App Service sites in the subscription, and reading resource group tags and the subscription's own tags | + | `AcrPull` | Fingerprinting the container images of your web apps from your container registries | + +3. **A tag on the subscription.** You tag the subscription `kosli-external-id` with your organization's external ID. Cloud Capture refuses to list a subscription whose tag does not match the external ID of the organization it is working for. + +The registration form in the Kosli UI shows the consent link and the three Azure CLI commands with your values filled in; see [Getting started](/administration/cloud_capture/getting_started). + +To withdraw access, remove the role assignments or the tag from the subscription, or delete the application's service principal from your tenant, and remove the subscription from your registered accounts in Kosli. + + + + +Google Cloud support is in early access. Kosli publishes a Terraform configuration, for use with -[Infrastructure Manager](https://cloud.google.com/infrastructure-manager/docs), showing the -permissions needed to snapshot Google Kubernetes Engine (GKE) clusters. 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 that holds clusters you want Cloud -Capture to snapshot. +[Infrastructure Manager](https://cloud.google.com/infrastructure-manager/docs), 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](https://cloud.google.com/iam/docs/workload-identity-federation). Cloud @@ -170,29 +315,91 @@ forge it. For readers familiar with the AWS setup: the account check plays the part of the principal in the assume-role trust policy, and the role check plays the part of the external ID. -Kosli needs two values to connect to your project: the full resource name of the workload identity -provider, and the email of the service account. The configuration emits both as Terraform outputs. -After the deployment completes, register them with Kosli through the Kosli API's cloud accounts -endpoint. You can read them at any time from the deployment's latest revision, under -`applyResults.outputs`, with `gcloud infra-manager revisions describe`. +### What the configuration creates -{/* TODO: Link to the cloud accounts endpoint in the API reference once it is published. */} +| Resource | Name | What it is for | +|---|---|---| +| Workload identity pool | `kosli-capture` | Exchanges Cloud Capture's AWS credentials for a Google token | +| AWS provider in the pool | `kosli-aws` | Accepts the Kosli AWS account and, within it, only the Kosli-side role for your organization | +| Service account | `kosli-capture@.iam.gserviceaccount.com` | The identity Cloud Capture acts as in the project. Only the Kosli-side role for your organization may impersonate it | +| Enabled APIs | IAM, IAM Credentials, Security Token Service, Cloud Run, Cloud Resource Manager, Cloud Asset | Needed to create the resources above and to make the read calls below. None is disabled if you destroy the deployment | -If you wish to grant access for Cloud Capture without using our published configuration, the -resources needed are those shown below. The pool must accept only the Kosli AWS account and, within -it, only the Kosli-side role for your organization, and only that role may impersonate the service -account. The specific permissions needed to find and snapshot GKE clusters are in the custom role. +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 [Getting started](/administration/cloud_capture/getting_started). -### Workload identity federation +### Permissions granted to the service account -The Terraform configuration creates a workload identity pool, an AWS provider within it that trusts -the Kosli-side role for your organization, and a service account that only that role may -impersonate. This appears as: +All of the grants are read-only, and all are on the project. + +| Grant | Permissions | What Cloud Capture uses it for | +|---|---|---| +| `roles/run.viewer` | Google's predefined Cloud Run viewer role | Listing a region's Cloud Run services and jobs with their labels, and reading each service's revisions and images | +| Custom role `kosliCaptureRegistry` | `artifactregistry.tags.get` | Resolving an image referenced by tag to its digest. This is a metadata read; no image layer is ever pulled | +| Custom role `kosliCaptureGke` | `container.clusters.list`, `cloudasset.assets.listContainerPod`, `serviceusage.services.use` | Listing the project's GKE clusters with their labels, and reading the project's pods from [Cloud Asset Inventory](https://cloud.google.com/asset-inventory/docs/overview), in the same way as [`kosli snapshot gke`](/client_reference/kosli_snapshot_gke). Google requires `serviceusage.services.use` of every Cloud Asset Inventory call | + +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.viewer` + would 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. + +If you wish to grant access for Cloud Capture without using our published configuration, create +the resources and grants in the two tables above. The pool must accept only the Kosli AWS account +and, within it, only the Kosli-side role for your organization, and only that role may impersonate +the service account. + +### The configuration in full + + ```hcl +# The Google Cloud resources Kosli Cloud Capture needs in a customer's +# project, for use with Infrastructure Manager; the README beside this +# directory says how to deploy it and why it is shaped as it is. +# +# Cloud Capture runs in AWS and reaches the project through Workload Identity +# Federation: it exchanges its own short-lived AWS credentials for a +# short-lived Google token, then impersonates the service account created +# here. No service account key is ever created, stored or shared. The pool +# makes two checks before it issues a token: the credentials were issued by +# the Kosli AWS account that serves the customer, and within that account by +# the one IAM role Kosli keeps for the customer's organisation. A Cloud +# Capture job for another tenant runs under a different role and is refused. + +terraform { + required_version = ">= 1.5" + + required_providers { + google = { + source = "hashicorp/google" + version = ">= 5.0, < 8.0" + } + } +} + +provider "google" { + project = var.project_id +} + variable "project_id" { type = string - description = "The GCP project that holds the GKE clusters Cloud Capture will snapshot." + description = "The GCP project that holds the Cloud Run services and jobs, and the GKE clusters, Cloud Capture will snapshot." + + validation { + condition = can(regex("^[a-z][a-z0-9-]{4,28}[a-z0-9]$", var.project_id)) + error_message = "Must be a project id: 6 to 30 lowercase letters, digits and hyphens, starting with a letter." + } } variable "kosli_aws_account_id" { @@ -213,10 +420,10 @@ variable "kosli_role_name" { type = string description = <<-EOT The name of the IAM role, in the Kosli AWS account, that Cloud Capture - uses when working for your organization. Supplied by Kosli. Each Kosli - organization has its own role, and the workload identity pool accepts + uses when working for your organisation. Supplied by Kosli. Each Kosli + organisation has its own role, and the workload identity pool accepts only this one, so only Cloud Capture jobs run on behalf of your - organization can obtain a token from your project. In the AWS setup, + organisation can obtain a token from your project. In the AWS setup, the external ID plays the same part. EOT @@ -226,9 +433,33 @@ variable "kosli_role_name" { } } -# Cloud Capture runs in AWS. Workload Identity Federation lets it exchange its -# own short-lived AWS credentials for a short-lived Google token, so no service -# account key is ever created, stored or shared. +# The APIs the exchange and the inventory go through. Cloud Run is enabled +# already in a project with services in it; the IAM ones are what creating a +# pool, a service account and the custom roles, and impersonating the account, +# need; Cloud Resource Manager is what granting the project roles below +# needs, and a fresh project does not have it on; Cloud Asset is the +# inventory a GKE snapshot reads the project's pods from, and costs nothing +# to have on. None is disabled on destroy: they may well be in use by +# something else in the project. +# +# The Kubernetes Engine API is not in the list. A project with clusters has +# it on already, and enabling it in a project without them would switch on +# Compute Engine and its other dependencies for nothing. +resource "google_project_service" "needed" { + for_each = toset([ + "iam.googleapis.com", + "iamcredentials.googleapis.com", + "sts.googleapis.com", + "run.googleapis.com", + "cloudresourcemanager.googleapis.com", + "cloudasset.googleapis.com", + ]) + + project = var.project_id + service = each.key + disable_on_destroy = false +} + resource "google_iam_workload_identity_pool" "kosli_capture" { project = var.project_id workload_identity_pool_id = "kosli-capture" @@ -237,6 +468,8 @@ resource "google_iam_workload_identity_pool" "kosli_capture" { Read-only access for Cloud Capture SDLC compliance evidence collection. Managed by Infrastructure Manager; do not edit in place. EOT + + depends_on = [google_project_service.needed] } resource "google_iam_workload_identity_pool_provider" "kosli_aws" { @@ -249,8 +482,14 @@ resource "google_iam_workload_identity_pool_provider" "kosli_aws" { account_id = var.kosli_aws_account_id } + # The role is read out of the assumed-role ARN AWS signed, less its + # session name, so every session of the role is the one principal. The + # subject is the role as well, and not the whole ARN: a subject is at most + # 127 bytes, and the ARN carries the account, the session name and the + # role's name, which can be 64 characters, so a long role name would put + # the ARN over the limit and every exchange would fail. attribute_mapping = { - "google.subject" = "assertion.arn" + "google.subject" = "assertion.arn.extract('assumed-role/{role}/')" "attribute.account" = "assertion.account" "attribute.aws_role" = "assertion.arn.extract('assumed-role/{role}/')" } @@ -258,7 +497,7 @@ resource "google_iam_workload_identity_pool_provider" "kosli_aws" { # Two checks before the pool issues a token. The account check accepts only # credentials issued by the Kosli AWS account, however the token reaches # Google. The role check accepts, within that account, only the Kosli-side - # role dedicated to your organization. A Cloud Capture job for another tenant + # role dedicated to your organisation. A Cloud Capture job for another tenant # runs under a different role and is refused here. In the AWS setup, these # checks correspond to the trust policy principal and the external ID. attribute_condition = join(" && ", [ @@ -271,10 +510,15 @@ resource "google_service_account" "kosli_capture" { project = var.project_id account_id = "kosli-capture" display_name = "Cloud Capture" - description = "Impersonated by Cloud Capture to snapshot GKE clusters. Managed by Infrastructure Manager." + description = "Impersonated by Cloud Capture to snapshot Cloud Run services and jobs, and GKE clusters. Managed by Infrastructure Manager." + + # Ordered after the APIs, as the pool is: creating a service account needs + # iam.googleapis.com, which a project may not have enabled before this, and + # the four bindings below follow through their references to the account. + depends_on = [google_project_service.needed] } -# Only the Kosli-side role for your organization may impersonate the service +# Only the Kosli-side role for your organisation may impersonate the service # account. The pool's attribute condition already refuses every other identity; # naming the role here as well keeps the binding correct even if that condition # is later loosened. @@ -284,86 +528,113 @@ resource "google_service_account_iam_member" "kosli_impersonation" { member = "principalSet://iam.googleapis.com/${google_iam_workload_identity_pool.kosli_capture.name}/attribute.aws_role/${var.kosli_role_name}" } -# Kosli needs these two values to connect. Infrastructure Manager records them -# on the deployment's latest revision, under applyResults.outputs. -output "kosli_capture_provider" { - description = "Full resource name of the workload identity provider; give this to Kosli." - value = google_iam_workload_identity_pool_provider.kosli_aws.name -} - -output "kosli_capture_service_account" { - description = "Email of the service account Cloud Capture impersonates; give this to Kosli." - value = google_service_account.kosli_capture.email +# What the service account may read. Discovery lists the region's Cloud Run +# services and jobs and reads each one's labels from the same listing, and +# the snapshot reads each service's revisions and the images they run: all +# of it is in roles/run.viewer, the predefined read-only role, and none of it +# returns application data. A revision's spec is the widest: it holds the +# container image, the command, and any environment variables written into +# the spec in plain text; a value taken from a Secret is named there rather +# than resolved, so what comes back is the reference and not the secret. +resource "google_project_iam_member" "kosli_capture_run" { + project = var.project_id + role = "roles/run.viewer" + member = google_service_account.kosli_capture.member } -``` -### GKE permissions - -The Terraform configuration grants the service account a custom role containing read-only -permissions. Cloud Capture reads the pods of your GKE clusters from -[Cloud Asset Inventory](https://cloud.google.com/asset-inventory/docs/overview), in the same way as -[`kosli snapshot gke`](/client_reference/kosli_snapshot_gke). It never calls a cluster's Kubernetes -API, so no Kubernetes RBAC objects need to be created inside your clusters, and Cloud Capture needs -no network access to any cluster control plane. +# The snapshot also resolves each image pinned by a tag to its digest, which +# the Kosli CLI (2.57.0 on) reads from the Artifact Registry API: metadata +# about the tag, and never the image. The predefined read-only role would +# also grant downloadArtifacts, which pulls image layers, so a custom role +# grants the one read the lookup makes and nothing that returns a layer. +# The CLI's other lookup, a tag for an image pinned by digest, is behind a +# flag Cloud Capture does not pass, so its permission +# (artifactregistry.dockerimages.get) is not granted either. The CLI falls +# back to reading the manifest when the API call fails; under this grant +# that fallback cannot succeed, and nothing depends on it, since the +# registries it could read are the ones the API lookup reads. Cloud Run +# reports a service's image already pinned by digest, which the CLI takes +# from the name, so what this grant resolves in practice is a job's image. +# Without this grant a snapshot still succeeds, with an empty digest for +# each tag-pinned image the account could not read. +resource "google_project_iam_custom_role" "kosli_capture_registry" { + project = var.project_id + role_id = "kosliCaptureRegistry" + title = "Cloud Capture registry metadata" + description = "Read-only image tag metadata for Cloud Capture SDLC compliance evidence collection." -The configuration also enables the Cloud Asset API in your project. These appear as: + permissions = ["artifactregistry.tags.get"] -{/* TODO: Confirm Cloud Capture still discovers clusters with container.clusters.list/get. If discovery also goes through Cloud Asset Inventory, replace those two permissions and the "How Capture finds what to snapshot" comment. */} + depends_on = [google_project_service.needed] +} -```hcl -# Cloud Capture reads pods through the Cloud Asset API, so it must be enabled -# in the project. -resource "google_project_service" "cloudasset" { - project = var.project_id - service = "cloudasset.googleapis.com" - disable_on_destroy = false +resource "google_project_iam_member" "kosli_capture_registry" { + project = var.project_id + role = google_project_iam_custom_role.kosli_capture_registry.id + member = google_service_account.kosli_capture.member } -# How Capture finds what to snapshot. Discovery lists the GKE clusters in the -# project and reads each cluster's labels from the same clusters.get call. +# What the service account may read of the project's GKE clusters (beta). +# Cloud Capture never connects to a cluster: it needs no network path to one, +# no kubeconfig and no Kubernetes RBAC. Discovery lists the project's +# clusters, with their labels, through the Kubernetes Engine API; the +# snapshot reads the project's pods from Cloud Asset Inventory, Google's own +# record of what is in the project, and Google requires +# serviceusage.services.use of every call to it. # -# Worth knowing for a security review: Cloud Capture reads pods from Cloud -# Asset Inventory rather than from each cluster's Kubernetes API, so it needs -# no Kubernetes RBAC and no network access to any cluster control plane. None -# of it returns application data. listContainerPod is the widest - a pod spec -# holds the container image, the command, and any environment variables -# written into the spec itself in plain text. Values taken from a Secret or -# ConfigMap are named there rather than resolved, so what comes back is the -# reference and not the secret. This role lists pod assets only; the broader -# roles/cloudasset.viewer would also list k8s.io/Secret assets. -resource "google_project_iam_custom_role" "kosli_capture" { +# A custom role because the predefined ones are wider than this: +# roles/cloudasset.viewer lists every asset type in the project, and +# roles/container.clusterViewer more than the one listing. It cannot be +# narrower than every pod in the project, since Cloud Asset Inventory filters +# by neither cluster nor namespace. A pod's record holds its spec and status: +# the images, commands and arguments, its labels and annotations, and any +# environment variables written into the spec in plain text; a value taken +# from a Secret is named there rather than resolved, so what comes back is +# the reference and not the secret. A cluster's listing holds its +# configuration and no credentials. +resource "google_project_iam_custom_role" "kosli_capture_gke" { project = var.project_id - role_id = "kosliCapture" - title = "Cloud Capture" - description = "Read-only GKE inventory for Cloud Capture SDLC compliance evidence collection." + role_id = "kosliCaptureGke" + title = "Cloud Capture (GKE)" + description = "Lists GKE clusters, and their pods from Cloud Asset Inventory, for Cloud Capture. Managed by Infrastructure Manager." permissions = [ - # Discovery - "container.clusters.get", "container.clusters.list", - - # Snapshot: the Cloud Asset Inventory calls that kosli snapshot gke makes. - # serviceusage.services.use lets the Cloud Asset API calls use this - # project as their quota project. "cloudasset.assets.listContainerPod", "serviceusage.services.use", ] + + depends_on = [google_project_service.needed] } -resource "google_project_iam_member" "kosli_capture" { +resource "google_project_iam_member" "kosli_capture_gke" { project = var.project_id - role = google_project_iam_custom_role.kosli_capture.id + role = google_project_iam_custom_role.kosli_capture_gke.id member = google_service_account.kosli_capture.member } + +# Kosli needs these two values to connect. Infrastructure Manager records them +# on the deployment's latest revision, under applyResults.outputs. +output "kosli_capture_provider" { + description = "Full resource name of the workload identity provider; give this to Kosli." + value = google_iam_workload_identity_pool_provider.kosli_aws.name +} + +output "kosli_capture_service_account" { + description = "Email of the service account Cloud Capture impersonates; give this to Kosli." + value = google_service_account.kosli_capture.email +} ``` + + ### Deploying with Infrastructure Manager -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. -Copy the Kosli AWS account ID and role name from the Cloud Capture section of your organization's -Settings page in the Kosli UI. +Download the configuration into an empty directory and run the following from it. 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. The Kosli AWS account ID and role name are shown in the first step of the Google Cloud +registration form in the Kosli UI. ```bash gcloud infra-manager deployments apply \ @@ -398,7 +669,18 @@ Capture is running. The ExternalId acts as a shared secret between Kosli and you Cloud Capture is permitted to assume the role. - + + +* The Kosli application's credentials are held by Kosli and are not readable by the part of Cloud + Capture that plans work, only by the workers that carry it out. +* Before a worker lists anything in a subscription, it reads the subscription's `kosli-external-id` + tag and compares it with the external ID of the organization the job is for. Only someone with + write access to your subscription can set that tag, so another Kosli tenant that registered your + subscription ID would be refused. +* The application has access only to the subscriptions on which you assigned it a role. + + + Each Cloud Capture job for your organization runs under the Kosli-side IAM role dedicated to your organization. The workload identity pool in your project accepts only that role, so a job running @@ -413,6 +695,8 @@ immediately sent to Kosli through the same ingest path as your existing pipeline ## Changing security permissions -If the role, or the service account and workload identity pool, that Cloud Capture uses is removed -or edited within your cloud accounts, Cloud Capture will fail to operate correctly. The failure will be detected and the account will be -removed from the list of accounts captured. +If the role, the service account and workload identity pool, or the role assignments and tag that +Cloud Capture uses are removed or edited within your cloud accounts, scans of that account fail. +Kosli is not notified of the change and does not remove the account for you: the account stays in +your **Registered accounts** table, with its scans shown as failed, until you restore the +permissions or remove the account.