feat(cli): add infraspec check command for pre-apply security checks#213
Open
robmorgan wants to merge 2 commits into
Open
feat(cli): add infraspec check command for pre-apply security checks#213robmorgan wants to merge 2 commits into
infraspec check command for pre-apply security checks#213robmorgan wants to merge 2 commits into
Conversation
Add InfraSpec Gatekeeper - a static analysis tool for Terraform configurations
that catches security misconfigurations before `terraform apply`.
Features:
- New `infraspec check` CLI command with comprehensive flags
- YAML-based rule schema with 10 operators (exists, equals, contains, matches, etc.)
- Logical combinators (all, any, not) for complex conditions
- HCL parser using hashicorp/hcl/v2 with variable resolution
- 13 built-in security rules for S3, Security Groups, VPC, and IAM
- Text output with lipgloss styling and JSON output for CI
- Message templating with {{.resource_name}}, {{.file}}, etc.
Built-in rules:
- S3_001-S3_004: Encryption, versioning, public access, logging
- SG_001-SG_004: SSH/RDP from 0.0.0.0/0, unrestricted ingress/egress
- VPC_001-VPC_002: Flow logs, default security group
- IAM_001-IAM_003: Inline policies, wildcard actions/resources
Exit codes: 0 (pass), 1 (violations), 2 (error)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Convert InfraSpec Gatekeeper to use HCL for rules instead of YAML,
following the `terraform test` pattern with `.tftest.hcl` files.
Key changes:
- Add HCL rule parser using hashicorp/hcl/v2
- Support `.infraspec.hcl` config files (auto-discovered in repo root)
- Support `*.spec.hcl` rule files alongside Terraform code
- Convert all 13 built-in rules from YAML to HCL format
- Add config options: min_severity, format, strict, no_builtin
- Implement rule override semantics (later sources override earlier)
- Maintain backwards compatibility with YAML via extension detection
New file discovery pattern:
- `.infraspec.hcl` found by walking up directory tree
- `*.spec.hcl` files discovered alongside `.tf` files
HCL rule schema supports:
- `rule` blocks with labels for IDs
- `condition` blocks with `check`, `all`, `any`, `not` combinators
- Go template syntax for message interpolation ({{.resource_name}})
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 365 days. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds InfraSpec Gatekeeper - a pre-apply guardrail that performs static analysis on Terraform configurations to catch security misconfigurations before
terraform apply.Features
infraspec check [path...] [flags]terraform testpattern with.spec.hclfilesexists,not_exists,equals,not_equals,contains,not_contains,matches,greater_than,less_than,one_ofall,any,notfor complex conditionshashicorp/hcl/v2with variable resolution (defaults + tfvars){{.resource_name}},{{.resource_type}},{{.file}},{{.line}}.infraspec.hclconfig files and*.spec.hclrule filesFile Discovery Pattern
HCL Rule Example
Config File Example
Built-in Rules
Usage Examples
Exit Codes
0- All checks passed1- One or more violations found2- Parse or configuration errorTest plan
pkg/gatekeeper/rules/hcl_loader_test.go)pkg/gatekeeper/config/config_test.go)pkg/gatekeeper/parser/parser_test.go)pkg/gatekeeper/engine/engine_test.go)pkg/gatekeeper/rules/builtin/builtin_test.go)examples/gatekeeper/🤖 Generated with Claude Code