Deterministic Verification for Infrastructure as Code (IaC) using Z3 and Graph Theory.
Project description
QWED-Infra ☁️🛡️
Deterministic Verification for Infrastructure as Code (IaC)
Part of the QWED Ecosystem - Verification Infrastructure for AI
🎯 What is QWED-Infra?
qwed-infra is a Python library that uses Formal Methods (Z3 Solver) and Graph Theory to mathematically prove the security and compliance of detailed infrastructure definitions (Terraform, AWS IAM, Kubernetes). It prevents AI agents (like Devin or Copilot Workspace) from deploying insecure or expensive infrastructure.
🚀 Features
1. 🛡️ IamGuard (Implemented)
Verifies AWS IAM Policies using the Z3 Theorem Prover. Instead of regex matching, it converts policies into logical formulas to prove reachability.
- Wildcard Logic: Correctly handles
s3:*,bucket/*. - Conditions: Supports
aws:SourceIp(CIDR),aws:CurrentTime(Date),StringEquals. - Deny Overrides: Proves that explicit Deny statements always override Allows.
- Least Privilege: Mathematically proves if a policy allows stronger permissions than intended.
2. 🌐 NetworkGuard (Implemented)
Verifies Network Reachability using Graph Theory (NetworkX).
- Public Access Check: Validates if
Internet -> IGW -> Route -> Security Group -> Instancepath exists. - Port Verification: Ensures critical ports (22, 3389) are not exposed to 0.0.0.0/0.
3. 💰 CostGuard (Implemented)
Deterministic Cloud Cost estimation before deployment.
- Budget Enforcement: Blocks deployment if estimated monthly cost > Budget.
- GPU Control: Detects expensive instances (e.g.,
p4d.24xlarge) to prevent $20k+ surprises. - Static Pricing: Embedded pricing catalog for standard AWS types.
📦 Installation
pip install qwed-infra
⚡ Usage
1. Parsing Real Terraform Files
from qwed_infra import TerraformParser, IamGuard
# Parse a real Terraform directory
parser = TerraformParser()
resources = parser.parse_directory("./terraform/prod")
# Verify IAM Policies found in Terraform
guard = IamGuard()
for policy in resources.get("policies", []):
# Context-Aware Verification
result = guard.verify_access(
policy,
action="s3:GetObject",
resource="*",
context={"aws:SourceIp": "192.168.1.5"} # Corporate VPN Only
)
print(f"Policy {policy['id']} allows VPN access? {result.allowed}")
2. Verifying Cloud Costs
from qwed_infra import CostGuard
cost = CostGuard()
# Define resources (or parse from Terraform)
resources = {
"instances": [
{"id": "web-cluster", "instance_type": "t3.micro", "count": 2},
{"id": "gpu-trainer", "instance_type": "p4d.24xlarge", "count": 1} # $32/hr!
]
}
# Check against budget
result = cost.verify_budget(resources, budget_monthly=500.0)
print(f"Within Budget? {result.within_budget}") # -> False
print(f"Total: ${result.total_monthly_cost:.2f}") # -> ~$23,900
print(f"Reason: {result.reason}")
3. Verifying Network Reachability
from qwed_infra import NetworkGuard
net_guard = NetworkGuard()
# Graph-based Verification
# (Normally parsed from TF, here shown as dict structure)
infra = {
"subnets": [
{"id": "public-subnet", "security_groups": ["sg-web"]}
],
"route_tables": [
{"subnet_id": "public-subnet", "routes": {"0.0.0.0/0": "igw-main"}}
],
"security_groups": {
"sg-web": {"ingress": [{"port": 80, "cidr": "0.0.0.0/0"}]}
}
}
# Is Web Accessible?
res = net_guard.verify_reachability(infra, "internet", "public-subnet", 80)
print(f"Internet Reachable? {res.reachable}") # -> True
🏗️ Architecture
graph TD
A[Terraform Code] -->|TerraformParser| B{QWED Engine}
B -->|Mathematical Proof| C["Z3 Solver (IAM)"]
B -->|Graph Traversal| D["NetworkX (Reachability)"]
B -->|Arithmetic| E["Pricing Catalog (Cost)"]
C --> F[Verification Result]
D --> F
E --> F
🤝 Contributing
We welcome contributions! Please see CONTRIBUTING.md.
📄 License
Apache 2.0 - See LICENSE
Built with ❤️ by QWED-AI
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qwed_infra-0.1.0.tar.gz.
File metadata
- Download URL: qwed_infra-0.1.0.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d74679f40cb3de62b5549489232cddec91af606332611f236a1a820fd6943e14
|
|
| MD5 |
7648b4b770855274e6ee4c01735cfd6d
|
|
| BLAKE2b-256 |
19a84655e37f8b12b2ada02b2292a6099e1d1a5270f2ea847b2384827151890b
|
Provenance
The following attestation bundles were made for qwed_infra-0.1.0.tar.gz:
Publisher:
publish.yml on QWED-AI/qwed-infra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qwed_infra-0.1.0.tar.gz -
Subject digest:
d74679f40cb3de62b5549489232cddec91af606332611f236a1a820fd6943e14 - Sigstore transparency entry: 850055404
- Sigstore integration time:
-
Permalink:
QWED-AI/qwed-infra@566049317e97f555b23b46b96f8811e8481b5994 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/QWED-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@566049317e97f555b23b46b96f8811e8481b5994 -
Trigger Event:
release
-
Statement type:
File details
Details for the file qwed_infra-0.1.0-py3-none-any.whl.
File metadata
- Download URL: qwed_infra-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee54834827ce8f5ead5775cda3d08516b6ccbc5e408c78221395c0b7a0237d9e
|
|
| MD5 |
0239605fd4cad970f6815538525bf30e
|
|
| BLAKE2b-256 |
6fd8aa5267ef6b81d35164959578fe1e2d1f4984a6e3ec68266164e11ec36868
|
Provenance
The following attestation bundles were made for qwed_infra-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on QWED-AI/qwed-infra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qwed_infra-0.1.0-py3-none-any.whl -
Subject digest:
ee54834827ce8f5ead5775cda3d08516b6ccbc5e408c78221395c0b7a0237d9e - Sigstore transparency entry: 850055438
- Sigstore integration time:
-
Permalink:
QWED-AI/qwed-infra@566049317e97f555b23b46b96f8811e8481b5994 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/QWED-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@566049317e97f555b23b46b96f8811e8481b5994 -
Trigger Event:
release
-
Statement type: