Labs / Cloud Security / Data left in the open: buckets, keys & code

Lab 2 of 3 · Data left in the open: buckets, keys & code

A deploy key that could read everything

A CI key scoped to `*`, caught over-reaching into the orders bucket and cut back to least privilege.

Start this lab 5 steps

The idea

Ronan looks after the cloud accounts at Quillfeather Books, an online bookshop. The CI pipeline (the automation that builds and publishes the shop's code) has an access key, AKIA…DEPLOY000, whose one job is to publish build artefacts to the quillfeather-builds bucket. This week's access review asks a blunt question: if that key leaked out of a CI log tomorrow, what could a stranger reach with it?

You are at Ronan's desk with the aws command-line tool and the key. Use it for its real job, read the policy attached to it, and test what the policy allows. Then cut it down to the one bucket the key needs, and prove the key's real job still works.

Who is calling, then what it may do
Who is calling, then what it may do
One star stands for every bucket
One star stands for every bucket
A leaked key is the same key
A leaked key is the same key
The policy sets the blast radius
The policy sets the blast radius
Two tests catch two mistakes
Two tests catch two mistakes

Steps

  1. The key and its job

    You are on operator with the CI deploy key. A key has two halves: an id (the AKIA… string, which says which key is calling) and a secret (used to sign the request, proving the caller really holds the key).

    The signature proves identity; it does not grant anything. What the request may do is decided separately, by the policy the cloud looks up from the key's id.

    Put the key in this command's environment, point it at its bucket, quillfeather-builds, and read the deploy log it leaves there. --endpoint-url sends the request to this lab's cloud API; on real AWS you leave it out.

    operator:~# AWS_ACCESS_KEY_ID=AKIAQUILLCIDEPLOY000 AWS_SECRET_ACCESS_KEY=ci-deploy-secret aws --endpoint-url http://10.0.1.20 s3 ls s3://quillfeather-builds
    operator:~# AWS_ACCESS_KEY_ID=AKIAQUILLCIDEPLOY000 AWS_SECRET_ACCESS_KEY=ci-deploy-secret aws --endpoint-url http://10.0.1.20 s3 cp s3://quillfeather-builds/deploy-log.txt -
  2. Read the policy

    Every access key is governed by a policy: the rule, attached to the user or role the key belongs to, that says which actions it may take and on which buckets.

    In this lab the account's policies live in a config file on api. On real AWS you would ask the IAM service instead, for example with aws iam get-user-policy. Print the keys section with jq and read the key's allow statement closely, in particular the buckets it names.

    api:~# jq .keys /opt/cloud/seeds/iam-overreach.json
  3. What the wildcard reaches

    A wildcard only matters if it reaches something worth having. Here it does: quillfeather-orders, where the shop keeps customer orders. The deploy key should have no path to it.

    Test the over-reach: list the orders bucket with the same CI key, then read an order file. Ronan may do this because the estate is Quillfeather's and auditing it is his job. Using a key you happen to hold against a system whose owner has not authorised you in writing is an intrusion, wildcard or not.

    operator:~# AWS_ACCESS_KEY_ID=AKIAQUILLCIDEPLOY000 AWS_SECRET_ACCESS_KEY=ci-deploy-secret aws --endpoint-url http://10.0.1.20 s3 ls s3://quillfeather-orders
    operator:~# AWS_ACCESS_KEY_ID=AKIAQUILLCIDEPLOY000 AWS_SECRET_ACCESS_KEY=ci-deploy-secret aws --endpoint-url http://10.0.1.20 s3 cp s3://quillfeather-orders/orders-2026-11.csv -
  4. Scope it down

    Least privilege is the principle that a key (or user, or role) should hold exactly the access its job needs, and nothing more. The point is blast radius: if a key can only reach one bucket, then a leak of it costs that one bucket, not the whole account.

    This key's job is to publish to quillfeather-builds, so that is the only bucket its policy should name. Rewrite the allow statement so buckets lists quillfeather-builds in place of the wildcard, leaving its actions (s3:ListBucket, s3:GetObject) as they are.

    The lab's cloud API re-reads the file the moment it changes, so the narrowed policy takes effect at once. On real AWS the same edit goes through aws iam put-user-policy or your infrastructure code.

  5. Prove least privilege

    Scoping a policy down can break the very job the key is for, so test both directions.

    First, the key must still do its work: list quillfeather-builds as it did at the start, so nothing in the CI pipeline breaks. Second, the over-reach must be gone: the same key, run against quillfeather-orders, must now be refused.

    If the orders bucket is denied and the build bucket still answers, the policy is right. Run the two commands and read both results.

    operator:~# AWS_ACCESS_KEY_ID=AKIAQUILLCIDEPLOY000 AWS_SECRET_ACCESS_KEY=ci-deploy-secret aws --endpoint-url http://10.0.1.20 s3 ls s3://quillfeather-builds
    operator:~# AWS_ACCESS_KEY_ID=AKIAQUILLCIDEPLOY000 AWS_SECRET_ACCESS_KEY=ci-deploy-secret aws --endpoint-url http://10.0.1.20 s3 ls s3://quillfeather-orders

Run these steps on real machines

Keep reading

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab