Compliance Automation and Tooling Questions
Using technology to make compliance continuous rather than point-in-time. Covers GRC platforms and control libraries (build versus buy, one control set mapped to many regulations, requirement-to-evidence traceability, risk roll-ups), compliance-as-code and policy-as-code checks mapped to framework controls (including testing, versioning and retiring the rules, and turning local legal and privacy obligations such as retention and masking into machine-checkable tests), continuous control monitoring and drift alerts, automated evidence collection and tamper-evident evidence pipelines for auditors, automated compliance and privacy reporting with traceable lineage (including regulatory SLA tracking such as DSAR deadlines), and wiring compliance checks into engineering pipelines without slowing teams. Focuses on what to automate first, how to map controls to machine-checkable tests, where to place checks, and the limits of automation. Does not cover designing or testing the controls themselves, the content of individual frameworks, hands-on security mechanics such as secrets, IAM, scanning or logging pipelines, or conducting the audit.
An internal review finds that production configurations across your cloud and on-premises estate have quietly drifted from the approved baseline, and the next audit asks you to prove they stay aligned. How would you set up automated baselining and drift detection, decide what auto-remediates versus what becomes a ticket, and keep the evidence the auditors will want?
Sample Answer
Direct answer
Treat the approved baseline as code in version control, compare reality to it on a schedule and on every change, and split findings by blast radius (how much could break, and for how many users, if the automatic fix is wrong): auto-revert the ones that are reversible and clearly wrong, ticket the ones that could break something or need a decision. Every detection, action and exception is logged, since that log is the audit evidence.
1. Establish the baseline
Define approved settings per system class (hardened server image, database, storage, network rules), based on an accepted benchmark such as a CIS Benchmark (a hardening checklist published by the Center for Internet Security, with recommended settings for operating systems, clouds and databases) where one exists, and keep them in git. Baseline changes go through review, so the baseline itself has a history.
2. Detect drift in three places
- Before it ships (pre-commit and CI): check infrastructure-as-code against the same baseline. Policy checks run on every pull request.
- Against reality:
terraform plan -detailed-exitcodeexits 0 for no changes, 1 for error and 2 when the plan differs from real state, which makes a scheduled drift job simple.terraform plancompares three things: the code, Terraform's state (its record of the resources it created) and what actually exists in the cloud, then lists what it would change to make reality match the code. Run on a schedule against code that has not changed, any difference it reports is drift rather than a pending change. Cloud inventory and configuration services cover resources not under code. On-premises hosts need an agent or configuration-management tool run in check mode (a dry run that reports what it would change without changing anything). - Across many repos and teams: publish the baseline as a shared rule library and make the pipeline template mandatory through organisation-level required checks (a setting on the code-hosting platform that makes chosen checks mandatory before a merge in every repository), so a new team inherits enforcement, not a to-do list.
3. Decide: auto-remediate or ticket
Auto-remediate only if the change is reversible, the correct state is unambiguous, the blast radius is small and the fix has been tested. Ticket if it touches stateful or application-specific settings, could cause an outage, or may be an approved exception. Always fix the code too (the code is the source of truth, the one place the approved state is defined), or the next apply reintroduces the drift.
Worked example (code run, output pasted)
import json
baseline = {
"bucket-logs": {"encryption": "aws:kms", "public_access_block": True, "versioning": True},
"sg-web": {"ingress_ports": [443], "ssh_open_to_world": False},
"db-prod": {"storage_encrypted": True, "backup_retention_days": 7},
}
observed = {
"bucket-logs": {"encryption": "aws:kms", "public_access_block": False, "versioning": True},
"sg-web": {"ingress_ports": [443, 22], "ssh_open_to_world": True},
"db-prod": {"storage_encrypted": True, "backup_retention_days": 3},
}
AUTO_FIX = {("bucket-logs", "public_access_block"), ("sg-web", "ssh_open_to_world")}
def diff(base, obs):
for res, want in base.items():
for key, expected in want.items():
actual = obs[res][key]
if actual != expected:
yield res, key, expected, actual
for res, key, expected, actual in diff(baseline, observed):
action = "AUTO-REMEDIATE" if (res, key) in AUTO_FIX else "TICKET"
print(json.dumps({"resource": res, "setting": key, "expected": expected,
"actual": actual, "action": action}))
Output:
{"resource": "bucket-logs", "setting": "public_access_block", "expected": true, "actual": false, "action": "AUTO-REMEDIATE"}
{"resource": "sg-web", "setting": "ingress_ports", "expected": [443], "actual": [443, 22], "action": "TICKET"}
{"resource": "sg-web", "setting": "ssh_open_to_world", "expected": false, "actual": true, "action": "AUTO-REMEDIATE"}
{"resource": "db-prod", "setting": "backup_retention_days", "expected": 7, "actual": 3, "action": "TICKET"}
Reading the code: baseline is the approved state and observed is what a scan found, each a set of settings per resource. AUTO_FIX is the short allow-list of (resource, setting) pairs that are safe to revert without a person. diff walks every approved setting, compares it with the observed value, and yields a record only where they differ. The loop at the bottom labels each difference AUTO-REMEDIATE if it is on the allow-list and TICKET otherwise, so anything not explicitly judged safe goes to a human by default.
Four drifts, two auto-fixed, two ticketed. Closing SSH to the world is revert-safe, but an extra open port may be something an application needs, so a person decides. Shortened backup retention is a data-protection decision, not a safe revert.
4. Evidence for the auditor
Keep the baseline version, each scan result with timestamp, each remediation (who or what, when, before and after values), exceptions with approver and expiry, and time to remediate by severity. Show the drift rate trending down, not a flat zero.
Pitfalls
- Auto-remediation fighting the deployment tool in a loop. Fix the source of truth first.
- Remediating with no notification: owners should learn their change was reverted.
- A baseline nobody updates trains people to ignore drift reports.
Your organisation has hundreds of policy-as-code rules written by different teams across clouds, and some rules are noisy, stale or contradictory. How would you test, version, roll out and retire policies safely (including warn-before-enforce), who owns them, and how do you handle exceptions and drift?
Sample Answer
Direct answer
Treat policy rules like production software with a named owner: every rule has tests, a version, a mode (warn or enforce), an expiry-dated exception path, and a retirement route. Roll out in the order test, warn, enforce on new resources, enforce everywhere. Retire a rule only after confirming the control it tested is still covered by another rule.
Ownership
- Rule content: the team that owns the risk (security for baseline guardrails, data platform for retention rules, each product team for its own service rules). Each rule file carries an owner field and is protected by CODEOWNERS (a repository file that forces the named team to approve changes).
- The platform: a small central team owns the engine, the shared test harness, the registry (the central catalog where released rule versions are stored) and the promotion pipeline (the automated steps that move a rule from test to warn to enforce). It does not own the content, otherwise it becomes the bottleneck and the rules go stale.
- Intent first: write each requirement once as a control objective (the outcome the rule protects, such as "storage is encrypted at rest"), then map it to per-cloud rules. Contradictions are then visible as two rules mapped to one objective.
Test
Every rule ships with unit tests against fixture resources (small JSON documents describing a compliant and a non-compliant resource). In CI, run the whole rule set against one shared fixture corpus (the shared collection of those fixture documents): two rules that give opposite answers on the same fixture fail the build, which is how contradictory rules from different teams get caught. The Open Policy Agent (OPA, an open-source policy engine) policy below, written in Rego (OPA's rule language), is a runnable example with a mode switch and expiring exceptions. Save the first block as s3_encryption.rego and the second as s3_encryption_test.rego.
package policy.s3_encryption
import rego.v1
# Rule metadata lives in data.rules; this file is the rule logic.
# data.rules["s3-encryption"] = {"mode": "warn" | "enforce", "owner": "...", "version": "1.2.0"}
# data.exceptions = [{"rule": ..., "resource": ..., "expires": "YYYY-MM-DD", "ticket": ...}]
default decision := {"action": "allow", "violations": []}
violated contains res.id if {
some res in input.resources
res.type == "bucket"
not res.encrypted
not excepted(res.id)
}
excepted(id) if {
some e in data.exceptions
e.rule == "s3-encryption"
e.resource == id
e.expires >= input.today
}
mode := data.rules["s3-encryption"].mode
decision := {"action": "deny", "violations": sort(violated)} if {
count(violated) > 0
mode == "enforce"
}
decision := {"action": "warn", "violations": sort(violated)} if {
count(violated) > 0
mode == "warn"
}
package policy.s3_encryption_test
import rego.v1
import data.policy.s3_encryption
base := {"today": "2026-10-04", "resources": [
{"id": "logs", "type": "bucket", "encrypted": true},
{"id": "scratch", "type": "bucket", "encrypted": false},
{"id": "legacy", "type": "bucket", "encrypted": false},
]}
exc := [
{"rule": "s3-encryption", "resource": "legacy", "expires": "2026-12-31", "ticket": "RISK-101"},
]
test_warn_mode_never_blocks if {
d := s3_encryption.decision with input as base
with data.rules as {"s3-encryption": {"mode": "warn"}}
with data.exceptions as exc
d == {"action": "warn", "violations": ["scratch"]}
}
test_enforce_mode_denies_unexcepted_only if {
d := s3_encryption.decision with input as base
with data.rules as {"s3-encryption": {"mode": "enforce"}}
with data.exceptions as exc
d == {"action": "deny", "violations": ["scratch"]}
}
test_expired_exception_stops_applying if {
late := object.union(base, {"today": "2027-01-01"})
d := s3_encryption.decision with input as late
with data.rules as {"s3-encryption": {"mode": "enforce"}}
with data.exceptions as exc
d == {"action": "deny", "violations": ["legacy", "scratch"]}
}
test_clean_input_allows if {
clean := {"today": "2026-10-04", "resources": [{"id": "logs", "type": "bucket", "encrypted": true}]}
d := s3_encryption.decision with input as clean
with data.rules as {"s3-encryption": {"mode": "enforce"}}
with data.exceptions as []
d.action == "allow"
}
$ opa test s3_encryption.rego s3_encryption_test.rego
PASS: 4/4
Reading the Rego in plain language. default decision := ... is the fallback answer, "allow" with no violations, used when no other decision rule applies. violated contains res.id if { ... } builds a set of resource ids: some res in input.resources loops over every resource, and the id is added only when all the lines in the body hold (it is a bucket, it is not encrypted, and no exception covers it). excepted(id) is a small helper that is true when some exception row names this rule and this resource and has not yet expired (ISO dates compare correctly as text). mode := ... reads the warn or enforce setting from configuration data. The last two decision rules each apply only when there is at least one violation and the mode matches, so exactly one fires and sort keeps the violation list in a stable order. In the test file, with input as base swaps in the test's own input for that one evaluation, and with data.rules as ... and with data.exceptions as ... swap in test configuration, which is how one rule file is exercised in both modes. Tracing the first test: logs is encrypted, legacy is covered by an exception that expires 2026-12-31 (not before 2026-10-04), so only scratch is violated, and warn mode returns warn. After 2027-01-01 the exception no longer applies, so both legacy and scratch are denied.
The tests pin three behaviors: warn mode never blocks, enforce mode blocks only unexcepted violations, and an exception stops applying after its expires date.
Version and roll out (warn before enforce)
| Stage | Behavior | Gate to move on |
|---|---|---|
| 1. Test | Runs in CI on fixtures only | Unit tests plus the conflict check pass |
| 2. Warn | Evaluates real resources, reports, blocks nothing | Warning triage shows a low false-positive rate |
| 3. Enforce new | Blocks only resources created or changed after the date | Owners have a remediation path |
| 4. Enforce all | Blocks or auto-remediates existing resources too | Remaining exceptions are approved and dated |
Use semantic versions (numbers in MAJOR.MINOR.PATCH form, where a major bump such as 1.2.0 to 2.0.0 signals a change that can break existing users, here a rule that gets stricter) and pin each pipeline to a version so a rule change never lands unannounced. The promotion gate is a number, not a feeling. Illustrative: if a rule raised 200 warnings in 30 days and owners triaged 38 as false positives, that is 38 / 200 = 19%. I would not promote it, because roughly one block in five that enforcement produced would be a false block (the 19% is a share of the warnings, not a share of all deploys, so how many deploys it hits depends on how many deploys trigger the rule at all). Fix the logic, restart the clock. Pick your own threshold with the owners; the point is that one exists before warn mode starts.
Exceptions
Exceptions are data, not rule edits: rule, resource, approver, ticket, mandatory expiry date. Expired ones stop applying automatically (tested above), and the count of active exceptions per rule is a key risk indicator (KRI, a metric that signals rising risk). A rule with many exceptions is usually a bad rule, which feeds retirement. Accepting a lasting exception is a risk acceptance (a formal, recorded decision to live with a known risk) and belongs to the risk owner (the named person with authority over the affected system or business area), not to the engineer who wants the deploy.
Drift and remediation playbooks
Drift means live state no longer matches the desired state in infrastructure-as-code (infrastructure described in version-controlled files, such as Terraform). Detect it by evaluating the same rules against live cloud state on a schedule. Route by blast radius (how much could break if you fix it): auto-revert for safe, reversible fixes such as turning encryption on; open a ticket with a deadline for owner-fixed items; page someone only when exposure is active, such as a public bucket holding sensitive data. Every automatic fix writes an evidence record and notifies the owner.
Retire
Flag noisy rules (high false-positive rate from triage labels) and stale ones (no hits for a long period, or targeting a service or API that changed). Move a retiring rule to warn or audit-only first (a mode that evaluates and records results but never blocks), check the control-to-rule mapping so no control loses its only test, then delete it. Git history keeps the record for the auditor.
What would change my call
If rules are few and one team owns them all, skip the central platform. If a rule guards regulated data, skip the long warn stage and enforce on new resources immediately with a fast exception path.
Leadership wants to know, every day rather than once a year, whether encryption, admin MFA and logging are actually in place across your cloud accounts. How would you build a continuous control monitoring pipeline for that, what would you do when a check fails, and how would you keep the results usable as evidence for internal and external auditors?
Sample Answer
Direct answer
Build a daily loop: collect configuration state from every cloud account, evaluate it against a small set of rules, store every result as timestamped evidence, route failures to owners with deadlines, and report pass rate and age of open failures to leadership. This is continuous control monitoring (CCM): automated, frequent testing of whether a control is in place, instead of one annual check.
Pipeline
- Collect. Use the cloud provider's configuration service in every account and aggregate centrally. On AWS, AWS Config is the service that records the settings of resources in an account and checks them against rules, and its managed rules (rules AWS ships ready-made) fit the three asks:
S3_BUCKET_SERVER_SIDE_ENCRYPTION_ENABLED(storage buckets encrypted by default),ROOT_ACCOUNT_MFA_ENABLED(root user requires multi-factor authentication) andCLOUD_TRAIL_ENABLED(an audit-log trail is enabled). Admin MFA for day-to-day administrators needs a check on the identity provider (IdP, the system that signs people in, such as Okta or Microsoft Entra ID) or IAM users too, since the root rule covers only the root user. - Evaluate. Each rule returns compliant, non-compliant or not applicable per resource. Treat not applicable carefully:
ROOT_ACCOUNT_MFA_ENABLEDreturns it when no root credentials exist, which is fine, but a rule that is not applicable because the feed is broken is not. - Store as evidence. Write each result (account, resource, rule and version, result, timestamp) to write-once storage (storage where saved records cannot be edited or deleted for a set period) with a hash, so the history cannot be quietly rewritten.
- Report. Executives see pass rate by control and open-failure age; engineers see the failing resource.
When a check fails
| Step | Action |
|---|---|
| Triage | Ticket auto-created with resource, owner (from tags), severity |
| Fix SLA (service-level agreement, the promised deadline for fixing) | Set by severity, for example days for high and weeks for low (agree it with the business) |
| Exception | Allowed only with a named approver and an expiry date, so it re-appears later |
| Closure | Retest passes and the passing result is stored next to the failing one |
Making results usable for auditors
- Keep the rule definition, its version and the framework control it supports (for example NIST SP 800-53, a US government catalogue of security controls, where IA-2(1) is the entry in the identification and authentication family that requires multi-factor authentication for privileged accounts) next to the results.
- Keep both failures and fixes; auditors trust a record that shows problems being found and closed more than one that shows no failures at all.
- Record gaps: if the collector was down on Tuesday, say so rather than leaving a hole.
- Sample the automation, because auditors still test whether the rule means what you say it means. A typical sample: the auditor picks a few accounts and dates, checks that the live setting matches the stored result for that date, and picks a few failed checks to confirm a ticket was opened and closed within the promised deadline.
Worked example
40 accounts times 3 checks is 120 evaluations per day. Two fail (one unencrypted bucket, one account with logging off): 118 of 120 pass, 98.3%. Over a year that is 43,800 data points, against one sample on one day in a point-in-time audit.
Limits
A passing rule shows the setting, not that it is the right setting. For example, a trail being enabled does not prove it covers every region or that anyone reviews it. Pair CCM with periodic effectiveness testing.
Your company passes its annual audit every year, yet a misconfiguration sat live for months between audits and nobody noticed. How would you explain to a newer engineer why point-in-time compliance fails, and which checks would you automate first to make compliance continuous?
Sample Answer
Direct answer
An annual audit is a snapshot: it checks a sample of evidence from a window and passes you if what it looked at was in order. It says little about the days it did not look at. Continuous compliance replaces the occasional look with automated checks that run all the time, so a problem is found in hours or days, not at the next audit.
An analogy for a newer engineer
A yearly car inspection can pass a car whose brake warning light came on in March. Continuous compliance is the warning light: it tells you when the problem starts. The inspection still matters, because it checks that the light itself works.
Why point-in-time fails
- Sampling: auditors test a sample, meaning a small subset of records picked from the period, not every day of it.
- Preparation effect: teams tidy up before the audit, so the audited state is not the typical state.
- Gap: if a misconfiguration is live for 90 days, that is 90 of 365, about 24.7% of the year, with nobody watching.
- Cost of lateness: a problem found months later has had months to be exploited and is harder to trace.
What I would automate first
A baseline is the approved list of settings a system should have, so most of these checks are comparisons against it. Pick checks that are objective, frequent and costly when wrong:
- Configuration baselining: encryption on, public exposure off, admin MFA on, logging on. The check compares live state to that baseline daily.
- Change management evidence: every production change links to a reviewed, approved pull request, and the pipeline flags changes with no approval.
- Immutable artifacts: build once, sign, and deploy that exact artifact; servers are replaced, not hand-edited. An artifact is the packaged build output (a container image or a program file). Signing means the build system attaches a cryptographic stamp made from the artifact's contents and a secret key, and the deploy step refuses anything whose stamp does not verify. If someone edits the file by hand, its contents change, the stamp no longer matches, and the edit becomes a detectable difference. The artifact's hash (a short fingerprint of its bytes) recorded at deploy time shows exactly what was deployed.
- Alert health: check that logging and alerting still work, since silent failure here undermines all the others.
For example, a change record might read: change 4812, reviewed and approved by a named second person, merged at 14:02, artifact hash recorded, deployed at 14:09 (illustrative). For alert health, a daily test event must appear in the alerting system within a set time, and the record shows the last pass. These signals double as audit evidence: baseline scan results, change records with approvals and artifact hashes are exactly what an auditor asks for, already timestamped.
Worked example
The annual audit passed in January. A storage bucket became public in March and stayed so until July. A daily baseline check would have failed on day one in March, opened a ticket, and the fix would be visible as evidence. The July discovery would not exist.
Caveats
Automation covers what can be measured; policies, training and judgement calls still need people. Start with a handful of checks that matter, not a hundred that nobody reads.
You are advising a team that must show continuous compliance for its cloud workloads, and the budget allows checks at only some points: before deploy, against the live cloud configuration, or from runtime and log signals. How would you decide where to place checks, what blind spots and false positives each placement brings, and how would you combine them?
Sample Answer
Direct answer
If the budget allows one placement, I would start with checks against the live cloud configuration, because it shows what actually exists and is the strongest evidence of continuous compliance. I would add pre-deploy checks next, driven by the same rules, because they stop problems cheaply, and use runtime and log signals only for the controls the other two cannot see. The three placements are not alternatives to rank; they answer different questions.
The three placements
Read the first row of the table first: each placement answers a different question, and the rows below it say where that placement is blind. Infrastructure-as-code means describing cloud resources in files (Terraform is a common tool) that a pipeline applies, instead of clicking in a console.
| Pre-deploy (infrastructure-as-code and pipeline) | Live cloud configuration | Runtime and log signals | |
|---|---|---|---|
| Question answered | Would this change break a rule? | Is this resource compliant right now? | Is the control actually working or being bypassed? |
| Strength | Cheapest fix, blocks before exposure, developer feedback in minutes | Ground truth for every resource, including out-of-band changes (made outside the pipeline, such as a console click) | Sees behaviour: real access, unusual admin activity |
| Blind spots | Anything created outside the pipeline, drift after deploy (a live setting changing away from what the code said), settings only known at runtime | Short window between change and next scan, no view of behaviour | Slow, noisy, needs good logs, silent about quiet misconfigurations |
| Typical false positives | Rule sees code, not the effective result (for example flags a bucket ACL (access control list) that an account-level public access block, a single AWS switch for the whole account that overrides public settings on its buckets, already overrides) | Tolerated exceptions, resources mid-deployment, ephemeral (short-lived, temporary) test accounts | Legitimate admin work and batch jobs that look like attacks |
| Preferred when | Most infrastructure goes through code and review | Evidence for auditors, mixed or legacy estates | Controls about behaviour: who used access, detection coverage |
Deciding where to put the first check
- What share of infrastructure is created through code? Suppose 400 of 500 buckets come from code (80%). Pre-deploy checks can then see 400 of them and miss the other 100, which only a live scan reaches; the higher the share, the more of the problem pre-deploy catches.
- Is there drift or manual change today? If yes, live configuration is mandatory, since pre-deploy cannot see it.
- Is the control about configuration or behaviour? Encryption and public exposure are configuration; "admins only use MFA" and "detections fire" are behavioural.
- What does the auditor accept as evidence? Live state with timestamps is the easiest to defend.
Combining them with one rule set
Write each rule once, tag it with the control it supports, and run it at two points. Disagreement is signal: a pass at deploy and a fail live means drift or an out-of-band change, so reconcile results by control and resource. Reserve runtime signals for a short list (privileged access use, detection of the control being disabled).
Worked example: a public storage bucket
- Pre-deploy: the plan shows
aws_s3_bucket_acl.sitewithacl = "public-read". A rule likeACL 'public-read' makes the bucket publicly readablefails the pipeline step, so the merge is blocked (or passes it with a note if the account-level block applies). - Live: a console user flips another bucket public at 3pm. The AWS Config rule
S3_BUCKET_PUBLIC_READ_PROHIBITED(it checks Block Public Access, the bucket policy and the ACL) re-evaluates on the configuration change and marks that bucket NON_COMPLIANT within minutes; a periodic scan would catch it at the next run. - Runtime: the bucket's access logs show GET requests where the requester field is
-(an unauthenticated request) with operationREST.GET.OBJECT, which turns a misconfiguration into a possible incident.
What would change the call
Mostly code-driven shop with strong review: pre-deploy first. Heavy regulatory detection requirement: raise runtime priority. Very small team: a managed live-posture service (a cloud or vendor product, such as AWS Security Hub or Microsoft Defender for Cloud, that runs configuration checks against your live accounts for you) with a short rule list beats a custom stack.
Unlock Full Question Bank
Get access to all 6 Compliance Automation and Tooling interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.