{"data":{"kind":"file","path":"README.md","version_id":"u1ipsjnek4fx8ezhbcjpepd1","entry":{"name":"README.md","path":"README.md","is_directory":false,"size":4670,"modified_at":"2026-11-30T15:03:16.531000","content_hash":"695b617ff81e80917d68531a206aff95b15cc7ddb2d0e22635fa0ca8796f4999"},"entries":[],"content":"# iam-least-privilege\n\nWrite a **least-privilege AWS IAM policy** for a workload, then get graded by a built-in IAM policy evaluator that replays hidden requests against it.\n\n| | |\n|---|---|\n| Type | single-turn, answer-only (defaults to the tool-less `null` harness) |\n| Tasks | procedurally generated, deterministic per `(seed, index)`, 1000 by default |\n| Reward | `allow_recall × deny_rate` in [0, 1]; 1.0 only for an exact least-privilege policy |\n| Dependencies | none beyond `verifiers` (the grader is pure Python) |\n\n## The task\n\nThe prompt gives the model:\n\n1. an AWS account, region and workload (for example \"the order service API running on ECS Fargate\");\n2. an **inventory of real-looking resource ARNs**, including decoys: the same resource in another stage or region, `-replica` buckets, `-archive` tables, `-dlq` queues, `.fifo` topics, `-canary` functions, and `-admin` secrets;\n3. two to four **access requirements**, for example \"Perform `GetObject` on objects whose keys start with `incoming/` in the `acme-invoices-prod` bucket\".\n\nThe model returns an identity-based policy inside `<policy></policy>` tags.\n\n## Grading\n\nEach task carries hidden probes, never shown to the model:\n\n* **allow probes**: requests the requirements need, for example `s3:GetObject` on `arn:aws:s3:::acme-invoices-prod/incoming/2026/03/inv-4821.pdf`;\n* **deny probes**: near misses that a sloppy policy lets through.\n\n| Mistake | Probe that catches it |\n|---|---|\n| Wildcard too broad (`acme-invoices-prod*`) | same action on the `-replica` bucket, `-archive` table, `-dlq` queue or `-canary` function |\n| Prefix without the trailing slash (`incoming*`) | object under `incoming-old/` |\n| Wrong region or account wildcard | same resource in another region |\n| Extra actions (`s3:*`, `dynamodb:*`) | `DeleteObject`, `DeleteTable`, `PurgeQueue`, `PutKeyPolicy`, ... on the right resource |\n| Table grant assumed to cover indexes | `Query` on `table/X/index/Y` |\n| Missing qualified Lambda ARNs | `InvokeFunction` on `function:X:live` and `function:X:7` |\n| Secret wildcard `name-*` | `GetSecretValue` on the `name-admin-AbC123` secret |\n| `\"Action\": \"*\"` / admin shortcuts | `iam:PassRole`, `sts:AssumeRole`, `ec2:TerminateInstances`, an unrelated audit bucket |\n| Deny statement too broad (`pii*`) | `GetObject` under `pii-summary/` must still work |\n\nThe evaluator implements IAM's decision logic for identity policies: explicit `Deny` beats `Allow`, and with no matching `Allow` the request is implicitly denied. It supports `Action`/`NotAction` (case-insensitive) and `Resource`/`NotResource` (case-sensitive), each with `*` and `?` wildcards. Unsupported keys such as `Condition` and `Principal` make the policy **invalid** (score 0) instead of being silently ignored, so a policy can never look stricter to the grader than it would be in AWS.\n\nReward: `least_privilege = allow_recall × deny_rate`. Both `Allow *:*` and an empty policy score 0. Metrics logged: `valid_policy`, `allow_recall`, `deny_rate`, `solved`. `trace.info[\"iam_grade\"]` stores the failing probes for debugging.\n\nEvery generated task is self-checked when it is built: the gold policy must solve it, and the generator raises if it doesn't. The unit tests also check, on 1,200 scenarios, that allow-all, deny-all and \"right actions on `Resource: *`\" never solve a task.\n\n## Difficulty\n\n| `difficulty` | Requirements | Requirement types |\n|---|---|---|\n| `easy` | 2 | S3 prefix objects, S3 bucket listing, DynamoDB table, SQS producer/consumer, SNS publish, Lambda invoke, Secrets Manager read |\n| `medium` | 3 | easy + KMS key by alias, DynamoDB table plus one GSI |\n| `hard` | 4 | medium + \"whole bucket except a prefix\" (needs a `Deny`), Lambda invoke including versions/aliases; at least one tricky type is always included |\n| `mixed` (default) | 2–4 | 30% easy / 40% medium / 30% hard |\n\n## Usage\n\n```bash\nprime env install <owner>/iam-least-privilege\nuv run vf-validate iam-least-privilege -n 5                       # gold check, no model calls\nuv run vf-run iam-least-privilege -m <model> -n 20 -r 3            # local eval\nuv run vf-run iam-least-privilege -n 5 -r 2 --env.taskset.difficulty hard\n```\n\nConfig: `--env.taskset.num-tasks` (default 1000), `--env.taskset.seed` (default 0), `--env.taskset.difficulty` (`easy|medium|hard|mixed`).\n\n## Local tests (no dependencies)\n\n```bash\npython -m unittest discover -s tests -v\n```\n\n## Limitations\n\nThe probes check (action, resource) pairs only. Real IAM also has condition keys, resource-based policies, SCPs, permission boundaries, and some actions that only take `Resource: \"*\"`. Requirements were chosen so that none of those are needed.\n","encoding":"utf-8","truncated":false,"total_bytes":4670},"status":null}