Skip to content

Commit 9e1defb

Browse files
sentinel-updates: adding in some flavoring text
1 parent ee8ca9a commit 9e1defb

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# This policy allows you to define a list of forbidden IAM policy statement actions
2+
# to prevent Terraform from creating. Put all statements in the forbidden_actions.
3+
# This does not do by-resource level restrictions, but restricts all resources with
4+
# these actions
5+
6+
import "json"
7+
import "tfplan"
8+
9+
forbidden_actions = [
10+
"iam:*",
11+
"iam:Create*",
12+
"iam:Delete*",
13+
]
14+
15+
# get all IAM policy resources from the tfplan
16+
all_policy_resources = func() {
17+
policies = []
18+
for tfplan.module_paths as path {
19+
resources = values(tfplan.module(path).resources.aws_iam_policy) else []
20+
for resources as _, r {
21+
policies += values(r)
22+
}
23+
}
24+
25+
return policies
26+
}
27+
28+
# get all IAM Policy statements
29+
policy_statements = func() {
30+
statements = []
31+
for all_policy_resources() as r {
32+
statements += json.unmarshal(r.applied.policy).Statement
33+
}
34+
return statements
35+
}
36+
37+
valid_statement = func(s,a) {
38+
if s.Action contains a {
39+
return false
40+
}
41+
return true
42+
}
43+
44+
# Main rule that requires other rules to be true
45+
main = rule {
46+
all policy_statements() as s {
47+
all forbidden_actions as a {
48+
valid_statement(s, a)
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)