Skip to main content

Preflight

Preflight is an infrastructure change risk analysis engine that parses Terraform plan JSON to detect destructive operations, security regressions, and architectural risks before deployment.

terraform plan -out=tfplan
terraform show -json tfplan | preflight analyze -

Performance & Quality Metrics

Measured across synthetic benchmarks and automated test suites:

Metric Measured Value Standard
Analysis Latency < 0.50 ms avg per plan Sub-millisecond static evaluation
Detection Rate 100% (11/11 target scenarios) Synthetic test fixtures
False Positive Rate 0 on control fixtures Clean control plans produce 0 findings
Test Coverage 88% statement coverage 105 unit and integration tests
Type Safety 100% strictly typed mypy --strict with zero warnings
Code Quality Zero errors Compliant with ruff linter and formatter
Scoring Determinism 100% bit-for-bit identical Zero drift across 50 sequential runs

Installation

Requires Python 3.12+.

Installs preflight into an isolated global environment so the binary is directly available in any terminal:

# Install from PyPI:
pipx install preflight-engine

# Or install directly from GitHub:
pipx install git+https://github.com/adityacodes-root/Preflight.git

With uv (Fastest)

uv tool install preflight-engine

Standard pip

pip install preflight-engine

From Source (Development)

git clone https://github.com/adityacodes-root/Preflight.git
cd preflight
python -m venv .venv
source .venv/bin/activate  # On Windows: .\.venv\Scripts\Activate.ps1
pip install -e ".[dev]"

Usage

# Pipe directly via stdin (recommended for CI/CD)
terraform show -json tfplan | preflight analyze -
terraform show -json tfplan | preflight analyze - --fail-on high

# Publish or update sticky PR comment in CI
terraform show -json tfplan | preflight comment - --fail-on high

# Generate SARIF report for GitHub Code Scanning
terraform show -json tfplan | preflight analyze - --format sarif --output preflight.sarif

# Analyze a local plan file
preflight analyze plan.json
preflight analyze plan.json --fail-on high
preflight analyze plan.json --environment staging
preflight analyze plan.json --format markdown --output report.md
preflight analyze plan.json --format json --output report.json

Options

Option Flag Description Default
--environment -e development, staging, or production production
--format -f terminal, json, markdown, or sarif terminal
--fail-on Block if findings reach: low, moderate, high, critical None
--output -o Output file path stdout
--config -c Custom YAML configuration path preflight.yaml
--verbose -v Show traceback on error false
--version -V Display version

Exit Codes

Code Status Meaning
0 Pass Analysis completed; no blocking policy conditions triggered.
1 Block Analysis completed; a configured policy threshold was met.
2 Error File not found, invalid JSON syntax, or bad configuration.

CI/CD & GitHub Integration

Preflight integrates directly into CI/CD pipelines to automate infrastructure risk gates and pull request reviews.

Pull Request Sticky Comments (preflight comment)

Posts an infrastructure risk analysis directly to active pull requests. Subsequent commits update the comment in place to prevent notification noise. Repository, token, and PR number are resolved automatically from environment variables (GITHUB_REPOSITORY, GITHUB_TOKEN, and GITHUB_REF).

# In GitHub Actions
terraform show -json tfplan | preflight comment - --fail-on high

# Local test or manual invocation
preflight comment plan.json --repo owner/repo --pr 42 --token $GITHUB_TOKEN --dry-run

SARIF Code Scanning (--format sarif)

Exports findings in OASIS SARIF v2.1.0 to surface inline risk annotations in GitHub Code Scanning, GitLab Security Dashboards, or Azure DevOps.

terraform show -json tfplan | preflight analyze - --format sarif --output preflight.sarif

See .github/workflows/terraform-pr-check.yml for a complete GitHub Actions workflow.


Risk Scoring Model

Preflight scores risks from 0.0 to 100.0 using five weighted dimensions:

Factor Weight Evaluation Scope
Change Impact 30% Structural blast radius (in-place modification vs. resource recreation vs. deletion)
Security Exposure 25% External reachability, administrative port ingress, permissive IAM wildcards
Reversibility 20% Recovery complexity (permanent data loss vs. declarative attribute update)
Environment Criticality 15% Target tier: development (1.0/5), staging (3.0/5), production (5.0/5)
Uncertainty 10% Attributes computed at apply-time that cannot be evaluated statically

$$\text{Score} = \sum_{i} \left( \text{Weight}_i \times \frac{\text{Factor Score}_i}{5.0} \right)$$

Risk Categories

  • 0 – 24.9: Low (tag updates, read-only data sources, benign attribute changes)
  • 25 – 49.9: Moderate (scoped additions, non-destructive replacements)
  • 50 – 74.9: High (recreations, destructive storage operations, broad IAM policies)
  • 75 – 100.0: Critical (public SSH/RDP, disabled S3 access blocks, DB deletion)

Overall plan risk is calculated as the maximum resource-level risk score to prevent critical issues from being masked by volume of benign changes.


Detection Rules

Generic Rules

  • GEN-DEL-001: Resource deletion in plan.
  • GEN-REP-001: Resource replacement (destroy and recreate due to immutable attributes).
  • GEN-ACT-001: Unrecognized or unsupported Terraform lifecycle action sequences.
  • GEN-UNK-001: Computed unknown values in critical configuration fields.
  • GEN-DST-001: Destructive changes to stateful resources (databases, volumes, clusters).

AWS Rules

  • AWS-NET-001: Security group ingress opening administrative ports (22, 3389) or all traffic to 0.0.0.0/0 or ::/0.
  • AWS-S3-001: S3 Public Access Block removal or disabled settings (block_public_acls, block_public_policy, etc.), or public bucket ACLs.
  • AWS-IAM-001: Context-sensitive IAM wildcard policies (* on * is Critical; service-level wildcards on * is High).
  • AWS-DB-001: Deletion or replacement of RDS instances, Aurora clusters, DynamoDB tables, or ElastiCache clusters.

Azure Rules

  • AZR-NET-001: Network Security Group (NSG) rules allowing 0.0.0.0/0 or Internet to ports 22, 3389, or wildcard *.
  • AZR-STG-001: Storage account public blob access or missing firewall restrictions.
  • AZR-KV-001: Azure Key Vault changes with purge_protection_enabled = false or soft delete retention < 7 days.
  • AZR-DB-001: Deletion or replacement of Azure SQL, Cosmos DB, or PostgreSQL flexible servers.

Google Cloud Rules

  • GCP-FW-001: Ingress compute firewall rules allowing 0.0.0.0/0 or ::/0 to sensitive administrative ports (22, 3389) or all traffic.
  • GCP-IAM-001: Cloud Storage bucket IAM bindings or members granting access to allUsers or allAuthenticatedUsers.
  • GCP-SQL-001: Cloud SQL instance deletion, replacement, or disabling deletion_protection.

Kubernetes Rules

  • K8S-SEC-001: Workloads or Helm charts deploying with security_context.privileged: true or hostNetwork: true.
  • K8S-RBAC-001: RoleBindings and ClusterRoleBindings binding to superuser role cluster-admin.

Policy Configuration (preflight.yaml)

environment: production
format: terminal
fail_on: high

blocked_rules:
  - AWS-DB-001
  - AWS-NET-001

allowed_rules: []

max_score: 75.0

Defensive Redaction

Preflight prevents secrets and credentials from appearing in terminal output, CI logs, or pull request comments. The engine recursively redacts:

  • Sensitive key names matching password, secret, token, api_key, private_key, or auth patterns.
  • Terraform plan attributes flagged via before_sensitive and after_sensitive metadata.

Verification & Benchmarks

pytest
pytest --cov=preflight --cov-report=term-missing
ruff check .
ruff format --check .
mypy src tests
python scripts/benchmark.py

License

Apache-2.0

Metadata

Release files for preflight-engine 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for preflight-engine 0.1.0
File Size Uploaded Provenance Actions
preflight_engine-0.1.0.tar.gz 53.3 kB With provenance Details for preflight_engine-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for preflight-engine 0.1.0
File Interpreter ABI Platform Actions
preflight_engine-0.1.0-py3-none-any.whl Python 3 none any Details for preflight_engine-0.1.0-py3-none-any.whl

Total release size: 100.9 kB

Release files / preflight_engine-0.1.0.tar.gz

Download URL preflight_engine-0.1.0.tar.gz
Size 53.3 kB
Tags Source
SHA-256 checksum
How to use checksums
58ecb54c763db0047499a64a882932e6bb2a2b465f925ae820487a917f591826
BLAKE2b-256 checksum
How to use checksums
964790591ab9f7be19cc9cb9c731b914fd7038018683de03d3138c91d2420ff2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Release files / preflight_engine-0.1.0-py3-none-any.whl

Download URL preflight_engine-0.1.0-py3-none-any.whl
Size 47.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4c51c4b227aa7934fdc107ff41f88e0774717d13cef3bedcc04f03e714c0837f
BLAKE2b-256 checksum
How to use checksums
4a0e88ca7d180c906525f93f3eceb168fa6a0ccb429849660d2b7940b3214785
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

Security for preflight-engine 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for preflight_engine-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page