iam-policy-validator 1.6.0__py3-none-any.whl → 1.7.1__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.
Files changed (33) hide show
  1. iam_policy_validator-1.7.1.dist-info/METADATA +429 -0
  2. {iam_policy_validator-1.6.0.dist-info → iam_policy_validator-1.7.1.dist-info}/RECORD +32 -31
  3. iam_validator/__version__.py +1 -1
  4. iam_validator/checks/action_condition_enforcement.py +3 -1
  5. iam_validator/checks/action_resource_matching.py +23 -6
  6. iam_validator/checks/full_wildcard.py +5 -1
  7. iam_validator/checks/policy_size.py +3 -7
  8. iam_validator/checks/policy_type_validation.py +9 -3
  9. iam_validator/checks/principal_validation.py +1 -1
  10. iam_validator/checks/resource_validation.py +54 -24
  11. iam_validator/checks/sensitive_action.py +5 -1
  12. iam_validator/checks/service_wildcard.py +3 -1
  13. iam_validator/checks/utils/sensitive_action_matcher.py +1 -2
  14. iam_validator/checks/utils/wildcard_expansion.py +1 -2
  15. iam_validator/checks/wildcard_action.py +7 -2
  16. iam_validator/checks/wildcard_resource.py +5 -1
  17. iam_validator/commands/analyze.py +98 -1
  18. iam_validator/commands/validate.py +4 -2
  19. iam_validator/core/access_analyzer.py +5 -0
  20. iam_validator/core/access_analyzer_report.py +2 -5
  21. iam_validator/core/aws_fetcher.py +14 -4
  22. iam_validator/core/config/config_loader.py +3 -6
  23. iam_validator/core/constants.py +74 -0
  24. iam_validator/core/models.py +29 -13
  25. iam_validator/core/pr_commenter.py +104 -18
  26. iam_validator/core/report.py +49 -36
  27. iam_validator/integrations/github_integration.py +21 -1
  28. iam_validator/sdk/arn_matching.py +108 -0
  29. iam_validator/utils/regex.py +7 -8
  30. iam_policy_validator-1.6.0.dist-info/METADATA +0 -1050
  31. {iam_policy_validator-1.6.0.dist-info → iam_policy_validator-1.7.1.dist-info}/WHEEL +0 -0
  32. {iam_policy_validator-1.6.0.dist-info → iam_policy_validator-1.7.1.dist-info}/entry_points.txt +0 -0
  33. {iam_policy_validator-1.6.0.dist-info → iam_policy_validator-1.7.1.dist-info}/licenses/LICENSE +0 -0
@@ -1,1050 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: iam-policy-validator
3
- Version: 1.6.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 + 18 built-in 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
- - **18 Built-in Security Checks** - Comprehensive validation across AWS requirements and security 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
- wildcard_action:
452
- enabled: true
453
- severity: high
454
-
455
- action_condition_enforcement:
456
- enabled: true
457
- severity: critical
458
- action_condition_requirements:
459
- - actions:
460
- - "iam:PassRole"
461
- severity: critical
462
- required_conditions:
463
- - condition_key: "iam:PassedToService"
464
- ```
465
-
466
- See [examples/configs/full-reference-config.yaml](examples/configs/full-reference-config.yaml) for a complete configuration reference with all available options.
467
-
468
- ### GitHub Action Inputs
469
-
470
- #### Core Options
471
- | Input | Description | Required | Default |
472
- | ------------------ | ----------------------------------------------------------- | -------- | ------- |
473
- | `path` | Path(s) to IAM policy file or directory (newline-separated) | Yes | - |
474
- | `config-file` | Path to custom configuration file (.yaml) | No | `""` |
475
- | `fail-on-warnings` | Fail validation if warnings are found | No | `false` |
476
- | `recursive` | Recursively search directories for policy files | No | `true` |
477
-
478
- #### GitHub Integration
479
- | Input | Description | Required | Default |
480
- | ---------------- | --------------------------------------------------------- | -------- | ------- |
481
- | `post-comment` | Post validation summary as PR conversation comment | No | `true` |
482
- | `create-review` | Create line-specific review comments on PR files | No | `true` |
483
- | `github-summary` | Write summary to GitHub Actions job summary (Actions tab) | No | `false` |
484
-
485
- #### Output Options
486
- | Input | Description | Required | Default |
487
- | ------------- | -------------------------------------------------------------------------------- | -------- | --------- |
488
- | `format` | Output format: `console`, `enhanced`, `json`, `markdown`, `sarif`, `csv`, `html` | No | `console` |
489
- | `output-file` | Path to save output file (for non-console formats) | No | `""` |
490
-
491
- #### AWS Access Analyzer
492
- | Input | Description | Required | Default |
493
- | ------------------------ | ------------------------------------------------------------------------------------------------------ | -------- | ----------------- |
494
- | `use-access-analyzer` | Use AWS IAM Access Analyzer for validation | No | `false` |
495
- | `access-analyzer-region` | AWS region for Access Analyzer | No | `us-east-1` |
496
- | `policy-type` | Policy type: `IDENTITY_POLICY`, `RESOURCE_POLICY`, `SERVICE_CONTROL_POLICY`, `RESOURCE_CONTROL_POLICY` | No | `IDENTITY_POLICY` |
497
- | `run-all-checks` | Run custom checks after Access Analyzer (sequential mode) | No | `false` |
498
-
499
- #### Custom Policy Checks (Access Analyzer)
500
- | Input | Description | Required | Default |
501
- | ----------------------------- | --------------------------------------------------------------------------- | -------- | ----------------- |
502
- | `check-access-not-granted` | Actions that should NOT be granted (space-separated, max 100) | No | `""` |
503
- | `check-access-resources` | Resources to check with check-access-not-granted (space-separated, max 100) | No | `""` |
504
- | `check-no-new-access` | Path to baseline policy to compare against (detect new permissions) | No | `""` |
505
- | `check-no-public-access` | Check that resource policies do not allow public access | No | `false` |
506
- | `public-access-resource-type` | Resource type(s) for public access check (29+ types supported, or `all`) | No | `AWS::S3::Bucket` |
507
-
508
- #### Advanced Options
509
- | Input | Description | Required | Default |
510
- | ------------------- | -------------------------------------------------------------- | -------- | --------- |
511
- | `custom-checks-dir` | Path to directory containing custom validation checks | No | `""` |
512
- | `log-level` | Logging level: `debug`, `info`, `warning`, `error`, `critical` | No | `warning` |
513
-
514
- **💡 Pro Tips:**
515
- - Use `custom-checks-dir` to add organization-specific validation rules
516
- - Set `log-level: debug` when troubleshooting workflow issues
517
- - Configure `aws-services-dir` in your config file for offline validation
518
- - The action automatically filters IAM policies from mixed JSON/YAML files
519
-
520
- See [examples/github-actions/](examples/github-actions/) for 9 ready-to-use workflow examples.
521
-
522
- ### As a CLI Tool
523
-
524
- Install and use locally for development:
525
-
526
- ```bash
527
- # Install from PyPI
528
- pip install iam-policy-validator
529
-
530
- # Or install with pipx (recommended for CLI tools)
531
- pipx install iam-policy-validator
532
-
533
- # Validate a single policy
534
- iam-validator validate --path policy.json
535
-
536
- # Validate all policies in a directory
537
- iam-validator validate --path ./policies/
538
-
539
- # Validate multiple paths
540
- iam-validator validate --path policy1.json --path ./policies/ --path ./more-policies/
541
-
542
- # Validate resource policies (S3 bucket policies, SNS topics, etc.)
543
- iam-validator validate --path ./bucket-policies/ --policy-type RESOURCE_POLICY
544
-
545
- # Validate AWS Organizations Resource Control Policies (RCPs)
546
- iam-validator validate --path ./rcps/ --policy-type RESOURCE_CONTROL_POLICY
547
-
548
- # Generate JSON output
549
- iam-validator validate --path ./policies/ --format json --output report.json
550
-
551
- # Validate with AWS IAM Access Analyzer
552
- iam-validator analyze --path policy.json
553
-
554
- # Analyze with specific region and profile
555
- iam-validator analyze --path policy.json --region us-west-2 --profile my-profile
556
-
557
- # Sequential validation: Access Analyzer → Custom Checks
558
- iam-validator analyze \
559
- --path policy.json \
560
- --github-comment \
561
- --run-all-checks \
562
- --github-review
563
- ```
564
-
565
- ### Policy Type Validation
566
-
567
- The validator supports four AWS policy types, each with specific validation rules:
568
-
569
- #### 🔷 IDENTITY_POLICY (Default)
570
- Standard IAM policies attached to users, groups, or roles.
571
-
572
- **Requirements:**
573
- - Should NOT have `Principal` element (implicit - the attached entity)
574
- - Must have `Action` and `Resource` elements
575
-
576
- **Example:**
577
- ```bash
578
- iam-validator validate --path ./user-policies/ --policy-type IDENTITY_POLICY
579
- ```
580
-
581
- #### 🔶 RESOURCE_POLICY
582
- Policies attached to AWS resources (S3 buckets, SNS topics, KMS keys, etc.).
583
-
584
- **Requirements:**
585
- - MUST have `Principal` element (who can access)
586
- - Must have `Action`, `Effect`, and `Resource` elements
587
- - Can use configurable security checks for principal validation
588
-
589
- **Example:**
590
- ```bash
591
- iam-validator validate --path ./bucket-policies/ --policy-type RESOURCE_POLICY
592
- ```
593
-
594
- **Advanced Principal Validation:**
595
- ```yaml
596
- # config.yaml
597
- principal_validation:
598
- enabled: true
599
- severity: high
600
- # Block public access
601
- blocked_principals: ["*"]
602
- # Or require specific conditions for public access
603
- require_conditions_for:
604
- "*":
605
- - "aws:SourceArn"
606
- - "aws:SourceAccount"
607
- ```
608
-
609
- #### 🔷 SERVICE_CONTROL_POLICY
610
- AWS Organizations SCPs that set permission guardrails.
611
-
612
- **Requirements:**
613
- - Must NOT have `Principal` element (applies to all principals in OU)
614
- - Typically uses `Deny` effect for guardrails
615
- - Must have `Action` and `Resource` elements
616
-
617
- **Example:**
618
- ```bash
619
- iam-validator validate --path ./scps/ --policy-type SERVICE_CONTROL_POLICY
620
- ```
621
-
622
- #### 🆕 RESOURCE_CONTROL_POLICY
623
- AWS Organizations RCPs for resource-level access control (released 2024).
624
-
625
- **Strict Requirements:**
626
- - `Effect` MUST be `Deny` (only AWS-managed `RCPFullAWSAccess` can use `Allow`)
627
- - `Principal` MUST be exactly `"*"` (use `Condition` to restrict)
628
- - `Action` cannot use `"*"` alone (must be service-specific like `"s3:*"`)
629
- - Only **5 supported services**: `s3`, `sts`, `sqs`, `secretsmanager`, `kms`
630
- - `NotAction` and `NotPrincipal` are NOT supported
631
- - Must have `Resource` or `NotResource` element
632
-
633
- **Example:**
634
- ```bash
635
- iam-validator validate --path ./rcps/ --policy-type RESOURCE_CONTROL_POLICY
636
- ```
637
-
638
- **Valid RCP:**
639
- ```json
640
- {
641
- "Version": "2012-10-17",
642
- "Statement": [{
643
- "Sid": "EnforceEncryptionInTransit",
644
- "Effect": "Deny",
645
- "Principal": "*",
646
- "Action": ["s3:*", "sqs:*"],
647
- "Resource": "*",
648
- "Condition": {
649
- "BoolIfExists": {
650
- "aws:SecureTransport": "false"
651
- }
652
- }
653
- }]
654
- }
655
- ```
656
-
657
- **What the validator catches:**
658
- ```
659
- ✓ Effect is "Deny" (required for RCPs)
660
- ✓ Principal is "*" (required - restrictions via Condition)
661
- ✓ Actions from supported services (s3, sqs)
662
- ✓ Uses Condition to scope the deny
663
- ```
664
-
665
- ### Custom Policy Checks
666
-
667
- AWS IAM Access Analyzer provides specialized checks to validate policies against specific security requirements:
668
-
669
- #### 1. CheckAccessNotGranted - Prevent Dangerous Actions
670
-
671
- Verify that policies do NOT grant specific actions (max 100 actions, 100 resources per check):
672
-
673
- ```bash
674
- # Check that policies don't grant dangerous S3 actions
675
- iam-validator analyze \
676
- --path ./policies/ \
677
- --check-access-not-granted s3:DeleteBucket s3:DeleteObject
678
-
679
- # Scope to specific resources
680
- iam-validator analyze \
681
- --path ./policies/ \
682
- --check-access-not-granted s3:PutObject \
683
- --check-access-resources "arn:aws:s3:::production-bucket/*"
684
-
685
- # Prevent privilege escalation
686
- iam-validator analyze \
687
- --path ./policies/ \
688
- --check-access-not-granted \
689
- iam:CreateAccessKey \
690
- iam:AttachUserPolicy \
691
- iam:PutUserPolicy
692
- ```
693
-
694
- **Supported:** IDENTITY_POLICY, RESOURCE_POLICY
695
-
696
- #### 2. CheckNoNewAccess - Validate Policy Updates
697
-
698
- Ensure policy changes don't grant new permissions:
699
-
700
- ```bash
701
- # Compare updated policy against baseline
702
- iam-validator analyze \
703
- --path ./new-policy.json \
704
- --check-no-new-access ./old-policy.json
705
-
706
- # In CI/CD - compare against main branch
707
- git show main:policies/policy.json > baseline-policy.json
708
- iam-validator analyze \
709
- --path policies/policy.json \
710
- --check-no-new-access baseline-policy.json
711
- ```
712
-
713
- **Supported:** IDENTITY_POLICY, RESOURCE_POLICY
714
-
715
- #### 3. CheckNoPublicAccess - Prevent Public Exposure
716
-
717
- Validate that resource policies don't allow public access (29+ resource types):
718
-
719
- ```bash
720
- # Check S3 bucket policies
721
- iam-validator analyze \
722
- --path ./bucket-policy.json \
723
- --policy-type RESOURCE_POLICY \
724
- --check-no-public-access \
725
- --public-access-resource-type "AWS::S3::Bucket"
726
-
727
- # Check multiple resource types
728
- iam-validator analyze \
729
- --path ./resource-policies/ \
730
- --policy-type RESOURCE_POLICY \
731
- --check-no-public-access \
732
- --public-access-resource-type "AWS::S3::Bucket" "AWS::Lambda::Function" "AWS::SNS::Topic"
733
-
734
- # Check ALL 29 resource types
735
- iam-validator analyze \
736
- --path ./resource-policies/ \
737
- --policy-type RESOURCE_POLICY \
738
- --check-no-public-access \
739
- --public-access-resource-type all
740
- ```
741
-
742
- **Supported Resource Types** (29 total, or use `all`):
743
- - **Storage**: S3 Bucket, S3 Access Point, S3 Express, S3 Glacier, S3 Outposts, S3 Tables, EFS
744
- - **Database**: DynamoDB Table/Stream, OpenSearch Domain
745
- - **Messaging**: Kinesis Stream, SNS Topic, SQS Queue
746
- - **Security**: KMS Key, Secrets Manager Secret, IAM Assume Role Policy
747
- - **Compute**: Lambda Function
748
- - **API**: API Gateway REST API
749
- - **DevOps**: CodeArtifact Domain, Backup Vault, CloudTrail
750
-
751
- See [docs/custom-checks.md](docs/custom-checks.md) for complete documentation.
752
-
753
- ### As a Python Package
754
-
755
- Use as a library in your Python applications:
756
-
757
- ```python
758
- import asyncio
759
- from iam_validator.core.policy_loader import PolicyLoader
760
- from iam_validator.core.policy_checks import validate_policies
761
- from iam_validator.core.report import ReportGenerator
762
-
763
- async def main():
764
- # Load policies
765
- loader = PolicyLoader()
766
- policies = loader.load_from_path("./policies")
767
-
768
- # Validate
769
- results = await validate_policies(policies)
770
-
771
- # Generate report
772
- generator = ReportGenerator()
773
- report = generator.generate_report(results)
774
- generator.print_console_report(report)
775
-
776
- asyncio.run(main())
777
- ```
778
-
779
- **📚 For comprehensive Python library documentation, see:**
780
- - **[Python Library Usage Guide](docs/python-library-usage.md)** - Complete guide with examples
781
- - **[Library Examples](examples/library-usage/)** - Runnable code examples
782
-
783
- ## Validation Checks
784
-
785
- IAM Policy Validator performs **18 built-in checks** to ensure your policies are secure and valid.
786
-
787
- **📖 For detailed check documentation with configuration examples and pass/fail scenarios:**
788
- - **[Check Reference Guide](docs/check-reference.md)** - Complete reference for all 18 checks
789
- - **[Condition Requirements](docs/condition-requirements.md)** - Action condition enforcement
790
- - **[Privilege Escalation Detection](docs/privilege-escalation.md)** - Detecting escalation paths
791
-
792
- ### Quick Overview
793
-
794
- **AWS IAM Validation (12 checks)** - Ensure policies work correctly in AWS:
795
- - Statement ID uniqueness and format
796
- - Policy size limits
797
- - Action and condition key validation
798
- - Condition operator and value type checking
799
- - Set operator validation
800
- - MFA anti-pattern detection
801
- - Resource ARN format validation
802
- - Principal validation (resource policies)
803
- - Policy type validation
804
- - Action-resource constraint and matching
805
-
806
- **Security Best Practices (6 checks)** - Identify security risks:
807
- - Wildcard actions (`Action: "*"`)
808
- - Wildcard resources (`Resource: "*"`)
809
- - Full wildcard (CRITICAL: both wildcards together)
810
- - Service-level wildcards (`iam:*`, `s3:*`, etc.)
811
- - Sensitive actions without conditions (490 actions across 4 risk categories)
812
- - Action condition enforcement (MFA, IP restrictions, tags, etc.)
813
-
814
- ### Quick Examples
815
-
816
- **Action Validation:**
817
- ```json
818
- // ✅ PASS: Valid S3 action
819
- {
820
- "Effect": "Allow",
821
- "Action": "s3:GetObject",
822
- "Resource": "arn:aws:s3:::my-bucket/*"
823
- }
824
-
825
- // ❌ FAIL: Invalid action name
826
- {
827
- "Effect": "Allow",
828
- "Action": "s3:InvalidAction", // ERROR: Action doesn't exist
829
- "Resource": "*"
830
- }
831
- ```
832
-
833
- **Full Wildcard (Critical):**
834
- ```json
835
- // ✅ PASS: Specific actions and resources
836
- {
837
- "Effect": "Allow",
838
- "Action": ["s3:GetObject", "s3:PutObject"],
839
- "Resource": "arn:aws:s3:::my-bucket/*"
840
- }
841
-
842
- // ❌ FAIL: Administrative access
843
- {
844
- "Effect": "Allow",
845
- "Action": "*", // CRITICAL: All actions
846
- "Resource": "*" // CRITICAL: All resources
847
- }
848
- ```
849
-
850
- **Action Condition Enforcement:**
851
- ```json
852
- // ✅ PASS: iam:PassRole with required condition
853
- {
854
- "Effect": "Allow",
855
- "Action": "iam:PassRole",
856
- "Resource": "*",
857
- "Condition": {
858
- "StringEquals": {
859
- "iam:PassedToService": ["lambda.amazonaws.com"]
860
- }
861
- }
862
- }
863
-
864
- // ❌ FAIL: iam:PassRole without condition
865
- {
866
- "Effect": "Allow",
867
- "Action": "iam:PassRole", // HIGH: Missing iam:PassedToService condition
868
- "Resource": "*"
869
- }
870
- ```
871
-
872
- **📚 For complete documentation of all 18 checks with detailed examples, see [Check Reference Guide](docs/check-reference.md)**
873
-
874
- _Note: The old [CHECKS.md](docs/CHECKS.md) has been deprecated in favor of the new check-reference.md with better organization and examples._
875
-
876
- ## GitHub Integration Features
877
-
878
- ### Flexible Comment Options
879
-
880
- The validator provides **three independent ways** to display validation results in GitHub:
881
-
882
- #### 1. **PR Summary Comment** (`--github-comment`)
883
- Posts a high-level summary to the PR conversation with:
884
- - Overall metrics (total policies, issues, severities)
885
- - Grouped findings by file
886
- - Detailed issue descriptions with suggestions
887
-
888
- #### 2. **Line-Specific Review Comments** (`--github-review`)
889
- Creates inline review comments on the "Files changed" tab:
890
- - Comments appear directly on problematic lines
891
- - Includes rich context (examples, suggestions)
892
- - Automatically cleaned up on subsequent runs
893
- - Review status (REQUEST_CHANGES or COMMENT) based on `fail_on_severity` config
894
-
895
- #### 3. **GitHub Actions Job Summary** (`--github-summary`)
896
- Writes a high-level overview to the Actions tab:
897
- - Visible in workflow run summary
898
- - Shows key metrics and severity breakdown
899
- - Clean dashboard view without overwhelming details
900
-
901
- **Mix and Match:** Use any combination of these options:
902
- ```bash
903
- # All three for maximum visibility
904
- --github-comment --github-review --github-summary
905
-
906
- # Only line-specific review comments (clean, minimal)
907
- --github-review
908
-
909
- # Only PR summary comment
910
- --github-comment
911
-
912
- # Only Actions job summary
913
- --github-summary
914
- ```
915
-
916
- ### Smart PR Comment Management
917
-
918
- The validator intelligently manages PR comments to keep your PRs clean:
919
-
920
- **Comment Lifecycle:**
921
- 1. **Old Comments Cleanup**: Automatically removes outdated bot comments from previous runs
922
- 2. **Summary Comment**: Updates existing summary (no duplicates)
923
- 3. **Review Comments**: Posts line-specific issues
924
- 4. **Streaming Mode**: Progressive comments appear as files are validated
925
-
926
- **Behavior:**
927
- - ✅ **No Duplicates**: Summary comments are updated, not duplicated
928
- - ✅ **Clean PR**: Old review comments automatically deleted before new validation
929
- - ✅ **Identifiable**: All bot comments use HTML identifiers (invisible to users)
930
- - ✅ **Progressive**: In streaming mode, comments appear file-by-file
931
- - ✅ **Smart Review Status**: Uses `fail_on_severity` config to determine REQUEST_CHANGES vs COMMENT
932
-
933
- **Example:**
934
- ```
935
- Run 1: Finds 5 issues → Posts 5 review comments + 1 summary
936
- Run 2: Finds 3 issues → Deletes old 5 comments → Posts 3 new comments + updates summary
937
- Result: PR always shows current state, no stale comments
938
- ```
939
-
940
- ## Example Output
941
-
942
- ### Console Output
943
-
944
- ```
945
- ╭─────────────────── Validation Summary ───────────────────╮
946
- │ Total Policies: 3 │
947
- │ Valid: 2 Invalid: 1 │
948
- │ Total Issues: 5 │
949
- ╰──────────────────────────────────────────────────────────╯
950
-
951
- ❌ policies/invalid_policy.json
952
- ERROR invalid_action Statement 0: Action 's3:InvalidAction' not found
953
- WARNING overly_permissive Statement 1: Statement allows all actions (*)
954
- ERROR security_risk Statement 1: Statement allows all actions on all resources
955
- ```
956
-
957
- ### GitHub PR Comment
958
-
959
- ```markdown
960
- ## ❌ IAM Policy Validation Failed
961
-
962
- ### Summary
963
- | Metric | Count |
964
- | ---------------- | ----- |
965
- | Total Policies | 3 |
966
- | Valid Policies | 2 ✅ |
967
- | Invalid Policies | 1 ❌ |
968
- | Total Issues | 5 |
969
-
970
- ### Detailed Findings
971
-
972
- #### `policies/invalid_policy.json`
973
-
974
- **Errors:**
975
- - **Statement 0**: Action 's3:InvalidAction' not found in service 's3'
976
- - Action: `s3:InvalidAction`
977
-
978
- **Warnings:**
979
- - **Statement 1**: Statement allows all actions on all resources - CRITICAL SECURITY RISK
980
- - 💡 Suggestion: This grants full administrative access. Restrict to specific actions and resources.
981
- ```
982
-
983
- ## 📚 Documentation
984
-
985
- ### Core Documentation
986
- - **[📖 Complete Usage Guide (DOCS.md)](DOCS.md)** - Installation, CLI reference, GitHub Actions, configuration
987
- - **[✅ Validation Checks Reference](docs/check-reference.md)** - All 18 checks with pass/fail examples
988
- - **[🐍 Python SDK Guide (SDK.md)](docs/SDK.md)** - Use as a Python library in your applications
989
- - **[🤝 Contributing Guide (CONTRIBUTING.md)](CONTRIBUTING.md)** - How to contribute to the project
990
-
991
- ### Examples & Resources
992
- - **[Configuration Examples](examples/configs/)** - 9 configuration files for different use cases
993
- - **[GitHub Actions Workflows](examples/github-actions/)** - Ready-to-use workflow examples
994
- - **[Custom Checks](examples/custom_checks/)** - Example custom validation rules
995
- - **[Library Usage Examples](examples/library-usage/)** - Python SDK examples
996
- - **[Test IAM Policies](examples/iam-test-policies/)** - Example policies for testing
997
-
998
- ### Advanced Topics
999
- - **[Roadmap](docs/ROADMAP.md)** - Planned features and improvements
1000
- - **[AWS Services Backup Guide](docs/aws-services-backup.md)** - Offline validation setup
1001
- - **[Publishing Guide](docs/development/PUBLISHING.md)** - Release process for maintainers
1002
-
1003
- ### Quick Links
1004
- - **[GitHub Issues](https://github.com/boogy/iam-policy-validator/issues)** - Report bugs or request features
1005
- - **[GitHub Discussions](https://github.com/boogy/iam-policy-validator/discussions)** - Ask questions and share ideas
1006
-
1007
- ## 🤝 Contributing
1008
-
1009
- Contributions are welcome! We appreciate your help in making this project better.
1010
-
1011
- ### How to Contribute
1012
-
1013
- 1. **Read the [Contributing Guide](CONTRIBUTING.md)** - Comprehensive guide for contributors
1014
- 2. **Check [existing issues](https://github.com/boogy/iam-policy-validator/issues)** - Find something to work on
1015
- 3. **Fork the repository** - Create your own copy
1016
- 4. **Make your changes** - Follow our code quality standards
1017
- 5. **Submit a Pull Request** - We'll review and merge
1018
-
1019
- ### Development Setup
1020
-
1021
- ```bash
1022
- # Clone your fork
1023
- git clone https://github.com/YOUR-USERNAME/iam-policy-validator.git
1024
- cd iam-policy-validator
1025
-
1026
- # Install dependencies
1027
- uv sync --extra dev
1028
-
1029
- # Run tests
1030
- uv run pytest
1031
-
1032
- # Run linting
1033
- uv run ruff check .
1034
- ```
1035
-
1036
- See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed instructions.
1037
-
1038
- ## 📄 License
1039
-
1040
- This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
1041
-
1042
- ### Third-Party Code
1043
-
1044
- Portions of the ARN pattern matching code in [`iam_validator/sdk/arn_matching.py`](iam_validator/sdk/arn_matching.py) are derived from [Parliament](https://github.com/duo-labs/parliament) (Copyright 2019 Duo Security, [BSD 3-Clause License](https://github.com/duo-labs/parliament/blob/master/LICENSE)). See file header for details.
1045
-
1046
- ## 🆘 Support
1047
-
1048
- - **Documentation**: Check the [docs/](docs/) directory
1049
- - **Issues**: Report bugs or request features via [GitHub Issues](https://github.com/boogy/iam-policy-validator/issues)
1050
- - **Questions**: Ask questions in [GitHub Discussions](https://github.com/boogy/iam-policy-validator/discussions)