iam-policy-validator 1.0.3__py3-none-any.whl → 1.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of iam-policy-validator might be problematic. Click here for more details.
- {iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.0.4.dist-info}/METADATA +169 -473
- {iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.0.4.dist-info}/RECORD +7 -7
- iam_validator/__version__.py +1 -1
- iam_validator/core/cli.py +26 -9
- {iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.0.4.dist-info}/WHEEL +0 -0
- {iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.0.4.dist-info}/entry_points.txt +0 -0
- {iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.0.4.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: iam-policy-validator
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.4
|
|
4
4
|
Summary: Validate AWS IAM policies for correctness and security using AWS Service Reference API
|
|
5
5
|
Project-URL: Homepage, https://github.com/boogy/iam-policy-validator
|
|
6
6
|
Project-URL: Documentation, https://github.com/boogy/iam-policy-validator/tree/main/docs
|
|
@@ -40,7 +40,7 @@ Requires-Dist: types-boto3; extra == 'dev'
|
|
|
40
40
|
Requires-Dist: types-pyyaml; extra == 'dev'
|
|
41
41
|
Description-Content-Type: text/markdown
|
|
42
42
|
|
|
43
|
-
# IAM Validator
|
|
43
|
+
# IAM Policy Validator
|
|
44
44
|
|
|
45
45
|
A high-performance GitHub Action and Python CLI tool that validates AWS IAM policies for correctness and security by checking against the official AWS Service Reference API.
|
|
46
46
|
|
|
@@ -85,9 +85,11 @@ A high-performance GitHub Action and Python CLI tool that validates AWS IAM poli
|
|
|
85
85
|
|
|
86
86
|
## Quick Start
|
|
87
87
|
|
|
88
|
-
### As a GitHub Action
|
|
88
|
+
### As a GitHub Action (Recommended) ⭐
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
The easiest way to use IAM Policy Validator is as a GitHub Action in your workflows.
|
|
91
|
+
|
|
92
|
+
#### Basic Validation
|
|
91
93
|
|
|
92
94
|
Create `.github/workflows/iam-policy-validator.yml`:
|
|
93
95
|
|
|
@@ -108,38 +110,23 @@ jobs:
|
|
|
108
110
|
|
|
109
111
|
steps:
|
|
110
112
|
- name: Checkout code
|
|
111
|
-
uses: actions/checkout@
|
|
112
|
-
|
|
113
|
-
- name: Set up Python
|
|
114
|
-
uses: actions/setup-python@v5
|
|
115
|
-
with:
|
|
116
|
-
python-version: '3.12'
|
|
117
|
-
|
|
118
|
-
- name: Install uv
|
|
119
|
-
uses: astral-sh/setup-uv@v3
|
|
120
|
-
|
|
121
|
-
- name: Install dependencies
|
|
122
|
-
run: uv sync
|
|
113
|
+
uses: actions/checkout@v5
|
|
123
114
|
|
|
124
115
|
- name: Validate IAM Policies
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
--path ./policies/ \
|
|
132
|
-
--github-comment \
|
|
133
|
-
--github-review \
|
|
134
|
-
--fail-on-warnings
|
|
116
|
+
uses: boogy/iam-policy-validator@v1
|
|
117
|
+
with:
|
|
118
|
+
path: policies/
|
|
119
|
+
post-comment: true
|
|
120
|
+
create-review: true
|
|
121
|
+
fail-on-warnings: true
|
|
135
122
|
```
|
|
136
123
|
|
|
137
|
-
####
|
|
124
|
+
#### With AWS Access Analyzer
|
|
138
125
|
|
|
139
|
-
|
|
126
|
+
Use AWS's official policy validation service:
|
|
140
127
|
|
|
141
128
|
```yaml
|
|
142
|
-
name:
|
|
129
|
+
name: IAM Policy Validation with Access Analyzer
|
|
143
130
|
|
|
144
131
|
on:
|
|
145
132
|
pull_request:
|
|
@@ -156,7 +143,7 @@ jobs:
|
|
|
156
143
|
|
|
157
144
|
steps:
|
|
158
145
|
- name: Checkout code
|
|
159
|
-
uses: actions/checkout@
|
|
146
|
+
uses: actions/checkout@v5
|
|
160
147
|
|
|
161
148
|
- name: Configure AWS Credentials
|
|
162
149
|
uses: aws-actions/configure-aws-credentials@v4
|
|
@@ -164,94 +151,20 @@ jobs:
|
|
|
164
151
|
role-to-assume: arn:aws:iam::123456789012:role/GitHubActionsRole
|
|
165
152
|
aws-region: us-east-1
|
|
166
153
|
|
|
167
|
-
- name:
|
|
168
|
-
uses:
|
|
154
|
+
- name: Validate with Access Analyzer
|
|
155
|
+
uses: boogy/iam-policy-validator@v1
|
|
169
156
|
with:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
run: uv sync
|
|
177
|
-
|
|
178
|
-
- name: Sequential Validation
|
|
179
|
-
env:
|
|
180
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
181
|
-
GITHUB_REPOSITORY: ${{ github.repository }}
|
|
182
|
-
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
183
|
-
run: |
|
|
184
|
-
# Posts 2 separate PR comments:
|
|
185
|
-
# 1. Access Analyzer results (immediate)
|
|
186
|
-
# 2. Custom validation (only if Access Analyzer passes)
|
|
187
|
-
uv run iam-validator analyze \
|
|
188
|
-
--path ./policies/ \
|
|
189
|
-
--github-comment \
|
|
190
|
-
--run-all-checks \
|
|
191
|
-
--github-review \
|
|
192
|
-
--fail-on-warnings
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
**Why Sequential Validation?**
|
|
196
|
-
- ✅ Access Analyzer validates first (fast, official AWS validation)
|
|
197
|
-
- ✅ If errors found, stops immediately (saves time)
|
|
198
|
-
- ✅ Only runs custom checks if Access Analyzer passes
|
|
199
|
-
- ✅ Two separate PR comments for clear separation
|
|
200
|
-
|
|
201
|
-
#### Option 3: Multiple Paths
|
|
202
|
-
|
|
203
|
-
Validate policies across multiple directories and files:
|
|
204
|
-
|
|
205
|
-
```yaml
|
|
206
|
-
name: Multi-Path IAM Policy Validation
|
|
207
|
-
|
|
208
|
-
on:
|
|
209
|
-
pull_request:
|
|
210
|
-
paths:
|
|
211
|
-
- 'iam/**/*.json'
|
|
212
|
-
- 's3-policies/**/*.json'
|
|
213
|
-
- 'lambda-policies/**/*.json'
|
|
214
|
-
|
|
215
|
-
jobs:
|
|
216
|
-
validate:
|
|
217
|
-
runs-on: ubuntu-latest
|
|
218
|
-
permissions:
|
|
219
|
-
contents: read
|
|
220
|
-
pull-requests: write
|
|
221
|
-
|
|
222
|
-
steps:
|
|
223
|
-
- name: Checkout code
|
|
224
|
-
uses: actions/checkout@v4
|
|
225
|
-
|
|
226
|
-
- name: Set up Python
|
|
227
|
-
uses: actions/setup-python@v5
|
|
228
|
-
with:
|
|
229
|
-
python-version: '3.12'
|
|
230
|
-
|
|
231
|
-
- name: Install uv
|
|
232
|
-
uses: astral-sh/setup-uv@v3
|
|
233
|
-
|
|
234
|
-
- name: Install dependencies
|
|
235
|
-
run: uv sync
|
|
236
|
-
|
|
237
|
-
- name: Validate Multiple Paths
|
|
238
|
-
env:
|
|
239
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
240
|
-
GITHUB_REPOSITORY: ${{ github.repository }}
|
|
241
|
-
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
242
|
-
run: |
|
|
243
|
-
uv run iam-validator validate \
|
|
244
|
-
--path ./iam/ \
|
|
245
|
-
--path ./s3-policies/ \
|
|
246
|
-
--path ./lambda-policies/special-policy.json \
|
|
247
|
-
--github-comment \
|
|
248
|
-
--github-review \
|
|
249
|
-
--fail-on-warnings
|
|
157
|
+
path: policies/
|
|
158
|
+
use-access-analyzer: true
|
|
159
|
+
run-all-checks: true
|
|
160
|
+
post-comment: true
|
|
161
|
+
create-review: true
|
|
162
|
+
fail-on-warnings: true
|
|
250
163
|
```
|
|
251
164
|
|
|
252
|
-
####
|
|
165
|
+
#### Custom Policy Checks
|
|
253
166
|
|
|
254
|
-
|
|
167
|
+
Enforce specific security requirements:
|
|
255
168
|
|
|
256
169
|
```yaml
|
|
257
170
|
name: IAM Policy Security Validation
|
|
@@ -262,7 +175,7 @@ on:
|
|
|
262
175
|
- 'policies/**/*.json'
|
|
263
176
|
|
|
264
177
|
jobs:
|
|
265
|
-
validate-
|
|
178
|
+
validate-security:
|
|
266
179
|
runs-on: ubuntu-latest
|
|
267
180
|
permissions:
|
|
268
181
|
contents: read
|
|
@@ -271,7 +184,7 @@ jobs:
|
|
|
271
184
|
|
|
272
185
|
steps:
|
|
273
186
|
- name: Checkout code
|
|
274
|
-
uses: actions/checkout@
|
|
187
|
+
uses: actions/checkout@v5
|
|
275
188
|
|
|
276
189
|
- name: Configure AWS Credentials
|
|
277
190
|
uses: aws-actions/configure-aws-credentials@v4
|
|
@@ -281,7 +194,7 @@ jobs:
|
|
|
281
194
|
|
|
282
195
|
# Prevent dangerous actions
|
|
283
196
|
- name: Check for Dangerous Actions
|
|
284
|
-
uses: boogy/iam-policy-
|
|
197
|
+
uses: boogy/iam-policy-validator@v1
|
|
285
198
|
with:
|
|
286
199
|
path: policies/
|
|
287
200
|
use-access-analyzer: true
|
|
@@ -291,7 +204,7 @@ jobs:
|
|
|
291
204
|
|
|
292
205
|
# Check S3 bucket policies for public access
|
|
293
206
|
- name: Check S3 Public Access
|
|
294
|
-
uses: boogy/iam-policy-
|
|
207
|
+
uses: boogy/iam-policy-validator@v1
|
|
295
208
|
with:
|
|
296
209
|
path: s3-policies/
|
|
297
210
|
use-access-analyzer: true
|
|
@@ -309,7 +222,7 @@ jobs:
|
|
|
309
222
|
path: baseline
|
|
310
223
|
|
|
311
224
|
- name: Check for New Access
|
|
312
|
-
uses: boogy/iam-policy-
|
|
225
|
+
uses: boogy/iam-policy-validator@v1
|
|
313
226
|
with:
|
|
314
227
|
path: policies/role-policy.json
|
|
315
228
|
use-access-analyzer: true
|
|
@@ -318,46 +231,137 @@ jobs:
|
|
|
318
231
|
fail-on-warnings: true
|
|
319
232
|
```
|
|
320
233
|
|
|
321
|
-
|
|
234
|
+
#### Multiple Paths
|
|
235
|
+
|
|
236
|
+
Validate policies across multiple directories:
|
|
237
|
+
|
|
238
|
+
```yaml
|
|
239
|
+
- name: Validate Multiple Paths
|
|
240
|
+
uses: boogy/iam-policy-validator@v1
|
|
241
|
+
with:
|
|
242
|
+
path: |
|
|
243
|
+
iam/
|
|
244
|
+
s3-policies/
|
|
245
|
+
lambda-policies/special-policy.json
|
|
246
|
+
post-comment: true
|
|
247
|
+
fail-on-warnings: true
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
#### Custom Configuration
|
|
251
|
+
|
|
252
|
+
Use a custom configuration file to customize validation rules:
|
|
253
|
+
|
|
254
|
+
```yaml
|
|
255
|
+
name: IAM Policy Validation with Custom Config
|
|
256
|
+
|
|
257
|
+
on:
|
|
258
|
+
pull_request:
|
|
259
|
+
paths:
|
|
260
|
+
- 'policies/**/*.json'
|
|
261
|
+
- '.iam-validator.yaml'
|
|
262
|
+
|
|
263
|
+
jobs:
|
|
264
|
+
validate:
|
|
265
|
+
runs-on: ubuntu-latest
|
|
266
|
+
permissions:
|
|
267
|
+
contents: read
|
|
268
|
+
pull-requests: write
|
|
269
|
+
|
|
270
|
+
steps:
|
|
271
|
+
- name: Checkout code
|
|
272
|
+
uses: actions/checkout@v5
|
|
273
|
+
|
|
274
|
+
- name: Validate with Custom Config
|
|
275
|
+
uses: boogy/iam-policy-validator@v1
|
|
276
|
+
with:
|
|
277
|
+
path: policies/
|
|
278
|
+
config-file: .iam-validator.yaml
|
|
279
|
+
post-comment: true
|
|
280
|
+
create-review: true
|
|
281
|
+
fail-on-warnings: true
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
**Example `.iam-validator.yaml`:**
|
|
285
|
+
```yaml
|
|
286
|
+
settings:
|
|
287
|
+
fail_fast: false
|
|
288
|
+
enable_builtin_checks: true
|
|
289
|
+
|
|
290
|
+
# Custom check configurations
|
|
291
|
+
security_best_practices_check:
|
|
292
|
+
enabled: true
|
|
293
|
+
wildcard_action_check:
|
|
294
|
+
enabled: true
|
|
295
|
+
severity: high
|
|
296
|
+
|
|
297
|
+
action_condition_enforcement_check:
|
|
298
|
+
enabled: true
|
|
299
|
+
severity: critical
|
|
300
|
+
action_condition_requirements:
|
|
301
|
+
- actions:
|
|
302
|
+
- "iam:PassRole"
|
|
303
|
+
severity: critical
|
|
304
|
+
required_conditions:
|
|
305
|
+
- condition_key: "iam:PassedToService"
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
See [iam-validator.yaml](iam-validator.yaml) for a complete configuration example.
|
|
309
|
+
|
|
310
|
+
### GitHub Action Inputs
|
|
311
|
+
|
|
312
|
+
| Input | Description | Required | Default |
|
|
313
|
+
| ----------------------------- | ---------------------------------------------------------------------- | -------- | ----------------- |
|
|
314
|
+
| `path` | Path(s) to IAM policy file or directory (newline-separated) | Yes | - |
|
|
315
|
+
| `config-file` | Path to custom configuration file (iam-validator.yaml) | No | "" |
|
|
316
|
+
| `fail-on-warnings` | Fail validation if warnings are found | No | `false` |
|
|
317
|
+
| `post-comment` | Post validation results as PR comment | No | `true` |
|
|
318
|
+
| `create-review` | Create line-specific review comments on PR | No | `true` |
|
|
319
|
+
| `format` | Output format (console, json, markdown, sarif, csv, html) | No | `console` |
|
|
320
|
+
| `output-file` | Path to save output file | No | "" |
|
|
321
|
+
| `recursive` | Recursively search directories for policy files | No | `true` |
|
|
322
|
+
| `use-access-analyzer` | Use AWS IAM Access Analyzer for validation | No | `false` |
|
|
323
|
+
| `access-analyzer-region` | AWS region for Access Analyzer | No | `us-east-1` |
|
|
324
|
+
| `policy-type` | Policy type (IDENTITY_POLICY, RESOURCE_POLICY, SERVICE_CONTROL_POLICY) | No | `RESOURCE_POLICY` |
|
|
325
|
+
| `run-all-checks` | Run custom checks after Access Analyzer | No | `false` |
|
|
326
|
+
| `check-access-not-granted` | Actions that should NOT be granted (space-separated) | No | "" |
|
|
327
|
+
| `check-access-resources` | Resources to check with check-access-not-granted | No | "" |
|
|
328
|
+
| `check-no-new-access` | Path to baseline policy to compare against | No | "" |
|
|
329
|
+
| `check-no-public-access` | Check that resource policies do not allow public access | No | `false` |
|
|
330
|
+
| `public-access-resource-type` | Resource type(s) for public access check | No | `AWS::S3::Bucket` |
|
|
331
|
+
|
|
332
|
+
See [examples/github-actions/](examples/github-actions/) for more workflow examples.
|
|
322
333
|
|
|
323
334
|
### As a CLI Tool
|
|
324
335
|
|
|
336
|
+
Install and use locally for development:
|
|
337
|
+
|
|
325
338
|
```bash
|
|
326
|
-
#
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
339
|
+
# Install from PyPI
|
|
340
|
+
pip install iam-policy-validator
|
|
341
|
+
|
|
342
|
+
# Or install with pipx (recommended for CLI tools)
|
|
343
|
+
pipx install iam-policy-validator
|
|
330
344
|
|
|
331
345
|
# Validate a single policy
|
|
332
|
-
|
|
346
|
+
iam-validator validate --path policy.json
|
|
333
347
|
|
|
334
348
|
# Validate all policies in a directory
|
|
335
|
-
|
|
349
|
+
iam-validator validate --path ./policies/
|
|
336
350
|
|
|
337
|
-
# Validate multiple paths
|
|
338
|
-
|
|
351
|
+
# Validate multiple paths
|
|
352
|
+
iam-validator validate --path policy1.json --path ./policies/ --path ./more-policies/
|
|
339
353
|
|
|
340
354
|
# Generate JSON output
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
# Post validation results to a PR with line-specific comments
|
|
344
|
-
uv run iam-validator validate --path ./policies/ --github-comment --github-review
|
|
345
|
-
|
|
346
|
-
# Two-step workflow: generate report, then post to PR
|
|
347
|
-
uv run iam-validator validate --path ./policies/ --format json --output report.json
|
|
348
|
-
uv run iam-validator post-to-pr --report report.json
|
|
355
|
+
iam-validator validate --path ./policies/ --format json --output report.json
|
|
349
356
|
|
|
350
357
|
# Validate with AWS IAM Access Analyzer
|
|
351
|
-
|
|
358
|
+
iam-validator analyze --path policy.json
|
|
352
359
|
|
|
353
360
|
# Analyze with specific region and profile
|
|
354
|
-
|
|
361
|
+
iam-validator analyze --path policy.json --region us-west-2 --profile my-profile
|
|
355
362
|
|
|
356
|
-
#
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
# Sequential validation: Access Analyzer → Custom Checks (if AA passes)
|
|
360
|
-
uv run iam-validator analyze \
|
|
363
|
+
# Sequential validation: Access Analyzer → Custom Checks
|
|
364
|
+
iam-validator analyze \
|
|
361
365
|
--path policy.json \
|
|
362
366
|
--github-comment \
|
|
363
367
|
--run-all-checks \
|
|
@@ -374,18 +378,18 @@ Verify that policies do NOT grant specific actions (max 100 actions, 100 resourc
|
|
|
374
378
|
|
|
375
379
|
```bash
|
|
376
380
|
# Check that policies don't grant dangerous S3 actions
|
|
377
|
-
|
|
381
|
+
iam-validator analyze \
|
|
378
382
|
--path ./policies/ \
|
|
379
383
|
--check-access-not-granted s3:DeleteBucket s3:DeleteObject
|
|
380
384
|
|
|
381
|
-
# Scope to specific resources
|
|
382
|
-
|
|
385
|
+
# Scope to specific resources
|
|
386
|
+
iam-validator analyze \
|
|
383
387
|
--path ./policies/ \
|
|
384
388
|
--check-access-not-granted s3:PutObject \
|
|
385
389
|
--check-access-resources "arn:aws:s3:::production-bucket/*"
|
|
386
390
|
|
|
387
391
|
# Prevent privilege escalation
|
|
388
|
-
|
|
392
|
+
iam-validator analyze \
|
|
389
393
|
--path ./policies/ \
|
|
390
394
|
--check-access-not-granted \
|
|
391
395
|
iam:CreateAccessKey \
|
|
@@ -397,17 +401,17 @@ uv run iam-validator analyze \
|
|
|
397
401
|
|
|
398
402
|
#### 2. CheckNoNewAccess - Validate Policy Updates
|
|
399
403
|
|
|
400
|
-
Ensure policy changes don't grant new permissions
|
|
404
|
+
Ensure policy changes don't grant new permissions:
|
|
401
405
|
|
|
402
406
|
```bash
|
|
403
407
|
# Compare updated policy against baseline
|
|
404
|
-
|
|
408
|
+
iam-validator analyze \
|
|
405
409
|
--path ./new-policy.json \
|
|
406
410
|
--check-no-new-access ./old-policy.json
|
|
407
411
|
|
|
408
412
|
# In CI/CD - compare against main branch
|
|
409
413
|
git show main:policies/policy.json > baseline-policy.json
|
|
410
|
-
|
|
414
|
+
iam-validator analyze \
|
|
411
415
|
--path policies/policy.json \
|
|
412
416
|
--check-no-new-access baseline-policy.json
|
|
413
417
|
```
|
|
@@ -416,39 +420,25 @@ uv run iam-validator analyze \
|
|
|
416
420
|
|
|
417
421
|
#### 3. CheckNoPublicAccess - Prevent Public Exposure
|
|
418
422
|
|
|
419
|
-
Validate that resource policies don't allow public access (
|
|
423
|
+
Validate that resource policies don't allow public access (29+ resource types):
|
|
420
424
|
|
|
421
425
|
```bash
|
|
422
426
|
# Check S3 bucket policies
|
|
423
|
-
|
|
427
|
+
iam-validator analyze \
|
|
424
428
|
--path ./bucket-policy.json \
|
|
425
429
|
--policy-type RESOURCE_POLICY \
|
|
426
430
|
--check-no-public-access \
|
|
427
431
|
--public-access-resource-type "AWS::S3::Bucket"
|
|
428
432
|
|
|
429
|
-
# Check
|
|
430
|
-
|
|
431
|
-
--path ./lambda-policy.json \
|
|
432
|
-
--policy-type RESOURCE_POLICY \
|
|
433
|
-
--check-no-public-access \
|
|
434
|
-
--public-access-resource-type "AWS::Lambda::Function"
|
|
435
|
-
|
|
436
|
-
# Check KMS key policies
|
|
437
|
-
uv run iam-validator analyze \
|
|
438
|
-
--path ./kms-policy.json \
|
|
439
|
-
--policy-type RESOURCE_POLICY \
|
|
440
|
-
--check-no-public-access \
|
|
441
|
-
--public-access-resource-type "AWS::KMS::Key"
|
|
442
|
-
|
|
443
|
-
# Check multiple resource types at once
|
|
444
|
-
uv run iam-validator analyze \
|
|
433
|
+
# Check multiple resource types
|
|
434
|
+
iam-validator analyze \
|
|
445
435
|
--path ./resource-policies/ \
|
|
446
436
|
--policy-type RESOURCE_POLICY \
|
|
447
437
|
--check-no-public-access \
|
|
448
438
|
--public-access-resource-type "AWS::S3::Bucket" "AWS::Lambda::Function" "AWS::SNS::Topic"
|
|
449
439
|
|
|
450
440
|
# Check ALL 29 resource types
|
|
451
|
-
|
|
441
|
+
iam-validator analyze \
|
|
452
442
|
--path ./resource-policies/ \
|
|
453
443
|
--policy-type RESOURCE_POLICY \
|
|
454
444
|
--check-no-public-access \
|
|
@@ -464,17 +454,11 @@ uv run iam-validator analyze \
|
|
|
464
454
|
- **API**: API Gateway REST API
|
|
465
455
|
- **DevOps**: CodeArtifact Domain, Backup Vault, CloudTrail
|
|
466
456
|
|
|
467
|
-
See [docs/custom-policy-checks.md](docs/custom-policy-checks.md) for complete documentation
|
|
457
|
+
See [docs/custom-policy-checks.md](docs/custom-policy-checks.md) for complete documentation.
|
|
468
458
|
|
|
469
459
|
### As a Python Package
|
|
470
460
|
|
|
471
|
-
|
|
472
|
-
# Install from PyPI (once published)
|
|
473
|
-
pip install iam-policy-validator
|
|
474
|
-
|
|
475
|
-
# Or install from source
|
|
476
|
-
pip install git+https://github.com/boogy/iam-policy-auditor.git
|
|
477
|
-
```
|
|
461
|
+
Use as a library in your Python applications:
|
|
478
462
|
|
|
479
463
|
```python
|
|
480
464
|
import asyncio
|
|
@@ -496,82 +480,6 @@ async def main():
|
|
|
496
480
|
asyncio.run(main())
|
|
497
481
|
```
|
|
498
482
|
|
|
499
|
-
## Memory Management & Performance
|
|
500
|
-
|
|
501
|
-
### Streaming Mode (Recommended for Large Policy Sets)
|
|
502
|
-
|
|
503
|
-
The validator supports two processing modes:
|
|
504
|
-
|
|
505
|
-
#### 1. **Batch Mode (Default)**
|
|
506
|
-
Loads all policies into memory at once. Best for:
|
|
507
|
-
- Small to medium policy sets (< 100 files)
|
|
508
|
-
- When you need the full summary upfront
|
|
509
|
-
- Local development
|
|
510
|
-
|
|
511
|
-
#### 2. **Streaming Mode** (`--stream`)
|
|
512
|
-
Processes policies one-by-one. Best for:
|
|
513
|
-
- Large policy sets (100+ files)
|
|
514
|
-
- CI/CD environments (auto-enabled)
|
|
515
|
-
- Limited memory environments
|
|
516
|
-
- Progressive feedback (see results as they come)
|
|
517
|
-
|
|
518
|
-
```bash
|
|
519
|
-
# Enable streaming mode explicitly
|
|
520
|
-
uv run iam-validator validate --path ./policies/ --stream
|
|
521
|
-
|
|
522
|
-
# Streaming mode with GitHub PR comments (posts per-file reviews progressively)
|
|
523
|
-
uv run iam-validator validate \
|
|
524
|
-
--path ./policies/ \
|
|
525
|
-
--stream \
|
|
526
|
-
--github-comment \
|
|
527
|
-
--github-review
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
**Streaming Benefits:**
|
|
531
|
-
- ✅ **Lower Memory Usage**: Only one policy in memory at a time
|
|
532
|
-
- ✅ **Progressive Feedback**: See results immediately as files are processed
|
|
533
|
-
- ✅ **Partial Results**: Get results even if later files fail
|
|
534
|
-
- ✅ **Better CI/CD Experience**: GitHub PR comments appear progressively
|
|
535
|
-
- ✅ **Auto-enabled in CI**: Automatically detects CI environment
|
|
536
|
-
|
|
537
|
-
**File Size Limits:**
|
|
538
|
-
- Default max file size: 100MB per policy file
|
|
539
|
-
- Files exceeding limit are skipped with a warning
|
|
540
|
-
- Prevents memory exhaustion from unexpectedly large files
|
|
541
|
-
|
|
542
|
-
### GitHub Action Memory Optimization
|
|
543
|
-
|
|
544
|
-
The GitHub Action automatically uses streaming mode in CI environments:
|
|
545
|
-
|
|
546
|
-
```yaml
|
|
547
|
-
- name: Validate Large Policy Set
|
|
548
|
-
run: |
|
|
549
|
-
# Streaming is auto-enabled in CI
|
|
550
|
-
uv run iam-validator validate \
|
|
551
|
-
--path ./policies/ \
|
|
552
|
-
--github-comment \
|
|
553
|
-
--github-review
|
|
554
|
-
```
|
|
555
|
-
|
|
556
|
-
## Configuration
|
|
557
|
-
|
|
558
|
-
### GitHub Action Inputs
|
|
559
|
-
|
|
560
|
-
| Input | Description | Required | Default |
|
|
561
|
-
| ------------------ | ----------------------------------------------------------- | -------- | ------- |
|
|
562
|
-
| `path` | Path(s) to IAM policy file or directory (newline-separated) | Yes | - |
|
|
563
|
-
| `fail-on-warnings` | Fail validation if warnings are found | No | `false` |
|
|
564
|
-
| `post-comment` | Post validation results as PR comment | No | `true` |
|
|
565
|
-
| `create-review` | Create line-specific review comments on PR | No | `true` |
|
|
566
|
-
|
|
567
|
-
### Environment Variables
|
|
568
|
-
|
|
569
|
-
For GitHub integration:
|
|
570
|
-
|
|
571
|
-
- `GITHUB_TOKEN`: GitHub API token (automatically provided in GitHub Actions)
|
|
572
|
-
- `GITHUB_REPOSITORY`: Repository in format `owner/repo`
|
|
573
|
-
- `GITHUB_PR_NUMBER`: Pull request number
|
|
574
|
-
|
|
575
483
|
## Validation Checks
|
|
576
484
|
|
|
577
485
|
### 1. Action Validation
|
|
@@ -664,156 +572,6 @@ Run 2: Finds 3 issues → Deletes old 5 comments → Posts 3 new comments + upda
|
|
|
664
572
|
Result: PR always shows current state, no stale comments
|
|
665
573
|
```
|
|
666
574
|
|
|
667
|
-
### Post PR Comments
|
|
668
|
-
|
|
669
|
-
Automatically posts validation results as PR comments:
|
|
670
|
-
|
|
671
|
-
```python
|
|
672
|
-
async with GitHubIntegration() as github:
|
|
673
|
-
await github.post_comment(validation_report)
|
|
674
|
-
```
|
|
675
|
-
|
|
676
|
-
### Line-Specific Comments
|
|
677
|
-
|
|
678
|
-
Add comments to specific lines in policy files:
|
|
679
|
-
|
|
680
|
-
```python
|
|
681
|
-
comments = [
|
|
682
|
-
{
|
|
683
|
-
"path": "policies/policy.json",
|
|
684
|
-
"line": 5,
|
|
685
|
-
"body": "Invalid action detected here",
|
|
686
|
-
}
|
|
687
|
-
]
|
|
688
|
-
await github.create_review_with_comments(comments)
|
|
689
|
-
```
|
|
690
|
-
|
|
691
|
-
### Manage Labels
|
|
692
|
-
|
|
693
|
-
Add or remove labels based on validation results:
|
|
694
|
-
|
|
695
|
-
```python
|
|
696
|
-
# Add labels
|
|
697
|
-
await github.add_labels(["iam-policy", "security-review"])
|
|
698
|
-
|
|
699
|
-
# Remove labels
|
|
700
|
-
await github.remove_label("needs-review")
|
|
701
|
-
|
|
702
|
-
# Set labels (replaces all existing)
|
|
703
|
-
await github.set_labels(["approved", "security-validated"])
|
|
704
|
-
```
|
|
705
|
-
|
|
706
|
-
### Set Commit Status
|
|
707
|
-
|
|
708
|
-
Update commit status based on validation:
|
|
709
|
-
|
|
710
|
-
```python
|
|
711
|
-
await github.set_commit_status(
|
|
712
|
-
state="success", # or "error", "failure", "pending"
|
|
713
|
-
context="IAM Policy Validator",
|
|
714
|
-
description="All policies validated successfully"
|
|
715
|
-
)
|
|
716
|
-
```
|
|
717
|
-
|
|
718
|
-
## CLI Usage
|
|
719
|
-
|
|
720
|
-
### Analyze Command (AWS IAM Access Analyzer)
|
|
721
|
-
|
|
722
|
-
The `analyze` command uses AWS IAM Access Analyzer's ValidatePolicy API to validate IAM policies. This provides AWS's official policy validation with detailed findings about errors, security warnings, and suggestions.
|
|
723
|
-
|
|
724
|
-
**New in latest version:** Post results to GitHub PRs and run sequential validation (Access Analyzer → Custom Checks).
|
|
725
|
-
|
|
726
|
-
**Prerequisites**: You need AWS credentials configured. The tool will use the standard AWS credential chain (environment variables, AWS profile, IAM role, etc.).
|
|
727
|
-
|
|
728
|
-
```bash
|
|
729
|
-
iam-validator analyze --path PATH [OPTIONS]
|
|
730
|
-
|
|
731
|
-
Options:
|
|
732
|
-
--path PATH, -p PATH Path to IAM policy file or directory (required)
|
|
733
|
-
--format {console,json,markdown}
|
|
734
|
-
Output format (default: console)
|
|
735
|
-
--output OUTPUT, -o OUTPUT Output file path (only for json/markdown)
|
|
736
|
-
--region REGION, -r REGION AWS region for Access Analyzer (default: us-east-1)
|
|
737
|
-
--policy-type {IDENTITY_POLICY,RESOURCE_POLICY,SERVICE_CONTROL_POLICY}
|
|
738
|
-
Type of IAM policy to validate (default: IDENTITY_POLICY)
|
|
739
|
-
--profile PROFILE AWS profile name to use for credentials
|
|
740
|
-
--github-comment Post Access Analyzer results as GitHub PR comment
|
|
741
|
-
--run-all-checks Run full validation if Access Analyzer passes
|
|
742
|
-
--github-review Add line-specific review comments (requires --run-all-checks)
|
|
743
|
-
--no-recursive Don't recursively search directories
|
|
744
|
-
--fail-on-warnings Fail validation if warnings are found
|
|
745
|
-
--verbose, -v Enable verbose logging
|
|
746
|
-
```
|
|
747
|
-
|
|
748
|
-
**Examples**:
|
|
749
|
-
|
|
750
|
-
```bash
|
|
751
|
-
# Analyze a single identity policy
|
|
752
|
-
iam-validator analyze --path policy.json
|
|
753
|
-
|
|
754
|
-
# Analyze an S3 bucket policy (resource policy)
|
|
755
|
-
iam-validator analyze --path bucket-policy.json --policy-type RESOURCE_POLICY
|
|
756
|
-
|
|
757
|
-
# Analyze multiple paths
|
|
758
|
-
iam-validator analyze --path ./iam/ --path ./s3-policies/ --path bucket-policy.json
|
|
759
|
-
|
|
760
|
-
# Analyze with specific AWS profile and region
|
|
761
|
-
iam-validator analyze --path policy.json --profile prod --region us-west-2
|
|
762
|
-
|
|
763
|
-
# Post Access Analyzer results to PR
|
|
764
|
-
iam-validator analyze --path policy.json --github-comment
|
|
765
|
-
|
|
766
|
-
# Sequential validation: Run Access Analyzer, then custom checks if it passes
|
|
767
|
-
iam-validator analyze \
|
|
768
|
-
--path policy.json \
|
|
769
|
-
--github-comment \
|
|
770
|
-
--run-all-checks \
|
|
771
|
-
--github-review
|
|
772
|
-
|
|
773
|
-
# Generate JSON output
|
|
774
|
-
iam-validator analyze --path ./policies/ --format json --output analyzer-report.json
|
|
775
|
-
|
|
776
|
-
# Fail on any finding (including warnings and suggestions)
|
|
777
|
-
iam-validator analyze --path policy.json --fail-on-warnings
|
|
778
|
-
```
|
|
779
|
-
|
|
780
|
-
**Access Analyzer Finding Types**:
|
|
781
|
-
- **ERROR**: Syntax errors or invalid policy elements that prevent the policy from working
|
|
782
|
-
- **SECURITY_WARNING**: Security issues that should be addressed
|
|
783
|
-
- **WARNING**: Best practice violations or potential issues
|
|
784
|
-
- **SUGGESTION**: Recommendations for policy improvements
|
|
785
|
-
|
|
786
|
-
### Validate Command
|
|
787
|
-
|
|
788
|
-
```bash
|
|
789
|
-
iam-validator validate --path PATH [OPTIONS]
|
|
790
|
-
|
|
791
|
-
Options:
|
|
792
|
-
--path PATH, -p PATH Path to IAM policy file or directory (required)
|
|
793
|
-
--format {console,json,markdown}
|
|
794
|
-
Output format (default: console)
|
|
795
|
-
--output OUTPUT, -o OUTPUT Output file path (only for json/markdown)
|
|
796
|
-
--no-recursive Don't recursively search directories
|
|
797
|
-
--fail-on-warnings Fail validation if warnings are found
|
|
798
|
-
--github-comment Post validation results as GitHub PR comment
|
|
799
|
-
--github-review Create line-specific review comments (requires --github-comment)
|
|
800
|
-
--verbose, -v Enable verbose logging
|
|
801
|
-
```
|
|
802
|
-
|
|
803
|
-
### Post-to-PR Command
|
|
804
|
-
|
|
805
|
-
```bash
|
|
806
|
-
iam-validator post-to-pr --report REPORT [OPTIONS]
|
|
807
|
-
|
|
808
|
-
Options:
|
|
809
|
-
--report REPORT, -r REPORT Path to JSON report file (required)
|
|
810
|
-
--create-review Create line-specific review comments (default: true)
|
|
811
|
-
--no-review Don't create line-specific review comments
|
|
812
|
-
--add-summary Add summary comment (default: true)
|
|
813
|
-
--no-summary Don't add summary comment
|
|
814
|
-
--verbose, -v Enable verbose logging
|
|
815
|
-
```
|
|
816
|
-
|
|
817
575
|
## Example Output
|
|
818
576
|
|
|
819
577
|
### Console Output
|
|
@@ -857,68 +615,6 @@ Options:
|
|
|
857
615
|
- 💡 Suggestion: This grants full administrative access. Restrict to specific actions and resources.
|
|
858
616
|
```
|
|
859
617
|
|
|
860
|
-
## Development
|
|
861
|
-
|
|
862
|
-
### Project Structure
|
|
863
|
-
|
|
864
|
-
```
|
|
865
|
-
iam-policy-auditor/
|
|
866
|
-
├── action.yaml # GitHub Action definition
|
|
867
|
-
├── pyproject.toml # Python project configuration
|
|
868
|
-
├── iam_validator/ # Main Python package
|
|
869
|
-
│ ├── iam_validator/
|
|
870
|
-
│ │ ├── __init__.py
|
|
871
|
-
│ │ ├── models.py # Pydantic models
|
|
872
|
-
│ │ ├── aws_fetcher.py # AWS Service Reference API client
|
|
873
|
-
│ │ ├── github_integration.py # GitHub API client
|
|
874
|
-
│ │ ├── cli.py # CLI interface
|
|
875
|
-
│ │ ├── utils.py # Utility functions
|
|
876
|
-
│ │ └── core/
|
|
877
|
-
│ │ ├── policy_loader.py # Policy file loader
|
|
878
|
-
│ │ ├── policy_checks.py # Validation logic
|
|
879
|
-
│ │ └── report.py # Report generation
|
|
880
|
-
│ └── pyproject.toml
|
|
881
|
-
└── examples/
|
|
882
|
-
├── sample_policy.json # Valid example
|
|
883
|
-
└── invalid_policy.json # Invalid example
|
|
884
|
-
```
|
|
885
|
-
|
|
886
|
-
### Running Tests
|
|
887
|
-
|
|
888
|
-
```bash
|
|
889
|
-
cd iam-policy-validator
|
|
890
|
-
uv run pytest
|
|
891
|
-
```
|
|
892
|
-
|
|
893
|
-
### Type Checking
|
|
894
|
-
|
|
895
|
-
```bash
|
|
896
|
-
uv run mypy iam_validator/
|
|
897
|
-
```
|
|
898
|
-
|
|
899
|
-
## Architecture
|
|
900
|
-
|
|
901
|
-
### AWS Service Reference API
|
|
902
|
-
|
|
903
|
-
The validator fetches real-time service information from AWS's official service reference API:
|
|
904
|
-
|
|
905
|
-
```
|
|
906
|
-
https://servicereference.us-east-1.amazonaws.com/
|
|
907
|
-
```
|
|
908
|
-
|
|
909
|
-
This ensures validation is always up-to-date with the latest AWS services and actions.
|
|
910
|
-
|
|
911
|
-
### Validation Flow
|
|
912
|
-
|
|
913
|
-
1. **Load Policies**: Parse JSON/YAML policy files
|
|
914
|
-
2. **Fetch Service Data**: Get service information from AWS API (with caching)
|
|
915
|
-
3. **Validate Actions**: Check each action against service definitions
|
|
916
|
-
4. **Validate Conditions**: Verify condition keys are valid for actions
|
|
917
|
-
5. **Validate Resources**: Check ARN format and structure
|
|
918
|
-
6. **Security Checks**: Identify security best practice violations
|
|
919
|
-
7. **Generate Report**: Create formatted output in desired format
|
|
920
|
-
8. **GitHub Integration**: Post comments/labels to PR (if enabled)
|
|
921
|
-
|
|
922
618
|
## 📚 Documentation
|
|
923
619
|
|
|
924
620
|
**[📖 Complete Documentation →](DOCS.md)**
|
|
@@ -949,7 +645,7 @@ Contributions are welcome! We appreciate your help in making this project better
|
|
|
949
645
|
### How to Contribute
|
|
950
646
|
|
|
951
647
|
1. **Read the [Contributing Guide](CONTRIBUTING.md)** - Comprehensive guide for contributors
|
|
952
|
-
2. **Check [existing issues](https://github.com/boogy/iam-policy-
|
|
648
|
+
2. **Check [existing issues](https://github.com/boogy/iam-policy-validator/issues)** - Find something to work on
|
|
953
649
|
3. **Fork the repository** - Create your own copy
|
|
954
650
|
4. **Make your changes** - Follow our code quality standards
|
|
955
651
|
5. **Submit a Pull Request** - We'll review and merge
|
|
@@ -958,17 +654,17 @@ Contributions are welcome! We appreciate your help in making this project better
|
|
|
958
654
|
|
|
959
655
|
```bash
|
|
960
656
|
# Clone your fork
|
|
961
|
-
git clone https://github.com/YOUR-USERNAME/iam-policy-
|
|
962
|
-
cd iam-policy-
|
|
657
|
+
git clone https://github.com/YOUR-USERNAME/iam-policy-validator.git
|
|
658
|
+
cd iam-policy-validator
|
|
963
659
|
|
|
964
660
|
# Install dependencies
|
|
965
661
|
uv sync --extra dev
|
|
966
662
|
|
|
967
663
|
# Run tests
|
|
968
|
-
|
|
664
|
+
uv run pytest
|
|
969
665
|
|
|
970
|
-
# Run
|
|
971
|
-
|
|
666
|
+
# Run linting
|
|
667
|
+
uv run ruff check .
|
|
972
668
|
```
|
|
973
669
|
|
|
974
670
|
See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed instructions.
|
|
@@ -980,5 +676,5 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
980
676
|
## 🆘 Support
|
|
981
677
|
|
|
982
678
|
- **Documentation**: Check the [docs/](docs/) directory
|
|
983
|
-
- **Issues**: Report bugs or request features via [GitHub Issues](https://github.com/boogy/iam-policy-
|
|
984
|
-
- **Questions**: Ask questions in [GitHub Discussions](https://github.com/boogy/iam-policy-
|
|
679
|
+
- **Issues**: Report bugs or request features via [GitHub Issues](https://github.com/boogy/iam-policy-validator/issues)
|
|
680
|
+
- **Questions**: Ask questions in [GitHub Discussions](https://github.com/boogy/iam-policy-validator/discussions)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
iam_validator/__init__.py,sha256=APnMR3Fu4fHhxfsHBvUM2dJIwazgvLKQbfOsSgFPidg,693
|
|
2
2
|
iam_validator/__main__.py,sha256=to_nz3n_IerJpVVZZ6WSFlFR5s_06J0csfPOTfQZG8g,197
|
|
3
|
-
iam_validator/__version__.py,sha256=
|
|
3
|
+
iam_validator/__version__.py,sha256=YOIURWR5ocuvaQTQgwFi1XjHm_ifJDzicMOQSJZqmZc,206
|
|
4
4
|
iam_validator/checks/__init__.py,sha256=q-_rIYGZJMjsiHK-R_3CbSUCBVGN5e137LPNDnMRZmw,841
|
|
5
5
|
iam_validator/checks/action_condition_enforcement.py,sha256=3V8Wnz6BYnataKzuFMx8fHukVjzpIZaVfde9-RqZjPc,25357
|
|
6
6
|
iam_validator/checks/action_validation.py,sha256=KbUw1SV-2nN-HtLlj3zrE6sdd0z8iAF0ubqz35Vwb7c,6921
|
|
@@ -20,7 +20,7 @@ iam_validator/core/access_analyzer_report.py,sha256=iTIFKul6zQZd2qBg8V6zaDNPMKF8
|
|
|
20
20
|
iam_validator/core/aws_fetcher.py,sha256=fUCIMItIWmrbgsoVCz_9Oe5k3SjuXBlNBVwQ60IWwns,25492
|
|
21
21
|
iam_validator/core/aws_global_conditions.py,sha256=ADVcMEWhgvDZWdBmRUQN3HB7a9OycbTLecXFAy3LPbo,5837
|
|
22
22
|
iam_validator/core/check_registry.py,sha256=wXg4Yw5LJ-rAVLiPUIJOtw8Y49Q1PY00Zbu37LzyjHY,15477
|
|
23
|
-
iam_validator/core/cli.py,sha256=
|
|
23
|
+
iam_validator/core/cli.py,sha256=5UHsHS8o7Fkag4d6MNaaqjCFSGu8evCIbtpa81591lE,3831
|
|
24
24
|
iam_validator/core/config_loader.py,sha256=k4D5TT_D6B9N8BbIEg0nE3wUXu0naFLHOVVJsjYZzh4,14880
|
|
25
25
|
iam_validator/core/models.py,sha256=SUEbxDUtkX1uvgMy6-LPzomyGu82PTpXdDXZ9RKqfTY,9655
|
|
26
26
|
iam_validator/core/policy_checks.py,sha256=xK5CntsEKVDgN27uIdQ92jCL97t7eBqOk0SChWU9cgw,23872
|
|
@@ -38,8 +38,8 @@ iam_validator/core/formatters/sarif.py,sha256=tqp8g7RmUh0HRk-kKDaucx4sa-5I9ikgkS
|
|
|
38
38
|
iam_validator/integrations/__init__.py,sha256=7Hlor_X9j0NZaEjFuSvoXAAuSKQ-zgY19Rk-Dz3JpKo,616
|
|
39
39
|
iam_validator/integrations/github_integration.py,sha256=bKs94vNT4PmcmUPUeuY2WJFhCYpUY2SWiBP1vj-andA,25673
|
|
40
40
|
iam_validator/integrations/ms_teams.py,sha256=t2PlWuTDb6GGH-eDU1jnOKd8D1w4FCB68bahGA7MJcE,14475
|
|
41
|
-
iam_policy_validator-1.0.
|
|
42
|
-
iam_policy_validator-1.0.
|
|
43
|
-
iam_policy_validator-1.0.
|
|
44
|
-
iam_policy_validator-1.0.
|
|
45
|
-
iam_policy_validator-1.0.
|
|
41
|
+
iam_policy_validator-1.0.4.dist-info/METADATA,sha256=QQAQsAQCDiPen37apynaUzYjOUmiTpn8NYgrM6C7l0E,22070
|
|
42
|
+
iam_policy_validator-1.0.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
43
|
+
iam_policy_validator-1.0.4.dist-info/entry_points.txt,sha256=8HtWd8O7mvPiPdZR5YbzY8or_qcqLM4-pKaFdhtFT8M,62
|
|
44
|
+
iam_policy_validator-1.0.4.dist-info/licenses/LICENSE,sha256=AMnbFTBDcK4_MITe2wiQBkj0vg-jjBBhsc43ydC7tt4,1098
|
|
45
|
+
iam_policy_validator-1.0.4.dist-info/RECORD,,
|
iam_validator/__version__.py
CHANGED
iam_validator/core/cli.py
CHANGED
|
@@ -10,18 +10,24 @@ from iam_validator import __version__
|
|
|
10
10
|
from iam_validator.commands import ALL_COMMANDS
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
def setup_logging(verbose: bool = False) -> None:
|
|
13
|
+
def setup_logging(log_level: str | None = None, verbose: bool = False) -> None:
|
|
14
14
|
"""Setup logging configuration.
|
|
15
15
|
|
|
16
16
|
Args:
|
|
17
|
-
|
|
17
|
+
log_level: Log level from CLI argument (debug, info, warning, error, critical)
|
|
18
|
+
verbose: Enable verbose logging (deprecated, use --log-level debug instead)
|
|
18
19
|
|
|
19
20
|
Environment Variables:
|
|
20
21
|
LOG_LEVEL: Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
|
21
|
-
|
|
22
|
+
|
|
23
|
+
Priority:
|
|
24
|
+
1. --log-level CLI argument (highest priority)
|
|
25
|
+
2. LOG_LEVEL environment variable
|
|
26
|
+
3. --verbose flag (sets DEBUG level)
|
|
27
|
+
4. Default: WARNING (lowest priority)
|
|
22
28
|
"""
|
|
23
29
|
# Check for LOG_LEVEL environment variable
|
|
24
|
-
|
|
30
|
+
env_log_level = os.getenv("LOG_LEVEL", "").upper()
|
|
25
31
|
|
|
26
32
|
# Map string to logging level
|
|
27
33
|
level_map = {
|
|
@@ -32,13 +38,15 @@ def setup_logging(verbose: bool = False) -> None:
|
|
|
32
38
|
"CRITICAL": logging.CRITICAL,
|
|
33
39
|
}
|
|
34
40
|
|
|
35
|
-
# Priority: LOG_LEVEL env var > --verbose flag > default (
|
|
36
|
-
if
|
|
37
|
-
level = level_map[
|
|
41
|
+
# Priority: CLI --log-level > LOG_LEVEL env var > --verbose flag > default (WARNING)
|
|
42
|
+
if log_level:
|
|
43
|
+
level = level_map[log_level.upper()]
|
|
44
|
+
elif env_log_level in level_map:
|
|
45
|
+
level = level_map[env_log_level]
|
|
38
46
|
elif verbose:
|
|
39
47
|
level = logging.DEBUG
|
|
40
48
|
else:
|
|
41
|
-
level = logging.
|
|
49
|
+
level = logging.WARNING
|
|
42
50
|
|
|
43
51
|
logging.basicConfig(
|
|
44
52
|
level=level,
|
|
@@ -66,6 +74,14 @@ def main() -> int:
|
|
|
66
74
|
help="Show version information and exit",
|
|
67
75
|
)
|
|
68
76
|
|
|
77
|
+
# Add global log level argument
|
|
78
|
+
parser.add_argument(
|
|
79
|
+
"--log-level",
|
|
80
|
+
choices=["debug", "info", "warning", "error", "critical"],
|
|
81
|
+
default=None,
|
|
82
|
+
help="Set logging level (default: warning)",
|
|
83
|
+
)
|
|
84
|
+
|
|
69
85
|
subparsers = parser.add_subparsers(dest="command", help="Command to run")
|
|
70
86
|
|
|
71
87
|
# Register all commands
|
|
@@ -88,8 +104,9 @@ def main() -> int:
|
|
|
88
104
|
return 1
|
|
89
105
|
|
|
90
106
|
# Setup logging
|
|
107
|
+
log_level = getattr(args, "log_level", None)
|
|
91
108
|
verbose = getattr(args, "verbose", False)
|
|
92
|
-
setup_logging(verbose)
|
|
109
|
+
setup_logging(log_level, verbose)
|
|
93
110
|
|
|
94
111
|
# Execute command
|
|
95
112
|
try:
|
|
File without changes
|
{iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.0.4.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{iam_policy_validator-1.0.3.dist-info → iam_policy_validator-1.0.4.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|