<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>CI/CD | Law Zava</title><link>https://lawzava.com/topics/ci-cd/</link><description>Build, test, and release pipelines, and how deployment mechanics shape what a team can safely ship.</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Sat, 07 Nov 2026 00:07:23 +0000</lastBuildDate><atom:link href="https://lawzava.com/topics/ci-cd/index.xml" rel="self" type="application/rss+xml"/><item><title>Container Image Scanning Without the Security Theater</title><link>https://lawzava.com/blog/2022-07-11-container-security-scanning/</link><pubDate>Mon, 11 Jul 2022 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2022-07-11-container-security-scanning/</guid><description>Most container scanning setups produce hundreds of unread findings. Scan in CI, rescan the registry, gate admission, and triage by exploitability.</description><content:encoded><![CDATA[<p>Earlier in my career I took part in cyber-defense exercises. One thing that stuck with me: the gap between &ldquo;we have a scanner&rdquo; and &ldquo;we&rsquo;re secure&rdquo; is enormous. Most teams I&rsquo;ve seen have a container scanner somewhere in their CI pipeline. Most of them also have hundreds of unread findings, no triage process, and a vague feeling that they&rsquo;re covered.</p>
<p>They aren&rsquo;t.</p>
<h2 id="what-are-you-actually-scanning">What Are You Actually Scanning</h2>
<p>A container image is a layer cake of risk. The base OS, the system packages, the application dependencies, your code, and whatever config and secrets accidentally ended up in there. Scanning just the OS packages, which is what most default setups do, covers only the bottom layers of that cake.</p>
<p>A useful scan covers:</p>
<ul>
<li>Base image and OS packages</li>
<li>Application dependencies (npm, pip, Go modules, whatever)</li>
<li>Misconfigurations: running as root, exposed ports, writable filesystems</li>
<li>Secrets embedded in image layers (it happens more than you think)</li>
</ul>
<p>If your scanner only does the first one, you have a false sense of security. Which is worse than no scanner at all, because at least without a scanner you know you&rsquo;re exposed.</p>
<h2 id="where-to-scan">Where to Scan</h2>
<p><strong>CI, before merge.</strong> This is where fixes are cheap. Block on critical findings. Let medium and low findings through with a warning. If you block on everything, developers will route around the scanner. I&rsquo;ve seen it happen at three different companies. The scanner becomes a rubber stamp or, worse, gets disabled.</p>
<p><strong>Registry, on a schedule.</strong> An image that was clean last Tuesday might have a critical CVE by Friday, and a clean scan was never the whole story at  <a href="/blog/2020-11-30-container-runtime-security/"
   
   >runtime</a>
 anyway. Rescan images in the registry weekly at minimum. Alert on new critical findings. This is the part most teams skip, and it&rsquo;s the part that matters most for long-lived images.</p>
<p><strong>Admission control.</strong> Prevent unscanned images from running in production. This doesn&rsquo;t need to be complicated: a simple OPA policy or Kyverno rule that rejects images without a scan annotation. The goal is to close the gap between &ldquo;we scanned it&rdquo; and &ldquo;we&rsquo;re running it.&rdquo;</p>
<h2 id="prioritization-over-volume">Prioritization Over Volume</h2>
<p>A scanner that reports 500 findings isn&rsquo;t helping. It&rsquo;s generating noise. Prioritize by four factors:</p>
<ol>
<li><strong>Exploitability.</strong> Is there a known exploit in the wild? A theoretical vulnerability in a library you don&rsquo;t use isn&rsquo;t urgent.</li>
<li><strong>Exposure.</strong> Is this component internet-facing or buried behind three layers of internal networking?</li>
<li><strong>Criticality.</strong> Is this your payment service or your internal metrics dashboard?</li>
<li><strong>Fix availability.</strong> If there&rsquo;s no patch, what exactly do you want the team to do about it?</li>
</ol>
<p>Handle exceptions with documented waivers: owner, reason, expiry date. No permanent exceptions. If a waiver expires and nobody renews it, the finding blocks again.</p>
<h2 id="base-images-are-dependencies">Base Images Are Dependencies</h2>
<p>Treat them like one. Pin versions. Set a monthly upgrade cadence. Use minimal bases like <code>distroless</code> or <code>alpine</code>, because fewer packages means fewer CVEs means less noise.</p>
<p>I&rsquo;ve seen teams running Ubuntu 20.04 base images with 200+ packages when their Go binary needs exactly zero of them. That isn&rsquo;t a base image. That&rsquo;s an attack surface donation.</p>
<h2 id="sign-your-images">Sign Your Images</h2>
<p>Scanning tells you what&rsquo;s inside an image. Signing tells you it&rsquo;s the image you built and nobody tampered with it between your CI pipeline and your cluster. Use cosign, use Notary, use whatever, but sign your artifacts and verify on pull.</p>
<p>After the  <a href="/blog/2020-12-14-solarwinds-attack-analysis/"
   
   >SolarWinds</a>
 and Codecov incidents, &ldquo;trust but don&rsquo;t verify&rdquo; isn&rsquo;t a defensible position anymore.</p>
<h2 id="the-minimum-viable-pipeline">The Minimum Viable Pipeline</h2>
<ol>
<li>Scan in CI with Trivy or Grype. Block on critical, warn on high.</li>
<li>Rescan in your registry weekly. Alert on new criticals.</li>
<li>Admission control in Kubernetes. Reject unscanned images.</li>
<li>Pin and regularly update base images.</li>
<li>Sign images in CI. Verify at deploy.</li>
</ol>
<p>That&rsquo;s it. Five steps. None of them are hard individually. The hard part is maintaining the discipline to triage findings, update waivers, and keep base images current.</p>
]]></content:encoded></item><item><title>Zero-Downtime PostgreSQL Migrations Without the Drama</title><link>https://lawzava.com/blog/2022-02-21-database-migration-strategies/</link><pubDate>Mon, 21 Feb 2022 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2022-02-21-database-migration-strategies/</guid><description>A single ALTER TABLE can ruin your weekend. How to migrate safely with expand-and-contract, batched backfills, and compatible deploys.</description><content:encoded><![CDATA[<p>On one system I worked on, we once ran a migration that added a NOT NULL column with a default value to a table with about 40 million rows. PostgreSQL 9.x. The migration locked the table for a full rewrite. Reads blocked. Writes queued. The API started timing out. Customers noticed within seconds. We rolled it back, but the rollback itself took minutes because the lock queue was backed up.</p>
<p>The total outage was maybe eight minutes. Felt like an hour. And the fix was something we should have known: add the column nullable, backfill in batches, then add the constraint. Three deploys instead of one. No table rewrite, no drama.</p>
<p>That experience permanently changed how I think about database migrations. The schema change itself is rarely the problem. The problem is live traffic hitting the change while it runs.</p>
<h2 id="the-expand-and-contract-pattern">The expand-and-contract pattern</h2>
<p>Every breaking schema change should follow expand-and-contract. It isn&rsquo;t glamorous. It&rsquo;s slow. It works.</p>
<p><strong>Expand</strong>: Add the new structure alongside the old one. Deploy code that writes to both.</p>
<p><strong>Migrate</strong>: Backfill data from old to new. Switch reads to the new path.</p>
<p><strong>Contract</strong>: Once the old path is fully retired and you have confirmed stability, drop the old columns or tables.</p>
<p>A simple column rename looks like this:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#75715e">-- Step 1: Expand
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">ALTER</span> <span style="color:#66d9ef">TABLE</span> users <span style="color:#66d9ef">ADD</span> <span style="color:#66d9ef">COLUMN</span> full_name text;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">-- Step 2: Backfill (in batches, see below)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">UPDATE</span> users <span style="color:#66d9ef">SET</span> full_name <span style="color:#f92672">=</span> name
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">WHERE</span> id <span style="color:#66d9ef">BETWEEN</span> <span style="color:#ae81ff">1</span> <span style="color:#66d9ef">AND</span> <span style="color:#ae81ff">10000</span> <span style="color:#66d9ef">AND</span> full_name <span style="color:#66d9ef">IS</span> <span style="color:#66d9ef">NULL</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">-- Step 3: Contract (after all code reads full_name)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">ALTER</span> <span style="color:#66d9ef">TABLE</span> users <span style="color:#66d9ef">DROP</span> <span style="color:#66d9ef">COLUMN</span> name;
</span></span></code></pre></div><p>Three deploys. Three PRs. Each one is small, reversible, and independently verifiable. This is slower than a single <code>ALTER TABLE ... RENAME COLUMN</code>, but the rename breaks every running instance of the old code the moment it commits. Expand-and-contract doesn&rsquo;t, and it doesn&rsquo;t require a maintenance window.</p>
<h2 id="application-code-has-to-play-along">Application code has to play along</h2>
<p>The migration only works if the application tolerates both schemas during the transition. This means:</p>
<ul>
<li><strong>Write to both columns</strong> during the expand phase. Old code writes to <code>name</code>. New code writes to both <code>name</code> and <code>full_name</code>.</li>
<li><strong>Read from new, fallback to old.</strong> <code>COALESCE(full_name, name)</code> in your queries, or handle it in application code.</li>
<li><strong> <a href="/blog/2021-09-06-feature-flags-at-scale/"
   
   >Feature flags</a>
 help.</strong> Switch reads to the new column behind a flag. Flip it when the backfill is done.</li>
<li><strong>Keep old queries working</strong> until you ship the contract phase. If something goes wrong after the backfill, you want the ability to revert without data loss.</li>
</ul>
<p>The key discipline: never deploy a schema change and a code change that depends on it in the same release. Separate them. Deploy the schema first, then the code. If the schema deploy breaks something, you can roll back without touching the application.</p>
<h2 id="backfills-that-dont-melt-production">Backfills that don&rsquo;t melt production</h2>
<p>A naive <code>UPDATE users SET full_name = name</code> on a table with tens of millions of rows will generate massive WAL, spike  <a href="/blog/2020-01-20-database-replication-patterns/"
   
   >replication lag</a>
, and hold back autovacuum. I&rsquo;ve watched backfills bring down read replicas.</p>
<p>Batch it:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#75715e">-- Process 5000 rows at a time
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">UPDATE</span> users <span style="color:#66d9ef">SET</span> full_name <span style="color:#f92672">=</span> name
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">WHERE</span> id <span style="color:#66d9ef">BETWEEN</span> :<span style="color:#66d9ef">start</span> <span style="color:#66d9ef">AND</span> :<span style="color:#66d9ef">end</span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">AND</span> full_name <span style="color:#66d9ef">IS</span> <span style="color:#66d9ef">NULL</span>;
</span></span></code></pre></div><p>Run this in a loop with a small delay between batches. Keep transactions short. Commit after each batch. Record progress so the job can resume if it crashes.</p>
<p>Practical tips from doing this too many times:</p>
<ul>
<li><strong>Rate limit.</strong> 5,000 to 50,000 rows per batch depending on table width and load.</li>
<li><strong>Short transactions.</strong> Long transactions hold locks and block vacuum.</li>
<li><strong>Idempotent.</strong> The <code>WHERE full_name IS NULL</code> clause means you can safely restart.</li>
<li><strong>Off-peak when possible.</strong> Not always an option, but backfilling during low traffic reduces risk.</li>
<li><strong>Monitor replication lag.</strong> If replicas start falling behind, slow down or pause.</li>
</ul>
<h2 id="the-operations-postgresql-will-punish-you-for">The operations PostgreSQL will punish you for</h2>
<p>Some DDL operations are deceptively dangerous. They look like simple one-liners but can lock tables, rewrite data, or kill your replication.</p>
<p><strong>Creating an index without <code>CONCURRENTLY</code></strong>: A regular <code>CREATE INDEX</code> takes a <code>SHARE</code> lock on the table, blocking all writes until it finishes. On a large table, that can be minutes.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#66d9ef">SET</span> lock_timeout <span style="color:#f92672">=</span> <span style="color:#e6db74">&#39;5s&#39;</span>;
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">CREATE</span> <span style="color:#66d9ef">INDEX</span> CONCURRENTLY idx_users_email <span style="color:#66d9ef">ON</span> users(email);
</span></span></code></pre></div><p>Always use <code>CONCURRENTLY</code>. Always set a lock timeout so it fails fast instead of waiting indefinitely.</p>
<p><strong>Adding NOT NULL with a default (pre-PG 11)</strong>: Before PostgreSQL 11, <code>ALTER TABLE ADD COLUMN ... DEFAULT ... NOT NULL</code> rewrote the entire table. PG 11+ handles this without a rewrite (for non-volatile defaults), but if you&rsquo;re on an older version, add the column nullable first, backfill, then add the constraint. The final <code>SET NOT NULL</code> still scans the table under an exclusive lock. On PG 12+ you can add a <code>CHECK (col IS NOT NULL) NOT VALID</code> constraint, validate it, and <code>SET NOT NULL</code> will skip the scan.</p>
<p><strong>Foreign key additions</strong>: Adding a foreign key validates every existing row. On a big table, that&rsquo;s a scan with a lock. Use <code>NOT VALID</code> to add the constraint without validation, then <code>VALIDATE CONSTRAINT</code> separately:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#66d9ef">ALTER</span> <span style="color:#66d9ef">TABLE</span> orders <span style="color:#66d9ef">ADD</span> <span style="color:#66d9ef">CONSTRAINT</span> fk_customer
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">FOREIGN</span> <span style="color:#66d9ef">KEY</span> (customer_id) <span style="color:#66d9ef">REFERENCES</span> customers(id)
</span></span><span style="display:flex;"><span>  <span style="color:#66d9ef">NOT</span> <span style="color:#66d9ef">VALID</span>;
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">-- Later, without blocking writes:
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">ALTER</span> <span style="color:#66d9ef">TABLE</span> orders VALIDATE <span style="color:#66d9ef">CONSTRAINT</span> fk_customer;
</span></span></code></pre></div><h2 id="the-operational-workflow">The operational workflow</h2>
<p><strong>Before you touch production:</strong></p>
<ul>
<li>Document every step and its expected impact. Not a novel. A numbered list.</li>
<li>Rehearse on production-size data. Staging with 1,000 rows won&rsquo;t catch lock issues on a 50 million row table.</li>
<li>Verify your backups work. Not &ldquo;we have backups.&rdquo; Actually restore and check.</li>
<li>Decide your abort criteria in advance. &ldquo;If lock waits exceed 5 seconds or replication lag exceeds 30 seconds, we stop.&rdquo;</li>
</ul>
<p><strong>During the migration:</strong></p>
<ul>
<li>Watch lock waits, query latency, and replication lag in real time.</li>
<li>Validate each step before moving to the next one.</li>
<li>Have the rollback commands ready in a terminal. Not in a wiki. In a terminal.</li>
</ul>
<p><strong>After:</strong></p>
<ul>
<li>Verify data integrity. Row counts, null rates, spot checks.</li>
<li>Keep the old columns around for a few days. You want a rollback window.</li>
<li>Clean up temporary code paths and old columns only after you&rsquo;re confident.</li>
</ul>
<h2 id="rollback-isnt-always-possible">Rollback isn&rsquo;t always possible</h2>
<p>Additive changes are easy to roll back: just drop the new column. Destructive changes aren&rsquo;t. If you dropped a column and need it back, you need a restore from backup.</p>
<p>This is why the contract phase should be the last step, done only after the system has been stable for days or weeks. Keep old columns around longer than feels necessary. Storage is cheap. Outages aren&rsquo;t.</p>
<p> <a href="/blog/2016-08-15-database-migrations-without-downtime/"
   
   >Zero-downtime migrations</a>
 come down to discipline more than clever SQL or tooling. Small steps. Verified assumptions. Rollback plans written before you need them. The teams that do this well get to keep their weekends.</p>
]]></content:encoded></item><item><title>Feature Flags at Scale: Ownership, Expiry, and Cleanup</title><link>https://lawzava.com/blog/2021-09-06-feature-flags-at-scale/</link><pubDate>Mon, 06 Sep 2021 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2021-09-06-feature-flags-at-scale/</guid><description>847 feature flags, about 200 with owners. Lessons from production codebases on flag types, ownership rules, fail modes, and cleanup.</description><content:encoded><![CDATA[<p>Last year, on a platform I worked on, I ran a script to count our feature flags. We had 847. Active, production feature flags spread across every service we ran. I knew we had a lot. I didn&rsquo;t know we had that many.</p>
<p>The worst part: when I cross-referenced with our flag metadata, only about 200 had an owner listed. The rest were orphans. Nobody knew who created them, what they controlled, or whether they were safe to remove. One flag had been set to &ldquo;false&rdquo; for 14 months. The code path behind it was unreachable. But nobody dared delete it because nobody knew what it did.</p>
<p>That&rsquo;s what feature flags look like at scale when you don&rsquo;t have discipline. And I&rsquo;m writing this post because I don&rsquo;t want you to end up there.</p>
<h2 id="flags-are-great-stale-flags-are-debt">Flags are great. Stale flags are debt.</h2>
<p>The pitch for feature flags is solid. Separate deployment from release. Ship code to production behind a flag. Roll out  <a href="/blog/2021-02-08-gitops-progressive-delivery/"
   
   >gradually</a>
. Roll back instantly. Run experiments. Gate features by customer plan. Use kill switches during incidents.</p>
<p>All of that works. I&rsquo;m a believer. Flags have saved me multiple times during incidents. Flipping a kill switch is faster than deploying a rollback. Having a gradual rollout catch a regression at 5% of traffic instead of 100% is valuable.</p>
<p>The problem isn&rsquo;t the concept. The problem is lifecycle management. Flags are easy to create. Nobody wants to remove them.</p>
<h2 id="categorize-your-flags-or-drown">Categorize your flags or drown</h2>
<p>After the 847-flag incident, we introduced four categories:</p>
<p><strong>Release flags</strong> are short-lived. Control rollout of a new feature. Expected lifetime: days to weeks. Must be removed once the feature is fully rolled out.</p>
<p><strong>Experiment flags</strong> are medium-lived. Power A/B tests. Expected lifetime: duration of the experiment. Must be retired with a clear outcome documented.</p>
<p><strong>Operational flags</strong> are potentially long-lived. Kill switches, circuit breakers, graceful degradation. These can stay, but they need periodic review.</p>
<p><strong>Permission flags</strong> are permanent. Gate access by customer plan or contract. These are really entitlements, not feature flags, and should be treated differently in your code.</p>
<p>The categories matter because the cleanup rules are different. A release flag that&rsquo;s still around after a month is a problem. An operational kill switch that&rsquo;s been around for a year is fine.</p>
<h2 id="the-rules-that-saved-us">The rules that saved us</h2>
<p>After the cleanup, we implemented a simple policy. Every new flag must have:</p>
<ol>
<li>An owner (the person who will remove it)</li>
<li>A type (release, experiment, operational, permission)</li>
<li>An expected removal date (except operational and permission flags)</li>
<li>A documented default value and failure mode</li>
</ol>
<p>If any of those are missing, the flag can&rsquo;t be created. We enforced this in our flag management wrapper.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">type</span> <span style="color:#a6e22e">Flag</span> <span style="color:#66d9ef">struct</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">Name</span>       <span style="color:#66d9ef">string</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">Owner</span>      <span style="color:#66d9ef">string</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">Type</span>       <span style="color:#a6e22e">FlagType</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">RemoveBy</span>   <span style="color:#a6e22e">time</span>.<span style="color:#a6e22e">Time</span> <span style="color:#75715e">// zero for operational/permission</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">DefaultVal</span> <span style="color:#66d9ef">bool</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a6e22e">FailMode</span>   <span style="color:#a6e22e">FailMode</span>  <span style="color:#75715e">// FailOpen or FailClosed</span>
</span></span><span style="display:flex;"><span>}
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">func</span> (<span style="color:#a6e22e">s</span> <span style="color:#f92672">*</span><span style="color:#a6e22e">FlagService</span>) <span style="color:#a6e22e">Create</span>(<span style="color:#a6e22e">f</span> <span style="color:#a6e22e">Flag</span>) <span style="color:#66d9ef">error</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">f</span>.<span style="color:#a6e22e">Owner</span> <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;&#34;</span> {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">errors</span>.<span style="color:#a6e22e">New</span>(<span style="color:#e6db74">&#34;flag must have an owner&#34;</span>)
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">f</span>.<span style="color:#a6e22e">Type</span> <span style="color:#f92672">==</span> <span style="color:#a6e22e">Release</span> <span style="color:#f92672">&amp;&amp;</span> <span style="color:#a6e22e">f</span>.<span style="color:#a6e22e">RemoveBy</span>.<span style="color:#a6e22e">IsZero</span>() {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">errors</span>.<span style="color:#a6e22e">New</span>(<span style="color:#e6db74">&#34;release flags must have a removal date&#34;</span>)
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#75715e">// ...</span>
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>We also added a weekly report: flags past their removal date, flags with no evaluations in the last 30 days, and flags where the &ldquo;off&rdquo; path has never been exercised in production. That last one is subtle but important: if you&rsquo;ve never seen the fallback path in production, you don&rsquo;t actually know it works.</p>
<h2 id="fail-open-or-fail-closed">Fail-open or fail-closed</h2>
<p>This is the decision most teams skip. What happens when the flag service is down?</p>
<p>For a payment flow, you probably want fail-closed. Better to show an error than process a payment through an untested code path.</p>
<p>For a UI experiment, fail-open makes sense. Show the default experience. Nobody notices.</p>
<p>At one enterprise, the flag service went down for 20 minutes and their checkout flow broke because every flag defaulted to &ldquo;false&rdquo;, including the flag that enabled their only working checkout flow. They&rsquo;d never tested what &ldquo;all flags off&rdquo; looked like. Don&rsquo;t be that team.</p>
<h2 id="the-cleanup-problem-is-a-people-problem">The cleanup problem is a people problem</h2>
<p>Technical solutions help. Expiration dates, automated reports, lint rules that flag dead code paths. But the real problem is incentives.</p>
<p>Nobody gets credit for removing a feature flag. Shipping a new feature is visible. Cleaning up after it isn&rsquo;t. So flags accumulate, like any other  <a href="/blog/2017-12-18-technical-debt-triage-framework-for-prioritization/"
   
   >unowned tech debt</a>
.</p>
<p>On that platform, we made flag cleanup part of the definition of done. A feature isn&rsquo;t finished when it&rsquo;s rolled out to 100%. It&rsquo;s finished when the flag is removed and the old code path is deleted. We tracked &ldquo;flag debt&rdquo; on our engineering dashboard alongside other health metrics.</p>
<p>At larger organizations, I recommend a quarterly flag review. Pull up the full inventory. For every flag without a recent evaluation, ask: is this still needed? For every flag past its removal date, assign cleanup as a sprint task. It&rsquo;s unglamorous work. It prevents the kind of mess that makes your codebase feel hostile to new engineers.</p>
<h2 id="keep-it-simple">Keep it simple</h2>
<p>The best feature flag setup I&rsquo;ve seen is also the simplest. Boolean flags with deterministic evaluation. Clear categories. Mandatory ownership. Aggressive cleanup.</p>
<p>The worst setups are the ones with complex targeting rules, flags that depend on other flags, and evaluation logic spread across three different layers. If a single flag requires a whiteboard to explain, break it into smaller flags or put the complexity in application code where it can be tested properly.</p>
<p>Feature flags are a powerful tool. They&rsquo;re also a maintenance commitment. Treat them like production configuration, because that&rsquo;s what they are.</p>
]]></content:encoded></item><item><title>DevSecOps in Practice: The Pipeline Controls I Implement</title><link>https://lawzava.com/blog/2021-04-19-devsecops-practices/</link><pubDate>Mon, 19 Apr 2021 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2021-04-19-devsecops-practices/</guid><description>Pre-commit hooks, CI security stages, OPA Gatekeeper policies, and a triage system: the DevSecOps controls I set up so developers don&amp;amp;rsquo;t route around them.</description><content:encoded><![CDATA[<p>Security as a final gate doesn&rsquo;t work at enterprise scale. I&rsquo;ve been building DevSecOps pipelines at large telecom companies, drawing on what cyber-defense exercises taught me. What follows is what I implement: pre-commit hooks for secrets, CI pipeline security stages with real configs, container scanning, runtime policy enforcement with OPA, and the triage system that makes all of it sustainable. Every control has to be fast enough that developers don&rsquo;t route around it.</p>
<p>I have a rule when I start working with a new team: before I recommend anything, I ask the team to show me how code gets from a developer&rsquo;s laptop to production. Every step. Every tool. Every credential.</p>
<p>The answer is almost always incomplete. Not because people are hiding things, but because nobody has mapped the full path recently. That incomplete picture is where security gaps live.</p>
<p>DevSecOps is the practice of embedding security checks into the workflow developers already use. You can&rsquo;t buy it. If it slows them down, they&rsquo;ll circumvent it. If it&rsquo;s invisible and fast, they&rsquo;ll barely notice it&rsquo;s there. That&rsquo;s the target.</p>
<h2 id="layer-1-the-developers-machine">Layer 1: the developer&rsquo;s machine</h2>
<p>The cheapest place to catch a security issue is before it ever leaves the developer&rsquo;s laptop. Pre-commit hooks are the first line.</p>
<p>Here is what I install on every project:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#75715e"># .pre-commit-config.yaml</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">repos</span>:
</span></span><span style="display:flex;"><span>  - <span style="color:#f92672">repo</span>: <span style="color:#ae81ff">local</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">hooks</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">id</span>: <span style="color:#ae81ff">gitleaks</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">name</span>: <span style="color:#ae81ff">gitleaks</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">entry</span>: <span style="color:#ae81ff">gitleaks --path=. --unstaged -v</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">language</span>: <span style="color:#ae81ff">system</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">pass_filenames</span>: <span style="color:#66d9ef">false</span>
</span></span><span style="display:flex;"><span>  - <span style="color:#f92672">repo</span>: <span style="color:#ae81ff">https://github.com/hadolint/hadolint</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">rev</span>: <span style="color:#ae81ff">v2.1.0</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">hooks</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">id</span>: <span style="color:#ae81ff">hadolint</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">args</span>: [<span style="color:#e6db74">&#39;--ignore&#39;</span>, <span style="color:#e6db74">&#39;DL3008&#39;</span>]
</span></span><span style="display:flex;"><span>  - <span style="color:#f92672">repo</span>: <span style="color:#ae81ff">https://github.com/antonbabenko/pre-commit-terraform</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">rev</span>: <span style="color:#ae81ff">v1.48.0</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">hooks</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">id</span>: <span style="color:#ae81ff">terraform_validate</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">id</span>: <span style="color:#ae81ff">terraform_tfsec</span>
</span></span></code></pre></div><p>Gitleaks catches secrets before they hit Git history. Hadolint catches Dockerfile anti-patterns. Terraform validation and tfsec catch infrastructure misconfigurations.</p>
<p>The critical design principle: these hooks must run in under 10 seconds. If a pre-commit hook takes 30 seconds, developers disable it. I&rsquo;ve seen this happen at every organization I&rsquo;ve worked with. Speed isn&rsquo;t optional.</p>
<p>For Go projects specifically, I also add <code>go vet</code>, <code>staticcheck</code>, and <code>gosec</code> as pre-commit checks. Gosec catches common security issues like SQL injection patterns and hardcoded credentials.</p>
<h2 id="layer-2-ci-pipeline-security-stages">Layer 2: CI pipeline security stages</h2>
<p>Pre-commit hooks are a safety net, not a gate. The real enforcement happens in CI. Here is the pipeline structure I implement, using GitHub Actions as the example:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#75715e"># .github/workflows/security.yml</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">name</span>: <span style="color:#ae81ff">Security Checks</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">on</span>: [<span style="color:#ae81ff">push, pull_request]</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">jobs</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">secrets-scan</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">ubuntu-latest</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/checkout@v2</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">fetch-depth</span>: <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">zricethezav/gitleaks-action@v1.5.0</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">sast</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">ubuntu-latest</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/checkout@v2</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Run gosec</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">securego/gosec@master</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">args</span>: <span style="color:#e6db74">&#39;-exclude-generated ./...&#39;</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Run Semgrep</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">returntocorp/semgrep-action@v1</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">config</span>: &gt;-<span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">            p/owasp-top-ten
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">            p/golang</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">dependency-scan</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">ubuntu-latest</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/checkout@v2</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Run Trivy for dependencies</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">aquasecurity/trivy-action@master</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">scan-type</span>: <span style="color:#e6db74">&#39;fs&#39;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">severity</span>: <span style="color:#e6db74">&#39;CRITICAL,HIGH&#39;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">exit-code</span>: <span style="color:#e6db74">&#39;1&#39;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">container-scan</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">ubuntu-latest</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">needs</span>: [<span style="color:#ae81ff">sast]</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/checkout@v2</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Build image</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">run</span>: <span style="color:#ae81ff">docker build -t app:${{ github.sha }} .</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Scan image</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">aquasecurity/trivy-action@master</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">image-ref</span>: <span style="color:#e6db74">&#39;app:${{ github.sha }}&#39;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">severity</span>: <span style="color:#e6db74">&#39;CRITICAL,HIGH&#39;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">exit-code</span>: <span style="color:#e6db74">&#39;1&#39;</span>
</span></span></code></pre></div><p>Four jobs: secrets scanning, static analysis, and dependency scanning run in parallel, and container scanning runs once SAST passes. There&rsquo;s no point scanning an image if the code has critical issues.</p>
<p>The key decision is the gating policy. I use a two-tier approach:</p>
<ul>
<li><strong>Critical and High severity</strong>: block the pipeline. The PR can&rsquo;t merge.</li>
<li><strong>Medium and Low</strong>: create a tracking issue automatically, assign it to the team, set a remediation deadline. Don&rsquo;t block the pipeline.</li>
</ul>
<p>This is the balance that makes DevSecOps sustainable. If you block on everything, teams stop caring about the signal because it&rsquo;s always red. If you block on nothing, the findings pile up and nobody fixes them.</p>
<p>At one telecom company, we went from zero automated security checks to full pipeline coverage in three weeks. The first week was brutal: the initial scan found over 200 findings across their repositories. We triaged them into buckets, fixed the critical ones immediately, and created a backlog for the rest. Within a month, new PRs were consistently clean.</p>
<h2 id="layer-3-infrastructure-and-runtime-controls">Layer 3: infrastructure and runtime controls</h2>
<p>Static analysis catches what it can see. It can&rsquo;t see runtime behavior, configuration drift, or privilege escalation. That&rsquo;s where policy-as-code and runtime controls come in.</p>
<p>I use Open Policy Agent (OPA) with Gatekeeper for Kubernetes-based deployments, as part of the  <a href="/blog/2019-04-22-kubernetes-security-hardening/"
   
   >baseline hardening</a>
 every cluster should get. Here is a constraint that prevents containers from running as root:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">apiVersion</span>: <span style="color:#ae81ff">constraints.gatekeeper.sh/v1beta1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">kind</span>: <span style="color:#ae81ff">K8sPSPAllowedUsers</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">metadata</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">name</span>: <span style="color:#ae81ff">require-non-root</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">spec</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">match</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">kinds</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">apiGroups</span>: [<span style="color:#e6db74">&#34;&#34;</span>]
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">kinds</span>: [<span style="color:#e6db74">&#34;Pod&#34;</span>]
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">excludedNamespaces</span>: [<span style="color:#e6db74">&#34;kube-system&#34;</span>]
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">parameters</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runAsUser</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">rule</span>: <span style="color:#ae81ff">MustRunAsNonRoot</span>
</span></span></code></pre></div><p>And one that requires resource limits on every container:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">apiVersion</span>: <span style="color:#ae81ff">constraints.gatekeeper.sh/v1beta1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">kind</span>: <span style="color:#ae81ff">K8sContainerLimits</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">metadata</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">name</span>: <span style="color:#ae81ff">require-limits</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">spec</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">match</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">kinds</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">apiGroups</span>: [<span style="color:#e6db74">&#34;&#34;</span>]
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">kinds</span>: [<span style="color:#e6db74">&#34;Pod&#34;</span>]
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">parameters</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">cpu</span>: <span style="color:#e6db74">&#34;2&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">memory</span>: <span style="color:#e6db74">&#34;2Gi&#34;</span>
</span></span></code></pre></div><p>These constraints are enforced at admission time. If a deployment tries to run a container as root, the API server rejects it. No exceptions. No &ldquo;we&rsquo;ll fix it later.&rdquo; The cluster enforces the policy.</p>
<p>For network policies, I default to deny-all and explicitly allow what is needed:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">apiVersion</span>: <span style="color:#ae81ff">networking.k8s.io/v1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">kind</span>: <span style="color:#ae81ff">NetworkPolicy</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">metadata</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">name</span>: <span style="color:#ae81ff">default-deny-all</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">namespace</span>: <span style="color:#ae81ff">production</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">spec</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">podSelector</span>: {}
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">policyTypes</span>:
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">Ingress</span>
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">Egress</span>
</span></span></code></pre></div><p>Then each service gets a specific policy that allows only its known dependencies. This is tedious to set up and worth every minute. When a service gets compromised, lateral movement is limited by the network policy. I first saw this pattern in cyber-defense exercises. The principle is the same regardless of scale. Default deny. Explicit allow. No implicit trust.</p>
<h2 id="layer-4-triage-and-ownership">Layer 4: triage and ownership</h2>
<p>This is where most DevSecOps implementations die. The tools work. The scans run. The findings pile up. Nobody owns them.</p>
<p>My triage system is simple:</p>
<ul>
<li><strong>Critical</strong>: fix within 24 hours. Page the on-call if necessary. These are actively exploitable issues in production code.</li>
<li><strong>High</strong>: fix within one sprint. Track in the regular backlog. Team lead owns the follow-up.</li>
<li><strong>Medium</strong>: fix within 30 days. Batch these into security-focused work blocks.</li>
<li><strong>Low</strong>: fix when convenient, or accept the risk with documentation.</li>
</ul>
<p>Every finding gets an owner. Not a team: a person. &ldquo;The security team will handle it&rdquo; is how findings go to die.</p>
<p>I also set up a weekly triage meeting. Fifteen minutes. Review new findings, check progress on open items, and escalate anything that&rsquo;s stuck. At one company, this meeting reduced the median age of open vulnerabilities from 47 days to 11 days in two months. Not because we added more tools. Because someone was consistently asking &ldquo;is this fixed yet?&rdquo;</p>
<h2 id="secrets-management">Secrets management</h2>
<p>Secrets in source control are the most common security finding I see.  Hardcoded API keys, database passwords in config files, AWS credentials in test fixtures. It happens everywhere.</p>
<p>The fix is structural, not behavioral. Don&rsquo;t tell developers &ldquo;be careful with secrets.&rdquo; Give them a system that makes it hard to leak secrets in the first place.</p>
<ul>
<li>All secrets live in a vault (HashiCorp Vault, AWS Secrets Manager, whatever fits your stack).</li>
<li>Applications pull secrets at runtime, never at build time.</li>
<li>CI credentials are scoped to individual jobs and rotate automatically, the same rule I apply when  <a href="/blog/2021-01-11-supply-chain-security-practices/"
   
   >hardening build pipelines</a>
.</li>
<li>Pre-commit hooks catch anything that slips through.</li>
<li>Git history scanning runs on the full repository, not just the diff. Because secrets removed in a later commit are still in the history.</li>
</ul>
<h2 id="what-ive-learned-from-doing-this-repeatedly">What I&rsquo;ve learned from doing this repeatedly</h2>
<p>The technical setup is the easy part. The hard part is culture.</p>
<p>Developers aren&rsquo;t the enemy of security. They&rsquo;re the delivery mechanism for security. If you treat them as adversaries (locking everything down, blocking every build, requiring approvals for trivial changes), they&rsquo;ll find workarounds. Shadow builds. Personal accounts. Manual deployments that skip the pipeline entirely.</p>
<p>The organizations that succeed with DevSecOps are the ones that make secure the default and make the default fast. Secure container base images that are pre-approved. Templates that include security configs out of the box. Scanning that runs in parallel with tests instead of after them.</p>
<p>Security should feel like good tooling. When it does, adoption is automatic.</p>
]]></content:encoded></item><item><title>GitOps and Canary Rollouts: No More Gambling on Deploys</title><link>https://lawzava.com/blog/2021-02-08-gitops-progressive-delivery/</link><pubDate>Mon, 08 Feb 2021 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2021-02-08-gitops-progressive-delivery/</guid><description>How we wired Argo CD and Argo Rollouts together at my infrastructure startup: canary steps, Prometheus analysis gates, repo layout, and what still goes wrong.</description><content:encoded><![CDATA[<p>At my infrastructure startup, our first deployment pipeline was a shell script called <code>deploy.sh</code>. It was 140 lines of bash, it had three <code>sleep</code> statements in it, and it worked fine until it didn&rsquo;t.</p>
<p>The day it didn&rsquo;t was a Tuesday. Someone pushed a config change that looked innocent in the PR: an environment variable rename. The script deployed it to all pods simultaneously. The new variable name didn&rsquo;t match what the application expected at startup. Every pod crashed. Recovery took 45 minutes because the script had no rollback logic. It just pushed forward.</p>
<p>That was the week I decided to actually invest in deployment infrastructure.</p>
<p>GitOps (Git as the source of truth for cluster state) combined with progressive delivery (canary rollouts with automated analysis) gives you deployments that are auditable, reversible, and safe by default. We set this up at my infrastructure startup with Argo CD and Argo Rollouts. It took about three weeks to get right. It has prevented more incidents than I can count.</p>
<h2 id="gitops-the-boring-part-that-matters-most">GitOps: the boring part that matters most</h2>
<p> <a href="/blog/2019-02-11-gitops-principles-and-practices/"
   
   >GitOps</a>
 is an operating model. The desired state of your system lives in a Git repository. A controller running in the cluster watches that repo and continuously reconciles the actual state toward the declared state.</p>
<p>That&rsquo;s it. No magic. Just four properties:</p>
<ul>
<li><strong>Declarative.</strong> You describe what you want, not how to get there.</li>
<li><strong>Versioned.</strong> Every change has a commit, a diff, and a reviewer.</li>
<li><strong>Pull-based.</strong> The cluster pulls state from Git. No CI system needs credentials to push into production.</li>
<li><strong>Self-healing.</strong> Someone <code>kubectl edit</code>s a deployment? The controller reverts it. Drift is detected and corrected automatically.</li>
</ul>
<p>We use Argo CD for this. Flux is also solid. The tool matters less than the discipline of treating Git as the single source of truth for everything running in the cluster.</p>
<p>The immediate win was audit trail. Before GitOps, answering &ldquo;what changed and when&rdquo; during an incident meant digging through CI logs, Slack messages, and someone&rsquo;s memory. After GitOps, it was <code>git log</code>. Every deployment was a commit. Every rollback was a revert.</p>
<h2 id="progressive-delivery-the-part-that-keeps-you-safe">Progressive delivery: the part that keeps you safe</h2>
<p>GitOps tells you what should be running. Progressive delivery controls how new versions are introduced. Instead of flipping all traffic at once, which is what our bash script did, you advance in stages and check real signals at each step.</p>
<p>At my infrastructure startup we use canary deployments. A new version gets 20% of traffic. We wait three minutes. If error rates and latency look normal, we go to 60%. Another five minutes. Then full rollout.</p>
<p>Here is roughly what the Argo Rollout spec looks like:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">apiVersion</span>: <span style="color:#ae81ff">argoproj.io/v1alpha1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">kind</span>: <span style="color:#ae81ff">Rollout</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">metadata</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">name</span>: <span style="color:#ae81ff">api-gateway</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">spec</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">replicas</span>: <span style="color:#ae81ff">6</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">strategy</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">canary</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>        - <span style="color:#f92672">setWeight</span>: <span style="color:#ae81ff">20</span>
</span></span><span style="display:flex;"><span>        - <span style="color:#f92672">pause</span>: { <span style="color:#f92672">duration</span>: <span style="color:#ae81ff">3m }</span>
</span></span><span style="display:flex;"><span>        - <span style="color:#f92672">analysis</span>:
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">templates</span>:
</span></span><span style="display:flex;"><span>              - <span style="color:#f92672">templateName</span>: <span style="color:#ae81ff">error-rate-check</span>
</span></span><span style="display:flex;"><span>        - <span style="color:#f92672">setWeight</span>: <span style="color:#ae81ff">60</span>
</span></span><span style="display:flex;"><span>        - <span style="color:#f92672">pause</span>: { <span style="color:#f92672">duration</span>: <span style="color:#ae81ff">5m }</span>
</span></span><span style="display:flex;"><span>        - <span style="color:#f92672">analysis</span>:
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">templates</span>:
</span></span><span style="display:flex;"><span>              - <span style="color:#f92672">templateName</span>: <span style="color:#ae81ff">latency-check</span>
</span></span></code></pre></div><p>The analysis steps query Prometheus. If error rate exceeds the threshold, the rollout automatically aborts and rolls back. No human intervention. No 2am pages.</p>
<p>The key insight: rollout strategy, analysis thresholds, and promotion rules are all in Git. They are versioned, reviewed, and auditable. Nobody is hand-tuning production.</p>
<h2 id="how-the-pieces-fit-together">How the pieces fit together</h2>
<p>The full flow:</p>
<ol>
<li>CI builds the image, pushes to the registry, and opens a PR against the config repo with the new image tag.</li>
<li>Someone reviews and merges the PR.</li>
<li>Argo CD detects the new commit and syncs the cluster.</li>
<li>Argo Rollouts executes the canary steps.</li>
<li>Automated analysis gates decide promote or rollback.</li>
<li>A Slack notification tells the team what happened.</li>
</ol>
<p>Deployments are deterministic. If you run the same commit twice, you get the same result. If something goes wrong, you revert the commit and the cluster converges to the previous state.</p>
<h2 id="repo-structure-opinions-ive-earned">Repo structure: opinions I&rsquo;ve earned</h2>
<p>We tried monorepo (app code and manifests together) first. It worked for three services. By service ten, merge conflicts on shared infrastructure files were constant.</p>
<p>We switched to a split model: application repos hold code and build configs, a separate config repo holds Kubernetes manifests organized by environment. CI bridges the two by updating the config repo when a new image is built.</p>
<p>Some teams use &ldquo;app of apps&rdquo; patterns with Argo CD. That works if you have a platform team managing the hierarchy. For smaller teams, keep it simple. One repo, one folder per service, one overlay per environment.</p>
<p>Whatever you choose, optimize for clear ownership. If two teams are constantly editing the same files, your structure is wrong.</p>
<h2 id="the-guardrails-you-actually-need">The guardrails you actually need</h2>
<p>After running this for over a year, here are the guardrails that mattered in practice:</p>
<ul>
<li><strong>Meaningful success metrics.</strong> Error rate and latency are baseline. Add business-level signals if you can.</li>
<li><strong>Tested rollback thresholds.</strong> If you have never seen an automated rollback trigger, your thresholds are either too loose or your analysis is broken. We intentionally deploy known-bad versions to staging to verify the rollback path works.</li>
<li><strong>A manual override.</strong> Automated analysis is great until the metrics are noisy from an unrelated issue. You need a way to pause, skip, or manually promote. Argo Rollouts supports all of these.</li>
<li><strong>No secrets in Git.</strong> We use Sealed Secrets for Kubernetes secrets. GoDaddy&rsquo;s kubernetes-external-secrets is another option. The point is that credentials never appear in the config repo, not even encrypted in a way that a casual contributor can decrypt.</li>
<li><strong>Blast radius limits.</strong> Namespace isolation. Resource quotas. A bad deployment in one service shouldn&rsquo;t cascade.</li>
</ul>
<h2 id="what-still-goes-wrong">What still goes wrong</h2>
<p>I would be lying if I said this setup is bulletproof.</p>
<p>The most common problem: metrics are too noisy. If your baseline error rate fluctuates by 2% normally, setting a rollback threshold at 1% means every deployment gets aborted. Tuning thresholds is an ongoing process, not a one-time setup.</p>
<p>Second most common: someone makes a manual change in the cluster. Argo CD reverts it. The person who made the change gets confused. This is actually the system working correctly, but it requires educating the team that <code>kubectl edit</code> is no longer a valid workflow.</p>
<p>Third: configuration sprawl. As the number of services grows, the config repo gets messy. Kustomize overlays help, but you need discipline about what belongs in base vs. overlay and when to refactor.</p>
<h2 id="was-it-worth-it">Was it worth it?</h2>
<p>Our deployment frequency went from twice a week to multiple times a day. Our incident rate from bad deployments dropped to near zero. The 45-minute outage from that config variable rename? It would be caught in the first canary step now, rolled back automatically in under a minute, and nobody would lose sleep over it.</p>
<p>Three weeks of setup for that kind of confidence. I would make that trade again every time.</p>
]]></content:encoded></item><item><title>Supply Chain Security After SolarWinds: Where to Start</title><link>https://lawzava.com/blog/2021-01-11-supply-chain-security-practices/</link><pubDate>Mon, 11 Jan 2021 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2021-01-11-supply-chain-security-practices/</guid><description>After SolarWinds: how I map build paths, harden CI, pin and proxy dependencies, sign artifacts, and watch for tampering in enterprise pipelines.</description><content:encoded><![CDATA[<p>Most organizations can&rsquo;t answer &ldquo;what code is running in production and how did it get there?&rdquo; After SolarWinds, that&rsquo;s no longer acceptable. Here is what I&rsquo;ve been doing about it: mapping the full chain, hardening builds, locking down dependencies, signing everything, and monitoring for tampering. None of it is glamorous.</p>
<p> <a href="/blog/2020-12-14-solarwinds-attack-analysis/"
   
   >SolarWinds</a>
 broke something in people&rsquo;s heads. Good. It needed breaking.</p>
<p>For years, supply chain security was the thing everyone nodded about in security reviews and nobody actually funded. Then a nation-state actor slipped a backdoor into a trusted update mechanism, and suddenly as many as 18,000 organizations, including multiple US government agencies, were running compromised code they had willingly installed.</p>
<p>Within a week of the news, I had three separate calls asking some variant of the same question: &ldquo;Could this happen to us?&rdquo; The answer was yes. For most of them, absolutely yes.</p>
<h2 id="what-supply-chain-actually-means-here">What &ldquo;supply chain&rdquo; actually means here</h2>
<p>People hear &ldquo;supply chain&rdquo; and think dependencies. That&rsquo;s one piece. The full chain is everything between a developer&rsquo;s keyboard and running production code. Developer identities. Source control. Third-party libraries. Build systems. Artifact registries. Deployment pipelines. Update mechanisms.</p>
<p>SolarWinds wasn&rsquo;t a dependency attack. It was a build system compromise. The attackers injected code during the build process itself. The source looked clean. The artifact was poisoned. That distinction matters because it tells you where to focus.</p>
<h2 id="step-one-figure-out-what-you-actually-have">Step one: figure out what you actually have</h2>
<p>I can&rsquo;t tell you how many times I&rsquo;ve walked into an organization and asked &ldquo;show me every path code takes from commit to production&rdquo; and gotten blank stares. Not because people are incompetent. Because nobody ever mapped it.</p>
<p>At a large telecom company I worked with, we discovered that a critical billing service had three different build paths depending on which team member triggered the release. One used the CI pipeline. One used a local build script that predated the CI system by two years. One involved SSH-ing into a jump box. Same service. Three paths. Zero documentation.</p>
<p>You start here:</p>
<ul>
<li><strong>Enumerate every build pipeline.</strong> Not just the ones in your CI tool. The scripts. The manual processes. The &ldquo;temporary&rdquo; workarounds that have been running for years.</li>
<li><strong>Map dependency trees.</strong> Direct and transitive. For Go projects I use <code>go mod graph</code>. For Node, <code>npm ls --all</code>. You will be horrified by what you find in transitive dependencies.</li>
<li><strong>Identify who can publish what.</strong> Who has write access to your artifact registry? Who can trigger a production deployment? If the answer is &ldquo;most of the engineering team,&rdquo; that&rsquo;s your first problem.</li>
<li><strong>Generate SBOMs.</strong> A software bill of materials for every release. Not optional. This is the foundation everything else builds on. Tools like <code>syft</code> make this straightforward for Go projects.</li>
</ul>
<p>At another company, the dependency inventory alone surfaced 14 packages that had been abandoned by their maintainers. Two had known CVEs. Nobody knew they were even in the tree.</p>
<h2 id="step-two-harden-the-build">Step two: harden the build</h2>
<p>Your build system is a high-value target. If I can compromise your CI runner, I own your artifacts. Treat builds like production infrastructure.</p>
<p>What I put in place:</p>
<ul>
<li><strong>Ephemeral builders.</strong> Every build gets a fresh environment. No state leaks between jobs. If your CI runners have been alive for months with accumulated cruft, that&rsquo;s a risk.</li>
<li><strong>Network isolation during builds.</strong> Builds should pull from a known, audited set of sources. Not the open internet. This means running an internal proxy or mirror for package registries.</li>
<li><strong>Scoped, short-lived secrets.</strong> Every credential used in CI should be scoped to exactly one job and expire quickly. I&rsquo;ve seen enterprise CI systems with admin-level AWS credentials that hadn&rsquo;t been rotated in over a year. That&rsquo;s a ticking bomb.</li>
<li><strong>Input verification, output signing.</strong> Verify checksums of everything you pull in. Sign everything you produce. If an artifact isn&rsquo;t signed, it doesn&rsquo;t deploy. Full stop.</li>
<li><strong>Comprehensive build logs.</strong> Every step logged and retained. When something goes wrong, and it will, you need the forensic trail.</li>
</ul>
<p>For Go specifically, I keep <code>GONOSUMDB</code> empty so every module download gets verified against the checksum database. I also set <code>GOFLAGS=-mod=vendor</code> for critical services so the exact source code ships with the repo.</p>
<h2 id="step-three-lock-down-dependencies">Step three: lock down dependencies</h2>
<p>Most modern software is more dependency than original code. I&rsquo;ve seen Go services where the <code>go.sum</code> file has 400+ entries and the actual application is maybe 3,000 lines. That ratio should make you uncomfortable.</p>
<p>What works:</p>
<ul>
<li><strong>Pin everything.</strong> Lock files aren&rsquo;t optional. Review lock file changes in PRs the same way you review code changes.</li>
<li><strong>Proxy registries.</strong> Run an internal mirror for your package sources. Athens for Go modules. Verdaccio or Artifactory for npm. This gives you a cache, an audit trail, and a kill switch.</li>
<li><strong>Mandatory review for new dependencies.</strong> Adding a new dependency should require justification. Who maintains it? What is the bus factor? Does it pull in a transitive tree you aren&rsquo;t comfortable with?</li>
<li><strong>Prune aggressively.</strong> Unused dependencies are attack surface with zero value. I run <code>go mod tidy</code> in CI and fail the build if it produces changes. If your module file isn&rsquo;t clean, your build shouldn&rsquo;t pass.</li>
<li><strong>Watch for typosquatting.</strong> This sounds paranoid until you realize it&rsquo;s one of the most common attack vectors for npm and PyPI. Automated checks for package name similarity against known packages are cheap insurance.</li>
</ul>
<p>One audit turned up a Go service importing a fork of a popular library. The fork was created by a former contractor who had left the company two years earlier. Nobody remembered why the fork existed. The fork was 200 commits behind upstream and had none of the security patches. That&rsquo;s how supply chain risk works in practice: nothing dramatic, just risk quietly accumulating.</p>
<h2 id="step-four-protect-distribution">Step four: protect distribution</h2>
<p>You build a clean artifact. Great. Now what? If your artifact registry has loose access controls, or your deployment pipeline pulls artifacts without verification, you have a gap.</p>
<ul>
<li><strong>Immutable artifact storage.</strong> Once published, an artifact can&rsquo;t be overwritten. Publish is append-only.</li>
<li><strong>Signature verification at deploy time.</strong> Not just at build time. The deployment system should independently verify that the artifact it&rsquo;s about to run was signed by your build system.</li>
<li><strong>Separate credentials.</strong> The build system shouldn&rsquo;t have deployment credentials. The deployment system shouldn&rsquo;t have build credentials. Compromising one shouldn&rsquo;t give you both.</li>
<li><strong>Monitor your update channels.</strong> If you distribute software to customers (not just internal services), your update mechanism is critical infrastructure. Monitor it for unexpected changes, access patterns, and timing anomalies.</li>
</ul>
<h2 id="step-five-detect-what-you-missed">Step five: detect what you missed</h2>
<p>Prevention is necessary. It&rsquo;s not sufficient. You need detection.</p>
<ul>
<li><strong>Alert on build definition changes.</strong> If someone modifies a <code>Dockerfile</code>, a CI config, or a build script, that should trigger a review. These are high-leverage files.</li>
<li><strong>Flag dependency changes.</strong> New dependencies, major version bumps, changed checksums. All should be visible and reviewed.</li>
<li><strong>Watch build timing.</strong> A build that suddenly takes 40% longer might be doing something extra. Or it might just be a slow network day. Either way, investigate.</li>
<li><strong>Block unsigned artifacts.</strong> If verification fails, the deployment doesn&rsquo;t happen. No exceptions. No &ldquo;we&rsquo;ll fix it after this release.&rdquo;</li>
<li><strong>Have a playbook.</strong> Key revocation, artifact rollback, dependency quarantine. Know how to do these before you need to do them at 2am.</li>
</ul>
<h2 id="the-phased-approach">The phased approach</h2>
<p>I roll this out in three phases:</p>
<p><strong>Phase 1: Visibility (weeks 1-3).</strong> Inventory everything. Map pipelines. Generate SBOMs. This is unglamorous but essential. You can&rsquo;t secure what you can&rsquo;t see.</p>
<p><strong>Phase 2: Hardening (weeks 4-8).</strong> Isolate builds. Pin and proxy dependencies. Reduce privileges. Rotate credentials. This is where most of the immediate risk reduction happens.</p>
<p><strong>Phase 3: Verification (weeks 9-12).</strong> Sign artifacts. Verify at deploy. Set up monitoring and alerting. Build the incident response playbook.</p>
<p>The timeline varies. A startup with 10 services can do this in a month. An enterprise with hundreds of services and decades of accumulated build infrastructure? Longer. But the phases stay the same.</p>
<h2 id="what-i-keep-seeing-go-wrong">What I keep seeing go wrong</h2>
<p>The number one mistake:  <a href="/blog/2020-11-30-container-runtime-security/"
   
   >buying a scanning tool</a>
 and calling it &ldquo;supply chain security.&rdquo; Scanning finds problems. It doesn&rsquo;t fix them. If nobody owns the remediation, you&rsquo;re just generating reports that make you feel productive.</p>
<p>The number two mistake: hardening the build but ignoring everything after it. Your build is hermetic and signed, great. Your artifact registry allows anonymous pushes? Your deployment pipeline skips verification because &ldquo;it was slow&rdquo;? You have wasted your effort.</p>
<p>The number three mistake: making security so painful that developers route around it. If your controls add 30 minutes to every build and require three approvals for a one-line fix, people will find workarounds. Good security feels like good tooling.</p>
<h2 id="where-this-is-heading">Where this is heading</h2>
<p>SolarWinds was the wake-up call. Regulation will follow, SBOM requirements are coming, and build-integrity standards will come with them. This isn&rsquo;t going away.</p>
<p>The organizations that start now, even imperfectly, will be ahead when the requirements become mandatory. The ones that wait will be scrambling.</p>
<p>I&rsquo;ve been saying this for months. Some listened after SolarWinds. Some are still &ldquo;evaluating.&rdquo; The evaluation period ended when a trusted update mechanism became an attack vector for a nation-state operation. Get your house in order.</p>
]]></content:encoded></item><item><title>GitHub Actions in Production: Matrix, Caching, Secrets</title><link>https://lawzava.com/blog/2020-07-20-github-actions-advanced/</link><pubDate>Mon, 20 Jul 2020 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2020-07-20-github-actions-advanced/</guid><description>Matrix builds, dependency caching, gated deploys, and the security gotchas I hit building a startup&amp;amp;rsquo;s CI/CD pipeline on GitHub Actions.</description><content:encoded><![CDATA[<p>I migrated our CI/CD at my infrastructure startup from a janky CircleCI setup to GitHub Actions about four months ago. The basic stuff was trivial. Push code, run tests, green checkmark. Fine.</p>
<p>Then I needed matrix builds across three OSes, caching that doesn&rsquo;t invalidate every other commit, gated production deploys, and secrets that don&rsquo;t leak into fork PRs. That&rsquo;s where it got interesting. These are the patterns that survived, each learned by breaking something at least once.</p>
<h2 id="matrix-builds-cover-ground-without-burning-minutes">Matrix builds: cover ground without burning minutes</h2>
<p>The matrix strategy is the single best feature in Actions. One job definition, multiple OS and runtime combinations. But the defaults will burn through your free minutes fast if you&rsquo;re not careful.</p>
<p>Here&rsquo;s what our test workflow looks like:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">name</span>: <span style="color:#ae81ff">ci</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">on</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">push</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">branches</span>: [<span style="color:#ae81ff">main]</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">pull_request</span>:
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">jobs</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">test</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">${{ matrix.os }}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">timeout-minutes</span>: <span style="color:#ae81ff">15</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">strategy</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">fail-fast</span>: <span style="color:#66d9ef">false</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">matrix</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">os</span>: [<span style="color:#ae81ff">ubuntu-latest, macos-latest, windows-latest]</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">node</span>: [<span style="color:#ae81ff">12</span>, <span style="color:#ae81ff">14</span>]
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">exclude</span>:
</span></span><span style="display:flex;"><span>          - <span style="color:#f92672">os</span>: <span style="color:#ae81ff">windows-latest</span>
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">node</span>: <span style="color:#ae81ff">12</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/checkout@v2</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/setup-node@v1</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">node-version</span>: <span style="color:#ae81ff">${{ matrix.node }}</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">run</span>: <span style="color:#ae81ff">npm ci</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">run</span>: <span style="color:#ae81ff">npm test</span>
</span></span></code></pre></div><p>Few things to note.</p>
<p><strong><code>fail-fast: false</code>.</strong> I used to leave this at the default (<code>true</code>). Then we&rsquo;d get a flaky Windows test that killed the whole matrix, and we&rsquo;d lose the Linux and macOS results entirely. Set it to false. Let everything run. You want the full picture.</p>
<p><strong>Exclude dead combos.</strong> We dropped Node 10 entirely and excluded Node 12 on Windows because we don&rsquo;t ship Windows builds on that version. Every combination you exclude saves real minutes. We were running 9 combinations, trimmed it to 5. The monthly bill noticed.</p>
<p><strong><code>timeout-minutes</code> on everything.</strong> I learned this one the hard way. A hung test on macOS once ran for 6 hours before I noticed. GitHub&rsquo;s default timeout is also 6 hours. That&rsquo;s not a default, that&rsquo;s a trap. Set 15 minutes. If your tests take longer than that, you have a different problem.</p>
<h2 id="caching-the-difference-between-8-minutes-and-90-seconds">Caching: the difference between 8 minutes and 90 seconds</h2>
<p>Caching npm dependencies turned our builds from &ldquo;go get coffee&rdquo; to &ldquo;it&rsquo;s already done.&rdquo; But the cache key design matters more than you&rsquo;d think.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Cache node modules</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/cache@v1</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">path</span>: <span style="color:#ae81ff">~/.npm</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">key</span>: <span style="color:#ae81ff">${{ runner.os }}-node-${{ hashFiles(&#39;**/package-lock.json&#39;) }}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">restore-keys</span>: |<span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">      ${{ runner.os }}-node-</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Install dependencies</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">run</span>: <span style="color:#ae81ff">npm ci</span>
</span></span></code></pre></div><p>The <code>restore-keys</code> fallback is critical. Without it, any change to <code>package-lock.json</code> means a complete cache miss and a full install. With the fallback, you get the last close-enough cache and <code>npm ci</code> only fetches the diff. Went from 4-minute installs to about 20 seconds on cache hit.</p>
<p>One gotcha: <code>actions/cache@v1</code> has a 5GB limit per repo. We hit it after a few weeks because we were caching <code>node_modules</code> directly. Big mistake: cache the npm cache directory instead and let <code>npm ci</code> do the linking. Switched to caching <code>~/.npm</code> and the size dropped by 80%.</p>
<h2 id="job-orchestration-build-once-deploy-from-artifacts">Job orchestration: build once, deploy from artifacts</h2>
<p>This is the pattern I&rsquo;m most opinionated about. Never rebuild in your deploy step. Build once, upload the artifact, download it in deploy. Guarantees you deploy exactly what you tested.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">jobs</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">build</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">ubuntu-latest</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">timeout-minutes</span>: <span style="color:#ae81ff">10</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/checkout@v2</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Cache npm</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/cache@v1</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">path</span>: <span style="color:#ae81ff">~/.npm</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">key</span>: <span style="color:#ae81ff">${{ runner.os }}-node-${{ hashFiles(&#39;**/package-lock.json&#39;) }}</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">restore-keys</span>: |<span style="color:#e6db74">
</span></span></span><span style="display:flex;"><span><span style="color:#e6db74">            ${{ runner.os }}-node-</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">run</span>: <span style="color:#ae81ff">npm ci</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">run</span>: <span style="color:#ae81ff">npm run build</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">run</span>: <span style="color:#ae81ff">npm test</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/upload-artifact@v2</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">name</span>: <span style="color:#ae81ff">dist</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">path</span>: <span style="color:#ae81ff">dist/</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">deploy-staging</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">needs</span>: <span style="color:#ae81ff">build</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">if</span>: <span style="color:#ae81ff">github.ref == &#39;refs/heads/main&#39;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">ubuntu-latest</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">timeout-minutes</span>: <span style="color:#ae81ff">5</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/download-artifact@v2</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">name</span>: <span style="color:#ae81ff">dist</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Deploy to staging</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">run</span>: <span style="color:#ae81ff">./scripts/deploy.sh staging</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">env</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">DEPLOY_TOKEN</span>: <span style="color:#ae81ff">${{ secrets.STAGING_DEPLOY_TOKEN }}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">deploy-production</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">needs</span>: <span style="color:#ae81ff">deploy-staging</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">if</span>: <span style="color:#ae81ff">github.ref == &#39;refs/heads/main&#39;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">ubuntu-latest</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">timeout-minutes</span>: <span style="color:#ae81ff">5</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/download-artifact@v2</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">with</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">name</span>: <span style="color:#ae81ff">dist</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Deploy to production</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">run</span>: <span style="color:#ae81ff">./scripts/deploy.sh production</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">env</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">DEPLOY_TOKEN</span>: <span style="color:#ae81ff">${{ secrets.PROD_DEPLOY_TOKEN }}</span>
</span></span></code></pre></div><p>Watch artifact storage. Artifacts are kept for 90 days and there&rsquo;s no per-artifact retention setting yet. You don&rsquo;t need three months of build artifacts. You need maybe a week for debugging. We hit 12GB of stored artifacts before I noticed.</p>
<p>The <code>needs</code> chain (<code>build</code> -&gt; <code>deploy-staging</code> -&gt; <code>deploy-production</code>) gives you a natural pipeline. Staging has to pass before production even starts. Actions has no built-in approval gate, which is why our real production deploys go through a manual trigger (below). That keeps us at  <a href="/blog/2016-06-06-continuous-deployment-without-chaos/"
   
   >continuous delivery</a>
 for prod: the artifact is always ready, the last step is a human decision.</p>
<h2 id="trigger-filtering-stop-running-ci-on-readme-changes">Trigger filtering: stop running CI on README changes</h2>
<p>This was annoying before I figured it out. Every docs edit, every README typo fix, every changelog update triggered a full CI run. Waste.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">on</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">push</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">branches</span>: [<span style="color:#ae81ff">main]</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">paths</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#e6db74">&#39;src/**&#39;</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#e6db74">&#39;package.json&#39;</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#e6db74">&#39;package-lock.json&#39;</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#e6db74">&#39;.github/workflows/**&#39;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">pull_request</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">paths</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#e6db74">&#39;src/**&#39;</span>
</span></span></code></pre></div><p>Only run when code actually changes. I also include <code>.github/workflows/**</code> in the push paths because I want CI to test itself when I modify the workflow files. Learned that one after pushing a broken workflow that I didn&rsquo;t catch for two days because the paths filter excluded the workflows directory.</p>
<p>For production deploys, we use <code>workflow_dispatch</code>, which GitHub shipped this month, so nobody accidentally deploys on merge:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">on</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">workflow_dispatch</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">inputs</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">environment</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">description</span>: <span style="color:#e6db74">&#39;Deploy target&#39;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">required</span>: <span style="color:#66d9ef">true</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">default</span>: <span style="color:#e6db74">&#39;staging&#39;</span>
</span></span></code></pre></div><p>Manual button in the Actions tab. Feels old-school. Works perfectly.</p>
<h2 id="secrets-and-fork-prs-the-security-stuff-that-bit-me">Secrets and fork PRs: the security stuff that bit me</h2>
<p>The rule nobody states clearly enough: <strong>fork pull requests run your workflows, but secrets aren&rsquo;t injected</strong>. This is correct behavior and you shouldn&rsquo;t try to work around it.</p>
<p>I see people &ldquo;fixing&rdquo; the fork PR problem anyway, by finding some other way to hand secrets to a job that runs the PR&rsquo;s code. Don&rsquo;t. Any setup where untrusted PR code runs with access to your secrets is a supply chain attack waiting to happen.</p>
<p>Our approach:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">jobs</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">test</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">ubuntu-latest</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/checkout@v2</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">run</span>: <span style="color:#ae81ff">npm ci</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">run</span>: <span style="color:#ae81ff">npm test</span>
</span></span><span style="display:flex;"><span>      <span style="color:#75715e"># No secrets needed for tests</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">deploy</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">needs</span>: <span style="color:#ae81ff">test</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">if</span>: <span style="color:#ae81ff">github.event_name == &#39;push&#39; &amp;&amp; github.ref == &#39;refs/heads/main&#39;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">ubuntu-latest</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/checkout@v2</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Deploy</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">run</span>: <span style="color:#ae81ff">./scripts/deploy.sh</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">env</span>:
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">DEPLOY_TOKEN</span>: <span style="color:#ae81ff">${{ secrets.DEPLOY_TOKEN }}</span>
</span></span></code></pre></div><p>Tests run on PRs without secrets. Deploy only runs on push to main, where secrets are available and the code is trusted. Simple separation.</p>
<p>Also: always mask secrets in logs.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span>- <span style="color:#f92672">name</span>: <span style="color:#ae81ff">Mask token</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">run</span>: <span style="color:#ae81ff">echo &#34;::add-mask::${{ secrets.API_TOKEN }}&#34;</span>
</span></span></code></pre></div><p>GitHub does this automatically for secrets referenced directly, but if you derive a value from a secret (substring, base64 encode, whatever), the derived value isn&rsquo;t masked. Found that out when a deploy URL containing an embedded token showed up in our build logs. Fun morning.</p>
<h2 id="self-hosted-runners-probably-not-yet">Self-hosted runners: probably not yet</h2>
<p>We considered self-hosted runners for builds that need access to our internal Docker registry. Decided against it. The maintenance overhead of patching, isolating, and monitoring runner machines wasn&rsquo;t worth it for our team size. We just push to a public registry and pull in deploy.</p>
<p>If you do need them:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">jobs</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">build</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">runs-on</span>: <span style="color:#ae81ff">self-hosted</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">timeout-minutes</span>: <span style="color:#ae81ff">30</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">steps</span>:
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">uses</span>: <span style="color:#ae81ff">actions/checkout@v2</span>
</span></span><span style="display:flex;"><span>      - <span style="color:#f92672">run</span>: <span style="color:#ae81ff">make build</span>
</span></span></code></pre></div><p>Just know that self-hosted runners don&rsquo;t get automatic cleanup between jobs like hosted runners do. Previous job&rsquo;s files, environment variables, running processes: all still there. You need to handle that yourself or you&rsquo;ll get extremely confusing cross-contamination bugs.</p>
<h2 id="four-months-in">Four months in</h2>
<p>None of this is groundbreaking. But I spent a couple months learning each of these the hard way, so maybe this saves you the same debugging sessions. GitHub Actions is good in 2020. The YAML is verbose. The ecosystem is young. But the fundamentals are solid and the GitHub integration is unbeatable.</p>
]]></content:encoded></item><item><title>Zero-Downtime Deployments: Migrations, Probes, and Habits</title><link>https://lawzava.com/blog/2019-10-21-zero-downtime-deployments/</link><pubDate>Mon, 21 Oct 2019 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2019-10-21-zero-downtime-deployments/</guid><description>Zero-downtime deploys depend less on tooling than on expand-and-contract migrations, backward-compatible code, readiness probes, and graceful shutdown.</description><content:encoded><![CDATA[<p>Two production outages I caused still stick with me. One was at the fintech startup, when a database migration locked a table for eleven minutes during market open. The other was during my founder-program cohort, when I pushed a config change that broke backward compatibility with in-flight requests. Both times, the deploy tooling worked perfectly. The problem was me.</p>
<p>No deploy tool gives you zero downtime on its own. It&rsquo;s a discipline across code, database migrations, and infrastructure, and the hardest part is the schema changes, not the YAML.</p>
<h2 id="what-zero-downtime-means">What Zero Downtime Means</h2>
<p>Two things. That&rsquo;s it.</p>
<ol>
<li>Capacity never drops below what traffic needs.</li>
<li>Running code stays compatible with in-flight requests and existing data.</li>
</ol>
<p>If both hold, your deploy is invisible to users. If either breaks, you have an outage regardless of how fancy your canary setup is.</p>
<h2 id="database-migrations-are-the-hard-part">Database Migrations Are the Hard Part</h2>
<p>Rolling updates, blue-green, canary: pick your favorite. They all handle the application layer fine. The hard part is always the database.</p>
<p>A schema change that locks a table or drops a column still in use will take you down no matter what deployment pattern you&rsquo;re running. I learned this the painful way with Postgres at the fintech startup, where our users table had enough rows that a naive <code>ALTER TABLE</code> would hold a lock for minutes.</p>
<p>The fix is boring, and I covered it in more depth in  <a href="/blog/2016-08-15-database-migrations-without-downtime/"
   
   >database migrations without downtime</a>
. Expand, migrate, contract. In that order, across separate deploys.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sql" data-lang="sql"><span style="display:flex;"><span><span style="color:#75715e">-- Deploy 1: Expand (add the new column)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">ALTER</span> <span style="color:#66d9ef">TABLE</span> users <span style="color:#66d9ef">ADD</span> <span style="color:#66d9ef">COLUMN</span> phone VARCHAR(<span style="color:#ae81ff">20</span>);
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">-- Deploy 2: Migrate (backfill in batches by id range, not one giant UPDATE)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">UPDATE</span> users <span style="color:#66d9ef">SET</span> phone <span style="color:#f92672">=</span> legacy_phone
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">WHERE</span> id <span style="color:#f92672">&gt;</span> <span style="color:#ae81ff">0</span> <span style="color:#66d9ef">AND</span> id <span style="color:#f92672">&lt;=</span> <span style="color:#ae81ff">1000</span> <span style="color:#66d9ef">AND</span> phone <span style="color:#66d9ef">IS</span> <span style="color:#66d9ef">NULL</span>;
</span></span><span style="display:flex;"><span><span style="color:#75715e">-- ...repeat for the next id range until done
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span><span style="color:#75715e">-- Deploy 3: Contract (drop old column after all code uses the new one)
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">ALTER</span> <span style="color:#66d9ef">TABLE</span> users <span style="color:#66d9ef">DROP</span> <span style="color:#66d9ef">COLUMN</span> legacy_phone;
</span></span></code></pre></div><p>Three deploys for one column rename. Annoying? Yes. But nobody notices. That&rsquo;s the point.</p>
<p>On MySQL, tools like <code>gh-ost</code> or <code>pt-online-schema-change</code> do background table copies to avoid long locks. On Postgres, the work is mostly careful DDL: nullable columns without defaults, <code>CREATE INDEX CONCURRENTLY</code>, a short <code>lock_timeout</code>, and backfills in batches (Postgres <code>UPDATE</code> has no <code>LIMIT</code>, so batch by primary key range). Worth learning if you&rsquo;re running anything with real traffic.</p>
<h2 id="pick-a-rollout-pattern-and-keep-it-simple">Pick a Rollout Pattern and Keep It Simple</h2>
<h3 id="rolling-updates">Rolling Updates</h3>
<p>The default and usually the right choice. Set <code>maxUnavailable: 0</code> so you never lose capacity during the rollout.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">spec</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">strategy</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">type</span>: <span style="color:#ae81ff">RollingUpdate</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">rollingUpdate</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">maxUnavailable</span>: <span style="color:#ae81ff">0</span>
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">maxSurge</span>: <span style="color:#ae81ff">25</span><span style="color:#ae81ff">%</span>
</span></span></code></pre></div><p>This works when old and new versions can run side by side. Which means your APIs need to be backward compatible. If that sounds like extra work, it is. But it&rsquo;s the kind of extra work that prevents 3 a.m. pages.</p>
<h3 id="canary">Canary</h3>
<p>Send a small slice of traffic to the new version. Watch your error rate. If it&rsquo;s clean, ramp up. If it spikes, roll back automatically.</p>
<p>The key word there is &ldquo;automatically.&rdquo; A canary release without automated rollback is just a smaller blast radius with manual intervention. You might as well flip a coin.</p>
<h3 id="blue-green">Blue-Green</h3>
<p>Run two environments, switch traffic when the new one is verified. Fast rollback, but you&rsquo;re paying for double infrastructure. Fine for critical services. Overkill for most things.</p>
<h2 id="the-stuff-between-the-deploys">The Stuff Between the Deploys</h2>
<p>The patterns above are table stakes. What actually makes deploys boring (in a good way) is the plumbing around them.</p>
<p><strong>Readiness vs. liveness probes.</strong> These aren&rsquo;t the same thing. Liveness says &ldquo;is this process alive.&rdquo; Readiness says &ldquo;can this process handle traffic right now.&rdquo; If your readiness check passes before caches are warm and dependencies are verified, you&rsquo;re sending users to a half-alive instance.</p>
<p><strong>Graceful shutdown.</strong> When Kubernetes sends SIGTERM (see my  <a href="/blog/2019-01-14-kubernetes-best-practices-2019/"
   
   >Kubernetes production checklist</a>
), your app needs to stop accepting new connections, finish in-flight requests, then exit. Sounds obvious. Roughly half the Go services I&rsquo;ve reviewed get this wrong, usually by not waiting long enough for the load balancer to drain.</p>
<p><strong>Connection draining.</strong> Set a realistic termination grace period. If your longest request takes 30 seconds, a 5-second grace period is going to drop connections.</p>
<p><strong>DNS TTLs.</strong> Lower them before a cutover, raise them after. I&rsquo;ve seen teams spend hours debugging a &ldquo;failed deploy&rdquo; that was actually stale DNS.</p>
<h2 id="my-pre-deploy-checklist">My Pre-Deploy Checklist</h2>
<p>The questions I ask before every deploy:</p>
<ul>
<li>Can the new code read data written by the old code? Can the old code read data written by the new code?</li>
<li>Does the database migration need a lock? How long?</li>
<li>Do the readiness checks actually verify dependencies, or do they just return 200?</li>
<li>If this deploy goes wrong, can I roll back in under a minute?</li>
</ul>
<p>If any answer is &ldquo;I&rsquo;m not sure,&rdquo; that&rsquo;s where the work is. Not in the deploy tool.</p>
<h2 id="why-this-stays-hard">Why this stays hard</h2>
<p>Zero downtime deploys aren&rsquo;t hard technically. They&rsquo;re hard culturally. They require everyone on the team to think about backward compatibility, schema evolution, and graceful degradation before they write the code. Not after.</p>
<p>The teams I&rsquo;ve seen do this well, at the fintech startup, at startups in my founder-program cohort, and on other teams I&rsquo;ve worked with, all share one trait. Deploys are boring. Nobody watches them. Nobody holds their breath. The monitoring catches problems and the rollback is automatic.</p>
]]></content:encoded></item><item><title>Testing in Production: Why Staging Misses the Real Bugs</title><link>https://lawzava.com/blog/2019-06-03-testing-in-production/</link><pubDate>Mon, 03 Jun 2019 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2019-06-03-testing-in-production/</guid><description>Staging misses the bugs that matter. How I test in production safely: feature flags, 1% rollouts, canaries, shadow traffic, and synthetic checks.</description><content:encoded><![CDATA[<p>On one project I pushed a payments integration that had passed every test we had. Unit tests. Integration tests against a sandbox API. Manual QA on staging. All green.</p>
<p>It broke within forty minutes of hitting real users.</p>
<p>The sandbox API returned amounts as integers. The production API returned them as strings. Our staging environment had been confirming our assumptions, not testing our code. That fifteen-minute fire drill taught me more about testing strategy than any conference talk ever will.</p>
<h2 id="staging-is-a-comfortable-lie">Staging is a comfortable lie</h2>
<p>I&rsquo;ve worked at a fintech startup and a mobility startup, and now I&rsquo;m building a cloud infrastructure startup. Across all of them, the pattern repeats: staging looks just enough like production to give you confidence, but differs in all the ways that actually matter.</p>
<p>Different data shapes. Different load patterns. Different third-party API behaviors. Different timing. Different everything that&rsquo;s hard to fake and easy to ignore.</p>
<p>The bugs that wake you up at 3am are never the ones your test suite catches. They are the ones that only exist when a real user in a real timezone hits a real edge case with real data. Staging can&rsquo;t reproduce that. Full stop.</p>
<p>Pre-release testing is necessary but not sufficient. You need to verify behavior where it actually runs.</p>
<h2 id="the-rules-i-follow">The rules I follow</h2>
<p>After burning myself enough times at the fintech startup, the mobility startup, and now my infrastructure startup, I&rsquo;ve landed on a few non-negotiable principles.</p>
<p><strong>Small blast radius, always.</strong> Start with one percent of traffic. Not ten. Not &ldquo;just the beta users.&rdquo; One percent. If something is broken, one percent is a learning opportunity. Ten percent is an incident. I learned this the hard way at the mobility startup, where a &ldquo;small&rdquo; rollout to a single city still meant thousands of angry riders.</p>
<p><strong>Define success before you ship, not after.</strong> If you can&rsquo;t write down what &ldquo;working&rdquo; looks like in two sentences, you don&rsquo;t understand the change well enough to ship it. Error rate below X. Latency under Y. Conversion not worse than Z. Write it down. Pin it in Slack. Make it boring.</p>
<p><strong>Rollback must be one click.</strong> If reverting a change requires a redeploy, a database migration, or waking someone up, your deployment pipeline isn&rsquo;t ready for production testing. Feature flags make this trivial. I use them for everything at my infrastructure startup, even infrastructure changes.</p>
<p><strong>Never create real side effects.</strong> Production tests must not send real emails, charge real cards, or corrupt real analytics. Synthetic users, idempotent operations, and explicit safety checks aren&rsquo;t optional. They are the whole point.</p>
<h2 id="how-i-do-it">How I do it</h2>
<h3 id="feature-flags-and-progressive-rollout">Feature flags and progressive rollout</h3>
<p>This is the bread and butter. Ship the code dark, then turn it on for a sliver of traffic.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-go" data-lang="go"><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">handleCheckout</span>(<span style="color:#a6e22e">user</span> <span style="color:#a6e22e">User</span>) <span style="color:#a6e22e">Response</span> {
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> <span style="color:#a6e22e">featureFlags</span>.<span style="color:#a6e22e">Enabled</span>(<span style="color:#e6db74">&#34;new_checkout&#34;</span>, <span style="color:#a6e22e">user</span>.<span style="color:#a6e22e">ID</span>) {
</span></span><span style="display:flex;"><span>        <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">newCheckout</span>(<span style="color:#a6e22e">user</span>)
</span></span><span style="display:flex;"><span>    }
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">return</span> <span style="color:#a6e22e">legacyCheckout</span>(<span style="color:#a6e22e">user</span>)
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><p>I write this in Go because that&rsquo;s what I reach for, but the idea is language-agnostic. The flag gives you a kill switch. The progressive rollout gives you data. Together, they turn a risky deployment into a controlled experiment.</p>
<p>We stage rollouts by percentage: 1%, 5%, 25%, 100%. Each step gets at least a few hours of observation. If the error rate ticks up at 5%, we kill it at 5%. No drama.</p>
<h3 id="canary-releases">Canary releases</h3>
<p>When a change is bigger than a single feature, say a new version of a service, canary deployments do the same thing at the infrastructure level. Route a small slice of traffic to the new version, compare its behavior against the baseline, and promote only when the numbers look right. It&rsquo;s the same discipline that made  <a href="/blog/2016-06-06-continuous-deployment-without-chaos/"
   
   >continuous deployment workable</a>
 for us years ago.</p>
<h3 id="shadow-traffic">Shadow traffic</h3>
<p>For really scary changes, mirror production requests to the new code path without returning its results to users. Compare outputs offline. This is how I once validated a pricing engine rewrite: the old engine served every request while the new one ran in shadow mode for two weeks. We caught three discrepancies that would have been billing bugs.</p>
<h3 id="synthetic-monitoring">Synthetic monitoring</h3>
<p>Always-on health checks that hit your critical paths every minute. Signup. Login. Checkout. API token refresh. If synthetic checks fail, you know before your users do. This is table stakes but I&rsquo;m amazed how many teams skip it.</p>
<h2 id="when-to-not-do-this">When to not do this</h2>
<p>Some things should never be tested in production, no matter how good your flags and rollbacks are.</p>
<p>Irreversible data migrations. Authorization changes. Billing logic where a bug means overcharging real people. Compliance workflows where a mistake has legal consequences. If you can&rsquo;t undo it in thirty seconds, don&rsquo;t experiment with it live.</p>
<p>These areas need exhaustive pre-release testing, careful code review, and a deployment plan that reads more like a checklist than a YOLO push.</p>
<h2 id="what-this-requires">What this requires</h2>
<p>Testing in production is no shortcut, and it has nothing to do with &ldquo;move fast and break things.&rdquo; Move deliberately, instrument everything, and learn from real conditions while keeping the blast radius small enough that learning doesn&rsquo;t become damage.</p>
<p>Every production system I&rsquo;ve run, from the fintech startup&rsquo;s data pipeline to the mobility startup&rsquo;s real-time fleet tracking to whatever my infrastructure startup becomes, has taught me the same lesson. The gap between staging and production is where your real bugs live. You can ignore that gap and be surprised, or you can instrument it and be prepared.</p>
<p>I prefer being prepared. It&rsquo;s less exciting, but I sleep better.</p>
]]></content:encoded></item><item><title>GitOps with Flux and Argo CD: Stop Deploying From a Laptop</title><link>https://lawzava.com/blog/2019-02-11-gitops-principles-and-practices/</link><pubDate>Mon, 11 Feb 2019 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2019-02-11-gitops-principles-and-practices/</guid><description>How to move a team off ad-hoc kubectl deploys to Git-driven Kubernetes with Flux and Argo CD: repo layout, secrets, rollbacks, and my mistakes.</description><content:encoded><![CDATA[<p>If your deployment process involves someone running kubectl on a laptop, you don&rsquo;t have a deployment process. You have a person. GitOps replaces that person with a Git repo and a controller that remembers what it did.</p>
<p>At the fintech startup, our &ldquo;deployment pipeline&rdquo; for the first few months was me running <code>kubectl apply</code> from my MacBook at 11pm. I had a checklist in Notes.app. It worked until I forgot step 4 one night and took down the price feed for 45 minutes.</p>
<p>The outage wasn&rsquo;t catastrophic, but it made me realize that if I got hit by a bus, nobody else could deploy. The entire process lived in my head and my shell history.</p>
<p>GitOps fixed that. It took a while, and it stuck.</p>
<h2 id="what-gitops-is">What GitOps is</h2>
<p>GitOps is a principle: <strong>Git is the single source of truth for what your infrastructure should look like, and a controller continuously reconciles reality to match.</strong></p>
<p>That&rsquo;s it. Everything else is implementation detail.</p>
<p>The word gets thrown around a lot in 2019, mostly by vendors trying to sell dashboards. Strip away the marketing and you get three rules:</p>
<ol>
<li>Declare your desired state in  <a href="/blog/2018-10-29-infrastructure-as-code-patterns/"
   
   >files checked into Git</a>
</li>
<li>Run a controller that watches those files and applies changes automatically</li>
<li>Never touch the cluster directly</li>
</ol>
<p>If a change isn&rsquo;t in Git, it didn&rsquo;t happen. Full stop.</p>
<h2 id="why-pull-based-beats-push-based">Why pull-based beats push-based</h2>
<p>Most  <a href="/blog/2016-06-06-continuous-deployment-without-chaos/"
   
   >CI/CD pipelines</a>
 are push-based. Jenkins builds your image, then runs <code>kubectl apply</code> against the cluster. The problem: Jenkins now needs cluster credentials, network access, and the ability to mutate production state. Your CI system becomes a god-mode attack surface.</p>
<p>Pull-based GitOps flips this. The controller runs <em>inside</em> the cluster. It watches a Git repo and pulls changes when it sees a new commit. The cluster reaches out to Git, not the other way around.</p>
<pre tabindex="0"><code>Push model:  CI --&gt; kubectl apply --&gt; Cluster
Pull model:  Cluster &lt;-- controller watches &lt;-- Git repo
</code></pre><p>The pull model wins on security first. No cluster credentials in CI. No network path from build servers to production. And because the controller keeps comparing the cluster with Git, drift shows up instead of accumulating quietly.</p>
<h2 id="setting-it-up-a-real-example">Setting it up: a real example</h2>
<p>Here is the repo layout I settled on after trying three different approaches. It&rsquo;s for Go microservices on  <a href="/blog/2019-01-14-kubernetes-best-practices-2019/"
   
   >Kubernetes</a>
, so it&rsquo;s Kustomize-flavored.</p>
<pre tabindex="0"><code>infra/
  apps/
    api-gateway/
      base/
        deployment.yaml
        service.yaml
        kustomization.yaml
      overlays/
        staging/
          kustomization.yaml
          replicas.yaml
        production/
          kustomization.yaml
          replicas.yaml
          hpa.yaml
    auth-service/
      base/
        ...
      overlays/
        ...
  platform/
    namespaces/
    network-policies/
    rbac/
</code></pre><p>The <code>apps/</code> directory is owned by service teams. The <code>platform/</code> directory is owned by me (or whoever is on infra that week). This separation matters more than any specific tool choice.</p>
<h3 id="the-base-deployment">The base deployment</h3>
<p>Nothing exotic here. A standard Kubernetes deployment with explicit resource requests, health checks, and a pinned image tag. No <code>latest</code>. Ever.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#75715e"># apps/api-gateway/base/deployment.yaml</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">apiVersion</span>: <span style="color:#ae81ff">apps/v1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">kind</span>: <span style="color:#ae81ff">Deployment</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">metadata</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">name</span>: <span style="color:#ae81ff">api-gateway</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">spec</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">replicas</span>: <span style="color:#ae81ff">2</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">selector</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">matchLabels</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">app</span>: <span style="color:#ae81ff">api-gateway</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">template</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">metadata</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">labels</span>:
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">app</span>: <span style="color:#ae81ff">api-gateway</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">spec</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">containers</span>:
</span></span><span style="display:flex;"><span>        - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">api-gateway</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">image</span>: <span style="color:#ae81ff">registry.example.com/api-gateway:v0.8.3</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">ports</span>:
</span></span><span style="display:flex;"><span>            - <span style="color:#f92672">containerPort</span>: <span style="color:#ae81ff">8080</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">resources</span>:
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">requests</span>:
</span></span><span style="display:flex;"><span>              <span style="color:#f92672">cpu</span>: <span style="color:#e6db74">&#34;100m&#34;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#f92672">memory</span>: <span style="color:#e6db74">&#34;128Mi&#34;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">limits</span>:
</span></span><span style="display:flex;"><span>              <span style="color:#f92672">cpu</span>: <span style="color:#e6db74">&#34;500m&#34;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#f92672">memory</span>: <span style="color:#e6db74">&#34;256Mi&#34;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">livenessProbe</span>:
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">httpGet</span>:
</span></span><span style="display:flex;"><span>              <span style="color:#f92672">path</span>: <span style="color:#ae81ff">/healthz</span>
</span></span><span style="display:flex;"><span>              <span style="color:#f92672">port</span>: <span style="color:#ae81ff">8080</span>
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">initialDelaySeconds</span>: <span style="color:#ae81ff">10</span>
</span></span><span style="display:flex;"><span>          <span style="color:#f92672">readinessProbe</span>:
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">httpGet</span>:
</span></span><span style="display:flex;"><span>              <span style="color:#f92672">path</span>: <span style="color:#ae81ff">/ready</span>
</span></span><span style="display:flex;"><span>              <span style="color:#f92672">port</span>: <span style="color:#ae81ff">8080</span>
</span></span><span style="display:flex;"><span>            <span style="color:#f92672">initialDelaySeconds</span>: <span style="color:#ae81ff">5</span>
</span></span></code></pre></div><h3 id="the-production-overlay">The production overlay</h3>
<p>Production gets more replicas, an HPA, and a specific image tag. The overlay touches only what differs.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#75715e"># apps/api-gateway/overlays/production/kustomization.yaml</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">apiVersion</span>: <span style="color:#ae81ff">kustomize.config.k8s.io/v1beta1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">kind</span>: <span style="color:#ae81ff">Kustomization</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">namespace</span>: <span style="color:#ae81ff">production</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">resources</span>:
</span></span><span style="display:flex;"><span>  - <span style="color:#ae81ff">../../base</span>
</span></span><span style="display:flex;"><span>  - <span style="color:#ae81ff">hpa.yaml</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">patchesStrategicMerge</span>:
</span></span><span style="display:flex;"><span>  - <span style="color:#ae81ff">replicas.yaml</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">images</span>:
</span></span><span style="display:flex;"><span>  - <span style="color:#f92672">name</span>: <span style="color:#ae81ff">registry.example.com/api-gateway</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">newTag</span>: <span style="color:#ae81ff">v0.8.3</span>
</span></span></code></pre></div><p>This is the file that changes on every deploy. A version bump is a one-line diff in a pull request. Reviewable. Revertable. Boring.</p>
<h2 id="choosing-a-controller-flux-vs-argo-cd">Choosing a controller: Flux vs Argo CD</h2>
<p>In early 2019, the two serious options are Flux and Argo CD. I&rsquo;ve run both.</p>
<p><strong>Flux</strong> is simple. It watches a Git repo, syncs to a cluster, done. Installing it is one Helm chart that runs a Deployment pointed at your repo:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>helm repo add weaveworks https://weaveworks.github.io/flux
</span></span><span style="display:flex;"><span>helm install --name flux <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  --set git.url<span style="color:#f92672">=</span>git@github.com:example/infra.git <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  --set git.branch<span style="color:#f92672">=</span>master <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  --set git.path<span style="color:#f92672">=</span>apps/ <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  --namespace flux <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  weaveworks/flux
</span></span></code></pre></div><p>Flux feels like a Unix tool. It does one thing. If you want a UI or multi-cluster visibility, look elsewhere.</p>
<p><strong>Argo CD</strong> is heavier but more featureful. You define Applications as custom resources:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">apiVersion</span>: <span style="color:#ae81ff">argoproj.io/v1alpha1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">kind</span>: <span style="color:#ae81ff">Application</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">metadata</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">name</span>: <span style="color:#ae81ff">api-gateway</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">namespace</span>: <span style="color:#ae81ff">argocd</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">spec</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">project</span>: <span style="color:#ae81ff">default</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">source</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">repoURL</span>: <span style="color:#ae81ff">https://github.com/example/infra</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">targetRevision</span>: <span style="color:#ae81ff">master</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">path</span>: <span style="color:#ae81ff">apps/api-gateway/overlays/production</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">destination</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">server</span>: <span style="color:#ae81ff">https://kubernetes.default.svc</span>
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">namespace</span>: <span style="color:#ae81ff">production</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">syncPolicy</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">automated</span>:
</span></span><span style="display:flex;"><span>      <span style="color:#f92672">prune</span>: <span style="color:#66d9ef">true</span>
</span></span></code></pre></div><p>Automated sync with <code>prune: true</code> makes a merged commit the deploy, deletions included. And when someone runs a manual <code>kubectl edit</code> in production, the UI marks the application OutOfSync, so drift is visible to the whole team. That alone is worth the setup cost.</p>
<p>My recommendation: start with Flux if you have one cluster and want simplicity. Move to Argo CD when you need multi-cluster, a UI for the team, or you&rsquo;re tired of explaining to people what state the cluster is in.</p>
<p>We started with Flux. Moved to Argo CD three months later. No regrets on either decision.</p>
<h2 id="the-deployment-workflow">The deployment workflow</h2>
<p>Here is how a deploy actually works once this is set up:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># Developer bumps the image tag after CI builds a new version</span>
</span></span><span style="display:flex;"><span>git checkout -b deploy/api-gateway-v0.8.4
</span></span><span style="display:flex;"><span>vim apps/api-gateway/overlays/production/kustomization.yaml
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Change newTag: v0.8.3 -&gt; v0.8.4</span>
</span></span><span style="display:flex;"><span>git add -A <span style="color:#f92672">&amp;&amp;</span> git commit -m <span style="color:#e6db74">&#34;deploy: api-gateway v0.8.4&#34;</span>
</span></span><span style="display:flex;"><span>git push origin deploy/api-gateway-v0.8.4
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Open PR, get review, merge</span>
</span></span></code></pre></div><p>After merge, the controller picks up the change on its next poll (every few minutes by default; the interval is configurable). The rollout happens. Monitoring confirms. Done.</p>
<p>Compare that to the old world:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># The old way -- do not do this</span>
</span></span><span style="display:flex;"><span>kubectl set image deployment/api-gateway <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  api-gateway<span style="color:#f92672">=</span>registry.example.com/api-gateway:v0.8.4 <span style="color:#ae81ff">\
</span></span></span><span style="display:flex;"><span><span style="color:#ae81ff"></span>  -n production
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Hope you remember what you just did</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Hope the next person knows too</span>
</span></span></code></pre></div><p>The first approach gives you an author, a reviewer, a timestamp, a diff, and a one-command rollback (<code>git revert</code>). The second gives you nothing.</p>
<h2 id="secrets-the-hard-part">Secrets: the hard part</h2>
<p>Secrets are where GitOps gets uncomfortable. You want everything in Git, but you can&rsquo;t commit plaintext credentials. In 2019, the options are:</p>
<p><strong>Mozilla SOPS</strong> encrypts values in-place using KMS or PGP. The file structure stays readable, only the values are encrypted. This is what I use.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#75715e"># secrets.enc.yaml (encrypted with SOPS)</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">apiVersion</span>: <span style="color:#ae81ff">v1</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">kind</span>: <span style="color:#ae81ff">Secret</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">metadata</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">name</span>: <span style="color:#ae81ff">api-gateway-secrets</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">data</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">DATABASE_URL</span>: <span style="color:#ae81ff">ENC[AES256_GCM,data:abc123...,type:str]</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">API_KEY</span>: <span style="color:#ae81ff">ENC[AES256_GCM,data:def456...,type:str]</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">sops</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">kms</span>:
</span></span><span style="display:flex;"><span>    - <span style="color:#f92672">arn</span>: <span style="color:#ae81ff">arn:aws:kms:eu-west-1:123:key/abc-def</span>
</span></span></code></pre></div><p><strong>Bitnami Sealed Secrets</strong> encrypts secrets with a cluster-side key. Safe to commit the encrypted form. Decryption only happens inside the cluster.</p>
<p><strong>External secret managers</strong> such as Vault or AWS Secrets Manager. The secret reference lives in Git, the actual value lives elsewhere. More moving parts, but better for large orgs.</p>
<p>Pick one. Don&rsquo;t commit plaintext. I&rsquo;ve seen production database passwords in public GitHub repos more times than I want to admit.</p>
<h2 id="handling-emergencies">Handling emergencies</h2>
<p>Sometimes you need to bypass the process. A P1 incident at 3am isn&rsquo;t the time to open a pull request.</p>
<p>The rule: <strong>fix it now, commit it immediately after.</strong></p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span><span style="color:#75715e"># 1. Fix the fire</span>
</span></span><span style="display:flex;"><span>kubectl rollout undo deployment/api-gateway -n production
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 2. Immediately capture in Git (before you forget or go back to sleep)</span>
</span></span><span style="display:flex;"><span>git checkout -b hotfix/api-gateway-rollback
</span></span><span style="display:flex;"><span><span style="color:#75715e"># Update manifests to match the rolled-back state</span>
</span></span><span style="display:flex;"><span>git commit -m <span style="color:#e6db74">&#34;hotfix: rollback api-gateway to v0.8.3 (incident #47)&#34;</span>
</span></span><span style="display:flex;"><span>git push <span style="color:#f92672">&amp;&amp;</span> <span style="color:#75715e"># open PR</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># 3. Write a note in the incident channel explaining why you bypassed GitOps</span>
</span></span></code></pre></div><p>If you skip step 2, the controller will eventually reconcile and re-deploy the broken version. I learned this the hard way: we had a demo the next morning and I rolled back manually without committing. Woke up to the broken version redeployed by Flux at 6am. Fun times.</p>
<h2 id="what-drift-detection-tells-you">What drift detection tells you</h2>
<p>When you first enable GitOps, the controller will fight you. It will revert manual changes, flag resources you forgot about, and generally make noise.</p>
<p>Good. That noise is telling you things:</p>
<ul>
<li>A developer ran <code>kubectl edit</code> because the PR process felt too slow. Fix the process.</li>
<li>A resource exists in the cluster that isn&rsquo;t in Git. Either add it to Git or delete it.</li>
<li>Someone created a secret manually during an incident. Capture it properly.</li>
</ul>
<p>Drift detection is your audit system running in real time. Treat every drift event as a process fix to make, and don&rsquo;t suppress it.</p>
<h2 id="repo-structure-mono-vs-split">Repo structure: mono vs split</h2>
<p>I tried three approaches before settling:</p>
<p><strong>Mono-repo (app + infra together).</strong> Simple for tiny teams. Falls apart when you have more than ~5 services because every deploy touches the same repo and branch protection gets weird.</p>
<p><strong>Split repos (one for app, one for infra).</strong> Clean ownership boundaries. The infra repo becomes the system of record. Cross-cutting changes require two PRs, which is annoying but forces you to think about coupling. This is what I recommend for most teams.</p>
<p><strong>Per-app manifests in app repos.</strong> Each service owns its deployment config. Great for autonomy, terrible for platform-wide changes like &ldquo;update the sidecar version on every service.&rdquo; You will end up writing a bot to open 30 PRs.</p>
<p>For a team of 3-10 engineers, split repos with Kustomize overlays is the sweet spot. You can always migrate later; your manifests are just files in Git.</p>
<h2 id="what-i-got-wrong">What I got wrong</h2>
<p>A few mistakes worth sharing:</p>
<p><strong>I over-automated image updates.</strong> I set up Flux&rsquo;s auto-image-update feature, which watches a registry and commits new tags automatically. Sounds great. In practice, it deployed a broken build at 2am because CI had a flaky test that passed on a bad commit. Explicit tag bumps via PRs are slower but safer. I turned off auto-updates within a week.</p>
<p><strong>I didn&rsquo;t enforce branch protection early enough.</strong> For the first month, anyone could push directly to master on the infra repo. One accidental force-push later, I added required reviews and status checks. Should have been day one.</p>
<p><strong>I skipped the README.</strong> New engineers had no idea how to deploy. The process was obvious to me because I built it. It wasn&rsquo;t obvious to anyone else. A one-page doc explaining &ldquo;how to deploy a new version&rdquo; saved hours of Slack questions.</p>
<h2 id="getting-started">Getting started</h2>
<p>If you&rsquo;re reading this and still deploying with kubectl from a laptop, here is what I would do tomorrow:</p>
<ol>
<li>Create an infra repo. Move your manifests there.</li>
<li>Install Flux and point it at the repo.</li>
<li>Enable branch protection on master. Require one review.</li>
<li>Deploy something small through a PR. Watch it sync.</li>
<li>Delete kubectl access for your CI system. If CI can&rsquo;t touch the cluster, it won&rsquo;t.</li>
</ol>
<p>You can do steps 1-4 in an afternoon. Step 5 takes courage, but it&rsquo;s the one that makes the whole thing stick.</p>
]]></content:encoded></item><item><title>Security Automation in CI: Stop Reviewing by Hand</title><link>https://lawzava.com/blog/2017-07-17-security-automation-from-manual-to-continuous/</link><pubDate>Mon, 17 Jul 2017 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2017-07-17-security-automation-from-manual-to-continuous/</guid><description>Manual security review can&amp;amp;rsquo;t keep up with continuous delivery. How I moved secret scanning, dependency audits, SAST, and DAST into a fintech CI pipeline.</description><content:encoded><![CDATA[<p>Automate the boring security checks. Put humans on the hard problems. Ship faster with fewer holes.</p>
<p>Classified government environments are rigid, process-heavy, approval-driven. Everything gated. Everything slow. For classified systems, that makes sense.</p>
<p>Fintech isn&rsquo;t classified systems.</p>
<p>At the fintech startup we  <a href="/blog/2016-06-06-continuous-deployment-without-chaos/"
   
   >ship multiple times a day</a>
. We handle financial data, user accounts, payment flows. The attack surface is real. But if I made every deploy wait for a manual security review, we&rsquo;d ship once a week. Maybe. And the devs would hate me. Rightfully so.</p>
<p>So I stopped pretending manual review scales and started building security into the pipeline itself.</p>
<h2 id="the-problem-with-manual-gates">The Problem with Manual Gates</h2>
<p>A manual security review at a startup doing continuous delivery looks like this: a Slack message saying &ldquo;hey can you look at this PR?&rdquo; followed by me context-switching from whatever I&rsquo;m actually working on, skimming the diff, and approving it because I&rsquo;ve got six other things on fire.</p>
<p>That&rsquo;s security theater.</p>
<p>Manual review is slow. It&rsquo;s inconsistent. I catch different things depending on whether I&rsquo;ve had coffee. It doesn&rsquo;t leave an audit trail beyond a thumbs-up emoji. And it absolutely can&rsquo;t cover every commit when you&rsquo;re pushing code dozens of times a day.</p>
<p>The goal is to stop wasting security engineers&rsquo; time on things a script can catch.</p>
<h2 id="what-i-built-layered-pipeline-checks">What I Built: Layered Pipeline Checks</h2>
<p>Security in a pipeline comes in layers. You want cheap, fast checks early and heavier analysis later. The key is that none of it requires a human to manually trigger.</p>
<p><strong>Pre-commit: catch secrets before they leave the laptop.</strong> This is the single highest-value automation I&rsquo;ve ever set up. One leaked API key in a public repo and you&rsquo;re having a very bad week. At the fintech startup, dealing with financial APIs, a leaked key could mean real money walking out the door.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-sh" data-lang="sh"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/sh
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#75715e">## .git/hooks/pre-commit</span>
</span></span><span style="display:flex;"><span>./scripts/scan-secrets.sh <span style="color:#f92672">||</span> exit <span style="color:#ae81ff">1</span>
</span></span></code></pre></div><p>Dead simple. Runs in under a second. Saves you from the kind of incident that makes the news.</p>
<p><strong>PR checks: block the merge if it&rsquo;s dirty.</strong> Static analysis, dependency audit, container scan. All automated. All required to pass. Never <code>allow_failure: true</code>, which turns a gate into a suggestion.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#f92672">security-checks</span>:
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">script</span>:
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">./scripts/sast.sh</span>
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">./scripts/dependency-audit.sh</span>
</span></span><span style="display:flex;"><span>    - <span style="color:#ae81ff">./scripts/container-scan.sh</span>
</span></span><span style="display:flex;"><span>  <span style="color:#f92672">allow_failure</span>: <span style="color:#66d9ef">false</span>
</span></span></code></pre></div><p>Cyber-defense exercises drill in the idea of &ldquo;deny by default.&rdquo; Same principle here. The merge doesn&rsquo;t happen unless the checks are green. No exceptions, no &ldquo;I&rsquo;ll fix it later&rdquo; PRs.</p>
<p><strong>Post-merge: the heavy stuff.</strong> DAST against staging. Security-focused integration tests. Things like &ldquo;can an unauthenticated user hit this admin endpoint?&rdquo; and &ldquo;are the CORS headers actually set right?&rdquo; Static analysis can&rsquo;t catch these. You need a running application.</p>
<p>In production, runtime monitoring and log analysis close the loop. Security becomes a continuous signal instead of a checkbox someone ticked three sprints ago.</p>
<h2 id="making-it-stick">Making It Stick</h2>
<p>Most teams screw up here: they turn on everything at once, get 400 findings on the first run, and the entire dev team starts ignoring the output within a week.</p>
<p>Don&rsquo;t do that.</p>
<p>Start with one check. Make it reliable. Make the failure messages useful. Instead of &ldquo;vulnerability found&rdquo;, say &ldquo;this dependency has a known RCE, upgrade to version X, here&rsquo;s the CVE link.&rdquo; The difference between a useful pipeline and an annoying one is whether the developer knows what to do when it fails.</p>
<p>At the fintech startup I rolled checks out one at a time over a few months. Secret scanning first. Then dependency auditing. Then SAST. Each one tuned, false positives suppressed, team trained on the output before adding the next. Boring, and effective.</p>
<p>Build a suppression process too. Some findings are false positives. Some are accepted risks. That&rsquo;s fine. But track the suppressions and review them. A suppression list that only grows is a red flag.</p>
<h2 id="humans-on-the-hard-problems">Humans on the Hard Problems</h2>
<p>Scanners catch known patterns. SQL injection signatures, outdated libraries, hardcoded credentials. Important stuff. But they can&rsquo;t think.</p>
<p>Threat modeling is a human job. So is reviewing the authentication architecture of a new feature, and penetration testing that simulates an attacker&rsquo;s creativity.  <a href="/blog/2016-05-23-security-incident-response-for-startups/"
   
   >Incident response</a>
 when something real happens at 2 AM is very much a human job.</p>
<p>The whole point of automating the repetitive checks is to free up time for this work. In cyber-defense exercises, dedicated teams handle threat analysis without getting bogged down running vulnerability scanners by hand. Same principle at a startup, except the &ldquo;dedicated team&rdquo; is me and maybe one other person. Which is exactly why automation matters even more.</p>
<h2 id="the-payoff">The Payoff</h2>
<p>Before automation, security at the fintech startup was me trying to review everything and inevitably missing things. After, every single commit gets checked. Every dependency gets audited. Every container gets scanned. And I spend my time on architecture reviews and threat modeling instead of eyeballing diffs.</p>
<p>The pipeline doesn&rsquo;t get tired. It doesn&rsquo;t get distracted. It doesn&rsquo;t approve a PR because it&rsquo;s Friday afternoon and everyone wants to go home.</p>
]]></content:encoded></item><item><title>Continuous Deployment Without the Chaos</title><link>https://lawzava.com/blog/2016-06-06-continuous-deployment-without-chaos/</link><pubDate>Mon, 06 Jun 2016 00:00:00 +0000</pubDate><guid>https://lawzava.com/blog/2016-06-06-continuous-deployment-without-chaos/</guid><description>Continuous deployment is a discipline problem. How we ship a mobility startup&amp;amp;rsquo;s backend many times a day: trusted tests, small changes, fast rollback.</description><content:encoded><![CDATA[<p>The teams that deploy often without breaking things aren&rsquo;t smarter or better staffed. They are more disciplined. Continuous deployment is a set of habits enforced by automation.</p>
<h3 id="deploying-many-times-a-day">Deploying Many Times a Day</h3>
<p>At a mobility startup we deploy our backend services multiple times a day. Not because we decided to be trendy. Because our business requires it. When you&rsquo;re running a shared mobility platform, a broken deploy means vehicles that don&rsquo;t unlock, payments that don&rsquo;t process, and users who open a competitor&rsquo;s app. The cost of a bad release is immediate and measurable.</p>
<p>That urgency forced us to take continuous deployment seriously much earlier than I expected. We were a small team, moving fast, and the only way to ship that fast without constant fires was to build discipline into the pipeline itself.</p>
<h3 id="cd-is-a-discipline-problem">CD Is a Discipline Problem</h3>
<p>Most teams that fail at continuous deployment fail because they treat it as a tooling problem. They install Jenkins, wire up a webhook, and wonder why production keeps breaking on Friday afternoon.</p>
<p>The tooling is the easy part. Jenkins works. GitLab CI is getting better by the month. The hard part is the set of habits that make frequent deploys safe. Habits like writing tests that actually catch regressions. Habits like reviewing changes with deployment risk in mind. Habits like keeping every change small enough to reason about when something goes wrong at midnight.</p>
<p>I&rsquo;ve watched teams with excellent pipelines ship broken code because nobody enforced the discipline around the pipeline. And I&rsquo;ve watched teams with mediocre tooling ship reliably because their habits were strong. Discipline beats tooling every time.</p>
<h3 id="the-pipeline-we-actually-run">The Pipeline We Actually Run</h3>
<p>Our Jenkins setup is straightforward. On every push, it runs the unit tests. If those pass, it builds the Docker image,  <a href="/blog/2016-02-08-docker-in-production-lessons-from-running-containers-at-scale/"
   
   >tags it with the commit SHA</a>
, and pushes it to our private registry. Integration tests run against that image. If everything is green, it deploys to staging automatically. Production deploys happen after a one-click approval (strictly speaking, that makes our production step continuous delivery), and the click takes about ten seconds because the person approving has already seen the diff, the test results, and the staging behavior.</p>
<p>The whole cycle from push to production takes under fifteen minutes on a good day. That speed matters. When the feedback loop is short, developers catch their own mistakes before context switches away. When the loop is long, commits pile up, responsibility diffuses, and nobody knows which change caused the problem.</p>
<p>We also run a nightly full regression suite that catches the slower, more expensive test cases. Those don&rsquo;t block individual deploys, but a red nightly build stops all production deploys the next morning until someone fixes it. No exceptions.</p>
<h3 id="tests-you-can-trust">Tests You Can Trust</h3>
<p>A continuous deployment pipeline is only as strong as the tests it runs. Flaky tests are poison. A test that fails randomly teaches the team to ignore failures. Once that habit forms, real failures get waved through too.</p>
<p>We spent weeks stabilizing our test suite before we trusted it to gate production deploys. That meant removing tests that depended on timing, isolating tests that shared state, and replacing slow end-to-end tests with faster contract tests where possible. It was unglamorous work. It was also the single highest-leverage investment we made in our deployment process.</p>
<p>The rule is simple: if a test fails, it means something is wrong with the code, not with the test. Any test that violates that rule gets fixed or deleted. There&rsquo;s no middle ground.</p>
<h3 id="small-changes-fast-rollback">Small Changes, Fast Rollback</h3>
<p>Every change we deploy is small. Not because we have a policy document that says so. Because small changes are easier to review, easier to test, and critically easier to roll back.</p>
<p>Rollback isn&rsquo;t an afterthought in our process. It&rsquo;s a first-class operation. We keep the previous three Docker images tagged and ready. Rolling back means pointing the load balancer at the previous image. It takes less than a minute. We practice it regularly, not just when things are on fire.</p>
<p>The worst continuous deployment failures I&rsquo;ve seen happened because rollback was theoretical. Someone wrote a wiki page describing the rollback steps, nobody ever tested them, and when the moment came, the steps didn&rsquo;t work. A rollback plan that hasn&rsquo;t been exercised isn&rsquo;t a plan. It&rsquo;s a wish.</p>
<h3 id="monitoring-that-closes-the-loop">Monitoring That Closes the Loop</h3>
<p>Deploying fast without watching the result is just shipping bugs faster. After every production deploy, we watch error rates, response latency, and a handful of business metrics for at least ten minutes. If anything moves in the wrong direction, we roll back first and investigate second.</p>
<p>This is where most teams cut corners. They deploy, see green in the pipeline, and move on. But the pipeline only tells you the tests passed. It doesn&rsquo;t tell you that the new code path is three times slower under real traffic, or that an edge case in the mobile client is now returning 500s.</p>
<p>We use basic Grafana dashboards with alerts that fire if error rate or p99 latency crosses a threshold within the first fifteen minutes after deploy. Nothing sophisticated. Just enough signal to catch the obvious problems before users do.</p>
<h3 id="when-cd-doesnt-fit">When CD Doesn&rsquo;t Fit</h3>
<p>I&rsquo;m not a purist about this. Some systems shouldn&rsquo;t deploy on every green build. Anything that touches payment processing gets an extra review gate. Schema migrations go through a separate, more careful process. And we don&rsquo;t pretend that mobile app releases can follow the same cadence as backend services when the App Store review cycle exists.</p>
<p>The point of continuous deployment isn&rsquo;t to deploy everything all the time. It&rsquo;s to make deployment a non-event for the systems where speed matters. For everything else, continuous delivery, where the artifact is always ready but the final step is manual, is perfectly fine.</p>
<h3 id="ship-the-habits-first">Ship the habits first</h3>
<p>After months of running this process, what matters most is the team&rsquo;s relationship with production. When developers  <a href="/blog/2016-03-10-building-devops-culture-from-scratch/"
   
   >own the deploy and own the monitoring</a>
, they write smaller changes and better tests, and they think about rollback before they write the feature.</p>
<p>If you want continuous deployment, start with discipline. Make your tests trustworthy. Make your changes small. Make rollback fast and practiced. Make monitoring non-negotiable. The tooling will follow. Jenkins, GitLab CI, or whatever comes next won&rsquo;t matter if the habits aren&rsquo;t there first.</p>
]]></content:encoded></item></channel></rss>