Skip to main content

Advanced Recommendations for Secure IaC

This annex presents reinforced practices for security in Infrastructure as Code (IaC) projects. The recommendations described here are not mandatory, but should be considered in:

  • Organisations with high security maturity;
  • Regulated environments or environments with certification requirements;
  • Projects with high exposure or risk (e.g. critical infrastructure);
  • Supply chains that require proof of compliance (e.g. SLSA, ISO 27001, DSOMM level 3).

📌 Policy and semantic enforcement with OPA / Sentinel​

ThemeDescription
OPA with detailed Rego rulesCreate rules by resource type, environment and project
Enforcement with Sentinel (TFC/TFE)Apply organisational policies with a Terraform execution gate
Linters with adapted rulesetsUse of Conftest, Checkov or tfsec with a customised profile per project
Comparison with the security baselineValidate deviations from policy per repository/project
Integration with CI/CDCI fails if the execution violates policies

🎯 Reinforces trust, standardises the application of rules and enables proof of compliance.


📊 Reinforced provenance and traceability​

ThemeDescription
Hash and retention of plan filesEach execution must generate a plan file with a hash and retention per version
Execution metadataCommit, branch, tag, user, runner and hash associated with the applied plan
IaC template versionInclude in the repository and in the artefact being deployed
Tamper-proof application recordStore the effective plan and apply in an auditable repository

📎 Facilitates audit, rollback, proof of state and forensic analysis.


🔁 Integration with cost and “drift”​

ThemeDescription
Integration with InfracostCompare the estimated cost per plan with the approved baseline
Continuous drift detectionActive monitoring of differences between code and real infrastructure
Alerts for modifications outside GitVerification of whether an apply occurred outside PRs or the pipeline

🧩 Integration with cost and drift enables early detection of anomalies, and financial and technical control.


🔐 Security in module provenance​

ThemeDescription
Generation of SBOM for templatesRecord the modules, resources and providers used in a readable format
Semantic validation of providersBlocking of unaudited or untested versions
Replacement of external sourcesSpecify internal mirrors, private registries and trusted repositories
Audit of changes to modulesValidate whether changes introduce insecure configurations (e.g. open ACLs)

💡 These practices help treat IaC modules as software, subject to a secure SDLC.


🧪 Programmatic infrastructure tests​

ThemeDescription
terratest with GoTests of resource application and rollback, validating outputs and routes
opa test for policiesUnit tests for security rules written in Rego
kitchen-terraformIntegration tests of temporary environments
Integration into the pipelineAutomatic tests per PR or release, with archived logs and results

🧬 Guarantees that the provisioned infrastructure is functional and secure, validating behaviour beyond syntax.


📋 Governance of technical exceptions​

ThemeDescription
Validation of exceptions with a cycleEach exception with an owner, deadline and formal review
Audit of executions with bypassLogs of bypasses or forced flags analysed periodically
Automation of reassessmentJobs that flag expired exceptions or exceptions due for review
Exception reports per stackCompliance dashboards per project and environment

🧾 Continuous governance of exceptions ensures that technical "security debt" is visible, traceable and reviewed.


✅ Conclusion​

These recommendations are not mandatory, but they constitute valuable reinforcements for teams with high maturity or that operate in regulated contexts.

📌 Their application directly reinforces the Design & Development, Build & Test and Operate & Monitor domains of OWASP DSOMM, making it possible to reach level 3 maturity in security practices applied to IaC.

For applications with an L3 risk classification, it is recommended to consider a subset of these practices as a mandatory baseline.