Set up
1
Create the IAM role
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 Permissions and 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.
2
Register your accounts
When you have created the IAM role, using the CloudFormation template, you can activate Cloud Capture within the Kosli user-interface.To check environment names, or to exclude resources, before any snapshots are recorded, switch on Dry run and add skip tags 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, 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. 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, and picks up a registered account the next time it runs - you should see environments and snapshots appearing within a few minutes.
Excluding resources
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.-
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: -
In the Skip tags panel, enter the key
kosli-captureand the valuefalse, select Add, then Save.
- 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=testdoes not matchenv=test. A key on its own does not match: to skip bothenv=testandenv=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. An S3 bucket is only ever snapshotted when it carries an S3 opt-in tag; 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:DescribeClustersandlambda:ListTags, so no change to the role is needed.
aws list of skip_tags; see Using the API.
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.
1
Name the buckets in the CloudFormation stack
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 What capturing S3 buckets grants for exactly what it grants.2
Choose an S3 opt-in tag
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.3
Tag each bucket you want captured
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.4
Select S3 on the account
In the Registered accounts table, edit the account and select s3 among its services.
- Each bucket is its own environment, of type S3, named by your environment name template with the bucket name as
{resource}. - Each bucket reports exactly one artifact, named after the bucket. A bucket holding several objects is fingerprinted as a directory, and a bucket holding a single object is fingerprinted as that file, so attest that file with
--artifact-type filefor the fingerprints to match. Either way the artifact carries the bucket’s name, not the object’s. - An empty bucket is captured, not failed. It reports one artifact, named after the bucket, with the fingerprint of an empty directory:
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855. Every empty bucket therefore shares that fingerprint. It is also the fingerprint of an empty file, so an empty bucket matches any artifact attested from one. - 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 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 an empty bucket. - 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 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.
opt_in_tags on the settings resource, with the same shape as skip_tags. The settings PUT replaces every setting, so a PUT that leaves opt_in_tags out removes them, and your buckets stop being captured.
Permissions and security
For the model that is common to every cloud, see Cloud Capture security. Kosli publishes a CloudFormation template, for use in AWS, showing the permissions needed. The template is publicly accessible and can be used directly within anaws 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. 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 Set up.
Assume role
The IAM role defined within the CloudFormation template includes an “assume role” policy granting permission from Kosli. This appears as:All permissions needed
The IAM role defined within the Cloudformation template includes a number of IAM policy statements, granting read-only access to some AWS APIs. In summary:- ECS and Lambda: read-only inventory calls on every cluster and function. None returns application data, and downloading a function’s or a layer’s code is explicitly denied.
- S3: bucket-level metadata for every bucket. Object keys and objects can be read only in the buckets you name, and not at all when you name none; see What capturing S3 buckets grants.
IAM policy statements, version v0.2.0
IAM policy statements, version v0.2.0
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
HeadObjectrequest, which returns metadata and no content. AWS has no permission for reading a checksum alone:HeadObjectis authorized bys3:GetObject, the permission that also authorizes a download. Cloud Capture downloads one object only, a.kosli_ignorefile at the root of a bucket if there is one. Reads of object versions, ACLs, tags, and attributes stay denied in every bucket, ands3:GetObjectstays 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 types3:bucketthat 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.
* 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.
Tenant isolation
- A Cloud Capture worker picks up a job for your organization and assumes the role in your account using your externalId. A worker running for a different tenant is unable to read the externalId for your cloud account.
- When the job finishes, the temporary credentials for your account are discarded. A worker holding credentials for your cloud account has no path to anyone else’s account.
- The ExternalId lives in Kosli’s Parameter Store and is readable only by the Kosli-side role for your organization. The shared task role cannot read any tenant’s ExternalId. Separation is enforced by IAM, not by application code.