iam-policy-validator 1.0.3__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of iam-policy-validator might be problematic. Click here for more details.
- {iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.1.0.dist-info}/METADATA +210 -436
- {iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.1.0.dist-info}/RECORD +20 -18
- iam_validator/__version__.py +1 -1
- iam_validator/checks/action_condition_enforcement.py +112 -28
- iam_validator/checks/security_best_practices.py +103 -12
- iam_validator/commands/validate.py +7 -5
- iam_validator/core/cli.py +26 -9
- iam_validator/core/config_loader.py +39 -3
- iam_validator/core/defaults.py +304 -0
- iam_validator/core/formatters/__init__.py +2 -0
- iam_validator/core/formatters/console.py +44 -7
- iam_validator/core/formatters/csv.py +7 -2
- iam_validator/core/formatters/enhanced.py +428 -0
- iam_validator/core/formatters/html.py +127 -37
- iam_validator/core/formatters/markdown.py +10 -2
- iam_validator/core/models.py +30 -6
- iam_validator/core/report.py +104 -25
- {iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.1.0.dist-info}/WHEEL +0 -0
- {iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.1.0.dist-info}/entry_points.txt +0 -0
- {iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.1.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Default configuration for IAM Policy Validator.
|
|
3
|
+
|
|
4
|
+
This module contains the default configuration that is used when no user
|
|
5
|
+
configuration file is provided. User configuration files will override
|
|
6
|
+
these defaults.
|
|
7
|
+
|
|
8
|
+
This configuration is synced with the default-config.yaml file.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
# ============================================================================
|
|
12
|
+
# SEVERITY LEVELS
|
|
13
|
+
# ============================================================================
|
|
14
|
+
# The validator uses two types of severity levels:
|
|
15
|
+
#
|
|
16
|
+
# 1. IAM VALIDITY SEVERITIES (for AWS IAM policy correctness):
|
|
17
|
+
# - error: Policy violates AWS IAM rules (invalid actions, ARNs, etc.)
|
|
18
|
+
# - warning: Policy may have IAM-related issues but is technically valid
|
|
19
|
+
# - info: Informational messages about the policy structure
|
|
20
|
+
#
|
|
21
|
+
# 2. SECURITY SEVERITIES (for security best practices):
|
|
22
|
+
# - critical: Critical security risk (e.g., wildcard action + resource)
|
|
23
|
+
# - high: High security risk (e.g., missing required conditions)
|
|
24
|
+
# - medium: Medium security risk (e.g., overly permissive wildcards)
|
|
25
|
+
# - low: Low security risk (e.g., minor best practice violations)
|
|
26
|
+
#
|
|
27
|
+
# Use 'error' for policy validity issues, and 'critical/high/medium/low' for
|
|
28
|
+
# security best practices. This distinction helps separate "broken policies"
|
|
29
|
+
# from "insecure but valid policies".
|
|
30
|
+
# ============================================================================
|
|
31
|
+
|
|
32
|
+
# Default configuration dictionary
|
|
33
|
+
DEFAULT_CONFIG = {
|
|
34
|
+
"settings": {
|
|
35
|
+
"fail_fast": False,
|
|
36
|
+
"max_concurrent": 10,
|
|
37
|
+
"enable_builtin_checks": True,
|
|
38
|
+
"parallel_execution": True,
|
|
39
|
+
"cache_enabled": True,
|
|
40
|
+
"cache_directory": ".cache/aws_services",
|
|
41
|
+
"cache_ttl_hours": 24,
|
|
42
|
+
"fail_on_severity": ["error", "critical"],
|
|
43
|
+
},
|
|
44
|
+
"sid_uniqueness_check": {
|
|
45
|
+
"enabled": True,
|
|
46
|
+
"severity": "error",
|
|
47
|
+
"description": "Validates that Statement IDs (Sids) are unique within the policy",
|
|
48
|
+
},
|
|
49
|
+
"policy_size_check": {
|
|
50
|
+
"enabled": True,
|
|
51
|
+
"severity": "error",
|
|
52
|
+
"description": "Validates that IAM policies don't exceed AWS size limits",
|
|
53
|
+
"policy_type": "managed",
|
|
54
|
+
},
|
|
55
|
+
"action_validation_check": {
|
|
56
|
+
"enabled": True,
|
|
57
|
+
"severity": "error",
|
|
58
|
+
"description": "Validates that actions exist in AWS services",
|
|
59
|
+
"disable_wildcard_warnings": True,
|
|
60
|
+
},
|
|
61
|
+
"condition_key_validation_check": {
|
|
62
|
+
"enabled": True,
|
|
63
|
+
"severity": "error",
|
|
64
|
+
"description": "Validates condition keys against AWS service definitions",
|
|
65
|
+
"validate_aws_global_keys": True,
|
|
66
|
+
},
|
|
67
|
+
"resource_validation_check": {
|
|
68
|
+
"enabled": True,
|
|
69
|
+
"severity": "error",
|
|
70
|
+
"description": "Validates ARN format for resources",
|
|
71
|
+
"arn_pattern": "^arn:(aws|aws-cn|aws-us-gov|aws-eusc|aws-iso|aws-iso-b|aws-iso-e|aws-iso-f):[a-z0-9\\-]+:[a-z0-9\\-*]*:[0-9*]*:.+$",
|
|
72
|
+
},
|
|
73
|
+
"security_best_practices_check": {
|
|
74
|
+
"enabled": True,
|
|
75
|
+
"description": "Checks for common security anti-patterns",
|
|
76
|
+
"wildcard_action_check": {
|
|
77
|
+
"enabled": True,
|
|
78
|
+
"severity": "medium",
|
|
79
|
+
"message": "Statement allows all actions (*)",
|
|
80
|
+
"suggestion": "Replace wildcard with specific actions needed for your use case",
|
|
81
|
+
"example": """Replace:
|
|
82
|
+
"Action": ["*"]
|
|
83
|
+
|
|
84
|
+
With specific actions:
|
|
85
|
+
"Action": [
|
|
86
|
+
"s3:GetObject",
|
|
87
|
+
"s3:PutObject",
|
|
88
|
+
"s3:ListBucket"
|
|
89
|
+
]
|
|
90
|
+
""",
|
|
91
|
+
},
|
|
92
|
+
"wildcard_resource_check": {
|
|
93
|
+
"enabled": True,
|
|
94
|
+
"severity": "medium",
|
|
95
|
+
"message": "Statement applies to all resources (*)",
|
|
96
|
+
"suggestion": "Replace wildcard with specific resource ARNs",
|
|
97
|
+
"example": """Replace:
|
|
98
|
+
"Resource": "*"
|
|
99
|
+
|
|
100
|
+
With specific ARNs:
|
|
101
|
+
"Resource": [
|
|
102
|
+
"arn:aws:service:region:account-id:resource-type/resource-id",
|
|
103
|
+
"arn:aws:service:region:account-id:resource-type/*"
|
|
104
|
+
]
|
|
105
|
+
""",
|
|
106
|
+
},
|
|
107
|
+
"full_wildcard_check": {
|
|
108
|
+
"enabled": True,
|
|
109
|
+
"severity": "critical",
|
|
110
|
+
"message": "Statement allows all actions on all resources - CRITICAL SECURITY RISK",
|
|
111
|
+
"suggestion": "This grants full administrative access. Replace both wildcards with specific actions and resources to follow least-privilege principle",
|
|
112
|
+
"example": """Replace:
|
|
113
|
+
"Action": "*",
|
|
114
|
+
"Resource": "*"
|
|
115
|
+
|
|
116
|
+
With specific values:
|
|
117
|
+
"Action": [
|
|
118
|
+
"s3:GetObject",
|
|
119
|
+
"s3:PutObject"
|
|
120
|
+
],
|
|
121
|
+
"Resource": [
|
|
122
|
+
"arn:aws:s3:::my-bucket/*"
|
|
123
|
+
]
|
|
124
|
+
""",
|
|
125
|
+
},
|
|
126
|
+
"service_wildcard_check": {
|
|
127
|
+
"enabled": True,
|
|
128
|
+
"severity": "high",
|
|
129
|
+
"allowed_services": ["logs", "cloudwatch"],
|
|
130
|
+
},
|
|
131
|
+
"sensitive_action_check": {
|
|
132
|
+
"enabled": True,
|
|
133
|
+
"severity": "medium",
|
|
134
|
+
"sensitive_actions": [
|
|
135
|
+
"iam:CreateUser",
|
|
136
|
+
"iam:CreateRole",
|
|
137
|
+
"iam:PutUserPolicy",
|
|
138
|
+
"iam:PutRolePolicy",
|
|
139
|
+
"iam:AttachUserPolicy",
|
|
140
|
+
"iam:AttachRolePolicy",
|
|
141
|
+
"iam:CreateAccessKey",
|
|
142
|
+
"iam:DeleteUser",
|
|
143
|
+
"iam:DeleteRole",
|
|
144
|
+
"s3:DeleteBucket",
|
|
145
|
+
"s3:PutBucketPolicy",
|
|
146
|
+
"s3:DeleteBucketPolicy",
|
|
147
|
+
"ec2:TerminateInstances",
|
|
148
|
+
"ec2:DeleteVolume",
|
|
149
|
+
"rds:DeleteDBInstance",
|
|
150
|
+
"lambda:DeleteFunction",
|
|
151
|
+
"eks:DeleteCluster",
|
|
152
|
+
],
|
|
153
|
+
"sensitive_action_patterns": ["^iam:Delete.*"],
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
"action_condition_enforcement_check": {
|
|
157
|
+
"enabled": True,
|
|
158
|
+
"severity": "high",
|
|
159
|
+
"description": "Enforce specific IAM condition requirements (unified: MFA, IP, tags, etc.)",
|
|
160
|
+
"action_condition_requirements": [
|
|
161
|
+
{
|
|
162
|
+
"actions": ["iam:PassRole"],
|
|
163
|
+
"action_patterns": ["^iam:Pas?.*$"],
|
|
164
|
+
"severity": "high",
|
|
165
|
+
"required_conditions": [
|
|
166
|
+
{
|
|
167
|
+
"condition_key": "iam:PassedToService",
|
|
168
|
+
"description": "Specify which AWS services are allowed to use the passed role to prevent privilege escalation",
|
|
169
|
+
"example": """"Condition": {
|
|
170
|
+
"StringEquals": {
|
|
171
|
+
"iam:PassedToService": [
|
|
172
|
+
"lambda.amazonaws.com",
|
|
173
|
+
"ecs-tasks.amazonaws.com",
|
|
174
|
+
"ec2.amazonaws.com",
|
|
175
|
+
"glue.amazonaws.com",
|
|
176
|
+
"lambda.amazonaws.com"
|
|
177
|
+
]
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
""",
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"actions": [
|
|
186
|
+
"iam:Create*",
|
|
187
|
+
"iam:CreateRole",
|
|
188
|
+
"iam:Put*Policy*",
|
|
189
|
+
"iam:PutUserPolicy",
|
|
190
|
+
"iam:PutRolePolicy",
|
|
191
|
+
"iam:Attach*Policy*",
|
|
192
|
+
"iam:AttachUserPolicy",
|
|
193
|
+
"iam:AttachRolePolicy",
|
|
194
|
+
],
|
|
195
|
+
"action_patterns": ["^iam:Create", "^iam:Put.*Policy", "^iam:Attach.*Policy"],
|
|
196
|
+
"severity": "high",
|
|
197
|
+
"required_conditions": [
|
|
198
|
+
{
|
|
199
|
+
"condition_key": "iam:PermissionsBoundary",
|
|
200
|
+
"description": "Require permissions boundary for sensitive IAM operations to prevent privilege escalation",
|
|
201
|
+
"expected_value": "arn:aws:iam::*:policy/DeveloperBoundary",
|
|
202
|
+
"example": """# See: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html
|
|
203
|
+
"Condition": {
|
|
204
|
+
"StringEquals": {
|
|
205
|
+
"iam:PermissionsBoundary": "arn:aws:iam::123456789012:policy/XCompanyBoundaries"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
""",
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"actions": ["s3:DeleteBucket", "s3:DeleteBucketPolicy", "s3:PutBucketPolicy"],
|
|
214
|
+
"severity": "high",
|
|
215
|
+
"required_conditions": [
|
|
216
|
+
{
|
|
217
|
+
"condition_key": "aws:MultiFactorAuthPresent",
|
|
218
|
+
"description": "Require MFA for S3 destructive operations",
|
|
219
|
+
"expected_value": True,
|
|
220
|
+
},
|
|
221
|
+
],
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
"action_patterns": [
|
|
225
|
+
"^ssm:StartSession$",
|
|
226
|
+
"^ssm:Run.*$",
|
|
227
|
+
"^s3:GetObject$",
|
|
228
|
+
"^rds:.*$",
|
|
229
|
+
],
|
|
230
|
+
"severity": "medium",
|
|
231
|
+
"required_conditions": [
|
|
232
|
+
{
|
|
233
|
+
"condition_key": "aws:SourceIp",
|
|
234
|
+
"description": "Restrict access to corporate IP ranges",
|
|
235
|
+
"example": """"Condition": {
|
|
236
|
+
"IpAddress": {
|
|
237
|
+
"aws:SourceIp": [
|
|
238
|
+
"10.0.0.0/8",
|
|
239
|
+
"172.16.0.0/12"
|
|
240
|
+
]
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
""",
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
"actions": ["ec2:RunInstances"],
|
|
249
|
+
"required_conditions": {
|
|
250
|
+
"all_of": [
|
|
251
|
+
{
|
|
252
|
+
"condition_key": "aws:ResourceTag/owner",
|
|
253
|
+
"operator": "StringEquals",
|
|
254
|
+
"expected_value": "${aws:PrincipalTag/owner}",
|
|
255
|
+
"description": "Resource owner must match the principal's owner tag",
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
"condition_key": "aws:RequestTag/env",
|
|
259
|
+
"operator": "StringEquals",
|
|
260
|
+
"expected_value": [
|
|
261
|
+
"prod",
|
|
262
|
+
"pre",
|
|
263
|
+
"dev",
|
|
264
|
+
"sandbox",
|
|
265
|
+
],
|
|
266
|
+
"description": "Must specify a valid Environment tag",
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
"action_patterns": ["^rds:Create.*", "^rds:Modify.*"],
|
|
273
|
+
"required_conditions": {
|
|
274
|
+
"all_of": [
|
|
275
|
+
{
|
|
276
|
+
"condition_key": "aws:RequestTag/DataClassification",
|
|
277
|
+
"description": "Must specify data classification",
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"condition_key": "aws:RequestTag/BackupPolicy",
|
|
281
|
+
"description": "Must specify backup policy",
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
"condition_key": "aws:RequestTag/Owner",
|
|
285
|
+
"description": "Must specify resource owner",
|
|
286
|
+
},
|
|
287
|
+
],
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
},
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def get_default_config() -> dict:
|
|
296
|
+
"""
|
|
297
|
+
Get a deep copy of the default configuration.
|
|
298
|
+
|
|
299
|
+
Returns:
|
|
300
|
+
A deep copy of the default configuration dictionary
|
|
301
|
+
"""
|
|
302
|
+
import copy
|
|
303
|
+
|
|
304
|
+
return copy.deepcopy(DEFAULT_CONFIG)
|
|
@@ -7,6 +7,7 @@ from iam_validator.core.formatters.base import (
|
|
|
7
7
|
)
|
|
8
8
|
from iam_validator.core.formatters.console import ConsoleFormatter
|
|
9
9
|
from iam_validator.core.formatters.csv import CSVFormatter
|
|
10
|
+
from iam_validator.core.formatters.enhanced import EnhancedFormatter
|
|
10
11
|
from iam_validator.core.formatters.html import HTMLFormatter
|
|
11
12
|
from iam_validator.core.formatters.json import JSONFormatter
|
|
12
13
|
from iam_validator.core.formatters.markdown import MarkdownFormatter
|
|
@@ -17,6 +18,7 @@ __all__ = [
|
|
|
17
18
|
"FormatterRegistry",
|
|
18
19
|
"get_global_registry",
|
|
19
20
|
"ConsoleFormatter",
|
|
21
|
+
"EnhancedFormatter",
|
|
20
22
|
"JSONFormatter",
|
|
21
23
|
"MarkdownFormatter",
|
|
22
24
|
"SARIFFormatter",
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
"""Console formatter -
|
|
1
|
+
"""Console formatter - Classic console output using report.py."""
|
|
2
|
+
|
|
3
|
+
from io import StringIO
|
|
4
|
+
|
|
5
|
+
from rich.console import Console
|
|
2
6
|
|
|
3
7
|
from iam_validator.core.formatters.base import OutputFormatter
|
|
4
8
|
from iam_validator.core.models import ValidationReport
|
|
5
9
|
|
|
6
10
|
|
|
7
11
|
class ConsoleFormatter(OutputFormatter):
|
|
8
|
-
"""
|
|
12
|
+
"""Classic console formatter - uses the standard report.py print_console_report output."""
|
|
9
13
|
|
|
10
14
|
@property
|
|
11
15
|
def format_id(self) -> str:
|
|
@@ -13,10 +17,43 @@ class ConsoleFormatter(OutputFormatter):
|
|
|
13
17
|
|
|
14
18
|
@property
|
|
15
19
|
def description(self) -> str:
|
|
16
|
-
return "
|
|
20
|
+
return "Classic console output with colors and tables"
|
|
17
21
|
|
|
18
22
|
def format(self, report: ValidationReport, **kwargs) -> str:
|
|
19
|
-
"""Format
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
"""Format validation report using the classic console output from report.py.
|
|
24
|
+
|
|
25
|
+
This delegates to the ReportGenerator.print_console_report method,
|
|
26
|
+
capturing its output to return as a string.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
report: Validation report to format
|
|
30
|
+
**kwargs: Additional options (color: bool = True)
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
Formatted string with classic console output
|
|
34
|
+
"""
|
|
35
|
+
# Import here to avoid circular dependency
|
|
36
|
+
from iam_validator.core.report import ReportGenerator
|
|
37
|
+
|
|
38
|
+
# Allow disabling color for plain text output
|
|
39
|
+
color = kwargs.get("color", True)
|
|
40
|
+
|
|
41
|
+
# Capture the output from print_console_report
|
|
42
|
+
string_buffer = StringIO()
|
|
43
|
+
console = Console(file=string_buffer, force_terminal=color, width=120)
|
|
44
|
+
|
|
45
|
+
# Create a generator instance with our custom console
|
|
46
|
+
generator = ReportGenerator()
|
|
47
|
+
|
|
48
|
+
# Replace the console temporarily to capture output
|
|
49
|
+
original_console = generator.console
|
|
50
|
+
generator.console = console
|
|
51
|
+
|
|
52
|
+
# Call the actual print_console_report method
|
|
53
|
+
generator.print_console_report(report)
|
|
54
|
+
|
|
55
|
+
# Restore original console
|
|
56
|
+
generator.console = original_console
|
|
57
|
+
|
|
58
|
+
# Return captured output
|
|
59
|
+
return string_buffer.getvalue()
|
|
@@ -68,9 +68,14 @@ class CSVFormatter(OutputFormatter):
|
|
|
68
68
|
writer.writerow(["Summary Statistics"])
|
|
69
69
|
writer.writerow(["Metric", "Value"])
|
|
70
70
|
writer.writerow(["Total Policies", report.total_policies])
|
|
71
|
-
writer.writerow(["Valid Policies", report.valid_policies])
|
|
72
|
-
writer.writerow(["Invalid Policies", report.invalid_policies])
|
|
71
|
+
writer.writerow(["Valid Policies (IAM)", report.valid_policies])
|
|
72
|
+
writer.writerow(["Invalid Policies (IAM)", report.invalid_policies])
|
|
73
|
+
writer.writerow(["Policies with Security Findings", report.policies_with_security_issues])
|
|
73
74
|
writer.writerow(["Total Issues", report.total_issues])
|
|
75
|
+
writer.writerow(["Validity Issues", report.validity_issues])
|
|
76
|
+
writer.writerow(["Security Issues", report.security_issues])
|
|
77
|
+
writer.writerow([""])
|
|
78
|
+
writer.writerow(["Legacy Severity Breakdown"])
|
|
74
79
|
writer.writerow(["Errors", errors])
|
|
75
80
|
writer.writerow(["Warnings", warnings])
|
|
76
81
|
writer.writerow(["Info", infos])
|