|
| 1 | +package builtin.aws.iam.aws0345 |
| 2 | + |
| 3 | +import rego.v1 |
| 4 | + |
| 5 | +test_with_allow_s3_full_access if { |
| 6 | + policies := [{ |
| 7 | + "name": "policy_with_s3_full_access", |
| 8 | + "document": {"value": json.marshal({ |
| 9 | + "Version": "2012-10-17", |
| 10 | + "Statement": [{ |
| 11 | + "Effect": "Allow", |
| 12 | + "Action": ["s3:*"], |
| 13 | + "Resource": ["*"], |
| 14 | + }], |
| 15 | + })}, |
| 16 | + }] |
| 17 | + |
| 18 | + r := deny with input as {"aws": {"iam": {"policies": policies}}} |
| 19 | + count(r) == 1 |
| 20 | +} |
| 21 | + |
| 22 | +test_with_deny_s3_full_access if { |
| 23 | + policies := [{ |
| 24 | + "name": "policy_with_s3_full_access", |
| 25 | + "document": {"value": json.marshal({ |
| 26 | + "Version": "2012-10-17", |
| 27 | + "Statement": [{ |
| 28 | + "Effect": "Deny", |
| 29 | + "Action": ["s3:*"], |
| 30 | + }], |
| 31 | + })}, |
| 32 | + }] |
| 33 | + |
| 34 | + r := deny with input as {"aws": {"iam": {"policies": policies}}} |
| 35 | + count(r) == 0 |
| 36 | +} |
| 37 | + |
| 38 | +test_with_no_s3_full_access if { |
| 39 | + policies := [{ |
| 40 | + "name": "policy_without_s3_full_access", |
| 41 | + "document": {"value": json.marshal({ |
| 42 | + "Version": "2012-10-17", |
| 43 | + "Statement": [{ |
| 44 | + "Effect": "Allow", |
| 45 | + "Action": ["s3:GetObject"], |
| 46 | + "Resource": ["arn:aws:s3:::examplebucket/*"], |
| 47 | + }], |
| 48 | + })}, |
| 49 | + }] |
| 50 | + |
| 51 | + r := deny with input as {"aws": {"iam": {"policies": policies}}} |
| 52 | + count(r) == 0 |
| 53 | +} |
| 54 | + |
| 55 | +test_with_role_using_amazon_s3_full_access_policy if { |
| 56 | + roles := [{ |
| 57 | + "name": "role_with_amazon_s3_full_access", |
| 58 | + "policies": [{"document": {"value": json.marshal({ |
| 59 | + "Version": "2012-10-17", |
| 60 | + "Statement": [{ |
| 61 | + "Effect": "Allow", |
| 62 | + "Action": ["s3:*"], |
| 63 | + "Resource": ["*"], |
| 64 | + }], |
| 65 | + })}}], |
| 66 | + }] |
| 67 | + |
| 68 | + r := deny with input as {"aws": {"iam": {"roles": roles}}} |
| 69 | + count(r) == 1 |
| 70 | +} |
| 71 | + |
| 72 | +test_with_role_not_using_amazon_s3_full_access_policy if { |
| 73 | + roles := [{ |
| 74 | + "name": "role_without_amazon_s3_full_access", |
| 75 | + "policies": [{"document": {"value": json.marshal({ |
| 76 | + "Version": "2012-10-17", |
| 77 | + "Statement": [{ |
| 78 | + "Effect": "Allow", |
| 79 | + "Action": ["s3:GetObject"], |
| 80 | + "Resource": ["arn:aws:s3:::examplebucket"], |
| 81 | + }], |
| 82 | + })}}], |
| 83 | + }] |
| 84 | + |
| 85 | + r := deny with input as {"aws": {"iam": {"roles": roles}}} |
| 86 | + count(r) == 0 |
| 87 | +} |
0 commit comments