iam-policy-analyzer 0.1.0__tar.gz
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.
- iam_policy_analyzer-0.1.0/LICENSE +21 -0
- iam_policy_analyzer-0.1.0/PKG-INFO +303 -0
- iam_policy_analyzer-0.1.0/README.md +262 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer/__init__.py +20 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer/analyzer.py +287 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer/checks.py +81 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer/cli.py +299 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer/models.py +80 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer/security_checks.py +429 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer.egg-info/PKG-INFO +303 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer.egg-info/SOURCES.txt +15 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer.egg-info/dependency_links.txt +1 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer.egg-info/entry_points.txt +2 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer.egg-info/requires.txt +12 -0
- iam_policy_analyzer-0.1.0/iam_policy_analyzer.egg-info/top_level.txt +1 -0
- iam_policy_analyzer-0.1.0/pyproject.toml +75 -0
- iam_policy_analyzer-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Amit Gupta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iam-policy-analyzer
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Automated security analysis tool for IAM policies across cloud providers and identity systems
|
|
5
|
+
Author-email: Amit Gupta <apphelp.csw@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/xamitgupta/iam-policy-analyzer
|
|
8
|
+
Project-URL: Documentation, https://github.com/xamitgupta/iam-policy-analyzer#readme
|
|
9
|
+
Project-URL: Repository, https://github.com/xamitgupta/iam-policy-analyzer.git
|
|
10
|
+
Project-URL: Issues, https://github.com/xamitgupta/iam-policy-analyzer/issues
|
|
11
|
+
Keywords: iam,security,policy-analysis,compliance,okta,aws,azure
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: System Administrators
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Natural Language :: English
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
24
|
+
Classifier: Topic :: System :: Systems Administration
|
|
25
|
+
Classifier: Topic :: Security
|
|
26
|
+
Requires-Python: >=3.8
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: typer[all]>=0.9.0
|
|
30
|
+
Requires-Dist: pydantic>=2.0.0
|
|
31
|
+
Requires-Dist: pyyaml>=6.0
|
|
32
|
+
Requires-Dist: tabulate>=0.9.0
|
|
33
|
+
Requires-Dist: rich>=13.0.0
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: ruff>=0.1.0; extra == "dev"
|
|
39
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# π IAM Policy Analyzer
|
|
43
|
+
|
|
44
|
+
[](https://opensource.org/licenses/MIT)
|
|
45
|
+
[](https://www.python.org/downloads/)
|
|
46
|
+
|
|
47
|
+
**Automated security analysis for IAM policies across cloud providers and identity systems.**
|
|
48
|
+
|
|
49
|
+
Every organization has IAM policies full of vulnerabilities, conflicts, and dead code. Most organizations don't know about them until something breaksβor worse, until a security incident. This tool finds them in seconds.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
## π― What It Does
|
|
53
|
+
|
|
54
|
+
IAM Policy Analyzer automatically scans your policies and reports:
|
|
55
|
+
|
|
56
|
+
- **Wildcard permissions** that violate least privilege
|
|
57
|
+
- **Admin access** granted to non-admin users
|
|
58
|
+
- **Sensitive actions without MFA** (e.g., DeleteUser, DisableKey)
|
|
59
|
+
- **Missing security boundaries** that enable privilege escalation
|
|
60
|
+
- **Hardcoded credentials** that could leak secrets
|
|
61
|
+
- **Over-permission** that should be restricted
|
|
62
|
+
- **Deprecated APIs** you should migrate away from
|
|
63
|
+
- **And 12+ more checks** covering common IAM mistakes
|
|
64
|
+
|
|
65
|
+
## β‘ Quick Start
|
|
66
|
+
|
|
67
|
+
### Install
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install iam-policy-analyzer
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Or from source:
|
|
74
|
+
```bash
|
|
75
|
+
git clone https://github.com/xamitgupta/iam-policy-analyzer.git
|
|
76
|
+
cd iam-policy-analyzer
|
|
77
|
+
pip install -e .
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Analyze a Policy
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# Analyze a single policy
|
|
84
|
+
iam-analyzer analyze my-policy.json
|
|
85
|
+
|
|
86
|
+
# Filter by severity
|
|
87
|
+
iam-analyzer analyze policy.yaml --min-severity HIGH
|
|
88
|
+
|
|
89
|
+
# Show detailed findings
|
|
90
|
+
iam-analyzer analyze policy.json --details
|
|
91
|
+
|
|
92
|
+
# Export as JSON
|
|
93
|
+
iam-analyzer analyze policy.json --format json > results.json
|
|
94
|
+
|
|
95
|
+
# Analyze entire directory
|
|
96
|
+
iam-analyzer batch ./policies/ --output results.json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## π Example Output
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
103
|
+
β π IAM Policy Analyzer β
|
|
104
|
+
β Automated security analysis for identity policies β
|
|
105
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
106
|
+
|
|
107
|
+
Analyzing: example-policy.json
|
|
108
|
+
|
|
109
|
+
π Analysis Summary
|
|
110
|
+
Total Findings 3
|
|
111
|
+
CRITICAL 1
|
|
112
|
+
HIGH 2
|
|
113
|
+
MEDIUM 0
|
|
114
|
+
LOW 0
|
|
115
|
+
INFO 0
|
|
116
|
+
|
|
117
|
+
π Findings (3)
|
|
118
|
+
|
|
119
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
120
|
+
β 1. CRITICAL β
|
|
121
|
+
β β
|
|
122
|
+
β ID: IAM-002 β
|
|
123
|
+
β Name: Wildcard Action Detected β
|
|
124
|
+
β Resource: AdminRole β
|
|
125
|
+
β β
|
|
126
|
+
β Issue: β
|
|
127
|
+
β Policy allows all actions (*), granting excessive β
|
|
128
|
+
β permissions β
|
|
129
|
+
β β
|
|
130
|
+
β Remediation: β
|
|
131
|
+
β Replace wildcard actions with specific, necessary β
|
|
132
|
+
β permissions. Example: Use 's3:GetObject' instead β
|
|
133
|
+
β of 's3:*' β
|
|
134
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## π Supported Checks
|
|
138
|
+
|
|
139
|
+
| Check ID | Name | Severity | Description |
|
|
140
|
+
|----------|------|----------|-------------|
|
|
141
|
+
| IAM-001 | Wildcard Principal | CRITICAL | Policy grants access to all principals (*) |
|
|
142
|
+
| IAM-002 | Wildcard Action | CRITICAL | Policy allows all actions (*) |
|
|
143
|
+
| IAM-003 | Wildcard Resource | HIGH | Policy grants access to all resources (*) |
|
|
144
|
+
| IAM-004 | Admin Access | CRITICAL | Policy grants administrative permissions |
|
|
145
|
+
| IAM-005 | Missing MFA | HIGH | Sensitive actions without MFA requirement |
|
|
146
|
+
| IAM-006 | Credential Exposure | CRITICAL | Hardcoded credentials detected |
|
|
147
|
+
| IAM-007 | Overly Permissive PassRole | HIGH | PassRole without resource restrictions |
|
|
148
|
+
| IAM-008 | No Permission Boundary | MEDIUM | Missing permission boundary enforcement |
|
|
149
|
+
| IAM-009 | Unencrypted Data Access | MEDIUM | S3 access without encryption requirement |
|
|
150
|
+
| IAM-010 | Deprecated API | LOW | Usage of deprecated/legacy APIs |
|
|
151
|
+
| IAM-011 | No Resource Tags | MEDIUM | Missing tag-based access control |
|
|
152
|
+
| IAM-012 | No Deny Statements | LOW | Policy lacks explicit Deny statements |
|
|
153
|
+
|
|
154
|
+
## π Supported Formats
|
|
155
|
+
|
|
156
|
+
- **AWS IAM** - Policy documents, inline policies, managed policies
|
|
157
|
+
- **Okta** - Access policies and rules
|
|
158
|
+
- **Azure AD** - Role definitions and permission assignments
|
|
159
|
+
- **GCP** - IAM policies and custom roles
|
|
160
|
+
- **Generic JSON/YAML** - Flexible structure for custom systems
|
|
161
|
+
|
|
162
|
+
## π Advanced Usage
|
|
163
|
+
|
|
164
|
+
### Integrate with CI/CD
|
|
165
|
+
|
|
166
|
+
```yaml
|
|
167
|
+
# GitHub Actions example
|
|
168
|
+
- name: Analyze IAM Policies
|
|
169
|
+
uses: xamitgupta/iam-policy-analyzer@v0.1.0
|
|
170
|
+
with:
|
|
171
|
+
policy-dir: ./policies/
|
|
172
|
+
fail-on-critical: true
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Python API
|
|
176
|
+
|
|
177
|
+
```python
|
|
178
|
+
from iam_policy_analyzer import IAMAnalyzer
|
|
179
|
+
|
|
180
|
+
analyzer = IAMAnalyzer()
|
|
181
|
+
|
|
182
|
+
# Analyze a file
|
|
183
|
+
result = analyzer.analyze_file("my-policy.json")
|
|
184
|
+
|
|
185
|
+
# Check findings
|
|
186
|
+
for finding in result.findings:
|
|
187
|
+
print(f"{finding.severity}: {finding.message}")
|
|
188
|
+
print(f"Remediation: {finding.remediation}")
|
|
189
|
+
|
|
190
|
+
# Filter by severity
|
|
191
|
+
critical_findings = [f for f in result.findings
|
|
192
|
+
if f.severity == Severity.CRITICAL]
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Custom Checks
|
|
196
|
+
|
|
197
|
+
Extend the analyzer with your own security checks:
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
from iam_policy_analyzer.checks import PolicyCheck
|
|
201
|
+
from iam_policy_analyzer.models import Finding, Severity
|
|
202
|
+
|
|
203
|
+
class MyCustomCheck(PolicyCheck):
|
|
204
|
+
check_id = "CUSTOM-001"
|
|
205
|
+
check_name = "My Custom Check"
|
|
206
|
+
severity = Severity.MEDIUM
|
|
207
|
+
|
|
208
|
+
def analyze(self, policy):
|
|
209
|
+
findings = []
|
|
210
|
+
# Your check logic here
|
|
211
|
+
if some_violation:
|
|
212
|
+
findings.append(self._create_finding(
|
|
213
|
+
message="Your message",
|
|
214
|
+
affected_resource=policy.name,
|
|
215
|
+
remediation="How to fix it"
|
|
216
|
+
))
|
|
217
|
+
return findings
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## π Real-World Examples
|
|
221
|
+
|
|
222
|
+
### Example 1: Admin Policy with Wildcards
|
|
223
|
+
|
|
224
|
+
```json
|
|
225
|
+
{
|
|
226
|
+
"Version": "2012-10-17",
|
|
227
|
+
"Statement": [{
|
|
228
|
+
"Effect": "Allow",
|
|
229
|
+
"Principal": "*",
|
|
230
|
+
"Action": "*",
|
|
231
|
+
"Resource": "*"
|
|
232
|
+
}]
|
|
233
|
+
}
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Findings:**
|
|
237
|
+
- β IAM-001: Wildcard Principal (CRITICAL)
|
|
238
|
+
- β IAM-002: Wildcard Action (CRITICAL)
|
|
239
|
+
- β IAM-003: Wildcard Resource (HIGH)
|
|
240
|
+
|
|
241
|
+
**Remediation:** Specify exact principals, actions, and resources.
|
|
242
|
+
|
|
243
|
+
### Example 2: Sensitive Actions Without MFA
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"Version": "2012-10-17",
|
|
248
|
+
"Statement": [{
|
|
249
|
+
"Effect": "Allow",
|
|
250
|
+
"Principal": {"AWS": "arn:aws:iam::123456789012:user/bob"},
|
|
251
|
+
"Action": "iam:DeleteUser",
|
|
252
|
+
"Resource": "*"
|
|
253
|
+
}]
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
**Findings:**
|
|
258
|
+
- β IAM-005: Sensitive Action Without MFA (HIGH)
|
|
259
|
+
|
|
260
|
+
**Remediation:** Add MFA requirement to the condition.
|
|
261
|
+
|
|
262
|
+
## π€ Contributing
|
|
263
|
+
|
|
264
|
+
Contributions are welcome! Areas to help:
|
|
265
|
+
|
|
266
|
+
- Adding new security checks
|
|
267
|
+
- Supporting additional policy formats
|
|
268
|
+
- Improving documentation
|
|
269
|
+
- GitHub Actions integration
|
|
270
|
+
- Bug reports and feature requests
|
|
271
|
+
|
|
272
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
273
|
+
|
|
274
|
+
## π Documentation
|
|
275
|
+
|
|
276
|
+
- [Contributing Guide](CONTRIBUTING.md)
|
|
277
|
+
|
|
278
|
+
## π Resources
|
|
279
|
+
|
|
280
|
+
- [AWS IAM Best Practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)
|
|
281
|
+
- [Okta Policy Documentation](https://developer.okta.com/docs/reference/api/policy/)
|
|
282
|
+
- [Azure AD Role Security](https://docs.microsoft.com/en-us/azure/active-directory/roles/security-planning)
|
|
283
|
+
- [GCP IAM Security](https://cloud.google.com/iam/docs/best-practices)
|
|
284
|
+
|
|
285
|
+
## π License
|
|
286
|
+
|
|
287
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
288
|
+
|
|
289
|
+
## π¨βπ» Author
|
|
290
|
+
|
|
291
|
+
**Amit Gupta**
|
|
292
|
+
- Staff Security Engineer @ Meta
|
|
293
|
+
- OSAC Panelist
|
|
294
|
+
- [Twitter](https://x.com/_xamitgupta)
|
|
295
|
+
- [LinkedIn](https://linkedin.com/in/yourprofile)
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
**Found an issue?** [Report it on GitHub](https://github.com/xamitgupta/iam-policy-analyzer/issues)
|
|
300
|
+
|
|
301
|
+
**Have an idea?** [Start a discussion](https://github.com/xamitgupta/iam-policy-analyzer/discussions)
|
|
302
|
+
|
|
303
|
+
**Like this tool?** Please β star the repo!
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# π IAM Policy Analyzer
|
|
2
|
+
|
|
3
|
+
[](https://opensource.org/licenses/MIT)
|
|
4
|
+
[](https://www.python.org/downloads/)
|
|
5
|
+
|
|
6
|
+
**Automated security analysis for IAM policies across cloud providers and identity systems.**
|
|
7
|
+
|
|
8
|
+
Every organization has IAM policies full of vulnerabilities, conflicts, and dead code. Most organizations don't know about them until something breaksβor worse, until a security incident. This tool finds them in seconds.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## π― What It Does
|
|
12
|
+
|
|
13
|
+
IAM Policy Analyzer automatically scans your policies and reports:
|
|
14
|
+
|
|
15
|
+
- **Wildcard permissions** that violate least privilege
|
|
16
|
+
- **Admin access** granted to non-admin users
|
|
17
|
+
- **Sensitive actions without MFA** (e.g., DeleteUser, DisableKey)
|
|
18
|
+
- **Missing security boundaries** that enable privilege escalation
|
|
19
|
+
- **Hardcoded credentials** that could leak secrets
|
|
20
|
+
- **Over-permission** that should be restricted
|
|
21
|
+
- **Deprecated APIs** you should migrate away from
|
|
22
|
+
- **And 12+ more checks** covering common IAM mistakes
|
|
23
|
+
|
|
24
|
+
## β‘ Quick Start
|
|
25
|
+
|
|
26
|
+
### Install
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pip install iam-policy-analyzer
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Or from source:
|
|
33
|
+
```bash
|
|
34
|
+
git clone https://github.com/xamitgupta/iam-policy-analyzer.git
|
|
35
|
+
cd iam-policy-analyzer
|
|
36
|
+
pip install -e .
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Analyze a Policy
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Analyze a single policy
|
|
43
|
+
iam-analyzer analyze my-policy.json
|
|
44
|
+
|
|
45
|
+
# Filter by severity
|
|
46
|
+
iam-analyzer analyze policy.yaml --min-severity HIGH
|
|
47
|
+
|
|
48
|
+
# Show detailed findings
|
|
49
|
+
iam-analyzer analyze policy.json --details
|
|
50
|
+
|
|
51
|
+
# Export as JSON
|
|
52
|
+
iam-analyzer analyze policy.json --format json > results.json
|
|
53
|
+
|
|
54
|
+
# Analyze entire directory
|
|
55
|
+
iam-analyzer batch ./policies/ --output results.json
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## π Example Output
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
62
|
+
β π IAM Policy Analyzer β
|
|
63
|
+
β Automated security analysis for identity policies β
|
|
64
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
65
|
+
|
|
66
|
+
Analyzing: example-policy.json
|
|
67
|
+
|
|
68
|
+
π Analysis Summary
|
|
69
|
+
Total Findings 3
|
|
70
|
+
CRITICAL 1
|
|
71
|
+
HIGH 2
|
|
72
|
+
MEDIUM 0
|
|
73
|
+
LOW 0
|
|
74
|
+
INFO 0
|
|
75
|
+
|
|
76
|
+
π Findings (3)
|
|
77
|
+
|
|
78
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
79
|
+
β 1. CRITICAL β
|
|
80
|
+
β β
|
|
81
|
+
β ID: IAM-002 β
|
|
82
|
+
β Name: Wildcard Action Detected β
|
|
83
|
+
β Resource: AdminRole β
|
|
84
|
+
β β
|
|
85
|
+
β Issue: β
|
|
86
|
+
β Policy allows all actions (*), granting excessive β
|
|
87
|
+
β permissions β
|
|
88
|
+
β β
|
|
89
|
+
β Remediation: β
|
|
90
|
+
β Replace wildcard actions with specific, necessary β
|
|
91
|
+
β permissions. Example: Use 's3:GetObject' instead β
|
|
92
|
+
β of 's3:*' β
|
|
93
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## π Supported Checks
|
|
97
|
+
|
|
98
|
+
| Check ID | Name | Severity | Description |
|
|
99
|
+
|----------|------|----------|-------------|
|
|
100
|
+
| IAM-001 | Wildcard Principal | CRITICAL | Policy grants access to all principals (*) |
|
|
101
|
+
| IAM-002 | Wildcard Action | CRITICAL | Policy allows all actions (*) |
|
|
102
|
+
| IAM-003 | Wildcard Resource | HIGH | Policy grants access to all resources (*) |
|
|
103
|
+
| IAM-004 | Admin Access | CRITICAL | Policy grants administrative permissions |
|
|
104
|
+
| IAM-005 | Missing MFA | HIGH | Sensitive actions without MFA requirement |
|
|
105
|
+
| IAM-006 | Credential Exposure | CRITICAL | Hardcoded credentials detected |
|
|
106
|
+
| IAM-007 | Overly Permissive PassRole | HIGH | PassRole without resource restrictions |
|
|
107
|
+
| IAM-008 | No Permission Boundary | MEDIUM | Missing permission boundary enforcement |
|
|
108
|
+
| IAM-009 | Unencrypted Data Access | MEDIUM | S3 access without encryption requirement |
|
|
109
|
+
| IAM-010 | Deprecated API | LOW | Usage of deprecated/legacy APIs |
|
|
110
|
+
| IAM-011 | No Resource Tags | MEDIUM | Missing tag-based access control |
|
|
111
|
+
| IAM-012 | No Deny Statements | LOW | Policy lacks explicit Deny statements |
|
|
112
|
+
|
|
113
|
+
## π Supported Formats
|
|
114
|
+
|
|
115
|
+
- **AWS IAM** - Policy documents, inline policies, managed policies
|
|
116
|
+
- **Okta** - Access policies and rules
|
|
117
|
+
- **Azure AD** - Role definitions and permission assignments
|
|
118
|
+
- **GCP** - IAM policies and custom roles
|
|
119
|
+
- **Generic JSON/YAML** - Flexible structure for custom systems
|
|
120
|
+
|
|
121
|
+
## π Advanced Usage
|
|
122
|
+
|
|
123
|
+
### Integrate with CI/CD
|
|
124
|
+
|
|
125
|
+
```yaml
|
|
126
|
+
# GitHub Actions example
|
|
127
|
+
- name: Analyze IAM Policies
|
|
128
|
+
uses: xamitgupta/iam-policy-analyzer@v0.1.0
|
|
129
|
+
with:
|
|
130
|
+
policy-dir: ./policies/
|
|
131
|
+
fail-on-critical: true
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Python API
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from iam_policy_analyzer import IAMAnalyzer
|
|
138
|
+
|
|
139
|
+
analyzer = IAMAnalyzer()
|
|
140
|
+
|
|
141
|
+
# Analyze a file
|
|
142
|
+
result = analyzer.analyze_file("my-policy.json")
|
|
143
|
+
|
|
144
|
+
# Check findings
|
|
145
|
+
for finding in result.findings:
|
|
146
|
+
print(f"{finding.severity}: {finding.message}")
|
|
147
|
+
print(f"Remediation: {finding.remediation}")
|
|
148
|
+
|
|
149
|
+
# Filter by severity
|
|
150
|
+
critical_findings = [f for f in result.findings
|
|
151
|
+
if f.severity == Severity.CRITICAL]
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Custom Checks
|
|
155
|
+
|
|
156
|
+
Extend the analyzer with your own security checks:
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from iam_policy_analyzer.checks import PolicyCheck
|
|
160
|
+
from iam_policy_analyzer.models import Finding, Severity
|
|
161
|
+
|
|
162
|
+
class MyCustomCheck(PolicyCheck):
|
|
163
|
+
check_id = "CUSTOM-001"
|
|
164
|
+
check_name = "My Custom Check"
|
|
165
|
+
severity = Severity.MEDIUM
|
|
166
|
+
|
|
167
|
+
def analyze(self, policy):
|
|
168
|
+
findings = []
|
|
169
|
+
# Your check logic here
|
|
170
|
+
if some_violation:
|
|
171
|
+
findings.append(self._create_finding(
|
|
172
|
+
message="Your message",
|
|
173
|
+
affected_resource=policy.name,
|
|
174
|
+
remediation="How to fix it"
|
|
175
|
+
))
|
|
176
|
+
return findings
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## π Real-World Examples
|
|
180
|
+
|
|
181
|
+
### Example 1: Admin Policy with Wildcards
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"Version": "2012-10-17",
|
|
186
|
+
"Statement": [{
|
|
187
|
+
"Effect": "Allow",
|
|
188
|
+
"Principal": "*",
|
|
189
|
+
"Action": "*",
|
|
190
|
+
"Resource": "*"
|
|
191
|
+
}]
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
**Findings:**
|
|
196
|
+
- β IAM-001: Wildcard Principal (CRITICAL)
|
|
197
|
+
- β IAM-002: Wildcard Action (CRITICAL)
|
|
198
|
+
- β IAM-003: Wildcard Resource (HIGH)
|
|
199
|
+
|
|
200
|
+
**Remediation:** Specify exact principals, actions, and resources.
|
|
201
|
+
|
|
202
|
+
### Example 2: Sensitive Actions Without MFA
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"Version": "2012-10-17",
|
|
207
|
+
"Statement": [{
|
|
208
|
+
"Effect": "Allow",
|
|
209
|
+
"Principal": {"AWS": "arn:aws:iam::123456789012:user/bob"},
|
|
210
|
+
"Action": "iam:DeleteUser",
|
|
211
|
+
"Resource": "*"
|
|
212
|
+
}]
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**Findings:**
|
|
217
|
+
- β IAM-005: Sensitive Action Without MFA (HIGH)
|
|
218
|
+
|
|
219
|
+
**Remediation:** Add MFA requirement to the condition.
|
|
220
|
+
|
|
221
|
+
## π€ Contributing
|
|
222
|
+
|
|
223
|
+
Contributions are welcome! Areas to help:
|
|
224
|
+
|
|
225
|
+
- Adding new security checks
|
|
226
|
+
- Supporting additional policy formats
|
|
227
|
+
- Improving documentation
|
|
228
|
+
- GitHub Actions integration
|
|
229
|
+
- Bug reports and feature requests
|
|
230
|
+
|
|
231
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
232
|
+
|
|
233
|
+
## π Documentation
|
|
234
|
+
|
|
235
|
+
- [Contributing Guide](CONTRIBUTING.md)
|
|
236
|
+
|
|
237
|
+
## π Resources
|
|
238
|
+
|
|
239
|
+
- [AWS IAM Best Practices](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)
|
|
240
|
+
- [Okta Policy Documentation](https://developer.okta.com/docs/reference/api/policy/)
|
|
241
|
+
- [Azure AD Role Security](https://docs.microsoft.com/en-us/azure/active-directory/roles/security-planning)
|
|
242
|
+
- [GCP IAM Security](https://cloud.google.com/iam/docs/best-practices)
|
|
243
|
+
|
|
244
|
+
## π License
|
|
245
|
+
|
|
246
|
+
MIT License - see [LICENSE](LICENSE) for details.
|
|
247
|
+
|
|
248
|
+
## π¨βπ» Author
|
|
249
|
+
|
|
250
|
+
**Amit Gupta**
|
|
251
|
+
- Staff Security Engineer @ Meta
|
|
252
|
+
- OSAC Panelist
|
|
253
|
+
- [Twitter](https://x.com/_xamitgupta)
|
|
254
|
+
- [LinkedIn](https://linkedin.com/in/yourprofile)
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
**Found an issue?** [Report it on GitHub](https://github.com/xamitgupta/iam-policy-analyzer/issues)
|
|
259
|
+
|
|
260
|
+
**Have an idea?** [Start a discussion](https://github.com/xamitgupta/iam-policy-analyzer/discussions)
|
|
261
|
+
|
|
262
|
+
**Like this tool?** Please β star the repo!
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""
|
|
2
|
+
IAM Policy Analyzer - Automated security analysis for IAM policies.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
__version__ = "0.1.0"
|
|
6
|
+
__author__ = "Amit Gupta"
|
|
7
|
+
__email__ = "apphelp.csw@gmail.com"
|
|
8
|
+
__license__ = "MIT"
|
|
9
|
+
|
|
10
|
+
from iam_policy_analyzer.models import Finding, AnalysisResult, PolicyDocument, Severity
|
|
11
|
+
from iam_policy_analyzer.analyzer import IAMAnalyzer, PolicyParser
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"Finding",
|
|
15
|
+
"AnalysisResult",
|
|
16
|
+
"PolicyDocument",
|
|
17
|
+
"Severity",
|
|
18
|
+
"IAMAnalyzer",
|
|
19
|
+
"PolicyParser",
|
|
20
|
+
]
|