How delgadoroberto/terraform-s3-security-lab works
1. What this repository is
- This is a local AWS S3 security lab, not a production application.
- The architecture centers on provisioning a single S3 bucket with Terraform, but targeting LocalStack so the AWS APIs are emulated locally.
2. Primary control plane
- The terraform/ directory is the main infrastructure definition boundary.
- main.tf, variables.tf, terraform.tfvars, outputs.tf, and versions.tf define the desired S3 configuration, parameterization, provider/runtime constraints, and exported identifiers for verification.
3. Execution/runtime environment
- Docker runs LocalStack, which acts as the AWS-compatible endpoint.
- Terraform and the AWS CLI are pointed at LocalStack instead of real AWS, using dummy credentials and the local endpoint URL.
- This makes the whole lab self-contained and repeatable on a developer machine.
4. Provisioning flow
- The intended flow is: edit Terraform variables → run terraform init/plan/apply → Terraform calls the S3 API through LocalStack → LocalStack creates the bucket and related settings.
- The Terraform outputs likely provide the bucket name or other identifiers needed for verification.
5. Verification and inspection path
- After provisioning, the AWS CLI is used against the LocalStack endpoint to confirm the bucket exists and inspect its state.
- This is the operational verification boundary: Terraform declares the desired state, and AWS CLI checks the realized state.
6. Security validation subsystem
- Two IaC scanners validate the Terraform code itself:
- Checkov for policy and misconfiguration checks
- Trivy config for IaC/security scanning
- Their reports are stored under scans/, making the repo both a lab and an artifact collection point.
7. Audit automation
- scripts/audit_s3.sh is a Bash-based audit step that checks S3 security posture from the outside, likely focusing on controls such as versioning and public access behavior.
- This script bridges infrastructure provisioning and security validation by testing the deployed resource, not just the code.
8. Security and compliance findings
- The findings/ folder captures discovered issues and remediation notes.
- findings/insecure-config.md and findings/remediation.md suggest the repo is used to document misconfigurations and how they were fixed, which is important for the lab’s learning loop.
9. CI / automation boundary
- .github/workflows/security-pipeline.yml shows there is an automation layer in GitHub Actions.
- Its role is likely to run scans and validations consistently in CI, turning the lab into a repeatable DevSecOps workflow rather than only a manual exercise.
10. Documentation and learning artifacts
- docs/lessons-learned.md and the architecture diagram under architecture/ are supporting artifacts.
- These do not participate in runtime provisioning, but they document decisions, outcomes, and the intended system layout.
11. Data flow summary
- Human edits Terraform config → Terraform provisions via LocalStack → AWS CLI and the audit script verify the bucket → Checkov/Trivy analyze the Terraform code → results are captured in scans/ and findings/.
- The key boundary is between static IaC analysis and runtime resource validation.
12. Architectural constraints that matter
- The system is intentionally local-first and AWS-emulated, so there is no dependency on live cloud infrastructure.
- Security controls emphasized in the lab are S3-focused: versioning, public access restrictions, and general misconfiguration detection.
- The architecture is built for learning, testing, and validation, not for hosting user-facing workloads.
Main entry points: main.tf Main stack · security-pipeline.yml CI pipeline · checkov-report.txt Checkov · trivy-report.txt Trivy config
Components 15
Terraform lab
Main infrastructure boundary for the local S3 provisioning flow.
- Main stack · Defines the S3 bucket and related infrastructure resources.
terraform/main.tf - Variables · Parameterizes bucket and environment settings.
terraform/variables.tf - Lab values · Concrete local lab inputs used for planning and apply.
terraform/terraform.tfvars - Outputs · Exports bucket identifiers and other verification values.
terraform/outputs.tf - Versions · Pins provider and Terraform version constraints.
terraform/versions.tf
Local runtime
LocalStack and CLI-based runtime used to emulate AWS and verify resources.
- LocalStack · Local AWS-compatible endpoint that receives Terraform API calls.
- AWS CLI · Inspects the emulated S3 state after provisioning.
Security validation
Static scans, runtime audits, and captured findings.
- Audit script · Checks deployed S3 security posture from the outside.
scripts/audit_s3.sh - Checkov · Static policy and misconfiguration analysis for Terraform.
scans/checkov-report.txt - Trivy config · IaC security scanning and configuration analysis.
scans/trivy-report.txt - Issues · Captured insecure configuration observations.
findings/insecure-config.md - Remediation · Documented fixes and recovery notes.
findings/remediation.md
Automation
Repository automation that runs validation in GitHub Actions.
- CI pipeline · Automates scans and validation in GitHub Actions.
.github/workflows/security-pipeline.yml
Connections 18
- Versions → Main stack: pins · Constrains the infrastructure stack runtime and provider versions.
- Variables → Main stack: feeds · Provides configurable inputs to the Terraform stack.
- Lab values → Variables: instantiates · Supplies local lab values for the declared variables.
- Main stack → LocalStack: provisions via · Terraform targets the emulated AWS endpoint instead of real AWS.
- Outputs → AWS CLI: verifies with · Exports identifiers used to inspect the created bucket.
- LocalStack → AWS CLI: serves · AWS CLI queries the same local AWS-compatible endpoint.
- Audit script → LocalStack: checks · Runs external security checks against the deployed S3 resource.
- Checkov → Main stack: analyzes · Scans the Terraform definition for policy and misconfiguration issues.
- Trivy config → Main stack: analyzes · Scans the Terraform configuration for security issues.
- Checkov → Issues: records · Captured issues are summarized in findings documentation.
- Trivy config → Issues: records · Captured issues are summarized in findings documentation.
- Issues → Remediation: leads to · Observed issues inform remediation notes.
- CI pipeline → Checkov: runs · CI automates static IaC scanning.
- CI pipeline → Trivy config: runs · CI automates IaC security scanning.
- CI pipeline → Audit script: runs · CI can execute runtime security checks as part of the pipeline.
- Lessons → Remediation: documents · Lessons learned are tied to remediation outcomes.
- Diagram → Main stack: depicts · Diagram documents the main provisioning boundary.
- Diagram → LocalStack: depicts · Diagram documents the local emulation runtime.