# main.tf — IAM violations fixture # Triggers all 6 IAM policy violations terraform { required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } } # IAM-006 — Hardcoded credentials in provider block provider "aws" { region = "ap-south-1" access_key = "AKIAS3ZBGQD4PAB4RPYY" secret_key = "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" } # IAM-001 — Policy attached directly to user resource "aws_iam_user" "bad_user" { name = "bad-user" } resource "aws_iam_user_policy" "bad_inline" { name = "bad-inline-policy" user = aws_iam_user.bad_user.name policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Action = ["s3:GetObject"] Resource = "*" }] }) } resource "aws_iam_policy" "bad_policy" { name = "bad-managed-policy" policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Action = ["s3:GetObject"] Resource = "*" }] }) } resource "aws_iam_user_policy_attachment" "bad_attachment" { user = aws_iam_user.bad_user.name policy_arn = aws_iam_policy.bad_policy.arn } # IAM-002 — Long-term IAM access key resource "aws_iam_access_key" "bad_key" { user = aws_iam_user.bad_user.name } # IAM-003 — Broad KMS permissions in inline role policy resource "aws_iam_role" "app_role" { name = "app-role" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Principal = { Service = "ec2.amazonaws.com" } Action = "sts:AssumeRole" }] }) # IAM-004 — No permissions_boundary set } resource "aws_iam_role_policy" "bad_kms" { name = "bad-kms-policy" role = aws_iam_role.app_role.name policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Action = ["kms:Decrypt"] Resource = "*" }] }) } # IAM-005 — Cross-account trust with Principal * and no Condition resource "aws_iam_role" "bad_cross_account" { name = "bad-cross-account-role" assume_role_policy = jsonencode({ Version = "2012-10-17" Statement = [{ Effect = "Allow" Principal = "*" Action = "sts:AssumeRole" }] }) # IAM-004 — No permissions_boundary set (second violation) }