Skip to content

operationalwrocław--:-- cet

RITE NRG

∕ insights / security-as-code.md

Security As Code

Security as Code: How to Build Controls Into Delivery

Learn what security as code means, the four patterns to implement, and how to measure whether automated controls protect delivery without slowing it.

>_article.meta

published
2026-11-01
reading_time
13 min read
topics
security as code, policy as code, DevSecOps, CI/CD security, IaC security

#01/article

Security as Code: How to Build Controls Into Delivery

Your team ships faster every sprint, but security still arrives as a late review, a spreadsheet, or a reason to delay launch. That gap costs you twice. You lose time to market, and you fix problems when they're most expensive to change. Security as code closes that gap by turning security requirements into version-controlled, executable controls that run on every change, with a named owner for every exception and evidence you can show an auditor without a scramble.

What Security as Code Means in Practice

It's Friday afternoon. Your team has finished a feature, the release notes are ready, and a security review finds an open storage bucket that should've been caught weeks earlier. Nobody meant to expose it. The setting was in a template, the template was copied, and no check ran until the end.

That's the relatable failure security as code is built to prevent. Think of building codes written into blueprints instead of checked only at final inspection. The rule about storage, encryption, or approved libraries lives as code, runs in the pipeline, and gives the same answer every time.

A diagram explaining Security as Code concepts, showing a team releasing software while identifying security vulnerabilities early.

Three Business Outcomes, Not Just More Tools

Done well, this shift gives you fewer late-stage surprises that delay launches, because checks run while the code is still fresh. It lowers remediation effort for the same reason. And it produces audit evidence automatically, so your team isn't assembling screenshots the week before an audit.

The idea grew out of the DevOps shift toward treating infrastructure, configuration, testing, and deployment rules as version-controlled artifacts. The 2016 State of DevOps Report, which surveyed more than 4,600 technical professionals worldwide, found that high-performing software-delivery organizations spent 50% less time remediating security issues than low-performing organizations.

That result points to a practical principle. Security works better when it's embedded in everyday delivery, not postponed until a final audit. Buying a scanner doesn't give you that. A scanner is one tool, and a tool without ownership, tuning, and an exception process quickly becomes noise.

Security requirements, expressed as code, enforced automatically at every change.

That's the definition you can repeat to a colleague. If a requirement can't be expressed, tested, and enforced that way, it's still guidance, and guidance gets skipped under deadline pressure.

Four Security-as-Code Patterns and Where They Run

Start with placement. A control only helps if it runs at the point where a team can still fix the problem cheaply, and if you know whether it's allowed to stop a release.

Pattern Where It Runs What It Catches Blocks Delivery?
Policy as code Pull request checks and deployment admission Rules on approved libraries, configurations and deployment conditions Yes, for critical rules only
IaC hardening scans Pre-merge checks on Terraform, Kubernetes and cloud templates Open storage, weak network rules and missing encryption Yes, for high-confidence critical findings
CI security checks Every build in the CI pipeline Static analysis, dependency risk, exposed secrets and container issues Mostly warns; gates only exploitable criticals
Automated compliance evidence After each build and release Signed scan results, approvals and test records for audits No, it produces evidence

How the Four Patterns Fit Together

Policy as code evaluates the conditions a change must meet, such as approved libraries, configuration rules, and deployment conditions. It's the decision layer. IaC hardening scans apply that thinking to infrastructure before merge, catching risky Terraform, Kubernetes, and cloud template settings like open storage or missing encryption.

CI security checks run on every build, covering static analysis, dependency risk, exposed secrets, and container issues. Automated compliance evidence then stores signed scan results, approvals, and test records as pipeline artifacts, so proof is a byproduct of delivery.

The benchmark is useful here. The DORA Accelerate State of DevOps Report 2022, representing more than 33,000 professional survey responses worldwide, found that 63% of respondents considered application-level security scanning within CI/CD pipelines for production releases to be "very" or "completely" established, the most commonly established practice examined. It also found security practices had no measurable positive effect on software-delivery performance when continuous integration was absent, but a strong positive effect when CI was implemented.

I'd sequence the work accordingly. If you don't have reliable CI, fix that first. Then add IaC scans and CI checks, and only then add blocking policy gates. For teams also keeping production services observable day to day, security resources for site reliability teams can complement pipeline controls with operational checks.

Don't confuse these automated checks with deeper manual assessment. Understanding the difference between security testing and penetration testing helps you place each activity where it belongs instead of expecting a pipeline scan to do everything.

How to Build the Security-as-Code Pipeline Step by Step

Build in this order. Each step creates the traceability the next step needs, so skipping ahead usually creates a gate nobody trusts.

The flow below shows the build order from design to production monitoring.

A five-step flowchart illustrating how to build a security-as-code pipeline, from design to continuous monitoring.

The Seven Steps in Build Order

  1. Run threat modeling during design. Do it before code exists and keep the model in a version-controlled, diffable format such as pytm or Threagile, so it can be reviewed in CI. Changing an architecture decision now costs far less than changing it after launch.
  2. Store policies with the code they govern. Keep security policies in the same repository as application and infrastructure code, and require peer review for every change. A policy change then has the same history and accountability as a code change.
  3. Add secrets detection and IaC scanning to pull requests. This catches exposed credentials and risky infrastructure settings before merge, when the author still has full context.
  4. Run static analysis, dependency checks, and container scans on every CI build. Every change gets the same treatment, whether a human or an AI assistant wrote it.
  5. Generate a software bill of materials and signed build metadata for every artifact. You need to know what's inside an artifact and prove where it came from.
  6. Enforce policy gates at deployment. Use least-privilege identities for the deploying service, so the pipeline itself can't make changes it shouldn't.
  7. Keep machine-readable evidence. Link the commit, dependency set, test results, policy decisions, and deployed artifact together in one record.

Teams looking to improve security across deployment pipelines often focus on steps 3 and 4 first, which is understandable. Those steps give fast feedback. But steps 5 to 7 are what let you trust an artifact at promotion time.

The walkthrough below shows how these pipeline stages connect in practice.

What Good Looks Like in a Real Delivery Standard

We apply a similar discipline through the #riteway approach. Every change must pass architecture review by a named architect, automated tests, a security review, observability, and a documented runbook and decision record. We also treat understandable code, documentation, deployment assets, and knowledge transfer as part of delivery, not as a final administrative task.

That discipline matters more, not less, with AI-native delivery. AI can accelerate analysis, implementation, and testing, but it doesn't change the standard. Senior engineers still own architecture, data, security, and production quality.

Step 7 is the payoff. It's what turns your pipeline work into audit-ready proof rather than a folder of screenshots and good intentions.

Writing Policies Teams Will Not Bypass

More checks don't automatically mean more security. That's the assumption worth challenging. If a gate fires constantly with false alarms, engineers will learn to skip it, suppress it, or route around it. At that point the gate protects nothing, and you've added delay without reducing risk.

Start with a clear definition. The OWASP policy as code guidance defines policy as code as security, compliance, and operational rules expressed in machine-readable, version-controlled code that is automatically evaluated and enforced. OWASP also recommends unit-testing policies against representative inputs and requiring 100% test coverage for every deny rule before promoting the policy to enforcement mode.

Design Rules That Keep Gates Credible

  • Block only what matters most: Reserve blocking for high-confidence, exploitable, or compliance-critical conditions. Let lower-confidence findings appear as warnings that stay visible without stopping delivery.
  • Start every new policy in warning mode: Measure how often it fires and how often it's wrong before you let it stop a release. Promote it only after you've tuned it.
  • Test deny rules like product code: Give each rule representative passing and failing inputs. If you can't test it, you can't trust it to block.
  • Give every exception an owner, a reason, and an expiry date: Log it where auditors and teammates can see it. An exception without an expiry date becomes a permanent hole.

The trade-off is straightforward. A stricter rule catches more, but if it fires on half of all builds, the team will work around it. Signal quality beats rule count every time, because a trusted gate gets fixed and a noisy gate gets bypassed.

Practical rule: If a release is blocked, the team should be able to name the rule, the reason, and the exact change that unblocks them.

Apply that test to any proposed gate before you enforce it. If the message doesn't tell an engineer what to do next, improve the message and the rule first. That's Extreme Ownership in practice, owning the control's quality, not just its existence. A policy that senior engineers can explain in one sentence is a policy product teams will respect under pressure.

Who Owns Security as Code and How to Choose Tools

Tools fail when nobody's accountable for them, so settle ownership before you buy anything. The platform team owns the pipeline, templates, and policy repository. The security team owns the rules and their risk thresholds. The senior engineer on each product team owns exceptions in their services. Write that down in a one-page RACI before the first gate goes live.

Five Questions for Any Tool

  1. CI fit: Does it run inside your existing CI system without a separate server?
  2. Version control: Can its rules live in version control and be unit-tested?
  3. Exception handling: Does it report false-positive rates and let you suppress one finding with an owner and expiry date?
  4. Evidence export: Does it export machine-readable results you can store as evidence?
  5. Team control: Can your own engineers read and change its rules without depending on the vendor?

A tool that fails the second or third question is a warning sign. Compare options against your wider software delivery tools instead of judging scanners in isolation. A tool choice is reversible. Ownership and exception rules aren't, so settle the second before buying the first.

Measuring Whether Security as Code Works

Don't judge this program by counting scanners or policy files. Judge it by whether delivery gets safer without getting slower, and whether failures go down.

Metric What It Measures Warning Sign After Adding Controls
Change lead time Time from code commit to successful production deployment Steady growth after each new gate
Deployment frequency How often changes reach production Releases shrink into rare, large batches
Failed-deployment recovery time How long it takes to restore service after a failed release Recovery slows because rollback paths are unclear
Change fail rate Share of deployments that cause production failures Rises after AI-generated changes enter the pipeline
Deployment rework rate Share of deployments that are unplanned bug fixes Climbs when scan findings reach production unfixed

Reading the Scorecard Together

Those definitions come from DORA's measurement model, which separates throughput, including change lead time, deployment frequency, and failed-deployment recovery time, from instability, including change fail rate and deployment rework rate. Read them together. A single number rarely tells you what to fix.

If lead time climbs after a new gate, check whether the gate is tuned or just noisy before you blame the team. If change fail rate rises after AI-generated code enters the pipeline, tighten review of that code rather than adding more scanners. Speed without accountability just produces risk faster.

Add control-quality measures the scorecard doesn't show on its own. Track false-positive rate, override frequency, time to remediate by severity, escaped defects that reached production, and how many developers use the tools. Work at scale, such as enabling SecureOps in a global media enterprise, shows why those operating measures matter alongside delivery numbers.

Keep the routine simple. Once a month, pick three numbers, compare them with last quarter, and decide one change. Every trade-off then becomes a documented decision, tighten the control, improve its precision, change the release process, or accept a recorded risk.

Common Problems and How to Fix Them

The hardest problem is a pipeline that passes while production runs something different from what was approved. That happens when guarantees stop at the source repository. Infrastructure changes, dependency updates, artifact promotion, and manual production edits can all break the link between approved code and the running system.

IaC itself is part of the attack surface, not just a control. A 2025 empirical study of infrastructure-as-code repositories analyzing more than 1,600 infrastructure-as-code repositories found severe and recurring vulnerabilities spanning all ten OWASP Top 10 2021 categories.

Symptom Likely Cause Fix
Builds pass but production differs from approved configuration Drift from manual changes or out-of-band updates Add drift detection and reconcile production from source control
Critical findings stay open for weeks No remediation deadline by severity Set remediation SLAs for each severity level
Deployed artifact cannot be traced to source Missing signed provenance Verify provenance before deployment
Approved artifact behaves differently after a dependency update Dependency graph changes without re-review Re-verify the SBOM and provenance at each promotion

Runtime Drift and AI-Generated Code

Treat drift as a failed control, not an operational footnote. Verify the deployed artifact against signed provenance, monitor for drift at runtime, and keep the evidence you'd need for incident response. If production differs from source control, reconcile it from source control instead of documenting the difference and moving on.

Apply the same discipline to AI-assisted work. AI-generated code needs the same security review as human-written code. When AI accelerates implementation, senior engineers remain accountable for data, security, integration, and production quality. That accountability can't be delegated to a model or a scanner.

Security as code succeeds when it's a continuously verified property of the running system, not a one-time pipeline stage.

That's the assurance model to aim for. Pre-merge checks, signed provenance, SBOM-driven monitoring, admission rules, and drift detection work as one loop. Break any link, and you're trusting an artifact you can't prove is the one you approved.

Confirm Your First Security Gate Before Next Sprint

Don't start with your most complex system. Pick one repository that ships to production every week, where feedback is fast and the team feels the benefit quickly.

Choose one gate first, usually secrets detection or an IaC scan on pull requests, because it's fast to run and easy to explain. Run it in warning mode for two weeks and record the baseline, how many findings appear, how many are false positives, and how long fixes take. Name one owner for every exception and set a remediation deadline for each severity level.

Then schedule a 30-minute review at the end of the sprint to decide whether to promote the gate to blocking. Make that decision with evidence, not enthusiasm. If the false-positive rate is still high, tune first and promote later.

We can speed up that starting point. Our technical and operational assessment reviews architecture, dependencies, security position, observability, and operational risk, then agrees what must be corrected first. Required systems, data, environments, and access can be provided before Day 1, so the assessment starts without delay.

Answer one question by the end of the sprint. Which single gate will we trust enough to block a release?


If you want that first gate chosen, tuned, and owned properly, we can run the assessment, agree the priorities with you, and help your team enforce security as code without slowing delivery. Visit Rite NRG to talk with a senior team that takes responsibility for architecture, security, and production quality, not just the next ticket.

/ about the author

Written by the RITE NRG editorial team — the architects, engineers and delivery leads who build and operate AI-era software for our clients.

Technology Talent & Teams

IT Partnership Models: How to Choose the Right One

A decision-maker's guide to IT partnership models: what each model actually transfers to the partner, what it costs beyond the rate card, and how to match the model to your situation.

More guidance: all insights articles

Get a Free 30-Minute Scoping Call

Tell us about the system or idea behind this article. We tell you honestly if it is a fit — and what a fixed-scope delivery could look like.