Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2666f12
chore: add gitignore, uv lockfile, and project dependencies (pydantic…
bullhacks3 Jun 30, 2026
c648c62
feat: add IRNode, IREdge, RawGraph frozen Pydantic models with enums
bullhacks3 Jun 30, 2026
052f41a
feat: add ResourceTypeRegistry with 70+ AWS resource type mappings
bullhacks3 Jun 30, 2026
b33c28b
feat: add CFNParser converting CFN templates to RawGraph via Ref/GetA…
bullhacks3 Jun 30, 2026
74a98c3
test: add unit tests for ResourceTypeRegistry and CFNParser (99% cove…
bullhacks3 Jun 30, 2026
a6b0ca9
docs: add pipeline engineering README and CFN-to-RawGraph technical w…
bullhacks3 Jun 30, 2026
d4a28a4
feat: add CanonicalIR model and Stage 2 extractors (grouper, network,…
bullhacks3 Jul 2, 2026
07e2aae
feat: add Stage 3 view filters over CanonicalIR (DFD, network, IAM, c…
bullhacks3 Jul 2, 2026
269c77b
feat: add Stage 4 LLM threat generation via OpenRouter with grounding…
bullhacks3 Jul 2, 2026
6ea9fcf
feat: extend CLI with --raw, --canonical, --threats flags for full 4-…
bullhacks3 Jul 2, 2026
c919675
test: add unit tests for Stages 2-4 (extractors, views, grounding)
bullhacks3 Jul 2, 2026
ee54b5c
chore: add LLM-generated threat models for all 6 sample apps
bullhacks3 Jul 2, 2026
960c489
docs: update README and TECHNICAL_DETAILS to cover complete 4-stage p…
bullhacks3 Jul 2, 2026
66e31d1
feat: implement reachability drift detection and CLI enhancements for…
ish-codes-magic Jul 12, 2026
68bc356
feat: add privilege and control drift detection classes
Jul 17, 2026
2ad8681
architecture diff algo
ish-codes-magic Jul 31, 2026
9991bf2
Merge branch 'initial-structure' into drift-classes
cybersnacker Aug 4, 2026
3d0340c
added drift classes for new Datasets (#4)
AtharvKshirsagar Aug 4, 2026
99aa131
feat(ir): extract IAM posture, Lambda URL entry points into CanonicalIR
Aug 6, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
10 changes: 10 additions & 0 deletions ctm-iac/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.venv/
__pycache__/
*.py[cod]
.coverage
htmlcov/
.pytest_cache/
*.egg-info/
dist/
raw_graph.json
canonical_ir.json
120 changes: 120 additions & 0 deletions ctm-iac/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# ctm-iac — CloudFormation Threat Modeller

Converts a CDK/CloudFormation template into a structured security threat model using a
4-stage pipeline: **CFN → RawGraph → CanonicalIR → Views → ThreatModel**.

For pipeline internals see [`ctm_iac/README.md`](ctm_iac/README.md).
For stage-by-stage technical details see [`TECHNICAL_DETAILS.md`](TECHNICAL_DETAILS.md).

---

## Prerequisites

- Python 3.11+
- [`uv`](https://github.com/astral-sh/uv) (package manager)
- An [OpenRouter](https://openrouter.ai) API key (for Stage 4 LLM threat generation)

---

## Setup

```bash
# Install dependencies
uv sync --dev

# Export your OpenRouter key
export OPENROUTER_API_KEY=sk-or-v1-...
```

---

## Running the pipeline

### Full pipeline — CFN template → threat model

```bash
uv run python main.py \
--cfn cdk-dataset/simple-image-upload-download-website/cdk/cdk.out/SimpleImageWebAppStack-development.template.json \
--raw cdk-dataset/simple-image-upload-download-website/raw_graph.json \
--canonical cdk-dataset/simple-image-upload-download-website/canonical_ir.json \
--threats cdk-dataset/simple-image-upload-download-website/llm_threat_model.json
```

### Stages 1+2 only (no LLM call required)

```bash
uv run python main.py \
--cfn path/to/template.json \
--canonical canonical_ir.json
```

### Print CanonicalIR to stdout (default when no output flag is given)

```bash
uv run python main.py --cfn path/to/template.json
```

### Use a different LLM model

```bash
export OPENROUTER_MODEL=openai/gpt-4o
uv run python main.py --cfn path/to/template.json --threats threats.json
```

---

## CLI flags

| Flag | Required | Description |
|------|----------|-------------|
| `--cfn PATH` | Yes | Path to the CloudFormation JSON template (`cdk synth` output) |
| `--raw PATH` | No | Save Stage 1 RawGraph JSON to this file |
| `--canonical PATH` | No | Save Stage 2 CanonicalIR JSON to this file |
| `--threats PATH` | No | Run LLM threat generation and save ThreatModel JSON here |

All output flags are optional and independent. When none are given, the CanonicalIR is
printed to stdout.

---

## Output files

| File | Stage | Description |
|------|-------|-------------|
| `raw_graph.json` | 1 | All CFN resources as nodes, all Ref/GetAtt/DependsOn as edges |
| `canonical_ir.json` | 2 | Architecture-level components with semantic edges (NETWORK_PATH, CAN_DO, PROTECTED_BY, …) |
| `llm_threat_model.json` | 4 | JSON array of STRIDE threats in ground-truth format |

---

## Running all 6 sample apps

```bash
APPS=(
"automated-security-response:cdk/cdk.out/AutomatedSecurityResponseStack.template.json"
"aws-ai-chat-bot:cdk/cdk.out/AiChatbotStack-dev.template.json"
"code-execution-platform:cdk/cdk.out/CodeExecutionPlatformStack.template.json"
"containerized-microservices:cdk/cdk.out/ContainerizedMicroservicesStack.template.json"
"simple-image-upload-download-website:cdk/cdk.out/SimpleImageWebAppStack-development.template.json"
"support-ticketing-system:cdk/cdk.out/SupportTicketingStack-dev.template.json"
)

for entry in "${APPS[@]}"; do
APP="${entry%%:*}"
TMPL="${entry#*:}"
DIR="cdk-dataset/$APP"
uv run python main.py \
--cfn "$DIR/$TMPL" \
--raw "$DIR/raw_graph.json" \
--canonical "$DIR/canonical_ir.json" \
--threats "$DIR/llm_threat_model.json"
done
```

---

## Running tests

```bash
uv run pytest tests/ -v --cov=ctm_iac
```
Loading