iam-policy-validator 1.4.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 (56) hide show
  1. iam_policy_validator-1.4.0.dist-info/METADATA +1022 -0
  2. iam_policy_validator-1.4.0.dist-info/RECORD +56 -0
  3. iam_policy_validator-1.4.0.dist-info/WHEEL +4 -0
  4. iam_policy_validator-1.4.0.dist-info/entry_points.txt +2 -0
  5. iam_policy_validator-1.4.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 +27 -0
  10. iam_validator/checks/action_condition_enforcement.py +727 -0
  11. iam_validator/checks/action_resource_constraint.py +151 -0
  12. iam_validator/checks/action_validation.py +72 -0
  13. iam_validator/checks/condition_key_validation.py +70 -0
  14. iam_validator/checks/policy_size.py +151 -0
  15. iam_validator/checks/policy_type_validation.py +299 -0
  16. iam_validator/checks/principal_validation.py +282 -0
  17. iam_validator/checks/resource_validation.py +108 -0
  18. iam_validator/checks/security_best_practices.py +536 -0
  19. iam_validator/checks/sid_uniqueness.py +170 -0
  20. iam_validator/checks/utils/__init__.py +1 -0
  21. iam_validator/checks/utils/policy_level_checks.py +143 -0
  22. iam_validator/checks/utils/sensitive_action_matcher.py +252 -0
  23. iam_validator/checks/utils/wildcard_expansion.py +87 -0
  24. iam_validator/commands/__init__.py +25 -0
  25. iam_validator/commands/analyze.py +434 -0
  26. iam_validator/commands/base.py +48 -0
  27. iam_validator/commands/cache.py +392 -0
  28. iam_validator/commands/download_services.py +260 -0
  29. iam_validator/commands/post_to_pr.py +86 -0
  30. iam_validator/commands/validate.py +539 -0
  31. iam_validator/core/__init__.py +14 -0
  32. iam_validator/core/access_analyzer.py +666 -0
  33. iam_validator/core/access_analyzer_report.py +643 -0
  34. iam_validator/core/aws_fetcher.py +880 -0
  35. iam_validator/core/aws_global_conditions.py +137 -0
  36. iam_validator/core/check_registry.py +469 -0
  37. iam_validator/core/cli.py +134 -0
  38. iam_validator/core/config_loader.py +452 -0
  39. iam_validator/core/defaults.py +393 -0
  40. iam_validator/core/formatters/__init__.py +27 -0
  41. iam_validator/core/formatters/base.py +147 -0
  42. iam_validator/core/formatters/console.py +59 -0
  43. iam_validator/core/formatters/csv.py +170 -0
  44. iam_validator/core/formatters/enhanced.py +434 -0
  45. iam_validator/core/formatters/html.py +672 -0
  46. iam_validator/core/formatters/json.py +33 -0
  47. iam_validator/core/formatters/markdown.py +63 -0
  48. iam_validator/core/formatters/sarif.py +187 -0
  49. iam_validator/core/models.py +298 -0
  50. iam_validator/core/policy_checks.py +656 -0
  51. iam_validator/core/policy_loader.py +396 -0
  52. iam_validator/core/pr_commenter.py +338 -0
  53. iam_validator/core/report.py +859 -0
  54. iam_validator/integrations/__init__.py +28 -0
  55. iam_validator/integrations/github_integration.py +795 -0
  56. iam_validator/integrations/ms_teams.py +442 -0
@@ -0,0 +1,1022 @@
1
+ Metadata-Version: 2.4
2
+ Name: iam-policy-validator
3
+ Version: 1.4.0
4
+ Summary: Validate AWS IAM policies for correctness and security using AWS Service Reference API
5
+ Project-URL: Homepage, https://github.com/boogy/iam-policy-validator
6
+ Project-URL: Documentation, https://github.com/boogy/iam-policy-validator/tree/main/docs
7
+ Project-URL: Repository, https://github.com/boogy/iam-policy-validator
8
+ Project-URL: Issues, https://github.com/boogy/iam-policy-validator/issues
9
+ Project-URL: Changelog, https://github.com/boogy/iam-policy-validator/blob/main/docs/CHANGELOG.md
10
+ Author-email: boogy <0xboogy@gmail.com>
11
+ License: MIT
12
+ License-File: LICENSE
13
+ Keywords: aws,github-action,iam,policy,security,validation
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: System Administrators
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Security
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: System :: Systems Administration
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: boto3>=1.28.0
27
+ Requires-Dist: botocore>=1.40.55
28
+ Requires-Dist: httpx[http2]>=0.27.0
29
+ Requires-Dist: pydantic>=2.0.0
30
+ Requires-Dist: pyyaml>=6.0
31
+ Requires-Dist: rich>=13.0.0
32
+ Provides-Extra: dev
33
+ Requires-Dist: mypy>=1.0.0; extra == 'dev'
34
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
35
+ Requires-Dist: pytest-benchmark>=4.0.0; extra == 'dev'
36
+ Requires-Dist: pytest-cov>=7.0.0; extra == 'dev'
37
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
38
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
39
+ Requires-Dist: types-boto3; extra == 'dev'
40
+ Requires-Dist: types-pyyaml; extra == 'dev'
41
+ Description-Content-Type: text/markdown
42
+
43
+ # IAM Policy Validator
44
+
45
+ > **Catch IAM policy errors before they reach production** - A comprehensive security and validation tool for AWS IAM policies that combines AWS's official Access Analyzer with powerful custom security checks.
46
+
47
+ [![GitHub Actions](https://img.shields.io/badge/GitHub%20Actions-Ready-blue)](https://github.com/marketplace/actions/iam-policy-validator)
48
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
49
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
50
+
51
+ ## 🚀 Why IAM Policy Validator?
52
+
53
+ **IAM policy errors are costly and dangerous.** A single misconfigured policy can:
54
+ - ❌ Grant unintended admin access (privilege escalation)
55
+ - ❌ Expose sensitive data to the public
56
+ - ❌ Break production deployments with invalid syntax
57
+ - ❌ Create security vulnerabilities that persist for months
58
+
59
+ **This tool prevents these issues** by:
60
+ - ✅ **Validating early** - Catch errors in PRs before merge
61
+ - ✅ **Comprehensive checks** - AWS Access Analyzer + 15+ security checks
62
+ - ✅ **Smart filtering** - Auto-detects IAM policies from mixed JSON/YAML files
63
+ - ✅ **Developer-friendly** - Clear error messages with fix suggestions
64
+ - ✅ **Zero setup** - Works as a GitHub Action out of the box
65
+
66
+ ## ✨ Key Features
67
+
68
+ ### 🔍 Multi-Layer Validation
69
+ - **AWS IAM Access Analyzer** - Official AWS validation (syntax, permissions, security)
70
+ - **Custom Security Checks** - 15+ specialized checks for best practices
71
+ - **Policy Comparison** - Detect new permissions vs baseline (prevent scope creep)
72
+ - **Public Access Detection** - Check 29+ AWS resource types for public exposure
73
+ - **Privilege Escalation Detection** - Identify dangerous action combinations
74
+
75
+ ### 🎯 Smart & Efficient
76
+ - **Automatic IAM Policy Detection** - Scans mixed repos, filters non-IAM files automatically
77
+ - **Wildcard Expansion** - Expands `s3:Get*` patterns to validate specific actions
78
+ - **Offline Validation** - Download AWS service definitions for air-gapped environments
79
+ - **JSON + YAML Support** - Native support for both formats
80
+ - **Streaming Mode** - Memory-efficient processing for large policy sets
81
+
82
+ ### ⚡ Performance Optimized
83
+ - **Service Pre-fetching** - Common AWS services cached at startup (faster validation)
84
+ - **LRU Memory Cache** - Recently accessed services cached with TTL
85
+ - **Request Coalescing** - Duplicate API requests automatically deduplicated
86
+ - **Parallel Execution** - Multiple checks run concurrently
87
+ - **HTTP/2 Support** - Multiplexed connections for better API performance
88
+
89
+ ### 📊 Output Formats
90
+ - **Console** (default) - Clean terminal output with colors and tables
91
+ - **Enhanced** - Modern visual output with progress bars and tree structure
92
+ - **JSON** - Structured format for programmatic processing
93
+ - **Markdown** - GitHub-flavored markdown for PR comments
94
+ - **SARIF** - GitHub code scanning integration format
95
+ - **CSV** - Spreadsheet-compatible for analysis
96
+ - **HTML** - Interactive reports with filtering and search
97
+
98
+ ### 🔌 Extensibility
99
+ - **Plugin System** - Easy-to-add custom validation checks
100
+ - **Configuration-Driven** - YAML-based configuration for all aspects
101
+ - **CI/CD Ready** - GitHub Actions, GitLab CI, Jenkins, CircleCI
102
+
103
+ ## 📈 Real-World Impact
104
+
105
+ ### Common IAM Policy Issues This Tool Catches
106
+
107
+ **Before IAM Policy Validator:**
108
+ ```json
109
+ {
110
+ "Statement": [{
111
+ "Effect": "Allow",
112
+ "Action": "s3:*", // ❌ Too permissive
113
+ "Resource": "*" // ❌ All buckets!
114
+ }]
115
+ }
116
+ ```
117
+ **Issue:** Grants full S3 access to ALL buckets (data breach risk)
118
+
119
+ **After IAM Policy Validator:**
120
+ ```
121
+ ❌ MEDIUM: Statement applies to all resources (*)
122
+ ❌ HIGH: Wildcard action 's3:*' with resource '*' is overly permissive
123
+ 💡 Suggestion: Specify exact actions and bucket ARNs
124
+ ```
125
+
126
+ ### Privilege Escalation Detection
127
+
128
+ **Dangerous combination across multiple statements:**
129
+ ```json
130
+ {
131
+ "Statement": [
132
+ {"Action": "iam:CreateUser"}, // Seems innocent
133
+ {"Action": "iam:AttachUserPolicy"} // Also seems innocent
134
+ ]
135
+ }
136
+ ```
137
+
138
+ **What the validator catches:**
139
+ ```
140
+ 🚨 CRITICAL: Privilege escalation risk detected!
141
+ Actions ['iam:CreateUser', 'iam:AttachUserPolicy'] allow:
142
+ 1. Create new IAM user
143
+ 2. Attach AdministratorAccess policy to that user
144
+ 3. Gain full AWS account access
145
+
146
+ 💡 Add conditions or separate these permissions
147
+ ```
148
+
149
+ ### Public Access Prevention
150
+
151
+ **Before merge:**
152
+ ```json
153
+ {
154
+ "Principal": "*", // ❌ Anyone on the internet!
155
+ "Action": "s3:GetObject",
156
+ "Resource": "arn:aws:s3:::my-private-data/*"
157
+ }
158
+ ```
159
+
160
+ **Blocked by validator:**
161
+ ```
162
+ 🛑 CRITICAL: Resource policy allows public access
163
+ 29 resource types checked: AWS::S3::Bucket
164
+ Principal "*" grants internet-wide access to private data
165
+
166
+ 💡 Use specific AWS principals or add IP restrictions
167
+ ```
168
+
169
+ ## Quick Start
170
+
171
+ ### As a GitHub Action (Recommended) ⭐
172
+
173
+ The IAM Policy Validator is available as **both** a standalone GitHub Action and a Python module. Choose the approach that best fits your needs:
174
+
175
+ #### **Option A: Standalone GitHub Action** (Recommended - Zero Setup)
176
+
177
+ Use the published action directly - it handles all setup automatically:
178
+
179
+ Create `.github/workflows/iam-policy-validator.yml`:
180
+
181
+ ```yaml
182
+ name: IAM Policy Validation
183
+
184
+ on:
185
+ pull_request:
186
+ paths:
187
+ - 'policies/**/*.json'
188
+
189
+ jobs:
190
+ validate:
191
+ runs-on: ubuntu-latest
192
+ permissions:
193
+ contents: read
194
+ pull-requests: write
195
+
196
+ steps:
197
+ - name: Checkout code
198
+ uses: actions/checkout@v5
199
+
200
+ - name: Validate IAM Policies
201
+ uses: boogy/iam-policy-validator@v1
202
+ with:
203
+ path: policies/
204
+ post-comment: true
205
+ create-review: true
206
+ fail-on-warnings: true
207
+ ```
208
+
209
+ **Benefits:**
210
+ - ✅ Zero setup - action handles Python, uv, and dependencies
211
+ - ✅ Automatic dependency caching
212
+ - ✅ Simple, declarative configuration
213
+ - ✅ Perfect for CI/CD workflows
214
+
215
+ #### With AWS Access Analyzer (Standalone Action)
216
+
217
+ Use AWS's official policy validation service:
218
+
219
+ ```yaml
220
+ name: IAM Policy Validation with Access Analyzer
221
+
222
+ on:
223
+ pull_request:
224
+ paths:
225
+ - 'policies/**/*.json'
226
+
227
+ jobs:
228
+ validate:
229
+ runs-on: ubuntu-latest
230
+ permissions:
231
+ contents: read
232
+ pull-requests: write
233
+ id-token: write # Required for AWS OIDC
234
+
235
+ steps:
236
+ - name: Checkout code
237
+ uses: actions/checkout@v5
238
+
239
+ - name: Configure AWS Credentials
240
+ uses: aws-actions/configure-aws-credentials@v4
241
+ with:
242
+ role-to-assume: arn:aws:iam::123456789012:role/GitHubActionsRole
243
+ aws-region: us-east-1
244
+
245
+ - name: Validate with Access Analyzer
246
+ uses: boogy/iam-policy-validator@v1
247
+ with:
248
+ path: policies/
249
+ use-access-analyzer: true
250
+ run-all-checks: true
251
+ post-comment: true
252
+ create-review: true
253
+ fail-on-warnings: true
254
+ ```
255
+
256
+ #### **Option B: As Python Module/CLI Tool**
257
+
258
+ For advanced use cases or when you need more control:
259
+
260
+ ```yaml
261
+ name: IAM Policy Validation (CLI)
262
+
263
+ on:
264
+ pull_request:
265
+ paths:
266
+ - 'policies/**/*.json'
267
+
268
+ jobs:
269
+ validate:
270
+ runs-on: ubuntu-latest
271
+ permissions:
272
+ contents: read
273
+ pull-requests: write
274
+
275
+ steps:
276
+ - name: Checkout code
277
+ uses: actions/checkout@v5
278
+
279
+ - name: Set up Python
280
+ uses: actions/setup-python@v5
281
+ with:
282
+ python-version: '3.12'
283
+
284
+ - name: Install uv
285
+ uses: astral-sh/setup-uv@v3
286
+
287
+ - name: Install dependencies
288
+ run: uv sync
289
+
290
+ - name: Validate IAM Policies
291
+ env:
292
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
293
+ GITHUB_REPOSITORY: ${{ github.repository }}
294
+ GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
295
+ run: |
296
+ uv run iam-validator validate \
297
+ --path ./policies/ \
298
+ --github-comment \
299
+ --github-review \
300
+ --fail-on-warnings \
301
+ --log-level info
302
+ ```
303
+
304
+ **Use this when you need:**
305
+ - Advanced CLI options (e.g., `--log-level`, `--custom-checks-dir`, `--stream`)
306
+ - Full control over the Python environment
307
+ - Integration with existing Python workflows
308
+ - Multiple validation commands in sequence
309
+
310
+ #### Custom Policy Checks (Standalone Action)
311
+
312
+ Enforce specific security requirements:
313
+
314
+ ```yaml
315
+ name: IAM Policy Security Validation
316
+
317
+ on:
318
+ pull_request:
319
+ paths:
320
+ - 'policies/**/*.json'
321
+
322
+ jobs:
323
+ validate-security:
324
+ runs-on: ubuntu-latest
325
+ permissions:
326
+ contents: read
327
+ pull-requests: write
328
+ id-token: write
329
+
330
+ steps:
331
+ - name: Checkout code
332
+ uses: actions/checkout@v5
333
+
334
+ - name: Configure AWS Credentials
335
+ uses: aws-actions/configure-aws-credentials@v4
336
+ with:
337
+ role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
338
+ aws-region: us-east-1
339
+
340
+ # Prevent dangerous actions
341
+ - name: Check for Dangerous Actions
342
+ uses: boogy/iam-policy-validator@v1
343
+ with:
344
+ path: policies/
345
+ use-access-analyzer: true
346
+ check-access-not-granted: "s3:DeleteBucket iam:CreateAccessKey iam:AttachUserPolicy"
347
+ post-comment: true
348
+ fail-on-warnings: true
349
+
350
+ # Check S3 bucket policies for public access
351
+ - name: Check S3 Public Access
352
+ uses: boogy/iam-policy-validator@v1
353
+ with:
354
+ path: s3-policies/
355
+ use-access-analyzer: true
356
+ policy-type: RESOURCE_POLICY
357
+ check-no-public-access: true
358
+ public-access-resource-type: "AWS::S3::Bucket"
359
+ post-comment: true
360
+ fail-on-warnings: true
361
+
362
+ # Compare against baseline to prevent new permissions
363
+ - name: Checkout baseline from main
364
+ uses: actions/checkout@v5
365
+ with:
366
+ ref: main
367
+ path: baseline
368
+
369
+ - name: Check for New Access
370
+ uses: boogy/iam-policy-validator@v1
371
+ with:
372
+ path: policies/role-policy.json
373
+ use-access-analyzer: true
374
+ check-no-new-access: baseline/policies/role-policy.json
375
+ post-comment: true
376
+ fail-on-warnings: true
377
+ ```
378
+
379
+ ---
380
+
381
+ ### Choosing the Right Approach
382
+
383
+ | Feature | Standalone Action | Python Module/CLI |
384
+ | --------------------- | ------------------------ | ------------------------------------------------------------------------ |
385
+ | Setup Required | None - fully automated | Manual (Python, uv, dependencies) |
386
+ | Configuration | YAML inputs | CLI arguments |
387
+ | Advanced Options | Limited to action inputs | Full CLI access (`--log-level`, `--custom-checks-dir`, `--stream`, etc.) |
388
+ | Custom Checks | Via config file only | Via config file or `--custom-checks-dir` |
389
+ | Best For | CI/CD, simple workflows | Development, advanced workflows, testing |
390
+ | Dependency Management | Automatic | Manual |
391
+
392
+ **Recommendation:** Use the **Standalone Action** for production CI/CD workflows, and the **Python Module/CLI** for development, testing, or when you need advanced features.
393
+
394
+ #### Multiple Paths (Standalone Action)
395
+
396
+ Validate policies across multiple directories:
397
+
398
+ ```yaml
399
+ - name: Validate Multiple Paths
400
+ uses: boogy/iam-policy-validator@v1
401
+ with:
402
+ path: |
403
+ iam/
404
+ s3-policies/
405
+ lambda-policies/special-policy.json
406
+ post-comment: true
407
+ fail-on-warnings: true
408
+ ```
409
+
410
+ #### Custom Configuration
411
+
412
+ Use a custom configuration file to customize validation rules:
413
+
414
+ ```yaml
415
+ name: IAM Policy Validation with Custom Config
416
+
417
+ on:
418
+ pull_request:
419
+ paths:
420
+ - 'policies/**/*.json'
421
+ - '.iam-validator.yaml'
422
+
423
+ jobs:
424
+ validate:
425
+ runs-on: ubuntu-latest
426
+ permissions:
427
+ contents: read
428
+ pull-requests: write
429
+
430
+ steps:
431
+ - name: Checkout code
432
+ uses: actions/checkout@v5
433
+
434
+ - name: Validate with Custom Config
435
+ uses: boogy/iam-policy-validator@v1
436
+ with:
437
+ path: policies/
438
+ config-file: .iam-validator.yaml
439
+ post-comment: true
440
+ create-review: true
441
+ fail-on-warnings: true
442
+ ```
443
+
444
+ **Example `.iam-validator.yaml`:**
445
+ ```yaml
446
+ settings:
447
+ fail_fast: false
448
+ enable_builtin_checks: true
449
+
450
+ # Custom check configurations
451
+ security_best_practices_check:
452
+ enabled: true
453
+ wildcard_action_check:
454
+ enabled: true
455
+ severity: high
456
+
457
+ action_condition_enforcement_check:
458
+ enabled: true
459
+ severity: critical
460
+ action_condition_requirements:
461
+ - actions:
462
+ - "iam:PassRole"
463
+ severity: critical
464
+ required_conditions:
465
+ - condition_key: "iam:PassedToService"
466
+ ```
467
+
468
+ See [default-config.yaml](default-config.yaml) for a complete configuration example.
469
+
470
+ ### GitHub Action Inputs
471
+
472
+ #### Core Options
473
+ | Input | Description | Required | Default |
474
+ | ------------------ | ----------------------------------------------------------- | -------- | ------- |
475
+ | `path` | Path(s) to IAM policy file or directory (newline-separated) | Yes | - |
476
+ | `config-file` | Path to custom configuration file (.yaml) | No | `""` |
477
+ | `fail-on-warnings` | Fail validation if warnings are found | No | `false` |
478
+ | `recursive` | Recursively search directories for policy files | No | `true` |
479
+
480
+ #### GitHub Integration
481
+ | Input | Description | Required | Default |
482
+ | ------------------ | ---------------------------------------------------- | -------- | ------- |
483
+ | `post-comment` | Post validation summary as PR conversation comment | No | `true` |
484
+ | `create-review` | Create line-specific review comments on PR files | No | `true` |
485
+ | `github-summary` | Write summary to GitHub Actions job summary (Actions tab) | No | `false` |
486
+
487
+ #### Output Options
488
+ | Input | Description | Required | Default |
489
+ | ------------- | -------------------------------------------------------------------------------- | -------- | --------- |
490
+ | `format` | Output format: `console`, `enhanced`, `json`, `markdown`, `sarif`, `csv`, `html` | No | `console` |
491
+ | `output-file` | Path to save output file (for non-console formats) | No | `""` |
492
+
493
+ #### AWS Access Analyzer
494
+ | Input | Description | Required | Default |
495
+ | ------------------------ | --------------------------------------------------------------------------- | -------- | ----------------- |
496
+ | `use-access-analyzer` | Use AWS IAM Access Analyzer for validation | No | `false` |
497
+ | `access-analyzer-region` | AWS region for Access Analyzer | No | `us-east-1` |
498
+ | `policy-type` | Policy type: `IDENTITY_POLICY`, `RESOURCE_POLICY`, `SERVICE_CONTROL_POLICY`, `RESOURCE_CONTROL_POLICY` | No | `IDENTITY_POLICY` |
499
+ | `run-all-checks` | Run custom checks after Access Analyzer (sequential mode) | No | `false` |
500
+
501
+ #### Custom Policy Checks (Access Analyzer)
502
+ | Input | Description | Required | Default |
503
+ | ----------------------------- | --------------------------------------------------------------------------- | -------- | ----------------- |
504
+ | `check-access-not-granted` | Actions that should NOT be granted (space-separated, max 100) | No | `""` |
505
+ | `check-access-resources` | Resources to check with check-access-not-granted (space-separated, max 100) | No | `""` |
506
+ | `check-no-new-access` | Path to baseline policy to compare against (detect new permissions) | No | `""` |
507
+ | `check-no-public-access` | Check that resource policies do not allow public access | No | `false` |
508
+ | `public-access-resource-type` | Resource type(s) for public access check (29+ types supported, or `all`) | No | `AWS::S3::Bucket` |
509
+
510
+ #### Advanced Options
511
+ | Input | Description | Required | Default |
512
+ | ------------------- | -------------------------------------------------------------- | -------- | --------- |
513
+ | `custom-checks-dir` | Path to directory containing custom validation checks | No | `""` |
514
+ | `log-level` | Logging level: `debug`, `info`, `warning`, `error`, `critical` | No | `warning` |
515
+
516
+ **💡 Pro Tips:**
517
+ - Use `custom-checks-dir` to add organization-specific validation rules
518
+ - Set `log-level: debug` when troubleshooting workflow issues
519
+ - Configure `aws-services-dir` in your config file for offline validation
520
+ - The action automatically filters IAM policies from mixed JSON/YAML files
521
+
522
+ See [examples/github-actions/](examples/github-actions/) for 8 ready-to-use workflow examples.
523
+
524
+ ### As a CLI Tool
525
+
526
+ Install and use locally for development:
527
+
528
+ ```bash
529
+ # Install from PyPI
530
+ pip install iam-policy-validator
531
+
532
+ # Or install with pipx (recommended for CLI tools)
533
+ pipx install iam-policy-validator
534
+
535
+ # Validate a single policy
536
+ iam-validator validate --path policy.json
537
+
538
+ # Validate all policies in a directory
539
+ iam-validator validate --path ./policies/
540
+
541
+ # Validate multiple paths
542
+ iam-validator validate --path policy1.json --path ./policies/ --path ./more-policies/
543
+
544
+ # Validate resource policies (S3 bucket policies, SNS topics, etc.)
545
+ iam-validator validate --path ./bucket-policies/ --policy-type RESOURCE_POLICY
546
+
547
+ # Validate AWS Organizations Resource Control Policies (RCPs)
548
+ iam-validator validate --path ./rcps/ --policy-type RESOURCE_CONTROL_POLICY
549
+
550
+ # Generate JSON output
551
+ iam-validator validate --path ./policies/ --format json --output report.json
552
+
553
+ # Validate with AWS IAM Access Analyzer
554
+ iam-validator analyze --path policy.json
555
+
556
+ # Analyze with specific region and profile
557
+ iam-validator analyze --path policy.json --region us-west-2 --profile my-profile
558
+
559
+ # Sequential validation: Access Analyzer → Custom Checks
560
+ iam-validator analyze \
561
+ --path policy.json \
562
+ --github-comment \
563
+ --run-all-checks \
564
+ --github-review
565
+ ```
566
+
567
+ ### Policy Type Validation
568
+
569
+ The validator supports four AWS policy types, each with specific validation rules:
570
+
571
+ #### 🔷 IDENTITY_POLICY (Default)
572
+ Standard IAM policies attached to users, groups, or roles.
573
+
574
+ **Requirements:**
575
+ - Should NOT have `Principal` element (implicit - the attached entity)
576
+ - Must have `Action` and `Resource` elements
577
+
578
+ **Example:**
579
+ ```bash
580
+ iam-validator validate --path ./user-policies/ --policy-type IDENTITY_POLICY
581
+ ```
582
+
583
+ #### 🔶 RESOURCE_POLICY
584
+ Policies attached to AWS resources (S3 buckets, SNS topics, KMS keys, etc.).
585
+
586
+ **Requirements:**
587
+ - MUST have `Principal` element (who can access)
588
+ - Must have `Action`, `Effect`, and `Resource` elements
589
+ - Can use configurable security checks for principal validation
590
+
591
+ **Example:**
592
+ ```bash
593
+ iam-validator validate --path ./bucket-policies/ --policy-type RESOURCE_POLICY
594
+ ```
595
+
596
+ **Advanced Principal Validation:**
597
+ ```yaml
598
+ # config.yaml
599
+ principal_validation_check:
600
+ enabled: true
601
+ severity: high
602
+ # Block public access
603
+ blocked_principals: ["*"]
604
+ # Or require specific conditions for public access
605
+ require_conditions_for:
606
+ "*":
607
+ - "aws:SourceArn"
608
+ - "aws:SourceAccount"
609
+ ```
610
+
611
+ #### 🔷 SERVICE_CONTROL_POLICY
612
+ AWS Organizations SCPs that set permission guardrails.
613
+
614
+ **Requirements:**
615
+ - Must NOT have `Principal` element (applies to all principals in OU)
616
+ - Typically uses `Deny` effect for guardrails
617
+ - Must have `Action` and `Resource` elements
618
+
619
+ **Example:**
620
+ ```bash
621
+ iam-validator validate --path ./scps/ --policy-type SERVICE_CONTROL_POLICY
622
+ ```
623
+
624
+ #### 🆕 RESOURCE_CONTROL_POLICY
625
+ AWS Organizations RCPs for resource-level access control (released 2024).
626
+
627
+ **Strict Requirements:**
628
+ - `Effect` MUST be `Deny` (only AWS-managed `RCPFullAWSAccess` can use `Allow`)
629
+ - `Principal` MUST be exactly `"*"` (use `Condition` to restrict)
630
+ - `Action` cannot use `"*"` alone (must be service-specific like `"s3:*"`)
631
+ - Only **5 supported services**: `s3`, `sts`, `sqs`, `secretsmanager`, `kms`
632
+ - `NotAction` and `NotPrincipal` are NOT supported
633
+ - Must have `Resource` or `NotResource` element
634
+
635
+ **Example:**
636
+ ```bash
637
+ iam-validator validate --path ./rcps/ --policy-type RESOURCE_CONTROL_POLICY
638
+ ```
639
+
640
+ **Valid RCP:**
641
+ ```json
642
+ {
643
+ "Version": "2012-10-17",
644
+ "Statement": [{
645
+ "Sid": "EnforceEncryptionInTransit",
646
+ "Effect": "Deny",
647
+ "Principal": "*",
648
+ "Action": ["s3:*", "sqs:*"],
649
+ "Resource": "*",
650
+ "Condition": {
651
+ "BoolIfExists": {
652
+ "aws:SecureTransport": "false"
653
+ }
654
+ }
655
+ }]
656
+ }
657
+ ```
658
+
659
+ **What the validator catches:**
660
+ ```
661
+ ✓ Effect is "Deny" (required for RCPs)
662
+ ✓ Principal is "*" (required - restrictions via Condition)
663
+ ✓ Actions from supported services (s3, sqs)
664
+ ✓ Uses Condition to scope the deny
665
+ ```
666
+
667
+ ### Custom Policy Checks
668
+
669
+ AWS IAM Access Analyzer provides specialized checks to validate policies against specific security requirements:
670
+
671
+ #### 1. CheckAccessNotGranted - Prevent Dangerous Actions
672
+
673
+ Verify that policies do NOT grant specific actions (max 100 actions, 100 resources per check):
674
+
675
+ ```bash
676
+ # Check that policies don't grant dangerous S3 actions
677
+ iam-validator analyze \
678
+ --path ./policies/ \
679
+ --check-access-not-granted s3:DeleteBucket s3:DeleteObject
680
+
681
+ # Scope to specific resources
682
+ iam-validator analyze \
683
+ --path ./policies/ \
684
+ --check-access-not-granted s3:PutObject \
685
+ --check-access-resources "arn:aws:s3:::production-bucket/*"
686
+
687
+ # Prevent privilege escalation
688
+ iam-validator analyze \
689
+ --path ./policies/ \
690
+ --check-access-not-granted \
691
+ iam:CreateAccessKey \
692
+ iam:AttachUserPolicy \
693
+ iam:PutUserPolicy
694
+ ```
695
+
696
+ **Supported:** IDENTITY_POLICY, RESOURCE_POLICY
697
+
698
+ #### 2. CheckNoNewAccess - Validate Policy Updates
699
+
700
+ Ensure policy changes don't grant new permissions:
701
+
702
+ ```bash
703
+ # Compare updated policy against baseline
704
+ iam-validator analyze \
705
+ --path ./new-policy.json \
706
+ --check-no-new-access ./old-policy.json
707
+
708
+ # In CI/CD - compare against main branch
709
+ git show main:policies/policy.json > baseline-policy.json
710
+ iam-validator analyze \
711
+ --path policies/policy.json \
712
+ --check-no-new-access baseline-policy.json
713
+ ```
714
+
715
+ **Supported:** IDENTITY_POLICY, RESOURCE_POLICY
716
+
717
+ #### 3. CheckNoPublicAccess - Prevent Public Exposure
718
+
719
+ Validate that resource policies don't allow public access (29+ resource types):
720
+
721
+ ```bash
722
+ # Check S3 bucket policies
723
+ iam-validator analyze \
724
+ --path ./bucket-policy.json \
725
+ --policy-type RESOURCE_POLICY \
726
+ --check-no-public-access \
727
+ --public-access-resource-type "AWS::S3::Bucket"
728
+
729
+ # Check multiple resource types
730
+ iam-validator analyze \
731
+ --path ./resource-policies/ \
732
+ --policy-type RESOURCE_POLICY \
733
+ --check-no-public-access \
734
+ --public-access-resource-type "AWS::S3::Bucket" "AWS::Lambda::Function" "AWS::SNS::Topic"
735
+
736
+ # Check ALL 29 resource types
737
+ iam-validator analyze \
738
+ --path ./resource-policies/ \
739
+ --policy-type RESOURCE_POLICY \
740
+ --check-no-public-access \
741
+ --public-access-resource-type all
742
+ ```
743
+
744
+ **Supported Resource Types** (29 total, or use `all`):
745
+ - **Storage**: S3 Bucket, S3 Access Point, S3 Express, S3 Glacier, S3 Outposts, S3 Tables, EFS
746
+ - **Database**: DynamoDB Table/Stream, OpenSearch Domain
747
+ - **Messaging**: Kinesis Stream, SNS Topic, SQS Queue
748
+ - **Security**: KMS Key, Secrets Manager Secret, IAM Assume Role Policy
749
+ - **Compute**: Lambda Function
750
+ - **API**: API Gateway REST API
751
+ - **DevOps**: CodeArtifact Domain, Backup Vault, CloudTrail
752
+
753
+ See [docs/custom-policy-checks.md](docs/custom-policy-checks.md) for complete documentation.
754
+
755
+ ### As a Python Package
756
+
757
+ Use as a library in your Python applications:
758
+
759
+ ```python
760
+ import asyncio
761
+ from iam_validator.core.policy_loader import PolicyLoader
762
+ from iam_validator.core.policy_checks import validate_policies
763
+ from iam_validator.core.report import ReportGenerator
764
+
765
+ async def main():
766
+ # Load policies
767
+ loader = PolicyLoader()
768
+ policies = loader.load_from_path("./policies")
769
+
770
+ # Validate
771
+ results = await validate_policies(policies)
772
+
773
+ # Generate report
774
+ generator = ReportGenerator()
775
+ report = generator.generate_report(results)
776
+ generator.print_console_report(report)
777
+
778
+ asyncio.run(main())
779
+ ```
780
+
781
+ **📚 For comprehensive Python library documentation, see:**
782
+ - **[Python Library Usage Guide](docs/python-library-usage.md)** - Complete guide with examples
783
+ - **[Library Examples](examples/library-usage/)** - Runnable code examples
784
+
785
+ ## Validation Checks
786
+
787
+ ### 1. Action Validation
788
+
789
+ Verifies that IAM actions exist in AWS services:
790
+
791
+ ```json
792
+ {
793
+ "Effect": "Allow",
794
+ "Action": "s3:GetObject", // ✅ Valid
795
+ "Resource": "*"
796
+ }
797
+ ```
798
+
799
+ ```json
800
+ {
801
+ "Effect": "Allow",
802
+ "Action": "s3:InvalidAction", // ❌ Invalid - action doesn't exist
803
+ "Resource": "*"
804
+ }
805
+ ```
806
+
807
+ ### 2. Condition Key Validation
808
+
809
+ Checks that condition keys are valid for the specified actions:
810
+
811
+ ```json
812
+ {
813
+ "Effect": "Allow",
814
+ "Action": "s3:GetObject",
815
+ "Resource": "*",
816
+ "Condition": {
817
+ "StringEquals": {
818
+ "aws:RequestedRegion": "us-east-1" // ✅ Valid global condition key
819
+ }
820
+ }
821
+ }
822
+ ```
823
+
824
+ ### 3. Resource ARN Validation
825
+
826
+ Ensures ARNs follow proper AWS format:
827
+
828
+ ```json
829
+ {
830
+ "Effect": "Allow",
831
+ "Action": "s3:GetObject",
832
+ "Resource": "arn:aws:s3:::my-bucket/*" // ✅ Valid ARN
833
+ }
834
+ ```
835
+
836
+ ```json
837
+ {
838
+ "Effect": "Allow",
839
+ "Action": "s3:GetObject",
840
+ "Resource": "not-a-valid-arn" // ❌ Invalid ARN format
841
+ }
842
+ ```
843
+
844
+ ### 4. Security Best Practices
845
+
846
+ Identifies potential security risks:
847
+
848
+ - Overly permissive wildcard usage (`*` for both Action and Resource)
849
+ - Sensitive actions without conditions
850
+ - Administrative permissions without restrictions
851
+
852
+ ## GitHub Integration Features
853
+
854
+ ### Flexible Comment Options
855
+
856
+ The validator provides **three independent ways** to display validation results in GitHub:
857
+
858
+ #### 1. **PR Summary Comment** (`--github-comment`)
859
+ Posts a high-level summary to the PR conversation with:
860
+ - Overall metrics (total policies, issues, severities)
861
+ - Grouped findings by file
862
+ - Detailed issue descriptions with suggestions
863
+
864
+ #### 2. **Line-Specific Review Comments** (`--github-review`)
865
+ Creates inline review comments on the "Files changed" tab:
866
+ - Comments appear directly on problematic lines
867
+ - Includes rich context (examples, suggestions)
868
+ - Automatically cleaned up on subsequent runs
869
+ - Review status (REQUEST_CHANGES or COMMENT) based on `fail_on_severity` config
870
+
871
+ #### 3. **GitHub Actions Job Summary** (`--github-summary`)
872
+ Writes a high-level overview to the Actions tab:
873
+ - Visible in workflow run summary
874
+ - Shows key metrics and severity breakdown
875
+ - Clean dashboard view without overwhelming details
876
+
877
+ **Mix and Match:** Use any combination of these options:
878
+ ```bash
879
+ # All three for maximum visibility
880
+ --github-comment --github-review --github-summary
881
+
882
+ # Only line-specific review comments (clean, minimal)
883
+ --github-review
884
+
885
+ # Only PR summary comment
886
+ --github-comment
887
+
888
+ # Only Actions job summary
889
+ --github-summary
890
+ ```
891
+
892
+ ### Smart PR Comment Management
893
+
894
+ The validator intelligently manages PR comments to keep your PRs clean:
895
+
896
+ **Comment Lifecycle:**
897
+ 1. **Old Comments Cleanup**: Automatically removes outdated bot comments from previous runs
898
+ 2. **Summary Comment**: Updates existing summary (no duplicates)
899
+ 3. **Review Comments**: Posts line-specific issues
900
+ 4. **Streaming Mode**: Progressive comments appear as files are validated
901
+
902
+ **Behavior:**
903
+ - ✅ **No Duplicates**: Summary comments are updated, not duplicated
904
+ - ✅ **Clean PR**: Old review comments automatically deleted before new validation
905
+ - ✅ **Identifiable**: All bot comments use HTML identifiers (invisible to users)
906
+ - ✅ **Progressive**: In streaming mode, comments appear file-by-file
907
+ - ✅ **Smart Review Status**: Uses `fail_on_severity` config to determine REQUEST_CHANGES vs COMMENT
908
+
909
+ **Example:**
910
+ ```
911
+ Run 1: Finds 5 issues → Posts 5 review comments + 1 summary
912
+ Run 2: Finds 3 issues → Deletes old 5 comments → Posts 3 new comments + updates summary
913
+ Result: PR always shows current state, no stale comments
914
+ ```
915
+
916
+ ## Example Output
917
+
918
+ ### Console Output
919
+
920
+ ```
921
+ ╭─────────────────── Validation Summary ───────────────────╮
922
+ │ Total Policies: 3 │
923
+ │ Valid: 2 Invalid: 1 │
924
+ │ Total Issues: 5 │
925
+ ╰──────────────────────────────────────────────────────────╯
926
+
927
+ ❌ policies/invalid_policy.json
928
+ ERROR invalid_action Statement 0: Action 's3:InvalidAction' not found
929
+ WARNING overly_permissive Statement 1: Statement allows all actions (*)
930
+ ERROR security_risk Statement 1: Statement allows all actions on all resources
931
+ ```
932
+
933
+ ### GitHub PR Comment
934
+
935
+ ```markdown
936
+ ## ❌ IAM Policy Validation Failed
937
+
938
+ ### Summary
939
+ | Metric | Count |
940
+ | ---------------- | ----- |
941
+ | Total Policies | 3 |
942
+ | Valid Policies | 2 ✅ |
943
+ | Invalid Policies | 1 ❌ |
944
+ | Total Issues | 5 |
945
+
946
+ ### Detailed Findings
947
+
948
+ #### `policies/invalid_policy.json`
949
+
950
+ **Errors:**
951
+ - **Statement 0**: Action 's3:InvalidAction' not found in service 's3'
952
+ - Action: `s3:InvalidAction`
953
+
954
+ **Warnings:**
955
+ - **Statement 1**: Statement allows all actions on all resources - CRITICAL SECURITY RISK
956
+ - 💡 Suggestion: This grants full administrative access. Restrict to specific actions and resources.
957
+ ```
958
+
959
+ ## 📚 Documentation
960
+
961
+ **[📖 Complete Documentation →](DOCS.md)**
962
+
963
+ The comprehensive [DOCS.md](DOCS.md) file contains everything you need:
964
+ - Installation & Quick Start
965
+ - GitHub Actions Integration
966
+ - CLI Reference & Examples
967
+ - Custom Policy Checks (CheckAccessNotGranted, CheckNoNewAccess, CheckNoPublicAccess)
968
+ - Configuration Guide
969
+ - Creating Custom Validation Rules
970
+ - Performance Optimization
971
+ - Troubleshooting
972
+
973
+ **Additional Resources:**
974
+ - **[Examples Directory](examples/)** - Real-world examples:
975
+ - [GitHub Actions Workflows](examples/github-actions/)
976
+ - [Custom Checks](examples/custom_checks/)
977
+ - [Configuration Files](examples/configs/)
978
+ - [Test IAM Policies](examples/iam-test-policies/)
979
+ - **[AWS Services Backup Guide](docs/aws-services-backup.md)** - Offline validation
980
+ - **[Contributing Guide](CONTRIBUTING.md)** - Contribution guidelines
981
+ - **[Publishing Guide](docs/development/PUBLISHING.md)** - Release process
982
+
983
+ ## 🤝 Contributing
984
+
985
+ Contributions are welcome! We appreciate your help in making this project better.
986
+
987
+ ### How to Contribute
988
+
989
+ 1. **Read the [Contributing Guide](CONTRIBUTING.md)** - Comprehensive guide for contributors
990
+ 2. **Check [existing issues](https://github.com/boogy/iam-policy-validator/issues)** - Find something to work on
991
+ 3. **Fork the repository** - Create your own copy
992
+ 4. **Make your changes** - Follow our code quality standards
993
+ 5. **Submit a Pull Request** - We'll review and merge
994
+
995
+ ### Development Setup
996
+
997
+ ```bash
998
+ # Clone your fork
999
+ git clone https://github.com/YOUR-USERNAME/iam-policy-validator.git
1000
+ cd iam-policy-validator
1001
+
1002
+ # Install dependencies
1003
+ uv sync --extra dev
1004
+
1005
+ # Run tests
1006
+ uv run pytest
1007
+
1008
+ # Run linting
1009
+ uv run ruff check .
1010
+ ```
1011
+
1012
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed instructions.
1013
+
1014
+ ## 📄 License
1015
+
1016
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
1017
+
1018
+ ## 🆘 Support
1019
+
1020
+ - **Documentation**: Check the [docs/](docs/) directory
1021
+ - **Issues**: Report bugs or request features via [GitHub Issues](https://github.com/boogy/iam-policy-validator/issues)
1022
+ - **Questions**: Ask questions in [GitHub Discussions](https://github.com/boogy/iam-policy-validator/discussions)