Stop Hand-Writing Least-Privilege IAM Policies: Policy Sentry + Parliament (and the KMS Trap)

Lately I've been doing IAM security remediation at work, and I keep running into policies like "Action": "s3:*", "Resource": "*".
Everyone agrees on "least privilege", but writing it by hand is painful:
- figuring out which actions you actually need takes forever
- once it's written, you're never quite sure it's really minimal
- a typo won't show up until
terraform apply(or production)
So I tried two tools that let you stop hand-writing policies:
| Tool | What it does |
|---|---|
| Policy Sentry | Generates a least-privilege policy from "which ARNs do I read / write" |
| Parliament | Lints a policy (typos, unnecessary *, resource mismatches) |
Both run offline, without an AWS account, so they're easy to try locally.
All screenshots in this post are real command output from my Linux box. ARNs and the account ID (111122223333) are dummies.
The flow
The example is a typical batch job's IAM role:
- read files from
input/in an S3 bucket - write results to
output/(encrypted with SSE-KMS) - read config from SSM Parameter Store
- decrypt with a KMS key
Environment
| Item | Version |
|---|---|
| OS | Ubuntu 24.04 |
| Python | 3.13 |
| policy_sentry | 0.13.2 |
| parliament | 1.6.4 |
pip install policy_sentry parliament Step 1: Create a template
policy_sentry create-template --output-file crud.yml --template-type crud You list ARNs under the official AWS access levels: read, write, list, tagging, permissions-management.
My first attempt (the KMS key is "just for reading", so read, right?):
# crud_v1.yml mode: crud name: 'ReportBatch' read: - 'arn:aws:s3:::example-report-bucket/input/*' - 'arn:aws:ssm:ap-northeast-1:111122223333:parameter/report-batch/*' - 'arn:aws:kms:ap-northeast-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' write: - 'arn:aws:s3:::example-report-bucket/output/*' list: - 'arn:aws:s3:::example-report-bucket' Trap #1: putting the KMS key under read does NOT give you Decrypt
The generated KMS statement only had kms:DescribeKey, kms:GetKeyPolicy and friends — no kms:Decrypt.
The reason: in AWS's own definitions, kms:Decrypt has the access level "Write". Policy Sentry can show you:
Decrypt sits in the same Write bucket as ScheduleKeyDeletion. So if you think "fine, I'll put it under write"...
Trap #2: under write you also get key deletion
The red lines are the scary part:
-
KmsWriteKeynow includeskms:ScheduleKeyDeletion,kms:DisableKey,kms:CreateAlias... - and a
MultMultNonestatement addskms:CreateKeyonResource: *
MultMultNone is where Policy Sentry puts dependent actions (actions AWS says you also need when calling another action). Because kms:CreateKey depends on kms:PutKeyPolicy and kms:TagResource, they get pulled in too.
Fix: trim with exclude-actions
Policy Sentry supports exclude-actions with wildcards. For KMS I keep only Decrypt (reading) and GenerateDataKey (writing with SSE-KMS). For S3 I drop ACL, replication and delete actions.
# crud_v3.yml mode: crud name: 'ReportBatch' read: - 'arn:aws:s3:::example-report-bucket/input/*' - 'arn:aws:ssm:ap-northeast-1:111122223333:parameter/report-batch/*' write: - 'arn:aws:s3:::example-report-bucket/output/*' - 'arn:aws:kms:ap-northeast-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab' list: - 'arn:aws:s3:::example-report-bucket' exclude-actions: # S3: no ACL / torrent / replication - 's3:*Acl' - 's3:*Torrent' - 's3:*ForReplication' - 's3:*Attributes' # S3: no delete / retention / replication either - 's3:Delete*' - 's3:*Replicat*' - 's3:RestoreObject' - 's3:*Retention' - 's3:*LegalHold' # KMS: drop every write action except Decrypt / GenerateDataKey - 'kms:Cancel*' - 'kms:Connect*' - 'kms:Create*' - 'kms:Delete*' - 'kms:Derive*' - 'kms:Disable*' - 'kms:Disconnect*' - 'kms:Enable*' - 'kms:Encrypt' - 'kms:GenerateDataKeyPair*' - 'kms:GenerateDataKeyWithout*' - 'kms:GenerateMac' - 'kms:GenerateRandom' - 'kms:Import*' - 'kms:ReEncrypt*' - 'kms:Replicate*' - 'kms:Rotate*' - 'kms:Schedule*' - 'kms:Sign' - 'kms:Synchronize*' - 'kms:Update*' - 'kms:Verify*' # also drop the dependent actions that came with CreateKey - 'kms:PutKeyPolicy' - 'kms:TagResource' - 'iam:CreateServiceLinkedRole' Note: Excluding
kms:Create*does not remove its dependent actions (kms:PutKeyPolicyetc.). Without the last three lines you still get aResource: *statement. Always read the generated output.
Step 2: Lint with Parliament
For comparison, here's a typical hand-written policy:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "S3All", "Effect": "Allow", "Action": ["s3:*"], "Resource": "*" }, { "Sid": "ReadInput", "Effect": "Allow", "Action": ["s3:GetObjects", "s3:ListBucket"], "Resource": "arn:aws:s3:::example-report-bucket/input/*" }, { "Sid": "Kms", "Effect": "Allow", "Action": "kms:*", "Resource": "*" } ] } (The real file also has an SSM statement.)
- it catches the typo
s3:GetObjects(should bes3:GetObject) -
s3:*/kms:*on*show up asUnnecessary use of Resource *
But all of them are LOW. If you filter by severity you'll happily ship kms:*, so in CI I'd rather fail on any finding.
Step 3: Check the tuned policy
- the generated policy has zero findings, exit code 0
- the untuned one (
crud_v2.ymloutput) with--minimum_severity MEDIUMexits 1
On the way I got a MEDIUM "No resources match" for
s3:GetObjectAttributes: the Parliament data I had treated it as an access-point action. The app doesn't need it, so I excludeds3:*Attributes. Tool data can lag behind AWS, so double-check findings against the Service Authorization Reference instead of trusting them blindly.
The final policy is short and readable:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "S3ReadObject", "Effect": "Allow", "Action": ["s3:GetObject", "s3:GetObjectTagging", "s3:GetObjectVersion", "s3:GetObjectVersionTagging"], "Resource": ["arn:aws:s3:::example-report-bucket/input/*"] }, { "Sid": "SsmReadParameter", "Effect": "Allow", "Action": ["ssm:GetParameter", "ssm:GetParameterHistory", "ssm:GetParameters", "ssm:GetParametersByPath"], "Resource": ["arn:aws:ssm:ap-northeast-1:111122223333:parameter/report-batch/*"] }, { "Sid": "S3WriteObject", "Effect": "Allow", "Action": ["s3:AbortMultipartUpload", "s3:PutObject"], "Resource": ["arn:aws:s3:::example-report-bucket/output/*"] }, { "Sid": "KmsWriteKey", "Effect": "Allow", "Action": ["kms:Decrypt", "kms:GenerateDataKey"], "Resource": ["arn:aws:kms:ap-northeast-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab"] }, { "Sid": "S3ListBucket", "Effect": "Allow", "Action": ["s3:ListBucket", "s3:ListBucketMultipartUploads", "s3:ListBucketVersions"], "Resource": ["arn:aws:s3:::example-report-bucket"] } ] } Running it in CI
In GitLab CI you can lint whenever a policy JSON changes:
iam-lint: stage: security image: python:3.13-slim script: - pip install --quiet parliament - parliament --directory policies/ --include_policy_extension json rules: - changes: - "policies/**/*.json" Note: Parliament 1.6.4 errors out with
You cannot pass a file with --file and use stdin togetherwhen stdin is not a TTY (as in CI) and you use--file. Use--directory, or pipe the policy in:parliament < policy.json.
Running Checkov over the whole Terraform codebase in CI is the topic of my next post.
Takeaways
- Policy Sentry's CRUD mode follows AWS's official access levels, and
kms:Decryptis Write - Putting a KMS key under
writealso grants key deletion andCreateKeyon*→ trim withexclude-actions - Dependent actions can sneak in
Resource: *→ always review the generated policy - Parliament catches typos and
*, but as LOW → fail CI on any finding - Verify tool findings against the official docs
The best part of not hand-writing policies: reviewers only need to check which ARNs get which access level, not 40 individual actions.




