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.
Steps
-
The key and its job
You are on
operatorwith the CI deploy key. A key has two halves: an id (theAKIA…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-urlsends 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 -
-
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 withaws iam get-user-policy. Print thekeyssection withjqand read the key'sallowstatement closely, in particular thebucketsit names.api:~# jq .keys /opt/cloud/seeds/iam-overreach.json
-
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 -
-
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 theallowstatement sobucketslistsquillfeather-buildsin 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-policyor your infrastructure code. -
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-buildsas it did at the start, so nothing in the CI pipeline breaks. Second, the over-reach must be gone: the same key, run againstquillfeather-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