Skip to content

Commit fde1458

Browse files
committed
chore: clean up repo and add .gitignore
0 parents  commit fde1458

File tree

12 files changed

+218
-0
lines changed

12 files changed

+218
-0
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: test
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
validate:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
16+
with:
17+
python-version: "3.10"
18+
- name: Install dependencies
19+
run: pip install .[dev]
20+
- name: Run tests
21+
run: pytest

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Python
2+
__pycache__/
3+
*.pyc
4+
5+
# Env & dependencies
6+
.venv/
7+
*.egg-info/
8+
.env
9+
10+
# IDE
11+
.vscode/
12+
.idea/
13+
14+
# OS
15+
.DS_Store
16+
Thumbs.db

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# devolv-validator
2+
3+
**devolv-validator** is a Python CLI tool that statically validates AWS IAM policies (JSON or YAML) for risky patterns such as wildcards, privilege escalation risks, and bad practices.
4+
5+
## 🚀 Features
6+
7+
- 🚩 Detects wildcards in `Action` and `Resource`
8+
- 🔐 Flags `iam:PassRole` on wildcard `Resource`
9+
- 📂 Supports both JSON and YAML formats
10+
- ⚙️ Clean CLI built with Typer
11+
- ✅ Ready for CI with GitHub Actions
12+
13+
## 📦 Installation
14+
15+
```bash
16+
pip install devolv-validator
17+
```
18+
19+
## 🛠 Usage
20+
21+
```bash
22+
devolv-validator validate path/to/policy.json
23+
```
24+
25+
## 📁 Example
26+
27+
```json
28+
{
29+
"Version": "2012-10-17",
30+
"Statement": [
31+
{
32+
"Effect": "Allow",
33+
"Action": "*",
34+
"Resource": "*"
35+
}
36+
]
37+
}
38+
```
39+
40+
This policy will be flagged with high-severity warnings.
41+
42+
## 🧪 Run Tests
43+
44+
```bash
45+
pytest
46+
```
47+
48+
## 🧰 About
49+
50+
This is part of the [devolv](https://github.com/devolvdev) OSS DevOps toolkit.

devolv/__init__.py

Whitespace-only changes.

devolv/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import typer
2+
from devolv.iam.validator.cli import app as validate_app
3+
4+
app = typer.Typer(help="Devolv CLI - Modular DevOps Toolkit")
5+
app.add_typer(validate_app, name="validate")
6+
7+
if __name__ == "__main__":
8+
app()

devolv/iam/__init__.py

Whitespace-only changes.

devolv/iam/validator/__init__.py

Whitespace-only changes.

devolv/iam/validator/cli.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import typer
2+
from devolv.iam.validator.core import validate_policy_file
3+
4+
app = typer.Typer(help="IAM Validator CLI")
5+
6+
@app.command("file")
7+
def validate_file(path: str):
8+
"""
9+
Validate an AWS IAM policy file (JSON or YAML).
10+
"""
11+
findings = validate_policy_file(path)
12+
if not findings:
13+
typer.secho("✅ Policy is valid and passed all checks.", fg=typer.colors.GREEN)
14+
else:
15+
for finding in findings:
16+
typer.secho(f"❌ {finding['level'].upper()}: {finding['message']}", fg=typer.colors.RED)
17+
raise typer.Exit(code=1)

devolv/iam/validator/core.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
import yaml
3+
from pathlib import Path
4+
from devolv.iam.validator.rules import RULES
5+
6+
def load_policy(path: str):
7+
with open(path, "r") as f:
8+
if path.endswith((".yaml", ".yml")):
9+
return yaml.safe_load(f)
10+
return json.load(f)
11+
12+
def validate_policy_file(path: str):
13+
data = load_policy(path)
14+
findings = []
15+
for rule in RULES:
16+
result = rule["check"](data)
17+
if result:
18+
findings.append({
19+
"id": rule["id"],
20+
"level": rule["level"],
21+
"message": result
22+
})
23+
return findings

devolv/iam/validator/rules.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def check_wildcard_actions(policy):
2+
statements = policy.get("Statement", [])
3+
if not isinstance(statements, list):
4+
statements = [statements]
5+
for stmt in statements:
6+
actions = stmt.get("Action", [])
7+
if isinstance(actions, str):
8+
actions = [actions]
9+
if any(a == "*" or a.endswith(":*") for a in actions):
10+
return "Policy uses wildcard in Action, which is overly permissive."
11+
return None
12+
13+
def check_passrole_wildcard(policy):
14+
statements = policy.get("Statement", [])
15+
if not isinstance(statements, list):
16+
statements = [statements]
17+
for stmt in statements:
18+
actions = stmt.get("Action", [])
19+
resources = stmt.get("Resource", [])
20+
if isinstance(actions, str): actions = [actions]
21+
if isinstance(resources, str): resources = [resources]
22+
if "iam:PassRole" in actions and "*" in resources:
23+
return "iam:PassRole with wildcard resource can lead to privilege escalation."
24+
return None
25+
26+
RULES = [
27+
{
28+
"id": "IAM001",
29+
"level": "high",
30+
"description": "Wildcard in action",
31+
"check": check_wildcard_actions
32+
},
33+
{
34+
"id": "IAM002",
35+
"level": "high",
36+
"description": "PassRole with wildcard",
37+
"check": check_passrole_wildcard
38+
}
39+
]

0 commit comments

Comments
 (0)