|
6 | 6 | import os.path |
7 | 7 |
|
8 | 8 | from policyuniverse.policy import Policy |
| 9 | +from parliament import analyze_policy_string |
9 | 10 |
|
10 | 11 | from netaddr import IPNetwork |
11 | 12 | from shared.common import Finding, make_list, get_us_east_1 |
12 | 13 | from shared.query import query_aws, get_parameter_file |
13 | 14 | from shared.nodes import Account, Region |
14 | 15 |
|
| 16 | + |
15 | 17 | KNOWN_BAD_POLICIES = { |
16 | 18 | "arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM": "Use AmazonSSMManagedInstanceCore instead and add privs as needed", |
17 | 19 | "arn:aws:iam::aws:policy/service-role/AmazonMachineLearningRoleforRedshiftDataSource": "Use AmazonMachineLearningRoleforRedshiftDataSourceV2 instead", |
@@ -196,6 +198,17 @@ def find_admins_in_account( |
196 | 198 |
|
197 | 199 | check_for_bad_policy(findings, region, policy["Arn"], policy_doc) |
198 | 200 |
|
| 201 | + analyzed_policy = analyze_policy_string(json.dumps(policy_doc)) |
| 202 | + for f in analyzed_policy.findings: |
| 203 | + findings.add( |
| 204 | + Finding( |
| 205 | + region, |
| 206 | + "IAM_LINTER", |
| 207 | + policy["Arn"], |
| 208 | + resource_details={"issue": str(f.issue), "severity": str(f.severity), "location": str(f.location), "policy": policy_doc}, |
| 209 | + ) |
| 210 | + ) |
| 211 | + |
199 | 212 | policy_action_counts[policy["Arn"]] = policy_action_count(policy_doc, location) |
200 | 213 |
|
201 | 214 | if is_admin_policy( |
@@ -260,6 +273,18 @@ def find_admins_in_account( |
260 | 273 |
|
261 | 274 | for policy in role["RolePolicyList"]: |
262 | 275 | policy_doc = policy["PolicyDocument"] |
| 276 | + |
| 277 | + analyzed_policy = analyze_policy_string(json.dumps(policy_doc)) |
| 278 | + for f in analyzed_policy.findings: |
| 279 | + findings.add( |
| 280 | + Finding( |
| 281 | + region, |
| 282 | + "IAM_LINTER", |
| 283 | + policy["Arn"], |
| 284 | + resource_details={"issue": str(f.issue), "severity": str(f.severity), "location": str(f.location), "policy": policy_doc}, |
| 285 | + ) |
| 286 | + ) |
| 287 | + |
263 | 288 | if is_admin_policy( |
264 | 289 | policy_doc, |
265 | 290 | location, |
@@ -430,6 +455,18 @@ def find_admins_in_account( |
430 | 455 | ) |
431 | 456 | for policy in user.get("UserPolicyList", []): |
432 | 457 | policy_doc = policy["PolicyDocument"] |
| 458 | + |
| 459 | + analyzed_policy = analyze_policy_string(json.dumps(policy_doc)) |
| 460 | + for f in analyzed_policy.findings: |
| 461 | + findings.add( |
| 462 | + Finding( |
| 463 | + region, |
| 464 | + "IAM_LINTER", |
| 465 | + policy["Arn"], |
| 466 | + resource_details={"issue": str(f.issue), "severity": str(f.severity), "location": str(f.location), "policy": policy_doc}, |
| 467 | + ) |
| 468 | + ) |
| 469 | + |
433 | 470 | if is_admin_policy( |
434 | 471 | policy_doc, |
435 | 472 | location, |
|
0 commit comments