iam-policy-validator 1.7.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.

Files changed (83) hide show
  1. iam_policy_validator-1.7.0.dist-info/METADATA +1057 -0
  2. iam_policy_validator-1.7.0.dist-info/RECORD +83 -0
  3. iam_policy_validator-1.7.0.dist-info/WHEEL +4 -0
  4. iam_policy_validator-1.7.0.dist-info/entry_points.txt +2 -0
  5. iam_policy_validator-1.7.0.dist-info/licenses/LICENSE +21 -0
  6. iam_validator/__init__.py +27 -0
  7. iam_validator/__main__.py +11 -0
  8. iam_validator/__version__.py +7 -0
  9. iam_validator/checks/__init__.py +43 -0
  10. iam_validator/checks/action_condition_enforcement.py +884 -0
  11. iam_validator/checks/action_resource_matching.py +441 -0
  12. iam_validator/checks/action_validation.py +72 -0
  13. iam_validator/checks/condition_key_validation.py +92 -0
  14. iam_validator/checks/condition_type_mismatch.py +259 -0
  15. iam_validator/checks/full_wildcard.py +71 -0
  16. iam_validator/checks/mfa_condition_check.py +112 -0
  17. iam_validator/checks/policy_size.py +147 -0
  18. iam_validator/checks/policy_type_validation.py +305 -0
  19. iam_validator/checks/principal_validation.py +776 -0
  20. iam_validator/checks/resource_validation.py +138 -0
  21. iam_validator/checks/sensitive_action.py +254 -0
  22. iam_validator/checks/service_wildcard.py +107 -0
  23. iam_validator/checks/set_operator_validation.py +157 -0
  24. iam_validator/checks/sid_uniqueness.py +170 -0
  25. iam_validator/checks/utils/__init__.py +1 -0
  26. iam_validator/checks/utils/policy_level_checks.py +143 -0
  27. iam_validator/checks/utils/sensitive_action_matcher.py +294 -0
  28. iam_validator/checks/utils/wildcard_expansion.py +87 -0
  29. iam_validator/checks/wildcard_action.py +67 -0
  30. iam_validator/checks/wildcard_resource.py +135 -0
  31. iam_validator/commands/__init__.py +25 -0
  32. iam_validator/commands/analyze.py +531 -0
  33. iam_validator/commands/base.py +48 -0
  34. iam_validator/commands/cache.py +392 -0
  35. iam_validator/commands/download_services.py +255 -0
  36. iam_validator/commands/post_to_pr.py +86 -0
  37. iam_validator/commands/validate.py +600 -0
  38. iam_validator/core/__init__.py +14 -0
  39. iam_validator/core/access_analyzer.py +671 -0
  40. iam_validator/core/access_analyzer_report.py +640 -0
  41. iam_validator/core/aws_fetcher.py +940 -0
  42. iam_validator/core/check_registry.py +607 -0
  43. iam_validator/core/cli.py +134 -0
  44. iam_validator/core/condition_validators.py +626 -0
  45. iam_validator/core/config/__init__.py +81 -0
  46. iam_validator/core/config/aws_api.py +35 -0
  47. iam_validator/core/config/aws_global_conditions.py +160 -0
  48. iam_validator/core/config/category_suggestions.py +104 -0
  49. iam_validator/core/config/condition_requirements.py +155 -0
  50. iam_validator/core/config/config_loader.py +472 -0
  51. iam_validator/core/config/defaults.py +523 -0
  52. iam_validator/core/config/principal_requirements.py +421 -0
  53. iam_validator/core/config/sensitive_actions.py +672 -0
  54. iam_validator/core/config/service_principals.py +95 -0
  55. iam_validator/core/config/wildcards.py +124 -0
  56. iam_validator/core/constants.py +74 -0
  57. iam_validator/core/formatters/__init__.py +27 -0
  58. iam_validator/core/formatters/base.py +147 -0
  59. iam_validator/core/formatters/console.py +59 -0
  60. iam_validator/core/formatters/csv.py +170 -0
  61. iam_validator/core/formatters/enhanced.py +440 -0
  62. iam_validator/core/formatters/html.py +672 -0
  63. iam_validator/core/formatters/json.py +33 -0
  64. iam_validator/core/formatters/markdown.py +63 -0
  65. iam_validator/core/formatters/sarif.py +251 -0
  66. iam_validator/core/models.py +327 -0
  67. iam_validator/core/policy_checks.py +656 -0
  68. iam_validator/core/policy_loader.py +396 -0
  69. iam_validator/core/pr_commenter.py +424 -0
  70. iam_validator/core/report.py +872 -0
  71. iam_validator/integrations/__init__.py +28 -0
  72. iam_validator/integrations/github_integration.py +815 -0
  73. iam_validator/integrations/ms_teams.py +442 -0
  74. iam_validator/sdk/__init__.py +187 -0
  75. iam_validator/sdk/arn_matching.py +382 -0
  76. iam_validator/sdk/context.py +222 -0
  77. iam_validator/sdk/exceptions.py +48 -0
  78. iam_validator/sdk/helpers.py +177 -0
  79. iam_validator/sdk/policy_utils.py +425 -0
  80. iam_validator/sdk/shortcuts.py +283 -0
  81. iam_validator/utils/__init__.py +31 -0
  82. iam_validator/utils/cache.py +105 -0
  83. iam_validator/utils/regex.py +206 -0
@@ -0,0 +1,523 @@
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 uses Python-native data structures (imported from
9
+ iam_validator.core.config) for optimal performance and PyPI packaging.
10
+
11
+ Benefits of code-first approach:
12
+ - Zero parsing overhead (no YAML/JSON parsing)
13
+ - Compiled to .pyc for faster imports
14
+ - Better IDE support and type hints
15
+ - No data files to manage in PyPI package
16
+ - 5-10x faster than YAML parsing
17
+ """
18
+
19
+ from iam_validator.core.config.category_suggestions import get_category_suggestions
20
+ from iam_validator.core.config.condition_requirements import CONDITION_REQUIREMENTS
21
+ from iam_validator.core.config.principal_requirements import (
22
+ get_default_principal_requirements,
23
+ )
24
+ from iam_validator.core.config.service_principals import DEFAULT_SERVICE_PRINCIPALS
25
+ from iam_validator.core.config.wildcards import (
26
+ DEFAULT_ALLOWED_WILDCARDS,
27
+ DEFAULT_SERVICE_WILDCARDS,
28
+ )
29
+
30
+ # ============================================================================
31
+ # SEVERITY LEVELS
32
+ # ============================================================================
33
+ # The validator uses two types of severity levels:
34
+ #
35
+ # 1. IAM VALIDITY SEVERITIES (for AWS IAM policy correctness):
36
+ # - error: Policy violates AWS IAM rules (invalid actions, ARNs, etc.)
37
+ # - warning: Policy may have IAM-related issues but is technically valid
38
+ # - info: Informational messages about the policy structure
39
+ #
40
+ # 2. SECURITY SEVERITIES (for security best practices):
41
+ # - critical: Critical security risk (e.g., wildcard action + resource)
42
+ # - high: High security risk (e.g., missing required conditions)
43
+ # - medium: Medium security risk (e.g., overly permissive wildcards)
44
+ # - low: Low security risk (e.g., minor best practice violations)
45
+ #
46
+ # Use 'error' for policy validity issues, and 'critical/high/medium/low' for
47
+ # security best practices. This distinction helps separate "broken policies"
48
+ # from "insecure but valid policies".
49
+ # ============================================================================
50
+
51
+ # ============================================================================
52
+ # DEFAULT CONFIGURATION
53
+ # ============================================================================
54
+ DEFAULT_CONFIG = {
55
+ # ========================================================================
56
+ # Global Settings
57
+ # ========================================================================
58
+ "settings": {
59
+ # Stop validation on first error
60
+ "fail_fast": False,
61
+ # Maximum number of concurrent policy validations
62
+ "max_concurrent": 10,
63
+ # Enable/disable ALL built-in checks (set to False when using AWS Access Analyzer)
64
+ "enable_builtin_checks": True,
65
+ # Enable parallel execution of checks for better performance
66
+ "parallel_execution": True,
67
+ # Path to directory containing pre-downloaded AWS service definitions
68
+ # Set to a directory path to use offline validation, or None to use AWS API
69
+ "aws_services_dir": None,
70
+ # Cache AWS service definitions locally (persists between runs)
71
+ "cache_enabled": True,
72
+ # Cache TTL in hours (default: 168 = 7 days)
73
+ "cache_ttl_hours": 168,
74
+ # Severity levels that cause validation to fail
75
+ # IAM Validity: error, warning, info
76
+ # Security: critical, high, medium, low
77
+ "fail_on_severity": ["error", "critical", "high"],
78
+ },
79
+ # ========================================================================
80
+ # AWS IAM Validation Checks (17 checks total)
81
+ # These validate that policies conform to AWS IAM requirements
82
+ # ========================================================================
83
+ # ========================================================================
84
+ # 1. SID UNIQUENESS
85
+ # ========================================================================
86
+ # Validate Statement ID (Sid) uniqueness as per AWS IAM requirements
87
+ # AWS requires:
88
+ # - Sids must be unique within the policy (duplicate_sid error)
89
+ # - Sids must contain only alphanumeric characters, hyphens, and underscores
90
+ # - No spaces or special characters allowed
91
+ "sid_uniqueness": {
92
+ "enabled": True,
93
+ "severity": "error", # IAM validity error
94
+ "description": "Validates that Statement IDs (Sids) are unique and follow AWS naming requirements",
95
+ },
96
+ # ========================================================================
97
+ # 2. POLICY SIZE
98
+ # ========================================================================
99
+ # Validate policy size against AWS limits
100
+ # Policy type determines which AWS limit to enforce:
101
+ # - managed: 6144 characters (excluding whitespace)
102
+ # - inline_user: 2048 characters
103
+ # - inline_group: 5120 characters
104
+ # - inline_role: 10240 characters
105
+ "policy_size": {
106
+ "enabled": True,
107
+ "severity": "error", # IAM validity error
108
+ "description": "Validates that IAM policies don't exceed AWS size limits",
109
+ "policy_type": "managed", # Change based on your policy type
110
+ },
111
+ # ========================================================================
112
+ # 3. ACTION VALIDATION
113
+ # ========================================================================
114
+ # Validate IAM actions against AWS service definitions
115
+ # Uses AWS Service Authorization Reference to validate action names
116
+ # Catches typos like "s3:GetObjekt" or non-existent actions
117
+ "action_validation": {
118
+ "enabled": True,
119
+ "severity": "error", # IAM validity error
120
+ "description": "Validates that actions exist in AWS services",
121
+ },
122
+ # ========================================================================
123
+ # 4. CONDITION KEY VALIDATION
124
+ # ========================================================================
125
+ # Validate condition keys for actions against AWS service definitions
126
+ # Ensures condition keys are valid for the specified actions
127
+ # Examples:
128
+ # ✅ s3:GetObject with s3:prefix condition
129
+ # ❌ s3:GetObject with ec2:InstanceType condition (invalid)
130
+ "condition_key_validation": {
131
+ "enabled": True,
132
+ "severity": "error", # IAM validity error
133
+ "description": "Validates condition keys against AWS service definitions for specified actions",
134
+ # Validate aws:* global condition keys against known list
135
+ "validate_aws_global_keys": True,
136
+ # Warn when global condition keys (aws:*) are used with actions that have action-specific keys
137
+ # While global condition keys can be used across all AWS services, they may not be available
138
+ # in every request context. This warning helps ensure proper validation.
139
+ # Set to False to disable warnings for global condition keys
140
+ "warn_on_global_condition_keys": False,
141
+ },
142
+ # ========================================================================
143
+ # 5. CONDITION TYPE MISMATCH
144
+ # ========================================================================
145
+ # Validate condition type matching
146
+ # Ensures condition operators match the expected types for condition keys
147
+ # Examples:
148
+ # ✅ StringEquals with string condition key
149
+ # ❌ NumericEquals with string condition key (type mismatch)
150
+ # ✅ DateGreaterThan with date condition key
151
+ # ❌ StringLike with date condition key (type mismatch)
152
+ "condition_type_mismatch": {
153
+ "enabled": True,
154
+ "severity": "error", # IAM validity error
155
+ "description": "Validates that condition operators match the expected types for condition keys",
156
+ },
157
+ # ========================================================================
158
+ # 6. SET OPERATOR VALIDATION
159
+ # ========================================================================
160
+ # Validate set operator usage (ForAllValues/ForAnyValue)
161
+ # Ensures set operators are only used with multi-value condition keys
162
+ # Using them with single-value keys can cause unexpected behavior
163
+ "set_operator_validation": {
164
+ "enabled": True,
165
+ "severity": "error", # IAM validity error
166
+ "description": "Validates that set operators are used with multi-value condition keys",
167
+ },
168
+ # ========================================================================
169
+ # 7. MFA CONDITION ANTIPATTERN
170
+ # ========================================================================
171
+ # Detect MFA condition anti-patterns
172
+ # Identifies dangerous MFA-related patterns that may not enforce MFA as intended:
173
+ # 1. Bool with aws:MultiFactorAuthPresent = false (key may not exist)
174
+ # 2. Null with aws:MultiFactorAuthPresent = false (only checks existence)
175
+ "mfa_condition_antipattern": {
176
+ "enabled": True,
177
+ "severity": "warning", # Security concern, not an IAM validity error
178
+ "description": "Detects dangerous MFA-related condition patterns",
179
+ },
180
+ # ========================================================================
181
+ # 8. RESOURCE VALIDATION
182
+ # ========================================================================
183
+ # Validate resource ARN formats
184
+ # Ensures ARNs follow the correct format:
185
+ # arn:partition:service:region:account-id:resource-type/resource-id
186
+ # Pattern allows wildcards (*) in region and account fields
187
+ "resource_validation": {
188
+ "enabled": True,
189
+ "severity": "error", # IAM validity error
190
+ "description": "Validates ARN format for resources",
191
+ "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*]*:.+$",
192
+ },
193
+ # ========================================================================
194
+ # 9. PRINCIPAL VALIDATION
195
+ # ========================================================================
196
+ # Validates Principal elements in resource-based policies
197
+ # (S3 buckets, SNS topics, SQS queues, etc.)
198
+ # Only runs when --policy-type RESOURCE_POLICY is specified
199
+ #
200
+ # See: iam_validator/core/config/service_principals.py for defaults
201
+ "principal_validation": {
202
+ "enabled": True,
203
+ "severity": "high", # Security issue, not IAM validity error
204
+ "description": "Validates Principal elements in resource policies for security best practices",
205
+ # blocked_principals: Principals that should NEVER be allowed (deny list)
206
+ # Default: ["*"] blocks public access to everyone
207
+ # Examples:
208
+ # ["*"] - Block public access
209
+ # ["*", "arn:aws:iam::*:root"] - Block public + all AWS accounts
210
+ "blocked_principals": ["*"],
211
+ # allowed_principals: When set, ONLY these principals are allowed (whitelist mode)
212
+ # Leave empty to allow all except blocked principals
213
+ # Examples:
214
+ # [] - Allow all (except blocked)
215
+ # ["arn:aws:iam::123456789012:root"] - Only allow specific account
216
+ # ["arn:aws:iam::*:role/OrgAccessRole"] - Allow specific role in any account
217
+ "allowed_principals": [],
218
+ # require_conditions_for: Principals that MUST have specific IAM conditions
219
+ # Format: {principal_pattern: [required_condition_keys]}
220
+ # Default: Public access (*) must specify source to limit scope
221
+ # Examples:
222
+ # "*": ["aws:SourceArn"] - Public access must specify source ARN
223
+ # "arn:aws:iam::*:root": ["aws:PrincipalOrgID"] - Cross-account must be from org
224
+ "require_conditions_for": {
225
+ "*": [
226
+ "aws:SourceArn",
227
+ "aws:SourceAccount",
228
+ "aws:SourceVpce",
229
+ "aws:SourceIp",
230
+ "aws:SourceOrgID",
231
+ "aws:SourceOrgPaths",
232
+ ],
233
+ },
234
+ # principal_condition_requirements: Advanced condition requirements for principals
235
+ # Similar to action_condition_enforcement but for principals
236
+ # Supports all_of/any_of/none_of logic with rich metadata
237
+ # Default: 2 critical requirements enabled (public_access, prevent_insecure_transport)
238
+ # See: iam_validator/core/config/principal_requirements.py
239
+ # To customize requirements, use Python API:
240
+ # from iam_validator.core.config import get_principal_requirements_by_names
241
+ # requirements = get_principal_requirements_by_names(['public_access', 'cross_account_org'])
242
+ # To disable: set to empty list []
243
+ "principal_condition_requirements": get_default_principal_requirements(),
244
+ # allowed_service_principals: AWS service principals that are always allowed
245
+ # Default: 16 common AWS services (cloudfront, s3, lambda, logs, etc.)
246
+ # These are typically safe as AWS services need access to resources
247
+ # See: iam_validator/core/config/service_principals.py
248
+ "allowed_service_principals": list(DEFAULT_SERVICE_PRINCIPALS),
249
+ },
250
+ # ========================================================================
251
+ # 10. POLICY TYPE VALIDATION
252
+ # ========================================================================
253
+ # Validate policy type requirements (new in v1.3.0)
254
+ # Ensures policies conform to the declared type (IDENTITY vs RESOURCE_POLICY)
255
+ # Also enforces RCP (Resource Control Policy) specific requirements
256
+ # RCP validation includes:
257
+ # - Must have Effect: Deny (RCPs are deny-only)
258
+ # - Must target specific resource types (no wildcards)
259
+ # - Principal must be "*" (applies to all)
260
+ "policy_type_validation": {
261
+ "enabled": True,
262
+ "severity": "error", # IAM validity error
263
+ "description": "Validates policies match declared type and enforces RCP requirements",
264
+ },
265
+ # ========================================================================
266
+ # 11. ACTION-RESOURCE MATCHING
267
+ # ========================================================================
268
+ # Validate action-resource matching
269
+ # Ensures resources match the required resource types for actions
270
+ # Handles both:
271
+ # 1. Account-level actions that require Resource: "*" (e.g., iam:ListUsers)
272
+ # 2. Resource-specific actions with correct ARN types (e.g., s3:GetObject)
273
+ # Inspired by Parliament's RESOURCE_MISMATCH check
274
+ # Examples:
275
+ # ✅ iam:ListUsers with Resource: "*"
276
+ # ❌ iam:ListUsers with arn:aws:iam::123:user/foo (account-level action)
277
+ # ✅ s3:GetObject with arn:aws:s3:::bucket/*
278
+ # ❌ s3:GetObject with arn:aws:s3:::bucket (missing /*)
279
+ # ✅ s3:ListBucket with arn:aws:s3:::bucket
280
+ # ❌ s3:ListBucket with arn:aws:s3:::bucket/* (should be bucket, not object)
281
+ "action_resource_matching": {
282
+ "enabled": True,
283
+ "severity": "error", # IAM validity error
284
+ "description": "Validates that resource ARNs match the required resource types for actions (including account-level actions)",
285
+ },
286
+ # ========================================================================
287
+ # Security Best Practices Checks (6 checks)
288
+ # ========================================================================
289
+ # Individual checks for security anti-patterns
290
+ #
291
+ # Configuration Fields Reference:
292
+ # - description: Technical description of what the check does (internal/docs)
293
+ # - message: Error/warning shown to users when issue is detected
294
+ # - suggestion: Guidance on how to fix or mitigate the issue
295
+ # - example: Concrete code example showing before/after or proper usage
296
+ #
297
+ # Field Progression: detect (description) → alert (message) → advise (suggestion) → demonstrate (example)
298
+ #
299
+ # For detailed explanation of these fields and how to customize them,
300
+ # see: docs/configuration.md#customizing-messages
301
+ #
302
+ # See: iam_validator/core/config/wildcards.py for allowed wildcards
303
+ # See: iam_validator/core/config/sensitive_actions.py for sensitive actions
304
+ # ========================================================================
305
+ # ========================================================================
306
+ # 12. WILDCARD ACTION
307
+ # ========================================================================
308
+ # Check for wildcard actions (Action: "*")
309
+ # Flags statements that allow all actions
310
+ "wildcard_action": {
311
+ "enabled": True,
312
+ "severity": "medium", # Security issue
313
+ "description": "Checks for wildcard actions (*)",
314
+ "message": "Statement allows all actions (*)",
315
+ "suggestion": "Replace wildcard with specific actions needed for your use case",
316
+ "example": (
317
+ "Replace:\n"
318
+ ' "Action": ["*"]\n'
319
+ "\n"
320
+ "With specific actions:\n"
321
+ ' "Action": ["s3:GetObject", "s3:PutObject", "s3:ListBucket"]\n'
322
+ ),
323
+ },
324
+ # ========================================================================
325
+ # 13. WILDCARD RESOURCE
326
+ # ========================================================================
327
+ # Check for wildcard resources (Resource: "*")
328
+ # Flags statements that apply to all resources
329
+ # Exception: Allowed if ALL actions are in allowed_wildcards list
330
+ "wildcard_resource": {
331
+ "enabled": True,
332
+ "severity": "medium", # Security issue
333
+ "description": "Checks for wildcard resources (*)",
334
+ # Allowed wildcard patterns for actions that can be used with Resource: "*"
335
+ # Default: 25 read-only patterns (Describe*, List*, Get*)
336
+ # See: iam_validator/core/config/wildcards.py
337
+ "allowed_wildcards": list(DEFAULT_ALLOWED_WILDCARDS),
338
+ "message": "Statement applies to all resources (*)",
339
+ "suggestion": "Replace wildcard with specific resource ARNs",
340
+ "example": (
341
+ "Replace:\n"
342
+ ' "Resource": "*"\n'
343
+ "\n"
344
+ "With specific ARNs:\n"
345
+ ' "Resource": [\n'
346
+ ' "arn:aws:service:region:account-id:resource-type/resource-id",\n'
347
+ ' "arn:aws:service:region:account-id:resource-type/*"\n'
348
+ " ]\n"
349
+ ),
350
+ },
351
+ # ========================================================================
352
+ # 14. FULL WILDCARD (CRITICAL)
353
+ # ========================================================================
354
+ # Check for BOTH Action: "*" AND Resource: "*" (CRITICAL)
355
+ # This grants full administrative access (AdministratorAccess equivalent)
356
+ "full_wildcard": {
357
+ "enabled": True,
358
+ "severity": "critical", # CRITICAL security risk
359
+ "description": "Checks for both action and resource wildcards together (critical risk)",
360
+ "message": "Statement allows all actions on all resources - CRITICAL SECURITY RISK",
361
+ "suggestion": (
362
+ "This grants full administrative access. Replace both wildcards with specific actions "
363
+ "and resources to follow least-privilege principle"
364
+ ),
365
+ "example": (
366
+ "Replace:\n"
367
+ ' "Action": "*",\n'
368
+ ' "Resource": "*"\n'
369
+ "\n"
370
+ "With specific values:\n"
371
+ ' "Action": ["s3:GetObject", "s3:PutObject"],\n'
372
+ ' "Resource": ["arn:aws:s3:::my-bucket/*"]\n'
373
+ ),
374
+ },
375
+ # ========================================================================
376
+ # 15. SERVICE WILDCARD
377
+ # ========================================================================
378
+ # Check for service-level wildcards (e.g., "iam:*", "s3:*", "ec2:*")
379
+ # These grant ALL permissions for a service (often too permissive)
380
+ # Exception: Some services like logs, cloudwatch are typically safe
381
+ #
382
+ # Template placeholders supported in message/suggestion/example:
383
+ # - {action}: The wildcard action found (e.g., "s3:*")
384
+ # - {service}: The service name (e.g., "s3")
385
+ "service_wildcard": {
386
+ "enabled": True,
387
+ "severity": "high", # Security issue
388
+ "description": "Checks for service-level wildcards (e.g., 'iam:*', 's3:*')",
389
+ # Services that are allowed to use wildcards (default: logs, cloudwatch, xray)
390
+ # See: iam_validator/core/config/wildcards.py
391
+ "allowed_services": list(DEFAULT_SERVICE_WILDCARDS),
392
+ },
393
+ # ========================================================================
394
+ # 16. SENSITIVE ACTION
395
+ # ========================================================================
396
+ # Check for sensitive actions without IAM conditions
397
+ # Sensitive actions: IAM changes, secrets access, destructive operations
398
+ # Default: 490 actions across 4 security risk categories
399
+ #
400
+ # Categories (with action counts):
401
+ # - credential_exposure (46): Actions exposing credentials, secrets, or tokens
402
+ # - data_access (109): Actions retrieving sensitive data
403
+ # - priv_esc (27): Actions enabling privilege escalation
404
+ # - resource_exposure (321): Actions modifying resource policies/permissions
405
+ #
406
+ # Scans at BOTH statement-level AND policy-level for security patterns
407
+ # See: iam_validator/core/config/sensitive_actions.py
408
+ # Source: https://github.com/primeharbor/sensitive_iam_actions
409
+ #
410
+ # Python API:
411
+ # from iam_validator.core.config.sensitive_actions import get_sensitive_actions
412
+ # # Get all sensitive actions (default)
413
+ # all_actions = get_sensitive_actions()
414
+ # # Get only specific categories
415
+ # priv_esc_only = get_sensitive_actions(['priv_esc'])
416
+ # # Get multiple categories
417
+ # critical = get_sensitive_actions(['credential_exposure', 'priv_esc'])
418
+ #
419
+ # Avoiding Duplicate Alerts:
420
+ # If you configure specific actions in action_condition_enforcement,
421
+ # use ignore_patterns to prevent duplicate alerts from sensitive_action:
422
+ #
423
+ # ignore_patterns:
424
+ # - action_matches: "^(iam:PassRole|iam:CreateUser|s3:PutObject)$"
425
+ #
426
+ # Template placeholders supported:
427
+ # - message_single uses {action}: Single action name (e.g., "iam:CreateRole")
428
+ # - message_multiple uses {actions}: Comma-separated list (e.g., "iam:CreateRole', 'iam:PutUserPolicy")
429
+ # - suggestion and example support both {action} and {actions}
430
+ "sensitive_action": {
431
+ "enabled": True,
432
+ "severity": "medium", # Security issue (can be overridden per-category)
433
+ "description": "Checks for sensitive actions without conditions",
434
+ # Categories to check (default: all categories enabled)
435
+ # Set to specific categories to limit scope:
436
+ # categories: ['credential_exposure', 'priv_esc'] # Only check critical actions
437
+ # categories: ['data_access'] # Only check data access actions
438
+ # Set to empty list to disable: categories: []
439
+ "categories": [
440
+ "credential_exposure", # Critical: Credential/secret exposure (46 actions)
441
+ "data_access", # High: Sensitive data retrieval (109 actions)
442
+ "priv_esc", # Critical: Privilege escalation (27 actions)
443
+ "resource_exposure", # High: Resource policy modifications (321 actions)
444
+ ],
445
+ # Per-category severity overrides (optional)
446
+ # If not specified, uses the default severity above
447
+ "category_severities": {
448
+ "credential_exposure": "critical", # Override: credential exposure is critical
449
+ "priv_esc": "critical", # Override: privilege escalation is critical
450
+ "data_access": "high", # Override: data access is high
451
+ "resource_exposure": "high", # Override: resource exposure is high
452
+ },
453
+ # Category-specific ABAC suggestions and examples
454
+ # These provide tailored guidance for each security risk category
455
+ # See: iam_validator/core/config/category_suggestions.py
456
+ # Can be overridden to customize suggestions per category
457
+ "category_suggestions": get_category_suggestions(),
458
+ # Custom message templates (support {action} and {actions} placeholders)
459
+ "message_single": "Sensitive action '{action}' should have conditions to limit when it can be used",
460
+ "message_multiple": "Sensitive actions '{actions}' should have conditions to limit when they can be used",
461
+ # Ignore patterns to prevent duplicate alerts
462
+ # Useful when you have specific condition enforcement for certain actions
463
+ # Example: Ignore iam:PassRole since it's checked by action_condition_enforcement
464
+ "ignore_patterns": [
465
+ {"action_matches": "^iam:PassRole$"},
466
+ ],
467
+ },
468
+ # ========================================================================
469
+ # 17. ACTION CONDITION ENFORCEMENT
470
+ # ========================================================================
471
+ # Enforce specific IAM condition requirements for actions
472
+ # Examples: iam:PassRole must specify iam:PassedToService,
473
+ # S3 writes must require MFA, EC2 launches must use tags
474
+ #
475
+ # Default: 5 enabled requirements
476
+ # Available requirements:
477
+ # Default (enabled):
478
+ # - iam_pass_role: Requires iam:PassedToService
479
+ # - s3_org_id: Requires organization ID for S3 writes
480
+ # - source_ip_restrictions: Restricts to corporate IPs
481
+ # - s3_secure_transport: Prevents insecure transport
482
+ # - prevent_public_ip: Prevents 0.0.0.0/0 IP ranges
483
+ #
484
+ # See: iam_validator/core/config/condition_requirements.py
485
+ # Python API:
486
+ # from iam_validator.core.config import CONDITION_REQUIREMENTS
487
+ # import copy
488
+ # requirements = copy.deepcopy(CONDITION_REQUIREMENTS)
489
+ "action_condition_enforcement": {
490
+ "enabled": True,
491
+ "severity": "high", # Default severity (can be overridden per-requirement)
492
+ "description": "Enforces conditions (MFA, IP, tags, etc.) for specific actions at both statement and policy level",
493
+ # STATEMENT-LEVEL: Load 5 requirements from Python module
494
+ # Deep copy to prevent mutation of the originals
495
+ # These check individual statements independently
496
+ "action_condition_requirements": __import__("copy").deepcopy(CONDITION_REQUIREMENTS),
497
+ # POLICY-LEVEL: Scan entire policy and enforce conditions across ALL matching statements
498
+ # Example: "If ANY statement grants iam:CreateUser, then ALL such statements must have MFA"
499
+ # Default: Empty list (opt-in feature)
500
+ # To enable, add requirements like:
501
+ # policy_level_requirements:
502
+ # - actions:
503
+ # any_of: ["iam:CreateUser", "iam:AttachUserPolicy"]
504
+ # scope: "policy"
505
+ # required_conditions:
506
+ # - condition_key: "aws:MultiFactorAuthPresent"
507
+ # expected_value: true
508
+ # severity: "critical"
509
+ "policy_level_requirements": [],
510
+ },
511
+ }
512
+
513
+
514
+ def get_default_config() -> dict:
515
+ """
516
+ Get a deep copy of the default configuration.
517
+
518
+ Returns:
519
+ A deep copy of the default configuration dictionary
520
+ """
521
+ import copy
522
+
523
+ return copy.deepcopy(DEFAULT_CONFIG)