Skip to content

Commit c84742e

Browse files
authored
Merge pull request #601 from 0xdabbad00/parliament_checks
Added parliament support
2 parents ecc8e01 + c0dcc77 commit c84742e

File tree

6 files changed

+49
-2
lines changed

6 files changed

+49
-2
lines changed

Pipfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ matplotlib = "==2.2.2"
1515
policyuniverse = "==1.1.0.1"
1616
PyYAML = "==4.2b4"
1717
Jinja2 = "==2.10.1"
18+
parliament = "==0.2.3"
1819

1920
[dev-packages]
2021
autoflake = "==0.7"

audit_config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ IAM_UNEXPECTED_S3_EXFIL_PRINCIPAL:
204204
is_global: True
205205
group: IAM
206206

207+
IAM_LINTER:
208+
title: IAM linting issues
209+
description: Issues identified by the IAM linter Parliament
210+
severity: Low
211+
is_global: True
212+
group: IAM
207213

208214
IAM_NAME_DOES_NOT_INDICATE_ADMIN:
209215
title: Name does not indicate admin

cloudmapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import pkgutil
3131
import importlib
3232

33-
__version__ = "2.7.2"
33+
__version__ = "2.8.0"
3434

3535

3636
def show_help(commands):

shared/audit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ def audit_guardduty(findings, region):
206206

207207

208208
def audit_iam(findings, region):
209+
# By calling the code to find the admins, we'll excercise the code that finds problems.
209210
find_admins_in_account(region, findings)
211+
210212
# By default we get the findings for the admins, but we can also look for specific
211213
# privileges, so we'll look for who has s3:ListAllMyBuckets and then only use those
212214
# findings that are for a compute resource having this privilege

shared/iam_audit.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
import os.path
77

88
from policyuniverse.policy import Policy
9+
from parliament import analyze_policy_string
910

1011
from netaddr import IPNetwork
1112
from shared.common import Finding, make_list, get_us_east_1
1213
from shared.query import query_aws, get_parameter_file
1314
from shared.nodes import Account, Region
1415

16+
1517
KNOWN_BAD_POLICIES = {
1618
"arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM": "Use AmazonSSMManagedInstanceCore instead and add privs as needed",
1719
"arn:aws:iam::aws:policy/service-role/AmazonMachineLearningRoleforRedshiftDataSource": "Use AmazonMachineLearningRoleforRedshiftDataSourceV2 instead",
@@ -196,6 +198,17 @@ def find_admins_in_account(
196198

197199
check_for_bad_policy(findings, region, policy["Arn"], policy_doc)
198200

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+
199212
policy_action_counts[policy["Arn"]] = policy_action_count(policy_doc, location)
200213

201214
if is_admin_policy(
@@ -260,6 +273,18 @@ def find_admins_in_account(
260273

261274
for policy in role["RolePolicyList"]:
262275
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+
263288
if is_admin_policy(
264289
policy_doc,
265290
location,
@@ -430,6 +455,18 @@ def find_admins_in_account(
430455
)
431456
for policy in user.get("UserPolicyList", []):
432457
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+
433470
if is_admin_policy(
434471
policy_doc,
435472
location,

tests/unit/test_audit.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def test_audit(self):
4444
"IAM_KNOWN_BAD_POLICY",
4545
"IAM_ROLE_ALLOWS_ASSUMPTION_FROM_ANYWHERE",
4646
"EC2_OLD",
47-
"IAM_UNEXPECTED_S3_EXFIL_PRINCIPAL"
47+
"IAM_UNEXPECTED_S3_EXFIL_PRINCIPAL",
48+
"IAM_LINTER"
4849
]
4950
),
5051
)

0 commit comments

Comments
 (0)