Skip to content

Commit 34549b2

Browse files
clean up excessive comments across all modules
1 parent 850086c commit 34549b2

17 files changed

Lines changed: 13 additions & 133 deletions

File tree

src/infraguard/cli.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@
1414
pretty_exceptions_enable=False,
1515
)
1616

17-
1817
def version_callback(value: bool) -> None:
1918
if value:
2019
typer.echo(f"infraguard {__version__}")
2120
raise typer.Exit()
2221

23-
2422
@app.callback()
2523
def main(
2624
version: bool = typer.Option(
@@ -34,8 +32,6 @@ def main(
3432
) -> None:
3533
"""Infrastructure guardrails for teams that ship fast."""
3634

37-
38-
# Register subcommands — imported here to avoid circular deps
3935
from infraguard.iam_check.command import app as iam_check_app # noqa: E402
4036
from infraguard.plan_risk.command import app as plan_risk_app # noqa: E402
4137
from infraguard.tag_audit.command import app as tag_audit_app # noqa: E402

src/infraguard/common/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def load_rules(path: Path) -> dict[str, Any]:
1414
data = yaml.safe_load(f)
1515
return data if data else {}
1616

17-
1817
def merge_rules(defaults: dict[str, Any], overrides: dict[str, Any]) -> dict[str, Any]:
1918
"""Deep-merge overrides into defaults. Lists are replaced, dicts are merged."""
2019
merged = defaults.copy()

src/infraguard/common/models.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def to_dict(self) -> dict[str, Any]:
3737
"metadata": self.metadata,
3838
}
3939

40-
4140
@dataclass
4241
class RiskChange:
4342
"""A scored resource change from a Terraform plan."""
@@ -63,7 +62,6 @@ def to_dict(self) -> dict[str, Any]:
6362
"detail": self.detail,
6463
}
6564

66-
6765
@dataclass
6866
class Report:
6967
"""Aggregated results from an infraguard analysis."""

src/infraguard/common/reporter.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616

1717
console = Console(stderr=True)
1818

19-
20-
# ── Table (Rich) ──────────────────────────────────────────────
21-
22-
2319
def render_plan_risk_table(report: Report, threshold: int | None = None) -> None:
2420
"""Print a Rich-formatted plan risk report to stderr."""
2521
console.print()
@@ -79,7 +75,6 @@ def render_plan_risk_table(report: Report, threshold: int | None = None) -> None
7975
)
8076
console.print()
8177

82-
8378
def render_findings_table(report: Report, title: str, threshold_info: str = "") -> None:
8479
"""Print a Rich-formatted findings report to stderr."""
8580
console.print()
@@ -119,18 +114,10 @@ def render_findings_table(report: Report, title: str, threshold_info: str = "")
119114
console.print(f" {threshold_info}")
120115
console.print()
121116

122-
123-
# ── JSON ──────────────────────────────────────────────────────
124-
125-
126117
def render_json(report: Report) -> None:
127118
"""Print JSON report to stdout."""
128119
sys.stdout.write(report.to_json() + "\n")
129120

130-
131-
# ── Markdown ──────────────────────────────────────────────────
132-
133-
134121
def render_plan_risk_markdown(report: Report, threshold: int | None = None) -> None:
135122
"""Print markdown-formatted plan risk report to stdout."""
136123
lines = ["## Terraform Plan Risk Report", ""]
@@ -162,7 +149,6 @@ def render_plan_risk_markdown(report: Report, threshold: int | None = None) -> N
162149

163150
sys.stdout.write("\n".join(lines) + "\n")
164151

165-
166152
def render_findings_markdown(report: Report, title: str) -> None:
167153
"""Print markdown-formatted findings report to stdout."""
168154
lines = [f"## {title}", ""]
@@ -186,10 +172,6 @@ def render_findings_markdown(report: Report, title: str) -> None:
186172

187173
sys.stdout.write("\n".join(lines) + "\n")
188174

189-
190-
# ── SARIF ─────────────────────────────────────────────────────
191-
192-
193175
def render_sarif(report: Report) -> None:
194176
"""Print SARIF 2.1.0 report to stdout for GitHub Code Scanning integration."""
195177
sarif: dict[str, Any] = {
@@ -248,10 +230,6 @@ def render_sarif(report: Report) -> None:
248230

249231
sys.stdout.write(json.dumps(sarif, indent=2) + "\n")
250232

251-
252-
# ── Helpers ───────────────────────────────────────────────────
253-
254-
255233
def _severity_emoji(severity: Severity) -> str:
256234
return {
257235
Severity.CRITICAL: ":red_circle:",
@@ -261,7 +239,6 @@ def _severity_emoji(severity: Severity) -> str:
261239
Severity.INFO: ":white_circle:",
262240
}[severity]
263241

264-
265242
def _sarif_level(severity: Severity) -> str:
266243
if severity >= Severity.HIGH:
267244
return "error"

src/infraguard/common/severity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ def color(self) -> str:
2626
def icon(self) -> str:
2727
return _ICONS[self]
2828

29-
3029
_COLORS: dict[Severity, str] = {
3130
Severity.INFO: "dim",
3231
Severity.LOW: "cyan",

src/infraguard/iam_check/analyzer.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
check_wildcard_resources,
1919
)
2020

21-
# All checks to run against each statement
2221
ALL_CHECKS = [
2322
check_admin_access,
2423
check_wildcard_actions,
@@ -28,7 +27,6 @@
2827
check_cross_account_access,
2928
]
3029

31-
3230
def analyze_policy_file(path: Path) -> Report:
3331
"""Analyze a single IAM policy JSON file.
3432
@@ -52,12 +50,10 @@ def analyze_policy_file(path: Path) -> Report:
5250
f"or 'policies' key in {path}"
5351
)
5452

55-
5653
def analyze_policy_document(document: dict[str, Any], policy_name: str = "inline") -> Report:
5754
"""Analyze a single IAM policy document dict."""
5855
return _analyze_single(document, policy_name)
5956

60-
6157
def analyze_aws_role(
6258
role_name: str, profile: str | None = None, region: str = "us-east-1"
6359
) -> Report:
@@ -75,7 +71,6 @@ def analyze_aws_role(
7571

7672
policies: list[dict[str, Any]] = []
7773

78-
# Inline policies
7974
inline_names = iam.list_role_policies(RoleName=role_name)["PolicyNames"]
8075
for name in inline_names:
8176
resp = iam.get_role_policy(RoleName=role_name, PolicyName=name)
@@ -84,7 +79,6 @@ def analyze_aws_role(
8479
doc = json.loads(unquote(doc))
8580
policies.append({"name": f"{role_name}/{name} (inline)", "document": doc})
8681

87-
# Attached managed policies
8882
attached = iam.list_attached_role_policies(RoleName=role_name)["AttachedPolicies"]
8983
for policy in attached:
9084
arn = policy["PolicyArn"]
@@ -98,7 +92,6 @@ def analyze_aws_role(
9892

9993
return _analyze_multiple(policies)
10094

101-
10295
def _analyze_single(document: dict[str, Any], policy_name: str) -> Report:
10396
"""Run all checks against a single policy document."""
10497
findings: list[Finding] = []
@@ -111,7 +104,6 @@ def _analyze_single(document: dict[str, Any], policy_name: str) -> Report:
111104
for check_fn in ALL_CHECKS:
112105
findings.extend(check_fn(stmt, i, policy_name))
113106

114-
# Deduplicate — same title + resource = same finding
115107
seen = set()
116108
unique_findings = []
117109
for f in findings:
@@ -123,7 +115,6 @@ def _analyze_single(document: dict[str, Any], policy_name: str) -> Report:
123115
summary = _build_summary(unique_findings, [policy_name])
124116
return Report(module="iam-check", findings=unique_findings, summary=summary)
125117

126-
127118
def _analyze_multiple(policies: list[dict[str, Any]]) -> Report:
128119
"""Run checks across multiple policy documents."""
129120
all_findings: list[Finding] = []
@@ -140,7 +131,6 @@ def _analyze_multiple(policies: list[dict[str, Any]]) -> Report:
140131
summary = _build_summary(all_findings, policy_names)
141132
return Report(module="iam-check", findings=all_findings, summary=summary)
142133

143-
144134
def _build_summary(findings: list[Finding], policy_names: list[str]) -> dict[str, Any]:
145135
"""Build summary statistics for an IAM check report."""
146136
counts: dict[str, int] = {s.label: 0 for s in Severity}

src/infraguard/iam_check/checks.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def check_admin_access(
3737
)
3838
return findings
3939

40-
4140
def check_wildcard_actions(
4241
statement: dict[str, Any], stmt_index: int, policy_name: str
4342
) -> list[Finding]:
@@ -51,7 +50,7 @@ def check_wildcard_actions(
5150

5251
for action in actions:
5352
if action == "*":
54-
continue # Handled by admin_access check
53+
continue
5554

5655
if action.endswith(":*"):
5756
service = action.split(":")[0]
@@ -77,7 +76,6 @@ def check_wildcard_actions(
7776
)
7877
return findings
7978

80-
8179
def check_wildcard_resources(
8280
statement: dict[str, Any], stmt_index: int, policy_name: str
8381
) -> list[Finding]:
@@ -93,11 +91,9 @@ def check_wildcard_resources(
9391
if "*" not in resources:
9492
return findings
9593

96-
# Skip if already flagged as full admin
9794
if "*" in actions:
9895
return findings
9996

100-
# Check if any action is on a sensitive service
10197
has_sensitive = any(
10298
any(a.startswith(prefix) for prefix in SENSITIVE_SERVICE_PREFIXES)
10399
for a in actions
@@ -116,7 +112,6 @@ def check_wildcard_resources(
116112
)
117113
return findings
118114

119-
120115
def check_dangerous_actions(
121116
statement: dict[str, Any], stmt_index: int, policy_name: str
122117
) -> list[Finding]:
@@ -142,7 +137,6 @@ def check_dangerous_actions(
142137
)
143138
return findings
144139

145-
146140
def check_missing_conditions(
147141
statement: dict[str, Any], stmt_index: int, policy_name: str
148142
) -> list[Finding]:
@@ -156,7 +150,7 @@ def check_missing_conditions(
156150
return findings
157151

158152
if conditions:
159-
return findings # Conditions present, skip
153+
return findings
160154

161155
sensitive_actions = [
162156
a for a in actions
@@ -175,7 +169,6 @@ def check_missing_conditions(
175169
)
176170
return findings
177171

178-
179172
def check_cross_account_access(
180173
statement: dict[str, Any], stmt_index: int, policy_name: str
181174
) -> list[Finding]:
@@ -191,7 +184,6 @@ def check_cross_account_access(
191184
if not principal:
192185
return findings
193186

194-
# Check for cross-account principals
195187
aws_principals = []
196188
if isinstance(principal, str):
197189
if principal == "*":
@@ -217,10 +209,6 @@ def check_cross_account_access(
217209
)
218210
return findings
219211

220-
221-
# ── Helpers ───────────────────────────────────────────────────
222-
223-
224212
def _normalize_list(value: Any) -> list[str]:
225213
"""Ensure a value is a list of strings (IAM allows string or list)."""
226214
if isinstance(value, str):

src/infraguard/iam_check/command.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
app = typer.Typer(no_args_is_help=True)
1919
console = Console(stderr=True)
2020

21-
2221
def _parse_max_findings(value: str) -> dict[str, int]:
2322
"""Parse max-findings threshold string like 'critical:0,high:3'."""
2423
result = {}
@@ -28,7 +27,6 @@ def _parse_max_findings(value: str) -> dict[str, int]:
2827
result[parts[0].strip().upper()] = int(parts[1].strip())
2928
return result
3029

31-
3230
@app.callback(invoke_without_command=True)
3331
def iam_check(
3432
file: Path | None = typer.Option(

src/infraguard/iam_check/rules.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44

55
from infraguard.common.severity import Severity
66

7-
# ── Dangerous actions ─────────────────────────────────────────
8-
# Actions that grant significant control and should be flagged.
9-
107
DANGEROUS_ACTIONS: dict[str, Severity] = {
11-
# IAM — identity escalation
128
"iam:CreateUser": Severity.HIGH,
139
"iam:CreateRole": Severity.HIGH,
1410
"iam:AttachUserPolicy": Severity.CRITICAL,
@@ -24,57 +20,45 @@
2420
"iam:CreatePolicyVersion": Severity.HIGH,
2521
"iam:SetDefaultPolicyVersion": Severity.HIGH,
2622

27-
# STS — credential abuse
2823
"sts:AssumeRole": Severity.MEDIUM,
2924
"sts:AssumeRoleWithSAML": Severity.MEDIUM,
3025
"sts:AssumeRoleWithWebIdentity": Severity.MEDIUM,
3126
"sts:GetFederationToken": Severity.MEDIUM,
3227

33-
# S3 — data destruction
3428
"s3:DeleteBucket": Severity.HIGH,
3529
"s3:PutBucketPolicy": Severity.HIGH,
3630
"s3:PutBucketAcl": Severity.HIGH,
3731

38-
# EC2 — infrastructure destruction
3932
"ec2:TerminateInstances": Severity.HIGH,
4033
"ec2:DeleteSecurityGroup": Severity.MEDIUM,
4134
"ec2:AuthorizeSecurityGroupIngress": Severity.MEDIUM,
4235
"ec2:ModifyInstanceAttribute": Severity.MEDIUM,
4336

44-
# RDS — data destruction
4537
"rds:DeleteDBInstance": Severity.HIGH,
4638
"rds:DeleteDBCluster": Severity.HIGH,
4739
"rds:ModifyDBInstance": Severity.MEDIUM,
4840

49-
# Lambda — code execution
5041
"lambda:CreateFunction": Severity.MEDIUM,
5142
"lambda:UpdateFunctionCode": Severity.HIGH,
5243
"lambda:AddPermission": Severity.HIGH,
5344
"lambda:CreateEventSourceMapping": Severity.MEDIUM,
5445

55-
# KMS — encryption control
5646
"kms:Decrypt": Severity.MEDIUM,
5747
"kms:ScheduleKeyDeletion": Severity.CRITICAL,
5848
"kms:DisableKey": Severity.HIGH,
5949
"kms:PutKeyPolicy": Severity.CRITICAL,
6050

61-
# Organizations — org-level control
6251
"organizations:LeaveOrganization": Severity.CRITICAL,
6352
"organizations:DeleteOrganization": Severity.CRITICAL,
6453

65-
# CloudTrail — audit evasion
6654
"cloudtrail:DeleteTrail": Severity.CRITICAL,
6755
"cloudtrail:StopLogging": Severity.CRITICAL,
6856
"cloudtrail:UpdateTrail": Severity.HIGH,
6957

70-
# GuardDuty — security evasion
7158
"guardduty:DeleteDetector": Severity.CRITICAL,
7259
"guardduty:DisassociateFromMasterAccount": Severity.HIGH,
7360
}
7461

75-
# ── Sensitive action prefixes ─────────────────────────────────
76-
# Actions on these services with broad wildcards are extra risky.
77-
7862
SENSITIVE_SERVICE_PREFIXES: list[str] = [
7963
"iam:",
8064
"sts:",
@@ -87,8 +71,6 @@
8771
"access-analyzer:",
8872
]
8973

90-
# ── Suggested replacements for common overpermissions ─────────
91-
9274
WILDCARD_SUGGESTIONS: dict[str, list[str]] = {
9375
"s3:*": ["s3:GetObject", "s3:PutObject", "s3:ListBucket", "s3:GetBucketLocation"],
9476
"ec2:*": ["ec2:DescribeInstances", "ec2:DescribeSecurityGroups", "ec2:DescribeVpcs"],

src/infraguard/plan_risk/command.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
app = typer.Typer(no_args_is_help=False)
1919

20-
2120
@app.callback(invoke_without_command=True)
2221
def plan_risk(
2322
file: Path | None = typer.Option(

0 commit comments

Comments
 (0)