Policy as code, OPA/Sentinel, tfsec, checkov — vocabulary for IaC security scanning and policy enforcement. Advanced
0 / 15 completed
1 / 15
A platform engineer says: "We integrated tfsec into the CI pipeline — it blocked a PR last week for an open security group."
What does tfsec do?
tfsec (now integrated into Trivy as trivy config) is a static analysis security tool (SAST) for Terraform configurations. It detects misconfigurations before any infrastructure is deployed.
shift-left security — catching misconfigurations in PRs rather than discovering them in production
misconfigurations as code — the class of vulnerabilities where the infrastructure definition itself is the security flaw
2 / 15
A security engineer writes compliance rules in OPA (Open Policy Agent) using the Rego language and integrates them into the CI pipeline for Kubernetes resource review.
What is "policy as code"?
Policy as code transforms governance from static documents into executable, version-controlled, automatically enforced rules:
Tool
Language
Target
OPA / Rego
Rego
Kubernetes admission, API gateways, Terraform plan JSON
Terraform Sentinel
Sentinel
Terraform Cloud/Enterprise plan evaluation
cfn-guard
Guard DSL
CloudFormation templates
cdk-nag
TypeScript
AWS CDK constructs at synth time
Hard enforcement — policy blocks deployment; cannot be bypassed
Soft enforcement — policy logs violations or notifies but does not block
Policy guardrails in CI — automated checks in the pipeline before code reaches production
3 / 15
Terraform Sentinel policies are categorised as "advisory", "soft-mandatory", and "hard-mandatory".
What does "soft-mandatory" mean?
Terraform Sentinel has three enforcement levels with different compliance implications:
Level
Behaviour when policy fails
Override possible?
Advisory
Logs a warning only — apply proceeds regardless
N/A — never blocks
Soft-mandatory
Blocks apply; authorised users can override with justification
Yes — by users with override permission
Hard-mandatory
Blocks apply; no override is possible by anyone
No — absolute enforcement
Policy override — the mechanism allowing authorised exceptions to soft-mandatory policies, typically with an audit log entry
Compliance gate — a checkpoint in the deployment pipeline that requires policy checks to pass before proceeding
Break-glass — emergency override procedures for time-critical situations that bypass normal controls
4 / 15
A checkov scan on a Terraform plan returns the following finding:
Check: CKV_AWS_18: "Ensure the S3 bucket has access logging enabled"
FAILED for resource: aws_s3_bucket.artifacts
File: main.tf, Line 12
What is the purpose of S3 access logging enforced by this checkov rule?
S3 access logging records every request to the bucket (GET, PUT, DELETE operations) including: requester IP address, timestamp, HTTP status code, bytes transferred, and object key accessed.
Use case
How access logs help
HIPAA / PCI compliance
Demonstrates audit trail of who accessed regulated data
Incident investigation
Identify which IPs downloaded files before a breach was detected
Data exfiltration detection
Anomalous volume of GET requests may indicate exfiltration
S3 access logs vs. CloudTrail — CloudTrail records AWS API calls (e.g. creating a bucket); S3 access logs record object-level operations (e.g. downloading a file) — both are often required for full audit coverage
CKV check identifiers — checkov uses IDs like CKV_AWS_18 to identify specific policy checks, enabling suppression of false positives in .checkov.yaml
5 / 15
A platform team's IaC pipeline is configured so that developers can run terraform apply for dev and staging environments but production applies are executed exclusively by the CI/CD service account after approvals.
What pattern is this implementing in an IaC context?
This is the environment promotion with RBAC pattern — a core principle of mature IaC workflows.
Environment
Who can apply
Approval required
dev
Developers directly
None
staging
Developers directly or CI
Optional PR review
production
CI/CD service account only
Mandatory PR approval + plan review
environment promotion — changes flow through environments in sequence (dev → staging → prod) before reaching production
immutable production changes — only reviewed, pipeline-executed changes reach production, never ad-hoc manual applies
CI/CD service account scoping — the service account has only the IAM permissions needed for production Terraform, not full admin access
break-glass procedures — documented emergency process for production access if CI/CD is unavailable
6 / 15
Review Comment: 'This Terraform module uses public S3 buckets. We need to ensure all data is encrypted at rest and in transit—consider using KMS for key management and TLS for transport.' What security best practice does this comment primarily address? tfsec
This comment focuses on TLS, which is a fundamental best practice for securing network traffic. While encryption at rest and key management are related concerns, the reviewer explicitly highlights protecting communication. The GDPR reference is tangential – while relevant to data protection in general, it wasn't the direct focus of the comment.
7 / 15
Slack Message from @johndoe: 'Just ran a Checkov scan on our new Kubernetes deployment. It flagged a bunch of insecure IAM roles - we need to tighten up the least privilege principle!' What concept is @johndoe referencing when discussing 'least privilege'? OPA
'Least privilege' is a core security principle that restricts users and services to the minimum level of access required. It's crucial for reducing the potential damage from compromised credentials or errors. Granting full access (option A) directly contradicts this principle.
8 / 15
PR Description: 'Applying Terraform changes to provision a new web server. We've added a Sentinel policy to ensure all instances are tagged with a unique identifier and have their security groups configured according to our approved templates.' What is the primary function of integrating Sentinel policies into this Terraform workflow? Terraform Sentinel
Terraform Sentinel's core purpose is to ensure that Terraform code adheres to defined policies. This involves validating configurations against rules before they are applied, preventing potentially insecure or non-compliant deployments. The other options describe features of IaC tools but not the policy enforcement aspect.
9 / 15
Standup Update from @alice: 'We're using OPA to define our infrastructure security policies as code. We've been focusing on implementing a policy that mandates encryption for all sensitive data at rest within our cloud environments.' What is the fundamental benefit of expressing these security rules as Rego rather than traditional configuration files?
Defining security policies as code (policy-as-code) with tools like OPA allows for automated enforcement. This eliminates the need for manual checks and reduces operational overhead. While flexibility and auditability are benefits, automated enforcement is the primary advantage of using a policy engine.
10 / 15
API Response (Checkov Scan Result): `{"status":"failure", "code":404, "message":"Resource not found: aws_s3_bucket.artifacts"}`. This response indicates a problem with a Checkov scan. What is the most likely reason for this failure? Checkov
A '404 Not Found' error typically indicates that the resource referenced by Checkov (the `aws_s3_bucket.artifacts` resource) cannot be located within the specified environment. This could be due to a missing or incorrectly configured Terraform configuration file.
11 / 15
Review Comment: 'This Terraform module uses public S3 buckets. We need to ensure all data is encrypted at rest and in transit—consider using KMS for key management and TLS for transport.' What security best practice does this comment primarily address? tfsec
This comment focuses on TLS, which is a fundamental best practice for securing network traffic. While encryption at rest and key management are related concerns, the reviewer explicitly highlights protecting communication. The GDPR reference is tangential – while relevant to data protection in general, it wasn't the direct focus of the comment.
12 / 15
Slack Message from @johndoe: 'Just ran a Checkov scan on our new Kubernetes deployment. It flagged a bunch of insecure IAM roles - we need to tighten up the least privilege principle!' What concept is @johndoe referencing when discussing 'least privilege'? OPA
'Least privilege' is a core security principle that restricts users and services to the minimum level of access required. It's crucial for reducing the potential damage from compromised credentials or errors. Granting full access (option A) directly contradicts this principle.
13 / 15
PR Description: 'Applying Terraform changes to provision a new web server. We've added a Sentinel policy to ensure all instances are tagged with a unique identifier and have their security groups configured according to our approved templates.' What is the primary function of integrating Sentinel policies into this Terraform workflow? Terraform Sentinel
Terraform Sentinel's core purpose is to ensure that Terraform code adheres to defined policies. This involves validating configurations against rules before they are applied, preventing potentially insecure or non-compliant deployments. The other options describe features of IaC tools but not the policy enforcement aspect.
14 / 15
Standup Update from @alice: 'We're using OPA to define our infrastructure security policies as code. We've been focusing on implementing a policy that mandates encryption for all sensitive data at rest within our cloud environments.' What is the fundamental benefit of expressing these security rules as Rego rather than traditional configuration files?
Defining security policies as code (policy-as-code) with tools like OPA allows for automated enforcement. This eliminates the need for manual checks and reduces operational overhead. While flexibility and auditability are benefits, automated enforcement is the primary advantage of using a policy engine.
15 / 15
API Response (Checkov Scan Result): `{"status":"failure", "code":404, "message":"Resource not found: aws_s3_bucket.artifacts"}`. This response indicates a problem with a Checkov scan. What is the most likely reason for this failure? Checkov
A '404 Not Found' error typically indicates that the resource referenced by Checkov (the `aws_s3_bucket.artifacts` resource) cannot be located within the specified environment. This could be due to a missing or incorrectly configured Terraform configuration file.
What will I practise in "IaC Security & Compliance Language Exercises"?
Practice English for IaC security: tfsec, checkov, policy as code, OPA/Sentinel enforcement levels, S3 access logging, and environment promotion RBAC vocabulary for senior DevOps and security engineers.
How many exercises are in this module?
This module has 15 multiple-choice exercises, each with instant feedback and a full explanation of the correct answer.
Is this exercise free to use?
Yes. Every exercise on CoderSlingo, including this one, is free to use with no account, sign-up, or paywall.
Do I need to create an account to do these exercises?
No account is required. Just click an option to answer — your score for this session is tracked automatically in the progress bar above.
What happens if I choose the wrong answer?
You'll immediately see which answer was correct, plus a full explanation covering the vocabulary and reasoning behind it — mistakes are where most of the learning happens.
Can I retry the exercises if I want a higher score?
Yes — use the "Try again" button on the results screen to reset and go through all the questions again.
Is my progress saved if I close the page?
No. Progress is tracked only for your current visit; reloading or leaving the page resets the counter. This keeps the exercise simple and account-free.
Where can I find more Infrastructure as Code exercises?
Browse the full Infrastructure as Code hub for related drills, or check the "Next up" link below to continue with a connected topic.
How is this different from reading an article on the same topic?
Articles explain vocabulary and concepts in prose; this exercise tests and reinforces that vocabulary through active recall with immediate feedback — the two work best together.
Who writes these exercises?
Every exercise is written by the CoderSlingo team, drawing on real workplace English used in IT roles, then reviewed for accuracy and clarity.