Skip to content

Commit 6129bf5

Browse files
authored
Merge pull request #68 from kmcquade/fix/GH-63-duplicate-inline-policy-names-and-attached-principals
Fixes #63 - Attached to Principals is now included in the finding card
2 parents a49e18c + 8ddd312 commit 6129bf5

File tree

6 files changed

+751
-156
lines changed

6 files changed

+751
-156
lines changed

cloudsplaining/command/scan.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,25 @@ def scan(
8383
with open(input) as f:
8484
contents = f.read()
8585
account_authorization_details_cfg = json.loads(contents)
86-
scan_account_authorization_details(
86+
rendered_html_report = scan_account_authorization_details(
8787
account_authorization_details_cfg, exclusions, account_name, output, write_data_files=True
8888
)
89+
html_output_file = os.path.join(output, f"iam-report-{account_name}.html")
90+
logger.info("Saving the report to %s", html_output_file)
91+
if os.path.exists(html_output_file):
92+
os.remove(html_output_file)
93+
94+
with open(html_output_file, "w") as f:
95+
f.write(rendered_html_report)
96+
97+
print(f"Wrote HTML results to: {html_output_file}")
98+
99+
# Open the report by default
100+
if not skip_open_report:
101+
print("Opening the HTML report")
102+
url = "file://%s" % os.path.abspath(html_output_file)
103+
webbrowser.open(url, new=2)
104+
89105
if os.path.isdir(input):
90106
logger.info(
91107
"The path given is a directory. Scanning for account authorization files and generating report."
@@ -103,6 +119,9 @@ def scan(
103119
account_authorization_details_cfg, exclusions, account_name, output, write_data_files=True
104120
)
105121
html_output_file = os.path.join(output, f"iam-report-{account_name}.html")
122+
logger.info("Saving the report to %s", html_output_file)
123+
if os.path.exists(html_output_file):
124+
os.remove(html_output_file)
106125

107126
with open(html_output_file, "w") as f:
108127
f.write(rendered_html_report)

cloudsplaining/output/templates/analysis/finding-card/names.html

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
<div class="card">
2-
<h6 class="card-header" id="{{ finding['PolicyName'] }}">
2+
<h6 class="card-header" id="{{ finding['PolicyName'] }}{% if finding['AttachedToPrincipal'] %}{{ finding['AttachedToPrincipal'] }}{% endif %}">
33
Name: {{ finding["PolicyName"] }}
44
<br>
55
<br>
66
Type: {% if finding["Type"] == "Policy" %}{{ finding["ManagedBy"] }}-Managed {{ finding["Type"] }}{% else %}Inline {{ finding["Type"] }} Policy{% endif %}
7+
{% if finding["Type"] == "Policy" %}
8+
{% if "Principals" in finding %}
9+
<br>
10+
<br>
11+
Attached to Principal(s):
12+
{% for principal in finding["Principals"] %}
13+
<br>
14+
- {{ principal }}{% endfor %}
15+
{% endif %}
16+
<!--/Policies Attached to principals-->
17+
{% else %}
18+
<!--Inline Policies - identify which ones are attached to which principal-->
19+
<!--This will only apply if finding["Type"] != "Policy"-->
20+
{% if finding["AttachedToPrincipal"] %}
21+
<br>
22+
<br>
23+
Attached to Principal: {{ finding["AttachedToPrincipal"] }}
24+
{% endif %}
25+
{% endif %}
26+
<!--/end AttachedToPrincipal-->
727
</h6>
828
<div class="card-body">
929
<p class="card-text">

cloudsplaining/output/templates/summary/aws-managed.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{% if finding["ManagedBy"] == "AWS" %}
3232
<tr>
3333
<td></td>
34-
<td><a href="#{{ finding['PolicyName'] }}">{{ finding['PolicyName'] }}</a></td>
34+
<td><a href="#{{ finding['PolicyName'] }}{% if finding['AttachedToPrincipal'] %}{{ finding['AttachedToPrincipal'] }}{% endif %}">{{ finding['PolicyName'] }}</a></td>
3535
<td>{{ finding["ServicesCount"] }}</td>
3636
<td><p style="max-height: 100px; overflow: scroll;">{% for service in finding["Services"] %}{{ service }}{% if not loop.last %}, {% endif %}{% endfor %}</p></td>
3737
<td>{{ finding["ActionsCount"] }}</td>

cloudsplaining/output/templates/summary/customer-managed.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<br>
22
<p style="text-align: justify">
3-
The following table shows a list of Customer created IAM Policies that are currently used in the account - both <a href="#definition-managed-policy">Managed Policies</a> and <a href="#definition-inline-policy">Inline Policies</a>. If the policy is an inline policy, the table indicates the <a href="#definition-principal">IAM Principal</a> that the inline policy is associated with. It only includes policies that (1) have findings and (2) are currently used in the account. If the policy contains IAM Actions - or combinations of actions - that fall under certain risk categories - <a href="#definition-infrastructure-modification">Infrastructure Modification</a>, <a href="#definition-privilege-escalation">Privilege Escalation</a>, <a href="#definition-resource-exposure">Resource Exposure</a>, or <a href="#definition-data-exfiltration">Data Exfiltration</a> - then the number of occurrences per-policy and per-risk is included in the table. <b>If there are no findings for a particular policy, or if the policy is not attached to any IAM Principals, then the policy is not included in the findings.</b>
3+
The following table shows a list of Customer created IAM Policies that are currently used in the account - both <a href="#definition-managed-policy">Managed Policies</a> and <a href="#definition-inline-policy">Inline Policies</a>. If the policy is an inline policy, the table indicates the <a href="#definition-principal">IAM Principal</a> that the inline policy is associated with. It only includes policies that (1) have findings and (2) are currently used in the account.
44
<br>
55
<br>
6-
If the policy contains IAM Actions - or combinations of actions - that fall under certain risk categories - <a href="#definition-privilege-escalation" class="popovers" data-toggle="popover" data-html="true" data-placement="top" title="Privilege Escalation" data-content='<p>These policies allow a combination of IAM actions that allow a principal with these permissions to escalate their privileges - for example, by creating an access key for another IAM user, or modifying their own permissions. This research was pioneered by Spencer Gietzen at Rhino Security Labs. Remediation guidance can be found <a href="https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/">here</a>.</p>'>Privilege Escalation</a>, <a href="#definition-resource-exposure" class="popovers" data-toggle="popover" data-html="true" data-placement="top" title="Resource Exposure" data-content='<p>Resource Exposure actions allow modification of Permissions to <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_identity-vs-resource.html">resource-based policies</a> or otherwise can expose AWS resources to the public via similar actions that can lead to resource exposure - for example, the ability to modify <a href="https://docs.aws.amazon.com/ram/latest/userguide/what-is.html">AWS Resource Access Manager</a>.</p>'>Resource Exposure</a>, <a href="#definition-infrastructure-modification" class="popovers" data-toggle="popover" data-html="true" data-placement="top" title="Infrastructure Modification" data-content='<p>Infrastructure Modification describes IAM actions with "modify" capabilities, and can therefore lead to <a href="https://attack.mitre.org/techniques/T1496/">Resource Hijacking</a>, unauthorized creation of Infrastructure, Backdoor creation, and/or modification of existing resources which can result in downtime.</p>'>Infrastructure Modification</a>, and <a href="#definition-data-exfiltration" class="popovers" data-toggle="popover" data-html="true" data-placement="top" title="Data Exfiltration" data-content='<div style="text-align:left"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>'>Data Exfiltration</a> - then the number of occurrences per-policy and per-risk is included in the table.
6+
If the policy contains IAM Actions - or combinations of actions - that fall under certain risk categories - <a href="#definition-privilege-escalation" class="popovers" data-toggle="popover" data-html="true" data-placement="top" title="Privilege Escalation" data-content='<p>These policies allow a combination of IAM actions that allow a principal with these permissions to escalate their privileges - for example, by creating an access key for another IAM user, or modifying their own permissions. This research was pioneered by Spencer Gietzen at Rhino Security Labs. Remediation guidance can be found <a href="https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/">here</a>.</p>'>Privilege Escalation</a>, <a href="#definition-resource-exposure" class="popovers" data-toggle="popover" data-html="true" data-placement="top" title="Resource Exposure" data-content='<p>Resource Exposure actions allow modification of Permissions to <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_identity-vs-resource.html">resource-based policies</a> or otherwise can expose AWS resources to the public via similar actions that can lead to resource exposure - for example, the ability to modify <a href="https://docs.aws.amazon.com/ram/latest/userguide/what-is.html">AWS Resource Access Manager</a>.</p>'>Resource Exposure</a>, <a href="#definition-infrastructure-modification" class="popovers" data-toggle="popover" data-html="true" data-placement="top" title="Infrastructure Modification" data-content='<p>Infrastructure Modification describes IAM actions with "modify" capabilities, and can therefore lead to <a href="https://attack.mitre.org/techniques/T1496/">Resource Hijacking</a>, unauthorized creation of Infrastructure, Backdoor creation, and/or modification of existing resources which can result in downtime.</p>'>Infrastructure Modification</a>, and <a href="#definition-data-exfiltration" class="popovers" data-toggle="popover" data-html="true" data-placement="top" title="Data Exfiltration" data-content='<div style="text-align:left"><p>Policies with Data Exfiltration potential allow certain read-only IAM actions without resource constraints, such as <code>s3:GetObject</code>, <code>ssm:GetParameter*</code>, or <code>secretsmanager:GetSecretValue</code>. <br> <ul> <li>Unrestricted <code>s3:GetObject</code> permissions has a long history of customer data leaks.</li> <li><code>ssm:GetParameter*</code> and <code>secretsmanager:GetSecretValue</code> are both used to access secrets.</li> <li><code>rds:CopyDBSnapshot</code> and <code>rds:CreateDBSnapshot</code> can be used to exfiltrate RDS database contents.</li> </ul></p></div>'>Data Exfiltration</a> - then the number of occurrences per-policy and per-risk is included in the table. <b>If there are no findings for a particular policy, or if the policy is not attached to any IAM Principals, then the policy is not included in the findings.</b>
77
<br>
88
<br>
99
If the IAM principal is a Role and is <a href="#definition-roles-assumable-by-compute-services">assumable by a Compute Service</a> - <code>ec2</code>, <code>ecs-tasks</code>, <code>lambda</code>, or <code>eks</code> - then that is indicated in the table as well.
@@ -39,7 +39,7 @@
3939
<tr>
4040
<td></td>
4141
<td>{% if finding["Type"] == "Policy" %}{{ finding["ManagedBy"] }}-Managed {{ finding["Type"] }}{% else %}Inline {{ finding["Type"] }} Policy{% endif %}</td>
42-
<td><a href="#{{ finding['PolicyName'] }}">{{ finding['PolicyName'] }}</a></td>
42+
<td><a href="#{{ finding['PolicyName'] }}{% if finding['AttachedToPrincipal'] %}{{ finding['AttachedToPrincipal'] }}{% endif %}">{{ finding['PolicyName'] }}</a></td>
4343
<td>{% if finding["Type"] == "Policy" %}{% else %}{{ finding['Name'] }}{% endif %}</td>
4444
<td>{{ finding["ServicesCount"] }}</td>
4545
<td><p style="max-height: 100px; overflow: scroll;">{% for service in finding["Services"] %}{{ service }}{% if not loop.last %}, {% endif %}{% endfor %}</p></td>

0 commit comments

Comments
 (0)