<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://blog.bogovic.dev/feed.xml" rel="self" type="application/atom+xml" /><link href="https://blog.bogovic.dev/" rel="alternate" type="text/html" hreflang="en" /><updated>2026-11-26T15:40:04+01:00</updated><id>https://blog.bogovic.dev/feed.xml</id><title type="html">Ivan Bogović</title><subtitle>IT Engineering Leader | Infrastructure, Security &amp; Scalable Operations | Zürich, Switzerland
</subtitle><author><name>Ivan Bogović</name></author><entry><title type="html">NFS mounts that do not hang your boot or your shell</title><link href="https://blog.bogovic.dev/2026/11/26/nfs-mounts-that-dont-hang-boot.html" rel="alternate" type="text/html" title="NFS mounts that do not hang your boot or your shell" /><published>2026-11-26T00:00:00+01:00</published><updated>2026-11-26T00:00:00+01:00</updated><id>https://blog.bogovic.dev/2026/11/26/nfs-mounts-that-dont-hang-boot</id><content type="html" xml:base="https://blog.bogovic.dev/2026/11/26/nfs-mounts-that-dont-hang-boot.html"><![CDATA[<p>The storage team reboots a filer during a maintenance window. Twenty minutes later half your application servers are stuck: <code class="language-plaintext highlighter-rouge">df</code> hangs, <code class="language-plaintext highlighter-rouge">ls /</code> hangs when tab completion touches the mount point, and one host that rebooted at the same time sits in emergency mode because <code class="language-plaintext highlighter-rouge">/srv/shared</code> never came up. Nothing on those servers was broken. The way the NFS share was mounted was.</p>

<p>Most fstab NFS lines I find in the wild look like this:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>filer01:/export/shared  /srv/shared  nfs  defaults  0 0
</code></pre></div></div>

<p>That line carries three problems. It is a hard dependency for boot, so systemd waits on it before reaching <code class="language-plaintext highlighter-rouge">local-fs.target</code> or <code class="language-plaintext highlighter-rouge">remote-fs.target</code> and fails the boot if it cannot mount. It is mounted at boot whether anything needs it or not. And with default hard semantics plus no timeout tuning, any process that touches it while the server is gone blocks in uninterruptible sleep until the server returns.</p>

<h2 id="let-systemd-mount-it-on-demand">Let systemd mount it on demand</h2>

<p>systemd reads fstab and generates <code class="language-plaintext highlighter-rouge">.mount</code> units from it. A few <code class="language-plaintext highlighter-rouge">x-systemd</code> options change the behaviour completely:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>filer01:/export/shared  /srv/shared  nfs  _netdev,nofail,noauto,x-systemd.automount,x-systemd.idle-timeout=10min,x-systemd.mount-timeout=30s,vers=4.2,hard,timeo=600,retrans=2  0 0
</code></pre></div></div>

<p>What each one does:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">x-systemd.automount</code> creates an autofs trigger at <code class="language-plaintext highlighter-rouge">/srv/shared</code>. The real mount happens on first access, not at boot.</li>
  <li><code class="language-plaintext highlighter-rouge">noauto</code> together with automount means boot never waits for the filer.</li>
  <li><code class="language-plaintext highlighter-rouge">nofail</code> keeps a missing mount from pulling the box into emergency mode.</li>
  <li><code class="language-plaintext highlighter-rouge">_netdev</code> marks it as network storage so ordering is after the network is up.</li>
  <li><code class="language-plaintext highlighter-rouge">x-systemd.idle-timeout=10min</code> unmounts after inactivity. That shrinks the window in which a dead server can wedge anything.</li>
  <li><code class="language-plaintext highlighter-rouge">x-systemd.mount-timeout=30s</code> caps how long a mount attempt may block.</li>
</ul>

<p>Apply it without a reboot:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>umount /srv/shared 2&gt;/dev/null <span class="o">||</span> <span class="nb">true
sudo </span>systemctl daemon-reload
<span class="nb">sudo </span>systemctl restart remote-fs.target
systemctl list-units <span class="nt">--type</span><span class="o">=</span>automount
<span class="nb">ls</span> /srv/shared <span class="o">&gt;</span>/dev/null <span class="o">&amp;&amp;</span> findmnt /srv/shared
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">findmnt</code> should now show two entries: an <code class="language-plaintext highlighter-rouge">autofs</code> layer and, after access, the <code class="language-plaintext highlighter-rouge">nfs4</code> mount underneath.</p>

<h2 id="hard-versus-soft-is-not-the-fix-you-think">Hard versus soft is not the fix you think</h2>

<p>The usual reaction to a hang is to switch to <code class="language-plaintext highlighter-rouge">soft</code>. Be careful. A soft mount returns <code class="language-plaintext highlighter-rouge">EIO</code> to the application after the retries expire, and many applications do not handle a failed write well. You can end up with truncated files and no error in the logs that anyone reads. For anything that writes data, keep <code class="language-plaintext highlighter-rouge">hard</code>. It is the correct default because it guarantees a write either completes or waits.</p>

<p>What you control instead is blast radius: automount plus idle timeout means fewer processes are holding the mount when the server disappears, and boot does not depend on it. For read-only shares like software repositories or reference data, <code class="language-plaintext highlighter-rouge">soft</code> with sensible <code class="language-plaintext highlighter-rouge">timeo</code> and <code class="language-plaintext highlighter-rouge">retrans</code> values is acceptable, because the worst case is a failed read that can be retried.</p>

<h2 id="keep-monitoring-and-tooling-off-the-mount">Keep monitoring and tooling off the mount</h2>

<p>A detail that bites in practice: your monitoring agent’s filesystem check calls <code class="language-plaintext highlighter-rouge">statfs</code> on every mount, including the NFS one, and hangs with it. Then you lose metrics for the whole host exactly when you need them. Exclude network filesystems from generic disk checks and monitor them separately with a timeout. For node_exporter that is the <code class="language-plaintext highlighter-rouge">--collector.filesystem.fs-types-exclude</code> flag; for ad hoc scripts, wrap the call:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/usr/bin/env bash</span>
<span class="c"># check-nfs.sh - report whether a mount responds within 5 seconds</span>
<span class="nv">mp</span><span class="o">=</span><span class="s2">"</span><span class="k">${</span><span class="nv">1</span><span class="k">:-</span><span class="p">/srv/shared</span><span class="k">}</span><span class="s2">"</span>
<span class="k">if </span><span class="nb">timeout </span>5 <span class="nb">stat</span> <span class="nt">-f</span> <span class="s2">"</span><span class="nv">$mp</span><span class="s2">"</span> <span class="o">&gt;</span>/dev/null 2&gt;&amp;1<span class="p">;</span> <span class="k">then
  </span><span class="nb">echo</span> <span class="s2">"OK </span><span class="nv">$mp</span><span class="s2">"</span>
<span class="k">else
  </span><span class="nb">echo</span> <span class="s2">"STALE_OR_SLOW </span><span class="nv">$mp</span><span class="s2">"</span>
  <span class="nb">exit </span>2
<span class="k">fi</span>
</code></pre></div></div>

<p>Note that <code class="language-plaintext highlighter-rouge">timeout</code> cannot always kill a process in <code class="language-plaintext highlighter-rouge">D</code> state, so run the check from a separate process per mount and do not let your agent wait on it serially.</p>

<p>Also check <code class="language-plaintext highlighter-rouge">updatedb</code>. On many distributions <code class="language-plaintext highlighter-rouge">mlocate</code> or <code class="language-plaintext highlighter-rouge">plocate</code> is configured to skip <code class="language-plaintext highlighter-rouge">nfs</code> and <code class="language-plaintext highlighter-rouge">nfs4</code> in <code class="language-plaintext highlighter-rouge">PRUNEFS</code>, but I have seen custom configs that dropped that line and had the nightly indexer walk a multi-terabyte share.</p>

<h2 id="verifying-the-behaviour-before-the-filer-does-it-for-you">Verifying the behaviour before the filer does it for you</h2>

<p>Test it on purpose. On a non-production host, block the filer with a temporary firewall rule, then confirm the box still reboots cleanly and that only processes actually touching <code class="language-plaintext highlighter-rouge">/srv/shared</code> stall:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>nft add table inet nfstest
<span class="nb">sudo </span>nft add chain inet nfstest out <span class="s1">'{ type filter hook output priority 0; }'</span>
<span class="nb">sudo </span>nft add rule inet nfstest out ip daddr 192.0.2.10 tcp dport 2049 drop
<span class="c"># reboot, log in, check: systemctl is-system-running; df -h -x nfs4</span>
<span class="nb">sudo </span>nft delete table inet nfstest
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">systemctl is-system-running</code> should report <code class="language-plaintext highlighter-rouge">running</code> or <code class="language-plaintext highlighter-rouge">degraded</code>, not leave you at an emergency shell.</p>

<h2 id="why-this-matters">Why this matters</h2>

<p>Every NFS incident I have been pulled into followed the same pattern: the storage outage was short and planned, and the outage it caused on the compute side was long and unplanned. Hosts sat in emergency mode waiting for someone with console access, monitoring went dark because the agent hung on <code class="language-plaintext highlighter-rouge">statfs</code>, and recovery meant rebooting machines that were never actually broken. Moving the mounts to systemd automount with <code class="language-plaintext highlighter-rouge">nofail</code> and timeouts is a one-line change per share. Doing it before the next filer maintenance window is cheaper than explaining afterwards why a storage reboot took out the application tier.</p>]]></content><author><name>Ivan Bogović</name></author><category term="Linux" /><summary type="html"><![CDATA[The storage team reboots a filer during a maintenance window. Twenty minutes later half your application servers are stuck: df hangs, ls / hangs when tab completion touches the mount point, and one host that rebooted at the same time sits in emergency mode because /srv/shared never came up. Nothing on those servers was broken. The way the NFS share was mounted was. Most fstab NFS lines I find in the wild look like this: filer01:/export/shared /srv/shared nfs defaults 0 0 That line carries three problems. It is a hard dependency for boot, so systemd waits on it before reaching local-fs.target or remote-fs.target and fails the boot if it cannot mount. It is mounted at boot whether anything needs it or not. And with default hard semantics plus no timeout tuning, any process that touches it while the server is gone blocks in uninterruptible sleep until the server returns. Let systemd mount it on demand systemd reads fstab and generates .mount units from it. A few x-systemd options change the behaviour completely: filer01:/export/shared /srv/shared nfs _netdev,nofail,noauto,x-systemd.automount,x-systemd.idle-timeout=10min,x-systemd.mount-timeout=30s,vers=4.2,hard,timeo=600,retrans=2 0 0 What each one does: x-systemd.automount creates an autofs trigger at /srv/shared. The real mount happens on first access, not at boot. noauto together with automount means boot never waits for the filer. nofail keeps a missing mount from pulling the box into emergency mode. _netdev marks it as network storage so ordering is after the network is up. x-systemd.idle-timeout=10min unmounts after inactivity. That shrinks the window in which a dead server can wedge anything. x-systemd.mount-timeout=30s caps how long a mount attempt may block. Apply it without a reboot: sudo umount /srv/shared 2&gt;/dev/null || true sudo systemctl daemon-reload sudo systemctl restart remote-fs.target systemctl list-units --type=automount ls /srv/shared &gt;/dev/null &amp;&amp; findmnt /srv/shared findmnt should now show two entries: an autofs layer and, after access, the nfs4 mount underneath. Hard versus soft is not the fix you think The usual reaction to a hang is to switch to soft. Be careful. A soft mount returns EIO to the application after the retries expire, and many applications do not handle a failed write well. You can end up with truncated files and no error in the logs that anyone reads. For anything that writes data, keep hard. It is the correct default because it guarantees a write either completes or waits. What you control instead is blast radius: automount plus idle timeout means fewer processes are holding the mount when the server disappears, and boot does not depend on it. For read-only shares like software repositories or reference data, soft with sensible timeo and retrans values is acceptable, because the worst case is a failed read that can be retried. Keep monitoring and tooling off the mount A detail that bites in practice: your monitoring agent’s filesystem check calls statfs on every mount, including the NFS one, and hangs with it. Then you lose metrics for the whole host exactly when you need them. Exclude network filesystems from generic disk checks and monitor them separately with a timeout. For node_exporter that is the --collector.filesystem.fs-types-exclude flag; for ad hoc scripts, wrap the call: #!/usr/bin/env bash # check-nfs.sh - report whether a mount responds within 5 seconds mp="${1:-/srv/shared}" if timeout 5 stat -f "$mp" &gt;/dev/null 2&gt;&amp;1; then echo "OK $mp" else echo "STALE_OR_SLOW $mp" exit 2 fi Note that timeout cannot always kill a process in D state, so run the check from a separate process per mount and do not let your agent wait on it serially. Also check updatedb. On many distributions mlocate or plocate is configured to skip nfs and nfs4 in PRUNEFS, but I have seen custom configs that dropped that line and had the nightly indexer walk a multi-terabyte share. Verifying the behaviour before the filer does it for you Test it on purpose. On a non-production host, block the filer with a temporary firewall rule, then confirm the box still reboots cleanly and that only processes actually touching /srv/shared stall: sudo nft add table inet nfstest sudo nft add chain inet nfstest out '{ type filter hook output priority 0; }' sudo nft add rule inet nfstest out ip daddr 192.0.2.10 tcp dport 2049 drop # reboot, log in, check: systemctl is-system-running; df -h -x nfs4 sudo nft delete table inet nfstest systemctl is-system-running should report running or degraded, not leave you at an emergency shell. Why this matters Every NFS incident I have been pulled into followed the same pattern: the storage outage was short and planned, and the outage it caused on the compute side was long and unplanned. Hosts sat in emergency mode waiting for someone with console access, monitoring went dark because the agent hung on statfs, and recovery meant rebooting machines that were never actually broken. Moving the mounts to systemd automount with nofail and timeouts is a one-line change per share. Doing it before the next filer maintenance window is cheaper than explaining afterwards why a storage reboot took out the application tier.]]></summary></entry><entry><title type="html">A kernel sysctl baseline that closes the easy doors</title><link href="https://blog.bogovic.dev/2026/11/25/kernel-sysctl-hardening-baseline.html" rel="alternate" type="text/html" title="A kernel sysctl baseline that closes the easy doors" /><published>2026-11-25T00:00:00+01:00</published><updated>2026-11-25T00:00:00+01:00</updated><id>https://blog.bogovic.dev/2026/11/25/kernel-sysctl-hardening-baseline</id><content type="html" xml:base="https://blog.bogovic.dev/2026/11/25/kernel-sysctl-hardening-baseline.html"><![CDATA[<p>A low-privileged shell on a server is not the end of an incident, it is the start of one. What happens next depends a lot on what the kernel is willing to tell and hand to that user. On a default install, an unprivileged account can often read kernel symbol addresses, read the full kernel log, load eBPF programs, attach ptrace to sibling processes, and create user namespaces. Each of those is a common step in a local privilege escalation chain. None of them is needed by a typical web, database or monitoring host.</p>

<p>The fix is a small set of sysctls, shipped as a drop-in file, checked into the same repo as the rest of your host config. This post walks through the baseline I use, what each setting breaks, and how to verify it actually applied.</p>

<h2 id="the-baseline">The baseline</h2>

<p>Put this in <code class="language-plaintext highlighter-rouge">/etc/sysctl.d/60-hardening.conf</code>. The numeric prefix matters: files are applied in lexical order and later values win, so make sure nothing with a higher number (some distro packages ship <code class="language-plaintext highlighter-rouge">99-*</code> files) overrides you.</p>

<div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Hide kernel pointers from /proc and logs, even for root without CAP_SYSLOG
</span><span class="py">kernel.kptr_restrict</span> <span class="p">=</span> <span class="s">2</span>

<span class="c"># Only privileged users can read dmesg
</span><span class="py">kernel.dmesg_restrict</span> <span class="p">=</span> <span class="s">1</span>

<span class="c"># Disallow unprivileged eBPF; 2 = disabled and cannot be re-enabled at runtime
</span><span class="py">kernel.unprivileged_bpf_disabled</span> <span class="p">=</span> <span class="s">1</span>
<span class="py">net.core.bpf_jit_harden</span> <span class="p">=</span> <span class="s">2</span>

<span class="c"># ptrace only on direct descendants (1); use 2 for admin-only on hosts without debuggers
</span><span class="py">kernel.yama.ptrace_scope</span> <span class="p">=</span> <span class="s">1</span>

<span class="c"># No perf events for unprivileged users
</span><span class="py">kernel.perf_event_paranoid</span> <span class="p">=</span> <span class="s">3</span>

<span class="c"># Disable the magic SysRq key except sync/remount-ro/reboot (16+32+128)
</span><span class="py">kernel.sysrq</span> <span class="p">=</span> <span class="s">176</span>

<span class="c"># Protect against symlink/hardlink tricks in world-writable sticky dirs
</span><span class="py">fs.protected_symlinks</span> <span class="p">=</span> <span class="s">1</span>
<span class="py">fs.protected_hardlinks</span> <span class="p">=</span> <span class="s">1</span>
<span class="py">fs.protected_fifos</span> <span class="p">=</span> <span class="s">2</span>
<span class="py">fs.protected_regular</span> <span class="p">=</span> <span class="s">2</span>

<span class="c"># No core dumps from setuid binaries
</span><span class="py">fs.suid_dumpable</span> <span class="p">=</span> <span class="s">0</span>

<span class="c"># Network: ignore redirects and source routing, log martians
</span><span class="py">net.ipv4.conf.all.accept_redirects</span> <span class="p">=</span> <span class="s">0</span>
<span class="py">net.ipv4.conf.default.accept_redirects</span> <span class="p">=</span> <span class="s">0</span>
<span class="py">net.ipv6.conf.all.accept_redirects</span> <span class="p">=</span> <span class="s">0</span>
<span class="py">net.ipv6.conf.default.accept_redirects</span> <span class="p">=</span> <span class="s">0</span>
<span class="py">net.ipv4.conf.all.send_redirects</span> <span class="p">=</span> <span class="s">0</span>
<span class="py">net.ipv4.conf.all.accept_source_route</span> <span class="p">=</span> <span class="s">0</span>
<span class="py">net.ipv6.conf.all.accept_source_route</span> <span class="p">=</span> <span class="s">0</span>
<span class="py">net.ipv4.conf.all.log_martians</span> <span class="p">=</span> <span class="s">1</span>
<span class="py">net.ipv4.tcp_syncookies</span> <span class="p">=</span> <span class="s">1</span>
</code></pre></div></div>

<p>Load it without a reboot:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>sysctl <span class="nt">--system</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">--system</code> reads every directory in the standard search path, so it also shows you which file set which value. Read that output once; it is the fastest way to spot a later file overriding yours.</p>

<h2 id="what-it-breaks">What it breaks</h2>

<p>This is the part that decides whether the baseline survives its first week.</p>

<ul>
  <li><strong><code class="language-plaintext highlighter-rouge">ptrace_scope = 1</code></strong> breaks attaching <code class="language-plaintext highlighter-rouge">gdb</code> or <code class="language-plaintext highlighter-rouge">strace -p</code> to an arbitrary process as a normal user. Root still can. On build or developer hosts you may want to leave this at 0; on production servers nobody should be attaching debuggers as a regular user anyway.</li>
  <li><strong><code class="language-plaintext highlighter-rouge">unprivileged_bpf_disabled = 1</code></strong> has no effect on root-run tooling like bpftrace, Cilium or most observability agents, because they run privileged. It only stops ordinary users loading programs. Several recent distros already default to 2.</li>
  <li><strong><code class="language-plaintext highlighter-rouge">perf_event_paranoid = 3</code></strong> is a Debian/Ubuntu-specific value (patched kernels). On upstream kernels, values above 2 behave like 2. Unprivileged <code class="language-plaintext highlighter-rouge">perf</code> stops working either way; profiling becomes a sudo task.</li>
  <li><strong>User namespaces</strong> are deliberately not in the list. Disabling them (<code class="language-plaintext highlighter-rouge">user.max_user_namespaces = 0</code>) removes a large attack surface but breaks rootless Podman, Flatpak, some browsers’ sandboxes and systemd features that use private namespaces. Decide per host role, not globally.</li>
  <li><strong>Redirect settings</strong> are wrong on a host that is actually a router or a VPN gateway. Those get their own role file.</li>
</ul>

<h2 id="verifying-it-stuck">Verifying it stuck</h2>

<p>Writing the file is not the same as having the settings. Containers, a stray <code class="language-plaintext highlighter-rouge">99-</code> file from a package, or a module loaded later (the <code class="language-plaintext highlighter-rouge">net.ipv4.conf.*</code> keys for interfaces that appear after boot) can all leave you with a different runtime state. Check the running values, not the file:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/bin/sh</span>
<span class="c"># check-sysctl.sh - exit non-zero if any runtime value differs from the baseline</span>
<span class="nv">rc</span><span class="o">=</span>0
<span class="nb">grep</span> <span class="nt">-Ev</span> <span class="s1">'^\s*(#|$)'</span> /etc/sysctl.d/60-hardening.conf | <span class="k">while </span><span class="nv">IFS</span><span class="o">=</span><span class="s1">'='</span> <span class="nb">read</span> <span class="nt">-r</span> key want<span class="p">;</span> <span class="k">do
    </span><span class="nv">key</span><span class="o">=</span><span class="si">$(</span><span class="nb">echo</span> <span class="s2">"</span><span class="nv">$key</span><span class="s2">"</span> | xargs<span class="si">)</span><span class="p">;</span> <span class="nv">want</span><span class="o">=</span><span class="si">$(</span><span class="nb">echo</span> <span class="s2">"</span><span class="nv">$want</span><span class="s2">"</span> | xargs<span class="si">)</span>
    <span class="nv">have</span><span class="o">=</span><span class="si">$(</span>sysctl <span class="nt">-n</span> <span class="s2">"</span><span class="nv">$key</span><span class="s2">"</span> 2&gt;/dev/null<span class="si">)</span> <span class="o">||</span> <span class="o">{</span> <span class="nb">echo</span> <span class="s2">"MISSING </span><span class="nv">$key</span><span class="s2">"</span><span class="p">;</span> <span class="k">continue</span><span class="p">;</span> <span class="o">}</span>
    <span class="o">[</span> <span class="s2">"</span><span class="nv">$have</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"</span><span class="nv">$want</span><span class="s2">"</span> <span class="o">]</span> <span class="o">||</span> <span class="nb">echo</span> <span class="s2">"DRIFT </span><span class="nv">$key</span><span class="s2"> want=</span><span class="nv">$want</span><span class="s2"> have=</span><span class="nv">$have</span><span class="s2">"</span>
<span class="k">done</span> | <span class="nb">tee</span> /dev/stderr | <span class="nb">grep</span> <span class="nt">-q</span> <span class="nb">.</span> <span class="o">&amp;&amp;</span> <span class="nv">rc</span><span class="o">=</span>1
<span class="nb">exit</span> <span class="nv">$rc</span>
</code></pre></div></div>

<p>Run it from your config management in check mode or as a node-exporter textfile collector job, and alert on a non-zero result. Note that <code class="language-plaintext highlighter-rouge">kernel.yama.ptrace_scope</code> will report missing on kernels without Yama; that is a real finding, not a script bug.</p>

<p>For new interfaces, <code class="language-plaintext highlighter-rouge">net.ipv4.conf.default.*</code> covers anything created after the setting is applied, while <code class="language-plaintext highlighter-rouge">all</code> covers the global switch. Setting both is the habit that avoids surprises with VLAN or bridge interfaces created later.</p>

<h2 id="why-this-matters">Why this matters</h2>

<p>In most post-incident reviews I have been part of, the initial foothold was not the interesting part; the step from service account to root was, and it was usually a kernel or local bug that a hardened default would have made harder or noisier. These settings cost nothing at runtime, take an afternoon to roll out per host role, and remove information leaks that exploit authors rely on. The real work is not the file, it is the role split and the drift check that keeps it true six months later.</p>]]></content><author><name>Ivan Bogović</name></author><category term="Security" /><summary type="html"><![CDATA[A low-privileged shell on a server is not the end of an incident, it is the start of one. What happens next depends a lot on what the kernel is willing to tell and hand to that user. On a default install, an unprivileged account can often read kernel symbol addresses, read the full kernel log, load eBPF programs, attach ptrace to sibling processes, and create user namespaces. Each of those is a common step in a local privilege escalation chain. None of them is needed by a typical web, database or monitoring host. The fix is a small set of sysctls, shipped as a drop-in file, checked into the same repo as the rest of your host config. This post walks through the baseline I use, what each setting breaks, and how to verify it actually applied. The baseline Put this in /etc/sysctl.d/60-hardening.conf. The numeric prefix matters: files are applied in lexical order and later values win, so make sure nothing with a higher number (some distro packages ship 99-* files) overrides you. # Hide kernel pointers from /proc and logs, even for root without CAP_SYSLOG kernel.kptr_restrict = 2 # Only privileged users can read dmesg kernel.dmesg_restrict = 1 # Disallow unprivileged eBPF; 2 = disabled and cannot be re-enabled at runtime kernel.unprivileged_bpf_disabled = 1 net.core.bpf_jit_harden = 2 # ptrace only on direct descendants (1); use 2 for admin-only on hosts without debuggers kernel.yama.ptrace_scope = 1 # No perf events for unprivileged users kernel.perf_event_paranoid = 3 # Disable the magic SysRq key except sync/remount-ro/reboot (16+32+128) kernel.sysrq = 176 # Protect against symlink/hardlink tricks in world-writable sticky dirs fs.protected_symlinks = 1 fs.protected_hardlinks = 1 fs.protected_fifos = 2 fs.protected_regular = 2 # No core dumps from setuid binaries fs.suid_dumpable = 0 # Network: ignore redirects and source routing, log martians net.ipv4.conf.all.accept_redirects = 0 net.ipv4.conf.default.accept_redirects = 0 net.ipv6.conf.all.accept_redirects = 0 net.ipv6.conf.default.accept_redirects = 0 net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.all.accept_source_route = 0 net.ipv6.conf.all.accept_source_route = 0 net.ipv4.conf.all.log_martians = 1 net.ipv4.tcp_syncookies = 1 Load it without a reboot: sudo sysctl --system --system reads every directory in the standard search path, so it also shows you which file set which value. Read that output once; it is the fastest way to spot a later file overriding yours. What it breaks This is the part that decides whether the baseline survives its first week. ptrace_scope = 1 breaks attaching gdb or strace -p to an arbitrary process as a normal user. Root still can. On build or developer hosts you may want to leave this at 0; on production servers nobody should be attaching debuggers as a regular user anyway. unprivileged_bpf_disabled = 1 has no effect on root-run tooling like bpftrace, Cilium or most observability agents, because they run privileged. It only stops ordinary users loading programs. Several recent distros already default to 2. perf_event_paranoid = 3 is a Debian/Ubuntu-specific value (patched kernels). On upstream kernels, values above 2 behave like 2. Unprivileged perf stops working either way; profiling becomes a sudo task. User namespaces are deliberately not in the list. Disabling them (user.max_user_namespaces = 0) removes a large attack surface but breaks rootless Podman, Flatpak, some browsers’ sandboxes and systemd features that use private namespaces. Decide per host role, not globally. Redirect settings are wrong on a host that is actually a router or a VPN gateway. Those get their own role file. Verifying it stuck Writing the file is not the same as having the settings. Containers, a stray 99- file from a package, or a module loaded later (the net.ipv4.conf.* keys for interfaces that appear after boot) can all leave you with a different runtime state. Check the running values, not the file: #!/bin/sh # check-sysctl.sh - exit non-zero if any runtime value differs from the baseline rc=0 grep -Ev '^\s*(#|$)' /etc/sysctl.d/60-hardening.conf | while IFS='=' read -r key want; do key=$(echo "$key" | xargs); want=$(echo "$want" | xargs) have=$(sysctl -n "$key" 2&gt;/dev/null) || { echo "MISSING $key"; continue; } [ "$have" = "$want" ] || echo "DRIFT $key want=$want have=$have" done | tee /dev/stderr | grep -q . &amp;&amp; rc=1 exit $rc Run it from your config management in check mode or as a node-exporter textfile collector job, and alert on a non-zero result. Note that kernel.yama.ptrace_scope will report missing on kernels without Yama; that is a real finding, not a script bug. For new interfaces, net.ipv4.conf.default.* covers anything created after the setting is applied, while all covers the global switch. Setting both is the habit that avoids surprises with VLAN or bridge interfaces created later. Why this matters In most post-incident reviews I have been part of, the initial foothold was not the interesting part; the step from service account to root was, and it was usually a kernel or local bug that a hardened default would have made harder or noisier. These settings cost nothing at runtime, take an afternoon to roll out per host role, and remove information leaks that exploit authors rely on. The real work is not the file, it is the role split and the drift check that keeps it true six months later.]]></summary></entry><entry><title type="html">Stop hand-editing hosts.ini: Ansible inventory straight from NetBox</title><link href="https://blog.bogovic.dev/2026/11/24/ansible-netbox-dynamic-inventory.html" rel="alternate" type="text/html" title="Stop hand-editing hosts.ini: Ansible inventory straight from NetBox" /><published>2026-11-24T00:00:00+01:00</published><updated>2026-11-24T00:00:00+01:00</updated><id>https://blog.bogovic.dev/2026/11/24/ansible-netbox-dynamic-inventory</id><content type="html" xml:base="https://blog.bogovic.dev/2026/11/24/ansible-netbox-dynamic-inventory.html"><![CDATA[<p>Every team I have worked with that runs Ansible against more than a few dozen devices ends up with the same problem: two sources of truth. NetBox (or a spreadsheet pretending to be NetBox) says one thing, and the <code class="language-plaintext highlighter-rouge">hosts.ini</code> in the automation repo says another. A switch gets decommissioned in NetBox, but it stays in the inventory, so the nightly playbook fails on it for three weeks and everyone learns to ignore the red line. A new site comes online, someone forgets to add it to the right group, and it misses the next compliance push.</p>

<p>The fix is not discipline. The fix is to stop keeping a second list. The <code class="language-plaintext highlighter-rouge">netbox.netbox</code> collection ships an inventory plugin that builds the Ansible inventory at runtime from the NetBox API. NetBox becomes the only place where you add, remove or regroup devices.</p>

<h2 id="the-minimal-setup">The minimal setup</h2>

<p>Install the collection and its Python dependency on the control node:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ansible-galaxy collection <span class="nb">install </span>netbox.netbox
python3 <span class="nt">-m</span> pip <span class="nb">install </span>pynetbox
</code></pre></div></div>

<p>Then create an inventory file. The filename must end in <code class="language-plaintext highlighter-rouge">netbox.yml</code> or <code class="language-plaintext highlighter-rouge">netbox.yaml</code>, otherwise the plugin will not claim it:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># inventory/prod.netbox.yml</span>
<span class="na">plugin</span><span class="pi">:</span> <span class="s">netbox.netbox.nb_inventory</span>
<span class="na">api_endpoint</span><span class="pi">:</span> <span class="s">https://netbox.example.internal</span>
<span class="na">validate_certs</span><span class="pi">:</span> <span class="no">true</span>
<span class="na">config_context</span><span class="pi">:</span> <span class="no">false</span>
<span class="na">interfaces</span><span class="pi">:</span> <span class="no">false</span>
<span class="na">flatten_custom_fields</span><span class="pi">:</span> <span class="no">true</span>

<span class="na">query_filters</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="na">status</span><span class="pi">:</span> <span class="s">active</span>
  <span class="pi">-</span> <span class="na">has_primary_ip</span><span class="pi">:</span> <span class="no">true</span>

<span class="na">device_query_filters</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="na">role</span><span class="pi">:</span> <span class="s">access-switch</span>
  <span class="pi">-</span> <span class="na">role</span><span class="pi">:</span> <span class="s">distribution-switch</span>
  <span class="pi">-</span> <span class="na">role</span><span class="pi">:</span> <span class="s">edge-router</span>

<span class="na">group_by</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="s">site</span>
  <span class="pi">-</span> <span class="s">device_roles</span>
  <span class="pi">-</span> <span class="s">platforms</span>

<span class="na">compose</span><span class="pi">:</span>
  <span class="na">ansible_network_os</span><span class="pi">:</span> <span class="s">platform.slug</span>
  <span class="na">ansible_host</span><span class="pi">:</span> <span class="s">primary_ip4.address | ansible.utils.ipaddr('address')</span>
</code></pre></div></div>

<p>The API token comes from the <code class="language-plaintext highlighter-rouge">NETBOX_TOKEN</code> environment variable. Do not put it in the YAML file; that file belongs in git.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">export </span><span class="nv">NETBOX_TOKEN</span><span class="o">=</span><span class="s2">"</span><span class="si">$(</span>pass show netbox/ansible-ro<span class="si">)</span><span class="s2">"</span>
ansible-inventory <span class="nt">-i</span> inventory/prod.netbox.yml <span class="nt">--graph</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">--graph</code> is the first thing to run. It shows you the group tree exactly as Ansible will see it, and it is the fastest way to discover that half your devices have no platform assigned.</p>

<h2 id="the-details-that-matter">The details that matter</h2>

<p><strong>Filter on status and primary IP.</strong> Without <code class="language-plaintext highlighter-rouge">status: active</code>, planned and decommissioned devices land in the inventory and your playbooks try to reach them. Without <code class="language-plaintext highlighter-rouge">has_primary_ip: true</code>, you get hosts with no address, and Ansible falls back to resolving the device name through DNS, which may or may not work and will fail in confusing ways.</p>

<p><strong>Map the platform slug to <code class="language-plaintext highlighter-rouge">ansible_network_os</code>.</strong> If your NetBox platform slugs are <code class="language-plaintext highlighter-rouge">cisco.ios.ios</code>, <code class="language-plaintext highlighter-rouge">cisco.nxos.nxos</code> and so on, the <code class="language-plaintext highlighter-rouge">compose</code> line above means no per-group <code class="language-plaintext highlighter-rouge">ansible_network_os</code> variable is needed. If your slugs are something like <code class="language-plaintext highlighter-rouge">ios-xe</code>, either rename them or add a mapping in <code class="language-plaintext highlighter-rouge">group_vars/platforms_ios-xe.yml</code>. I prefer renaming: one less layer to debug.</p>

<p><strong>Strip the prefix length.</strong> <code class="language-plaintext highlighter-rouge">primary_ip4.address</code> comes back as <code class="language-plaintext highlighter-rouge">10.20.0.5/24</code>. SSH will not accept that. The <code class="language-plaintext highlighter-rouge">ipaddr('address')</code> filter cuts it down; it needs the <code class="language-plaintext highlighter-rouge">ansible.utils</code> collection and the <code class="language-plaintext highlighter-rouge">netaddr</code> Python package.</p>

<p><strong>Groups are generated names.</strong> <code class="language-plaintext highlighter-rouge">group_by: [site]</code> produces groups like <code class="language-plaintext highlighter-rouge">site_zrh1</code>. Your existing playbooks probably target <code class="language-plaintext highlighter-rouge">zurich</code> or <code class="language-plaintext highlighter-rouge">[core]</code>. Either rewrite the <code class="language-plaintext highlighter-rouge">hosts:</code> lines once, or keep a small static file next to the dynamic one that defines parent groups:</p>

<div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># inventory/zz-aliases.ini
</span><span class="nn">[core:children]</span>
<span class="err">device_roles_distribution-switch</span>
<span class="err">device_roles_edge-router</span>
</code></pre></div></div>

<p>Point Ansible at the whole directory (<code class="language-plaintext highlighter-rouge">-i inventory/</code>) and both sources merge. The files load in alphabetical order, so the static aliases must sort after the NetBox file, hence the prefix.</p>

<p><strong>Cache it.</strong> The plugin makes several API calls per run. With a few thousand devices and ad-hoc commands, that adds noticeable latency and load on NetBox. Enable the built-in cache:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">cache</span><span class="pi">:</span> <span class="no">true</span>
<span class="na">cache_plugin</span><span class="pi">:</span> <span class="s">jsonfile</span>
<span class="na">cache_connection</span><span class="pi">:</span> <span class="s">~/.cache/ansible-netbox</span>
<span class="na">cache_timeout</span><span class="pi">:</span> <span class="m">900</span>
</code></pre></div></div>

<p>Fifteen minutes is a reasonable compromise. Run <code class="language-plaintext highlighter-rouge">ansible-inventory --flush-cache</code> when you have just added a device and want it now.</p>

<h2 id="use-a-read-only-token">Use a read-only token</h2>

<p>The inventory only needs read access. Create a dedicated NetBox user with view permissions on DCIM and IPAM, issue a token for it, and mark the token read-only. If the automation host is compromised, the attacker gets a device list, not the ability to rewrite your source of truth.</p>

<h2 id="guard-against-an-empty-inventory">Guard against an empty inventory</h2>

<p>The failure mode that bites hardest: NetBox is down or the token expired, the plugin returns zero hosts, and the scheduled playbook reports success because it ran against nothing. Add a pre-flight check to scheduled jobs:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nv">count</span><span class="o">=</span><span class="si">$(</span>ansible-inventory <span class="nt">-i</span> inventory/ <span class="nt">--list</span> | python3 <span class="nt">-c</span> <span class="s1">'import json,sys; print(len(json.load(sys.stdin)["_meta"]["hostvars"]))'</span><span class="si">)</span>
<span class="k">if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$count</span><span class="s2">"</span> <span class="nt">-lt</span> 50 <span class="o">]</span><span class="p">;</span> <span class="k">then
  </span><span class="nb">echo</span> <span class="s2">"inventory has only </span><span class="nv">$count</span><span class="s2"> hosts, refusing to run"</span> <span class="o">&gt;</span>&amp;2
  <span class="nb">exit </span>1
<span class="k">fi</span>
</code></pre></div></div>

<p>Set the threshold to something sensibly below your real fleet size. A green run against an empty inventory is worse than a red one.</p>

<h2 id="why-this-matters">Why this matters</h2>

<p>Inventory drift is boring until it is the reason a security fix did not reach a site, or a playbook pushed config to a box that was supposed to be gone. In my experience the second list always rots, no matter how good the team is, because updating it is nobody’s real job. Moving the inventory into NetBox makes the device lifecycle one action in one place, and it forces the data quality problems (missing platforms, missing IPs, wrong roles) into the open, where they get fixed instead of worked around.</p>]]></content><author><name>Ivan Bogović</name></author><category term="Automation" /><summary type="html"><![CDATA[Every team I have worked with that runs Ansible against more than a few dozen devices ends up with the same problem: two sources of truth. NetBox (or a spreadsheet pretending to be NetBox) says one thing, and the hosts.ini in the automation repo says another. A switch gets decommissioned in NetBox, but it stays in the inventory, so the nightly playbook fails on it for three weeks and everyone learns to ignore the red line. A new site comes online, someone forgets to add it to the right group, and it misses the next compliance push. The fix is not discipline. The fix is to stop keeping a second list. The netbox.netbox collection ships an inventory plugin that builds the Ansible inventory at runtime from the NetBox API. NetBox becomes the only place where you add, remove or regroup devices. The minimal setup Install the collection and its Python dependency on the control node: ansible-galaxy collection install netbox.netbox python3 -m pip install pynetbox Then create an inventory file. The filename must end in netbox.yml or netbox.yaml, otherwise the plugin will not claim it: # inventory/prod.netbox.yml plugin: netbox.netbox.nb_inventory api_endpoint: https://netbox.example.internal validate_certs: true config_context: false interfaces: false flatten_custom_fields: true query_filters: - status: active - has_primary_ip: true device_query_filters: - role: access-switch - role: distribution-switch - role: edge-router group_by: - site - device_roles - platforms compose: ansible_network_os: platform.slug ansible_host: primary_ip4.address | ansible.utils.ipaddr('address') The API token comes from the NETBOX_TOKEN environment variable. Do not put it in the YAML file; that file belongs in git. export NETBOX_TOKEN="$(pass show netbox/ansible-ro)" ansible-inventory -i inventory/prod.netbox.yml --graph --graph is the first thing to run. It shows you the group tree exactly as Ansible will see it, and it is the fastest way to discover that half your devices have no platform assigned. The details that matter Filter on status and primary IP. Without status: active, planned and decommissioned devices land in the inventory and your playbooks try to reach them. Without has_primary_ip: true, you get hosts with no address, and Ansible falls back to resolving the device name through DNS, which may or may not work and will fail in confusing ways. Map the platform slug to ansible_network_os. If your NetBox platform slugs are cisco.ios.ios, cisco.nxos.nxos and so on, the compose line above means no per-group ansible_network_os variable is needed. If your slugs are something like ios-xe, either rename them or add a mapping in group_vars/platforms_ios-xe.yml. I prefer renaming: one less layer to debug. Strip the prefix length. primary_ip4.address comes back as 10.20.0.5/24. SSH will not accept that. The ipaddr('address') filter cuts it down; it needs the ansible.utils collection and the netaddr Python package. Groups are generated names. group_by: [site] produces groups like site_zrh1. Your existing playbooks probably target zurich or [core]. Either rewrite the hosts: lines once, or keep a small static file next to the dynamic one that defines parent groups: # inventory/zz-aliases.ini [core:children] device_roles_distribution-switch device_roles_edge-router Point Ansible at the whole directory (-i inventory/) and both sources merge. The files load in alphabetical order, so the static aliases must sort after the NetBox file, hence the prefix. Cache it. The plugin makes several API calls per run. With a few thousand devices and ad-hoc commands, that adds noticeable latency and load on NetBox. Enable the built-in cache: cache: true cache_plugin: jsonfile cache_connection: ~/.cache/ansible-netbox cache_timeout: 900 Fifteen minutes is a reasonable compromise. Run ansible-inventory --flush-cache when you have just added a device and want it now. Use a read-only token The inventory only needs read access. Create a dedicated NetBox user with view permissions on DCIM and IPAM, issue a token for it, and mark the token read-only. If the automation host is compromised, the attacker gets a device list, not the ability to rewrite your source of truth. Guard against an empty inventory The failure mode that bites hardest: NetBox is down or the token expired, the plugin returns zero hosts, and the scheduled playbook reports success because it ran against nothing. Add a pre-flight check to scheduled jobs: count=$(ansible-inventory -i inventory/ --list | python3 -c 'import json,sys; print(len(json.load(sys.stdin)["_meta"]["hostvars"]))') if [ "$count" -lt 50 ]; then echo "inventory has only $count hosts, refusing to run" &gt;&amp;2 exit 1 fi Set the threshold to something sensibly below your real fleet size. A green run against an empty inventory is worse than a red one. Why this matters Inventory drift is boring until it is the reason a security fix did not reach a site, or a playbook pushed config to a box that was supposed to be gone. In my experience the second list always rots, no matter how good the team is, because updating it is nobody’s real job. Moving the inventory into NetBox makes the device lifecycle one action in one place, and it forces the data quality problems (missing platforms, missing IPs, wrong roles) into the open, where they get fixed instead of worked around.]]></summary></entry><entry><title type="html">Dropping spoofed traffic at the edge with uRPF on IOS XE</title><link href="https://blog.bogovic.dev/2026/11/23/urpf-on-ios-xe-edges.html" rel="alternate" type="text/html" title="Dropping spoofed traffic at the edge with uRPF on IOS XE" /><published>2026-11-23T00:00:00+01:00</published><updated>2026-11-23T00:00:00+01:00</updated><id>https://blog.bogovic.dev/2026/11/23/urpf-on-ios-xe-edges</id><content type="html" xml:base="https://blog.bogovic.dev/2026/11/23/urpf-on-ios-xe-edges.html"><![CDATA[<p>During a flood, the source addresses in the capture look random. Some of them come from your own public prefix, and some come from RFC 1918 space arriving on an internet-facing interface. None of that traffic should ever have reached the router’s forwarding path. An ingress ACL that lists bogons helps, but it goes stale and it says nothing about your customer-facing interfaces. Unicast Reverse Path Forwarding (uRPF) solves the general case using the routing table you already maintain.</p>

<h2 id="what-urpf-actually-checks">What uRPF actually checks</h2>

<p>For each packet arriving on an interface with uRPF enabled, the router looks up the packet’s source address in the FIB. The mode decides what counts as a pass:</p>

<ul>
  <li><strong>Strict mode</strong> (<code class="language-plaintext highlighter-rouge">rx</code>): the best route back to the source must point out the interface the packet came in on. Use it where routing is symmetric: customer access ports, single-homed sites and server VLANs.</li>
  <li><strong>Loose mode</strong> (<code class="language-plaintext highlighter-rouge">any</code>): any route to the source in the FIB is enough, as long as that route is not a null route. Use it on multi-homed internet edges, where return traffic often leaves through a different link than the one it arrived on.</li>
</ul>

<p>Loose mode looks weak, but it does two useful things. It drops traffic sourced from unrouted space. It also turns your RTBH setup into a source-based blackhole, because a source that resolves to Null0 fails the check.</p>

<h2 id="configuration">Configuration</h2>

<p>Customer-facing or single-homed interface, strict mode:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>interface GigabitEthernet0/0/2
 description CUST-ACME access
 ip address 198.51.100.1 255.255.255.252
 ip verify unicast source reachable-via rx
 ipv6 verify unicast source reachable-via rx
</code></pre></div></div>

<p>Internet transit interface on a dual-homed edge, loose mode:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>interface TenGigabitEthernet0/1/0
 description TRANSIT-A
 ip verify unicast source reachable-via any
 ipv6 verify unicast source reachable-via any
</code></pre></div></div>

<p>If you carry a default route from transit, loose mode passes everything, because every source matches 0.0.0.0/0. On IOS XE, the <code class="language-plaintext highlighter-rouge">allow-default</code> keyword controls this. Without it, a default route is not considered valid for the check, which is the behaviour you want. Leave it off unless you have a specific reason to add it.</p>

<p>Use a numbered ACL to log what you drop without letting the log hide what’s going on:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>access-list 199 deny   ip any any log-input
!
interface GigabitEthernet0/0/2
 ip verify unicast source reachable-via rx 199
</code></pre></div></div>

<p>When a packet fails uRPF, the router evaluates it against ACL 199. A <code class="language-plaintext highlighter-rouge">deny</code> keeps the drop and logs it. A <code class="language-plaintext highlighter-rouge">permit</code> would let the failing packet through, and that is your escape hatch during rollout. Rate-limit the logging (<code class="language-plaintext highlighter-rouge">logging rate-limit</code>) or you will flood your own syslog during an attack.</p>

<h2 id="verifying-it-does-something">Verifying it does something</h2>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>show ip interface GigabitEthernet0/0/2 | include verify|drops
show ip traffic | include RPF
show cef interface GigabitEthernet0/0/2 | include RPF
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">show ip interface</code> shows the per-interface verification drops. Take a baseline right after enabling uRPF, then compare after a day. If drops climb on a port where you expected zero, either a customer is leaking addresses or your routing is less symmetric than you thought. Check which one before you blame the customer.</p>

<p>To track it over time, poll the counters. A small check over SSH with Netmiko is enough for a daily report:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="nn">netmiko</span> <span class="kn">import</span> <span class="n">ConnectHandler</span>
<span class="kn">import</span> <span class="nn">re</span>

<span class="n">dev</span> <span class="o">=</span> <span class="p">{</span><span class="s">"device_type"</span><span class="p">:</span> <span class="s">"cisco_xe"</span><span class="p">,</span> <span class="s">"host"</span><span class="p">:</span> <span class="s">"edge1.example.net"</span><span class="p">,</span>
       <span class="s">"username"</span><span class="p">:</span> <span class="s">"netops"</span><span class="p">,</span> <span class="s">"use_keys"</span><span class="p">:</span> <span class="bp">True</span><span class="p">}</span>

<span class="k">with</span> <span class="n">ConnectHandler</span><span class="p">(</span><span class="o">**</span><span class="n">dev</span><span class="p">)</span> <span class="k">as</span> <span class="n">conn</span><span class="p">:</span>
    <span class="n">out</span> <span class="o">=</span> <span class="n">conn</span><span class="p">.</span><span class="n">send_command</span><span class="p">(</span><span class="s">"show ip interface"</span><span class="p">)</span>

<span class="n">current</span> <span class="o">=</span> <span class="bp">None</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">out</span><span class="p">.</span><span class="n">splitlines</span><span class="p">():</span>
    <span class="k">if</span> <span class="n">line</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">line</span><span class="p">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">" "</span><span class="p">):</span>
        <span class="n">current</span> <span class="o">=</span> <span class="n">line</span><span class="p">.</span><span class="n">split</span><span class="p">()[</span><span class="mi">0</span><span class="p">]</span>
    <span class="n">m</span> <span class="o">=</span> <span class="n">re</span><span class="p">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s">"(\d+) verification drops"</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">m</span> <span class="ow">and</span> <span class="nb">int</span><span class="p">(</span><span class="n">m</span><span class="p">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="k">print</span><span class="p">(</span><span class="sa">f</span><span class="s">"</span><span class="si">{</span><span class="n">current</span><span class="si">}</span><span class="s">: </span><span class="si">{</span><span class="n">m</span><span class="p">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="si">}</span><span class="s"> uRPF drops"</span><span class="p">)</span>
</code></pre></div></div>

<h2 id="where-it-bites">Where it bites</h2>

<ul>
  <li><strong>Asymmetric routing under strict mode.</strong> This is the usual outage. A site that’s dual-homed through two of your PEs, or a customer announcing a more-specific route through a backup link, gets its legitimate return traffic dropped. Before you enable strict mode, check <code class="language-plaintext highlighter-rouge">show ip cef &lt;customer-prefix&gt;</code> and confirm the best path points at that interface.</li>
  <li><strong>ECMP.</strong> Strict mode accepts a packet if the incoming interface is one of the equal-cost paths. That’s fine until an unequal-cost or backup path starts carrying traffic.</li>
  <li><strong>Platform support.</strong> Hardware platforms differ in whether uRPF runs in the forwarding ASIC and whether enabling it costs TCAM or reduces throughput. Read the datasheet and release notes for your exact platform and release rather than assuming software-router behaviour.</li>
  <li><strong>VRFs.</strong> The lookup runs in the interface’s VRF. Leaked routes and shared services in another VRF can fail the check in ways that are not obvious from the global table.</li>
</ul>

<h2 id="rollout-order-that-has-worked-for-me">Rollout order that has worked for me</h2>

<ol>
  <li>Enable loose mode on transit interfaces first. It carries the least risk and filters bogon sources immediately.</li>
  <li>Enable strict mode with a permit-and-log ACL on single-homed customer ports. Leave it for a week and review the log.</li>
  <li>Swap the ACL to deny on any port with clean logs.</li>
  <li>Document every port where strict mode cannot run, with the reason. That list is your asymmetric-routing inventory, and it is useful on its own.</li>
</ol>

<h2 id="why-this-matters">Why this matters</h2>

<p>Most spoofed traffic I have dealt with did not come from clever attackers. It came from misconfigured customer CPE, a NAT box leaking private addresses, or a compromised host on a network that never filtered its egress. uRPF is BCP 38 applied with a single interface command, and loose mode fixes a whole class of problem on edges where nobody wants to maintain a bogon ACL by hand. The real cost is learning where your routing is asymmetric, and you need to know that before an incident forces you to find out.</p>]]></content><author><name>Ivan Bogović</name></author><category term="Cisco" /><summary type="html"><![CDATA[During a flood, the source addresses in the capture look random. Some of them come from your own public prefix, and some come from RFC 1918 space arriving on an internet-facing interface. None of that traffic should ever have reached the router’s forwarding path. An ingress ACL that lists bogons helps, but it goes stale and it says nothing about your customer-facing interfaces. Unicast Reverse Path Forwarding (uRPF) solves the general case using the routing table you already maintain. What uRPF actually checks For each packet arriving on an interface with uRPF enabled, the router looks up the packet’s source address in the FIB. The mode decides what counts as a pass: Strict mode (rx): the best route back to the source must point out the interface the packet came in on. Use it where routing is symmetric: customer access ports, single-homed sites and server VLANs. Loose mode (any): any route to the source in the FIB is enough, as long as that route is not a null route. Use it on multi-homed internet edges, where return traffic often leaves through a different link than the one it arrived on. Loose mode looks weak, but it does two useful things. It drops traffic sourced from unrouted space. It also turns your RTBH setup into a source-based blackhole, because a source that resolves to Null0 fails the check. Configuration Customer-facing or single-homed interface, strict mode: interface GigabitEthernet0/0/2 description CUST-ACME access ip address 198.51.100.1 255.255.255.252 ip verify unicast source reachable-via rx ipv6 verify unicast source reachable-via rx Internet transit interface on a dual-homed edge, loose mode: interface TenGigabitEthernet0/1/0 description TRANSIT-A ip verify unicast source reachable-via any ipv6 verify unicast source reachable-via any If you carry a default route from transit, loose mode passes everything, because every source matches 0.0.0.0/0. On IOS XE, the allow-default keyword controls this. Without it, a default route is not considered valid for the check, which is the behaviour you want. Leave it off unless you have a specific reason to add it. Use a numbered ACL to log what you drop without letting the log hide what’s going on: access-list 199 deny ip any any log-input ! interface GigabitEthernet0/0/2 ip verify unicast source reachable-via rx 199 When a packet fails uRPF, the router evaluates it against ACL 199. A deny keeps the drop and logs it. A permit would let the failing packet through, and that is your escape hatch during rollout. Rate-limit the logging (logging rate-limit) or you will flood your own syslog during an attack. Verifying it does something show ip interface GigabitEthernet0/0/2 | include verify|drops show ip traffic | include RPF show cef interface GigabitEthernet0/0/2 | include RPF show ip interface shows the per-interface verification drops. Take a baseline right after enabling uRPF, then compare after a day. If drops climb on a port where you expected zero, either a customer is leaking addresses or your routing is less symmetric than you thought. Check which one before you blame the customer. To track it over time, poll the counters. A small check over SSH with Netmiko is enough for a daily report: from netmiko import ConnectHandler import re dev = {"device_type": "cisco_xe", "host": "edge1.example.net", "username": "netops", "use_keys": True} with ConnectHandler(**dev) as conn: out = conn.send_command("show ip interface") current = None for line in out.splitlines(): if line and not line.startswith(" "): current = line.split()[0] m = re.search(r"(\d+) verification drops", line) if m and int(m.group(1)) &gt; 0: print(f"{current}: {m.group(1)} uRPF drops") Where it bites Asymmetric routing under strict mode. This is the usual outage. A site that’s dual-homed through two of your PEs, or a customer announcing a more-specific route through a backup link, gets its legitimate return traffic dropped. Before you enable strict mode, check show ip cef &lt;customer-prefix&gt; and confirm the best path points at that interface. ECMP. Strict mode accepts a packet if the incoming interface is one of the equal-cost paths. That’s fine until an unequal-cost or backup path starts carrying traffic. Platform support. Hardware platforms differ in whether uRPF runs in the forwarding ASIC and whether enabling it costs TCAM or reduces throughput. Read the datasheet and release notes for your exact platform and release rather than assuming software-router behaviour. VRFs. The lookup runs in the interface’s VRF. Leaked routes and shared services in another VRF can fail the check in ways that are not obvious from the global table. Rollout order that has worked for me Enable loose mode on transit interfaces first. It carries the least risk and filters bogon sources immediately. Enable strict mode with a permit-and-log ACL on single-homed customer ports. Leave it for a week and review the log. Swap the ACL to deny on any port with clean logs. Document every port where strict mode cannot run, with the reason. That list is your asymmetric-routing inventory, and it is useful on its own. Why this matters Most spoofed traffic I have dealt with did not come from clever attackers. It came from misconfigured customer CPE, a NAT box leaking private addresses, or a compromised host on a network that never filtered its egress. uRPF is BCP 38 applied with a single interface command, and loose mode fixes a whole class of problem on edges where nobody wants to maintain a bogon ACL by hand. The real cost is learning where your routing is asymmetric, and you need to know that before an incident forces you to find out.]]></summary></entry><entry><title type="html">Stop the alert storm: Alertmanager inhibition rules that follow your topology</title><link href="https://blog.bogovic.dev/2026/11/20/alertmanager-inhibition-rules.html" rel="alternate" type="text/html" title="Stop the alert storm: Alertmanager inhibition rules that follow your topology" /><published>2026-11-20T00:00:00+01:00</published><updated>2026-11-20T00:00:00+01:00</updated><id>https://blog.bogovic.dev/2026/11/20/alertmanager-inhibition-rules</id><content type="html" xml:base="https://blog.bogovic.dev/2026/11/20/alertmanager-inhibition-rules.html"><![CDATA[<p>A site uplink drops at 02:10. Within a minute the on-call phone gets the uplink alert, then one alert per unreachable switch behind it, then blackbox probe failures for every service at that site, then a few “target down” alerts from the Prometheus scraping those hosts. Forty pages for one fault. The engineer spends the first ten minutes scrolling through them to find the root cause, when the uplink alert already told them.</p>

<p>Grouping does not fix this. <code class="language-plaintext highlighter-rouge">group_by</code> packs related alerts into one notification, but “related” only means “has the same label values”. The uplink alert and the probe failures carry different <code class="language-plaintext highlighter-rouge">alertname</code> values and often different <code class="language-plaintext highlighter-rouge">job</code> labels, so they end up in separate groups. What you need is a rule that says: while the cause is firing, don’t page on the symptoms. In Alertmanager that is an inhibition rule.</p>

<h2 id="how-inhibition-works">How inhibition works</h2>

<p>An inhibit rule has three parts:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">source_matchers</code>: the alert that, while it fires, does the muting.</li>
  <li><code class="language-plaintext highlighter-rouge">target_matchers</code>: the alerts that can be muted.</li>
  <li><code class="language-plaintext highlighter-rouge">equal</code>: labels that must have the same value on source and target. This keeps an outage at site A from muting alerts at site B.</li>
</ul>

<p>Inhibited alerts are still evaluated, still visible in the Alertmanager UI and API, and still marked as inhibited there. They just don’t produce notifications. Once the source resolves, any target that is still firing gets sent on the next group interval. That last point matters: if the uplink comes back and a switch stays dead, you still hear about the switch.</p>

<h2 id="labels-come-first">Labels come first</h2>

<p>Inhibition only works as well as your labels. If your switch alerts don’t carry a <code class="language-plaintext highlighter-rouge">site</code> label, <code class="language-plaintext highlighter-rouge">equal: [site]</code> has nothing to match, and Alertmanager treats a label that is missing on both sides as equal. That means one source alert with no <code class="language-plaintext highlighter-rouge">site</code> label can mute every target alert that also lacks it. Fix the labels before you write the rules. I add them at scrape time through relabeling or file_sd target labels, so every series and every alert built on it inherits them:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># file_sd target file, one per site</span>
<span class="pi">-</span> <span class="na">targets</span><span class="pi">:</span> <span class="pi">[</span><span class="s2">"</span><span class="s">sw-zrh-01:9116"</span><span class="pi">,</span> <span class="s2">"</span><span class="s">sw-zrh-02:9116"</span><span class="pi">]</span>
  <span class="na">labels</span><span class="pi">:</span>
    <span class="na">site</span><span class="pi">:</span> <span class="s">zrh</span>
    <span class="na">layer</span><span class="pi">:</span> <span class="s">access</span>
<span class="pi">-</span> <span class="na">targets</span><span class="pi">:</span> <span class="pi">[</span><span class="s2">"</span><span class="s">rtr-zrh-edge:9116"</span><span class="pi">]</span>
  <span class="na">labels</span><span class="pi">:</span>
    <span class="na">site</span><span class="pi">:</span> <span class="s">zrh</span>
    <span class="na">layer</span><span class="pi">:</span> <span class="s">edge</span>
</code></pre></div></div>

<p>Then add a severity and a coarse role to each alert rule, so the matchers can stay short:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">groups</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">site-connectivity</span>
    <span class="na">rules</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="na">alert</span><span class="pi">:</span> <span class="s">SiteUplinkDown</span>
        <span class="na">expr</span><span class="pi">:</span> <span class="s">ifOperStatus{layer="edge", ifAlias=~"UPLINK.*"} == </span><span class="m">2</span>
        <span class="na">for</span><span class="pi">:</span> <span class="s">1m</span>
        <span class="na">labels</span><span class="pi">:</span>
          <span class="na">severity</span><span class="pi">:</span> <span class="s">critical</span>
          <span class="na">role</span><span class="pi">:</span> <span class="s">cause</span>
      <span class="pi">-</span> <span class="na">alert</span><span class="pi">:</span> <span class="s">SwitchUnreachable</span>
        <span class="na">expr</span><span class="pi">:</span> <span class="s">up{job="snmp", layer="access"} == </span><span class="m">0</span>
        <span class="na">for</span><span class="pi">:</span> <span class="s">2m</span>
        <span class="na">labels</span><span class="pi">:</span>
          <span class="na">severity</span><span class="pi">:</span> <span class="s">critical</span>
          <span class="na">role</span><span class="pi">:</span> <span class="s">symptom</span>
</code></pre></div></div>

<p>Note the longer <code class="language-plaintext highlighter-rouge">for</code> on the symptom. If the symptom fires before the source, Alertmanager has nothing to inhibit against yet and the page goes out. Give the cause a head start.</p>

<h2 id="the-rules">The rules</h2>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">inhibit_rules</span><span class="pi">:</span>
  <span class="c1"># Uplink down at a site mutes reachability symptoms at the same site</span>
  <span class="pi">-</span> <span class="na">source_matchers</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="s">alertname = SiteUplinkDown</span>
    <span class="na">target_matchers</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="s">role = symptom</span>
    <span class="na">equal</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">site</span><span class="pi">]</span>

  <span class="c1"># A critical alert mutes the warning of the same alert on the same instance</span>
  <span class="pi">-</span> <span class="na">source_matchers</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="s">severity = critical</span>
    <span class="na">target_matchers</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="s">severity = warning</span>
    <span class="na">equal</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">alertname</span><span class="pi">,</span> <span class="nv">instance</span><span class="pi">]</span>

  <span class="c1"># Planned maintenance flag mutes everything at that site except itself</span>
  <span class="pi">-</span> <span class="na">source_matchers</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="s">alertname = SiteMaintenance</span>
    <span class="na">target_matchers</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="s">alertname != SiteMaintenance</span>
    <span class="na">equal</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">site</span><span class="pi">]</span>
</code></pre></div></div>

<p>The second rule is the cheapest win in most setups: disk at 85% warning and disk at 95% critical on the same host should not both page. The third gives you a maintenance switch driven by a metric (a static exporter value or a pushgateway flag), which leaves a trace in Git and in Prometheus, unlike a silence clicked in the UI and forgotten.</p>

<h2 id="test-before-you-reload">Test before you reload</h2>

<p><code class="language-plaintext highlighter-rouge">amtool</code> can validate the config and show you what the routing tree does with a given label set:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>amtool check-config alertmanager.yml
amtool config routes <span class="nb">test</span> <span class="nt">--config</span>.file<span class="o">=</span>alertmanager.yml <span class="nv">site</span><span class="o">=</span>zrh <span class="nv">severity</span><span class="o">=</span>critical <span class="nv">role</span><span class="o">=</span>symptom
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">routes test</code> covers routing, not inhibition. To check inhibition, fire a source alert at a staging Alertmanager and query for targets:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>amtool alert add SiteUplinkDown <span class="nv">site</span><span class="o">=</span>zrh <span class="nv">severity</span><span class="o">=</span>critical <span class="nv">role</span><span class="o">=</span>cause <span class="se">\</span>
  <span class="nt">--alertmanager</span>.url<span class="o">=</span>http://am-staging:9093
amtool alert add SwitchUnreachable <span class="nv">site</span><span class="o">=</span>zrh <span class="nv">instance</span><span class="o">=</span>sw-zrh-01 <span class="nv">role</span><span class="o">=</span>symptom <span class="se">\</span>
  <span class="nt">--alertmanager</span>.url<span class="o">=</span>http://am-staging:9093
amtool alert query <span class="nt">--inhibited</span> <span class="nt">--alertmanager</span>.url<span class="o">=</span>http://am-staging:9093
</code></pre></div></div>

<p>If <code class="language-plaintext highlighter-rouge">SwitchUnreachable</code> doesn’t show as inhibited, the label isn’t where you think it is. In my experience that’s the usual cause.</p>

<h2 id="things-that-bite">Things that bite</h2>

<ul>
  <li>Inhibition is evaluated per Alertmanager instance. In an HA cluster every node needs the same config, or different nodes will make different decisions. Deploy the config from one source.</li>
  <li>Don’t let a source inhibit itself. A broad <code class="language-plaintext highlighter-rouge">source_matchers: severity=critical</code> paired with <code class="language-plaintext highlighter-rouge">target_matchers: severity=critical</code> mutes everything. Alertmanager won’t let an alert inhibit itself, but two critical alerts that share the <code class="language-plaintext highlighter-rouge">equal</code> labels can still mute each other.</li>
  <li>Keep an eye on the cause. If the source alert’s expression breaks (renamed metric, dropped scrape), you lose the page about it and keep the inhibition logic around for nothing. Pair cause alerts with an absent-data check.</li>
</ul>

<h2 id="why-this-matters">Why this matters</h2>

<p>On a bad night the on-call engineer’s attention is the scarcest thing you have. Every symptom page is another thing they have to read, acknowledge and dismiss before they can act. I’ve seen teams start muting whole channels after a few storms, and then the one page that mattered got missed. Inhibition rules turn your network topology into alert logic: one page for the cause, with the symptoms still there in the UI for anyone who wants to check the blast radius. It’s maybe thirty lines of YAML plus the label hygiene you should have anyway.</p>]]></content><author><name>Ivan Bogović</name></author><category term="Monitoring" /><summary type="html"><![CDATA[A site uplink drops at 02:10. Within a minute the on-call phone gets the uplink alert, then one alert per unreachable switch behind it, then blackbox probe failures for every service at that site, then a few “target down” alerts from the Prometheus scraping those hosts. Forty pages for one fault. The engineer spends the first ten minutes scrolling through them to find the root cause, when the uplink alert already told them. Grouping does not fix this. group_by packs related alerts into one notification, but “related” only means “has the same label values”. The uplink alert and the probe failures carry different alertname values and often different job labels, so they end up in separate groups. What you need is a rule that says: while the cause is firing, don’t page on the symptoms. In Alertmanager that is an inhibition rule. How inhibition works An inhibit rule has three parts: source_matchers: the alert that, while it fires, does the muting. target_matchers: the alerts that can be muted. equal: labels that must have the same value on source and target. This keeps an outage at site A from muting alerts at site B. Inhibited alerts are still evaluated, still visible in the Alertmanager UI and API, and still marked as inhibited there. They just don’t produce notifications. Once the source resolves, any target that is still firing gets sent on the next group interval. That last point matters: if the uplink comes back and a switch stays dead, you still hear about the switch. Labels come first Inhibition only works as well as your labels. If your switch alerts don’t carry a site label, equal: [site] has nothing to match, and Alertmanager treats a label that is missing on both sides as equal. That means one source alert with no site label can mute every target alert that also lacks it. Fix the labels before you write the rules. I add them at scrape time through relabeling or file_sd target labels, so every series and every alert built on it inherits them: # file_sd target file, one per site - targets: ["sw-zrh-01:9116", "sw-zrh-02:9116"] labels: site: zrh layer: access - targets: ["rtr-zrh-edge:9116"] labels: site: zrh layer: edge Then add a severity and a coarse role to each alert rule, so the matchers can stay short: groups: - name: site-connectivity rules: - alert: SiteUplinkDown expr: ifOperStatus{layer="edge", ifAlias=~"UPLINK.*"} == 2 for: 1m labels: severity: critical role: cause - alert: SwitchUnreachable expr: up{job="snmp", layer="access"} == 0 for: 2m labels: severity: critical role: symptom Note the longer for on the symptom. If the symptom fires before the source, Alertmanager has nothing to inhibit against yet and the page goes out. Give the cause a head start. The rules inhibit_rules: # Uplink down at a site mutes reachability symptoms at the same site - source_matchers: - alertname = SiteUplinkDown target_matchers: - role = symptom equal: [site] # A critical alert mutes the warning of the same alert on the same instance - source_matchers: - severity = critical target_matchers: - severity = warning equal: [alertname, instance] # Planned maintenance flag mutes everything at that site except itself - source_matchers: - alertname = SiteMaintenance target_matchers: - alertname != SiteMaintenance equal: [site] The second rule is the cheapest win in most setups: disk at 85% warning and disk at 95% critical on the same host should not both page. The third gives you a maintenance switch driven by a metric (a static exporter value or a pushgateway flag), which leaves a trace in Git and in Prometheus, unlike a silence clicked in the UI and forgotten. Test before you reload amtool can validate the config and show you what the routing tree does with a given label set: amtool check-config alertmanager.yml amtool config routes test --config.file=alertmanager.yml site=zrh severity=critical role=symptom routes test covers routing, not inhibition. To check inhibition, fire a source alert at a staging Alertmanager and query for targets: amtool alert add SiteUplinkDown site=zrh severity=critical role=cause \ --alertmanager.url=http://am-staging:9093 amtool alert add SwitchUnreachable site=zrh instance=sw-zrh-01 role=symptom \ --alertmanager.url=http://am-staging:9093 amtool alert query --inhibited --alertmanager.url=http://am-staging:9093 If SwitchUnreachable doesn’t show as inhibited, the label isn’t where you think it is. In my experience that’s the usual cause. Things that bite Inhibition is evaluated per Alertmanager instance. In an HA cluster every node needs the same config, or different nodes will make different decisions. Deploy the config from one source. Don’t let a source inhibit itself. A broad source_matchers: severity=critical paired with target_matchers: severity=critical mutes everything. Alertmanager won’t let an alert inhibit itself, but two critical alerts that share the equal labels can still mute each other. Keep an eye on the cause. If the source alert’s expression breaks (renamed metric, dropped scrape), you lose the page about it and keep the inhibition logic around for nothing. Pair cause alerts with an absent-data check. Why this matters On a bad night the on-call engineer’s attention is the scarcest thing you have. Every symptom page is another thing they have to read, acknowledge and dismiss before they can act. I’ve seen teams start muting whole channels after a few storms, and then the one page that mattered got missed. Inhibition rules turn your network topology into alert logic: one page for the cause, with the symptoms still there in the UI for anyone who wants to check the blast radius. It’s maybe thirty lines of YAML plus the label hygiene you should have anyway.]]></summary></entry><entry><title type="html">Weekly recap: sshole, HTTP/2 heap bugs and a heavy Patch Tuesday</title><link href="https://blog.bogovic.dev/2026/11/20/weekly-recap-sshole-http2-patch-tuesday.html" rel="alternate" type="text/html" title="Weekly recap: sshole, HTTP/2 heap bugs and a heavy Patch Tuesday" /><published>2026-11-20T00:00:00+01:00</published><updated>2026-11-20T00:00:00+01:00</updated><id>https://blog.bogovic.dev/2026/11/20/weekly-recap-sshole-http2-patch-tuesday</id><content type="html" xml:base="https://blog.bogovic.dev/2026/11/20/weekly-recap-sshole-http2-patch-tuesday.html"><![CDATA[<p>This was a patching week, not a feature week. Nothing on the list is new in kind. Most of it is plumbing we tend to assume is fine: OpenSSH on embedded images, the HTTP/2 stack in front of our apps, and the Windows DNS and DHCP roles that everything else depends on. Here is what I would put on a change board this week, and why.</p>

<h2 id="1-sshole-openssh-on-musl-based-systems-allows-passwordless-login">1. “sshole”: OpenSSH on musl-based systems allows passwordless login</h2>

<p>F5 Labs’ <a href="https://www.f5.com/labs/articles/weekly-threat-bulletin-november-11th-2026">weekly threat bulletin</a> covers an authentication bypass dubbed “sshole”. It involves OpenSSH combined with musl libc and is tracked as CVE-2026-123158, with CVE-2016-6210 listed alongside it. The affected technologies listed are Alpine Linux, Buildroot, Docker, OpenWrt and the Yocto Project, and the victim industries include telecommunications, industrial control and medical devices. Softcat’s <a href="https://www.softcat.com/blog/post-patch-tuesday-roundup-november-2026">Patch Tuesday roundup</a> notes that Linux distributions have shipped fixes and links to the <a href="https://www.openssh.org/releasenotes.html#10.6p2">OpenSSH release notes</a>.</p>

<p>Why it matters operationally: glibc-based servers are not where I would look first. The risk is in Alpine container images that run sshd (they should not, but some do), OpenWrt routers, and appliances built with Buildroot or Yocto that your vendors will be slow to patch. For a network team, that means out-of-band management boxes, console servers and anything else with a small Linux image.</p>

<p>Start by finding out where you actually have musl and sshd together:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># On a host or inside a container: is libc musl, and is sshd present?</span>
ldd <span class="nt">--version</span> 2&gt;&amp;1 | <span class="nb">head</span> <span class="nt">-1</span>
<span class="nb">command</span> <span class="nt">-v</span> sshd <span class="o">&amp;&amp;</span> sshd <span class="nt">-V</span> 2&gt;&amp;1 | <span class="nb">head</span> <span class="nt">-1</span>

<span class="c"># Across running containers on a Docker host</span>
<span class="k">for </span>c <span class="k">in</span> <span class="si">$(</span>docker ps <span class="nt">-q</span><span class="si">)</span><span class="p">;</span> <span class="k">do
  </span><span class="nb">printf</span> <span class="s1">'%s '</span> <span class="s2">"</span><span class="si">$(</span>docker inspect <span class="nt">-f</span> <span class="s1">''</span> <span class="s2">"</span><span class="nv">$c</span><span class="s2">"</span><span class="si">)</span><span class="s2">"</span>
  docker <span class="nb">exec</span> <span class="s2">"</span><span class="nv">$c</span><span class="s2">"</span> sh <span class="nt">-c</span> <span class="s1">'ls /lib/ld-musl-* &gt;/dev/null 2&gt;&amp;1 &amp;&amp; echo musl || echo other; command -v sshd || true'</span> 2&gt;/dev/null | <span class="nb">tr</span> <span class="s1">'\n'</span> <span class="s1">' '</span>
  <span class="nb">echo
</span><span class="k">done</span>
</code></pre></div></div>

<p>If you can’t patch an appliance this week, limit TCP/22 to your management jump hosts at the network layer. Do that anyway, but treat it as a stopgap and keep the patch ticket open.</p>

<h2 id="2-http2-again-nodejs-and-apache-mod_http2">2. HTTP/2 again: Node.js and Apache mod_http2</h2>

<p>HTTP/2 implementations were the second theme. Node.js shipped its <a href="https://nodejs.org/en/blog/vulnerability/november-2026-security-releases">November security releases</a> on 11 November. The items I would read first:</p>

<ul>
  <li>CVE-2026-123863 (high): one unauthenticated request can remotely abort a default HTTP/2 server.</li>
  <li>CVE-2026-123864 (high): on HTTPS servers, a zero-length TLS write can make the server copy its own heap into a request body. <a href="https://phoenix.security/node-js-vulnerabilities-cve-2026-123864-tls-key-leak-http2-crash/">Phoenix Security</a> says this can leak TLS private keys and other users’ requests.</li>
  <li>CVE-2026-123867 (medium): CA-only SNI client-CA overrides fail open to the default CA. In plain terms, per-host mTLS authorization can be bypassed.</li>
  <li>CVE-2026-123871 (medium): proxy credentials appear in <code class="language-plaintext highlighter-rouge">ERR_PROXY_INVALID_CONFIG</code> error messages, so they end up in container logs and your log pipeline.</li>
</ul>

<p>Phoenix says there is no workaround and that the fixed versions are 22.23.5, 24.22.3 and 26.13.1. The proxy credential bug is the one people will underrate. If your services take <code class="language-plaintext highlighter-rouge">HTTPS_PROXY</code> with embedded credentials, assume those credentials may already be sitting in your log aggregation. Rotate them, and fix the log retention while you are at it.</p>

<p>On the Apache side, Phoenix also wrote up <a href="https://phoenix.security/cve-2026-119618-apache-mod-http2-rce/">HTTP2Reset (CVE-2026-119618)</a>, a pre-auth heap corruption bug in <code class="language-plaintext highlighter-rouge">mod_http2</code> with RCE potential. Distro <code class="language-plaintext highlighter-rouge">mod_http2</code> updates appeared in this week’s <a href="https://lwn.net/">LWN security update lists</a>. If you run httpd as a reverse proxy, check that the updated package is installed and that the service was restarted. A package that is installed but not reloaded is the usual gap.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># RHEL-family: confirm package version and that httpd restarted after the update</span>
rpm <span class="nt">-q</span> mod_http2 httpd
systemctl show httpd <span class="nt">-p</span> ActiveEnterTimestamp
</code></pre></div></div>

<h2 id="3-patch-tuesday-dns-dhcp-and-network-stack-on-windows">3. Patch Tuesday: DNS, DHCP and network stack on Windows</h2>

<p>Microsoft’s November release is large. ZDI’s <a href="https://www.thezdi.com/blog/2026/11/10/the-november-2026-security-update-review">review</a> is the easiest way to read it. For infrastructure teams the clusters that matter are:</p>

<ul>
  <li>Windows DHCP Server: several RCEs. ZDI’s table lists CVE-2026-88243 at CVSS 9.8.</li>
  <li>Windows DNS Server and DNS client: a group of RCE and elevation-of-privilege entries.</li>
  <li>Network stack: Schannel (CVE-2026-119952), NAT (CVE-2026-113862) and TCP/IP, all critical. Kerberos has an elevation-of-privilege entry rated 9.8 (CVE-2026-85844).</li>
</ul>

<p>Softcat also flags a zero-day exploited in the wild. A crafted Office file leaks NTLMv2 hashes, which is one more reason to keep pushing NTLM off your network.</p>

<p>Operational note: DHCP and DNS servers are the ones change boards like to push “to next window” because rebooting them is uncomfortable. That is backwards. If you run failover pairs, patch one node, check that leases and resolution still work, then do the partner. If you don’t run failover pairs, this month’s list is a good argument for getting them.</p>

<h2 id="4-edge-devices-are-still-being-exploited">4. Edge devices are still being exploited</h2>

<p>Softcat’s vendor roundup is a reminder that perimeter devices are still the main entry point. It lists two Ivanti Connect Secure vulnerabilities that were chained and exploited as zero-days since at least October, and a SonicOS SSL-VPN authentication bypass that has been exploited. The same roundup lists Fortinet’s monthly batch (FortiOS, FortiManager, FortiAnalyzer, FortiSASE) and critical Cisco fixes for Catalyst SD-WAN Controller, Secure Email Gateway and Meraki.</p>

<p>If you run any of these, patching is not enough. Assume the device may have been compromised before you patched it. Check for unexpected local accounts and configuration changes, and review session logs from the past several weeks. Rotate any credentials the device stored. Ivanti appliances have needed this treatment repeatedly.</p>

<h2 id="what-i-am-taking-into-next-week">What I am taking into next week</h2>

<ul>
  <li>Inventory sshd on musl-based images and appliances. Nobody has a complete list of these until they go and build one.</li>
  <li>Treat the Node.js proxy credential leak as a credential rotation task, not only an upgrade.</li>
  <li>Patch DNS and DHCP this cycle, one node of each failover pair at a time.</li>
  <li>For any exploited edge device, patch first, then run a compromise assessment.</li>
</ul>]]></content><author><name>Ivan Bogović</name></author><category term="Security" /><summary type="html"><![CDATA[This was a patching week, not a feature week. Nothing on the list is new in kind. Most of it is plumbing we tend to assume is fine: OpenSSH on embedded images, the HTTP/2 stack in front of our apps, and the Windows DNS and DHCP roles that everything else depends on. Here is what I would put on a change board this week, and why. 1. “sshole”: OpenSSH on musl-based systems allows passwordless login F5 Labs’ weekly threat bulletin covers an authentication bypass dubbed “sshole”. It involves OpenSSH combined with musl libc and is tracked as CVE-2026-123158, with CVE-2016-6210 listed alongside it. The affected technologies listed are Alpine Linux, Buildroot, Docker, OpenWrt and the Yocto Project, and the victim industries include telecommunications, industrial control and medical devices. Softcat’s Patch Tuesday roundup notes that Linux distributions have shipped fixes and links to the OpenSSH release notes. Why it matters operationally: glibc-based servers are not where I would look first. The risk is in Alpine container images that run sshd (they should not, but some do), OpenWrt routers, and appliances built with Buildroot or Yocto that your vendors will be slow to patch. For a network team, that means out-of-band management boxes, console servers and anything else with a small Linux image. Start by finding out where you actually have musl and sshd together: # On a host or inside a container: is libc musl, and is sshd present? ldd --version 2&gt;&amp;1 | head -1 command -v sshd &amp;&amp; sshd -V 2&gt;&amp;1 | head -1 # Across running containers on a Docker host for c in $(docker ps -q); do printf '%s ' "$(docker inspect -f '' "$c")" docker exec "$c" sh -c 'ls /lib/ld-musl-* &gt;/dev/null 2&gt;&amp;1 &amp;&amp; echo musl || echo other; command -v sshd || true' 2&gt;/dev/null | tr '\n' ' ' echo done If you can’t patch an appliance this week, limit TCP/22 to your management jump hosts at the network layer. Do that anyway, but treat it as a stopgap and keep the patch ticket open. 2. HTTP/2 again: Node.js and Apache mod_http2 HTTP/2 implementations were the second theme. Node.js shipped its November security releases on 11 November. The items I would read first: CVE-2026-123863 (high): one unauthenticated request can remotely abort a default HTTP/2 server. CVE-2026-123864 (high): on HTTPS servers, a zero-length TLS write can make the server copy its own heap into a request body. Phoenix Security says this can leak TLS private keys and other users’ requests. CVE-2026-123867 (medium): CA-only SNI client-CA overrides fail open to the default CA. In plain terms, per-host mTLS authorization can be bypassed. CVE-2026-123871 (medium): proxy credentials appear in ERR_PROXY_INVALID_CONFIG error messages, so they end up in container logs and your log pipeline. Phoenix says there is no workaround and that the fixed versions are 22.23.5, 24.22.3 and 26.13.1. The proxy credential bug is the one people will underrate. If your services take HTTPS_PROXY with embedded credentials, assume those credentials may already be sitting in your log aggregation. Rotate them, and fix the log retention while you are at it. On the Apache side, Phoenix also wrote up HTTP2Reset (CVE-2026-119618), a pre-auth heap corruption bug in mod_http2 with RCE potential. Distro mod_http2 updates appeared in this week’s LWN security update lists. If you run httpd as a reverse proxy, check that the updated package is installed and that the service was restarted. A package that is installed but not reloaded is the usual gap. # RHEL-family: confirm package version and that httpd restarted after the update rpm -q mod_http2 httpd systemctl show httpd -p ActiveEnterTimestamp 3. Patch Tuesday: DNS, DHCP and network stack on Windows Microsoft’s November release is large. ZDI’s review is the easiest way to read it. For infrastructure teams the clusters that matter are: Windows DHCP Server: several RCEs. ZDI’s table lists CVE-2026-88243 at CVSS 9.8. Windows DNS Server and DNS client: a group of RCE and elevation-of-privilege entries. Network stack: Schannel (CVE-2026-119952), NAT (CVE-2026-113862) and TCP/IP, all critical. Kerberos has an elevation-of-privilege entry rated 9.8 (CVE-2026-85844). Softcat also flags a zero-day exploited in the wild. A crafted Office file leaks NTLMv2 hashes, which is one more reason to keep pushing NTLM off your network. Operational note: DHCP and DNS servers are the ones change boards like to push “to next window” because rebooting them is uncomfortable. That is backwards. If you run failover pairs, patch one node, check that leases and resolution still work, then do the partner. If you don’t run failover pairs, this month’s list is a good argument for getting them. 4. Edge devices are still being exploited Softcat’s vendor roundup is a reminder that perimeter devices are still the main entry point. It lists two Ivanti Connect Secure vulnerabilities that were chained and exploited as zero-days since at least October, and a SonicOS SSL-VPN authentication bypass that has been exploited. The same roundup lists Fortinet’s monthly batch (FortiOS, FortiManager, FortiAnalyzer, FortiSASE) and critical Cisco fixes for Catalyst SD-WAN Controller, Secure Email Gateway and Meraki. If you run any of these, patching is not enough. Assume the device may have been compromised before you patched it. Check for unexpected local accounts and configuration changes, and review session logs from the past several weeks. Rotate any credentials the device stored. Ivanti appliances have needed this treatment repeatedly. What I am taking into next week Inventory sshd on musl-based images and appliances. Nobody has a complete list of these until they go and build one. Treat the Node.js proxy credential leak as a credential rotation task, not only an upgrade. Patch DNS and DHCP this cycle, one node of each failover pair at a time. For any exploited edge device, patch first, then run a compromise assessment.]]></summary></entry><entry><title type="html">When df says there is space but writes still fail: inode exhaustion</title><link href="https://blog.bogovic.dev/2026/11/19/inode-exhaustion.html" rel="alternate" type="text/html" title="When df says there is space but writes still fail: inode exhaustion" /><published>2026-11-19T00:00:00+01:00</published><updated>2026-11-19T00:00:00+01:00</updated><id>https://blog.bogovic.dev/2026/11/19/inode-exhaustion</id><content type="html" xml:base="https://blog.bogovic.dev/2026/11/19/inode-exhaustion.html"><![CDATA[<p>The page arrives at 03:00: a service cannot write its PID file, the package manager aborts with “No space left on device”, and the on-call engineer runs <code class="language-plaintext highlighter-rouge">df -h</code>. The root filesystem is at 41%. Plenty of room. Twenty minutes go into checking quotas, the read-only remount theory and SELinux before someone runs <code class="language-plaintext highlighter-rouge">df -i</code> and sees 100% in the IUse% column.</p>

<p>Inode exhaustion is not exotic. On ext4 the inode count is fixed when the filesystem is created, based on a bytes-per-inode ratio. A filesystem formatted for typical workloads has a lot of space and a finite number of file slots. Fill those slots with millions of tiny files and the disk is “full” while most of the blocks are still unused.</p>

<h2 id="where-the-small-files-come-from">Where the small files come from</h2>

<p>In my experience the culprits are almost always the same few:</p>

<ul>
  <li>PHP or application session directories that nobody cleans up.</li>
  <li>Mail queues (Postfix <code class="language-plaintext highlighter-rouge">maildrop</code> or <code class="language-plaintext highlighter-rouge">deferred</code>) after a relay breaks and cron keeps sending mail into the queue.</li>
  <li>Build caches and package manager caches on CI runners.</li>
  <li>Monitoring agents or scripts writing one small file per check per host.</li>
  <li>Old kernels’ module trees and headers on systems that never run <code class="language-plaintext highlighter-rouge">autoremove</code>.</li>
</ul>

<p>None of these are large in bytes, so they never appear in the usual “what’s using the disk” checks with <code class="language-plaintext highlighter-rouge">du -sh</code>.</p>

<h2 id="finding-the-directory-responsible">Finding the directory responsible</h2>

<p><code class="language-plaintext highlighter-rouge">du</code> can count inodes instead of bytes. Stay on one filesystem so you don’t wander into <code class="language-plaintext highlighter-rouge">/proc</code> or network mounts:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Which top-level directories hold the most inodes on /</span>
<span class="nb">sudo du</span> <span class="nt">--inodes</span> <span class="nt">-x</span> <span class="nt">-d</span> 1 / 2&gt;/dev/null | <span class="nb">sort</span> <span class="nt">-n</span> | <span class="nb">tail</span> <span class="nt">-15</span>

<span class="c"># Drill down into the worst one</span>
<span class="nb">sudo du</span> <span class="nt">--inodes</span> <span class="nt">-x</span> <span class="nt">-d</span> 1 /var 2&gt;/dev/null | <span class="nb">sort</span> <span class="nt">-n</span> | <span class="nb">tail</span> <span class="nt">-15</span>
</code></pre></div></div>

<p>Repeat the drill down until you find a directory with hundreds of thousands of entries. On older coreutils without <code class="language-plaintext highlighter-rouge">--inodes</code>, this works too:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">sudo </span>find /var <span class="nt">-xdev</span> <span class="nt">-type</span> d <span class="nt">-print0</span> <span class="se">\</span>
  | xargs <span class="nt">-0</span> <span class="nt">-I</span><span class="o">{}</span> sh <span class="nt">-c</span> <span class="s1">'echo "$(find "{}" -maxdepth 1 | wc -l) {}"'</span> <span class="se">\</span>
  | <span class="nb">sort</span> <span class="nt">-n</span> | <span class="nb">tail</span> <span class="nt">-15</span>
</code></pre></div></div>

<p>It is slow on a big tree, but it does not need anything installed.</p>

<h2 id="cleaning-up-without-making-it-worse">Cleaning up without making it worse</h2>

<p><code class="language-plaintext highlighter-rouge">rm -rf /var/lib/php/sessions/*</code> fails with “Argument list too long” once the glob expands past the kernel’s argument limit. Let <code class="language-plaintext highlighter-rouge">find</code> do the deletion itself:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Delete session files older than two days, one filesystem only</span>
<span class="nb">sudo </span>find /var/lib/php/sessions <span class="nt">-xdev</span> <span class="nt">-type</span> f <span class="nt">-mtime</span> +2 <span class="nt">-delete</span>
</code></pre></div></div>

<p>For a mail queue, use the MTA’s own tooling (<code class="language-plaintext highlighter-rouge">postsuper -d ALL deferred</code>) rather than deleting files under its feet. And fix the cause before you clean up, or the slots will be gone again by morning.</p>

<h2 id="making-it-stay-fixed">Making it stay fixed</h2>

<p>Cleanup in the middle of an incident is not a fix. Two things make it one.</p>

<p>First, put the cleanup under systemd-tmpfiles so it runs on a schedule you already trust:</p>

<div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># /etc/tmpfiles.d/app-sessions.conf
# type path                         mode user     group    age
</span><span class="err">d</span>      <span class="err">/var/lib/app/sessions</span>        <span class="err">0770</span> <span class="err">www-data</span> <span class="err">www-data</span> <span class="err">2d</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">systemd-tmpfiles-clean.timer</code> runs daily on most distributions and will age out files older than two days. Check it with <code class="language-plaintext highlighter-rouge">systemctl list-timers systemd-tmpfiles-clean.timer</code>.</p>

<p>Second, monitor inodes the same way you monitor bytes. If you run node_exporter, the metrics are already there; most teams just never wrote the alert:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>(
  node_filesystem_files_free{fstype=~"ext4|xfs"}
  / node_filesystem_files{fstype=~"ext4|xfs"}
) &lt; 0.10
and node_filesystem_readonly == 0
</code></pre></div></div>

<p>Alert at 10% free, give it a <code class="language-plaintext highlighter-rouge">for: 15m</code>, and attach the <code class="language-plaintext highlighter-rouge">du --inodes</code> one-liner to the runbook.</p>

<h2 id="planning-for-it-at-mkfs-time">Planning for it at mkfs time</h2>

<p>If you know a volume will hold huge numbers of small files (a mail spool, a cache, an artifact store), size the inode table when you create it:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># One inode per 4 KiB instead of the default ratio</span>
<span class="nb">sudo </span>mkfs.ext4 <span class="nt">-i</span> 4096 /dev/vg0/spool

<span class="c"># Check what an existing filesystem got</span>
<span class="nb">sudo </span>tune2fs <span class="nt">-l</span> /dev/vg0/spool | <span class="nb">grep</span> <span class="nt">-Ei</span> <span class="s1">'inode count|inodes per group'</span>
</code></pre></div></div>

<p>You cannot add inodes to an existing ext4 filesystem in place, except by growing it. XFS allocates inodes dynamically up to a percentage limit (<code class="language-plaintext highlighter-rouge">imaxpct</code>), so it runs out far less often, though it can still happen on a nearly full filesystem. Btrfs has no fixed inode table at all. That is a reasonable argument for XFS on volumes where you can’t predict file counts.</p>

<h2 id="why-this-matters">Why this matters</h2>

<p>Every team I have worked with has lost an hour to this exactly once, because the first instinct is <code class="language-plaintext highlighter-rouge">df -h</code> and the number looks fine. The fix is cheap: one alert expression, one tmpfiles entry per known small-file producer, and <code class="language-plaintext highlighter-rouge">df -i</code> added to the disk-full runbook next to <code class="language-plaintext highlighter-rouge">df -h</code>. The incident it prevents is the confusing kind, where the obvious tool tells you everything is healthy while services fail around you. Those are the ones that run long at night.</p>]]></content><author><name>Ivan Bogović</name></author><category term="Linux" /><summary type="html"><![CDATA[The page arrives at 03:00: a service cannot write its PID file, the package manager aborts with “No space left on device”, and the on-call engineer runs df -h. The root filesystem is at 41%. Plenty of room. Twenty minutes go into checking quotas, the read-only remount theory and SELinux before someone runs df -i and sees 100% in the IUse% column. Inode exhaustion is not exotic. On ext4 the inode count is fixed when the filesystem is created, based on a bytes-per-inode ratio. A filesystem formatted for typical workloads has a lot of space and a finite number of file slots. Fill those slots with millions of tiny files and the disk is “full” while most of the blocks are still unused. Where the small files come from In my experience the culprits are almost always the same few: PHP or application session directories that nobody cleans up. Mail queues (Postfix maildrop or deferred) after a relay breaks and cron keeps sending mail into the queue. Build caches and package manager caches on CI runners. Monitoring agents or scripts writing one small file per check per host. Old kernels’ module trees and headers on systems that never run autoremove. None of these are large in bytes, so they never appear in the usual “what’s using the disk” checks with du -sh. Finding the directory responsible du can count inodes instead of bytes. Stay on one filesystem so you don’t wander into /proc or network mounts: # Which top-level directories hold the most inodes on / sudo du --inodes -x -d 1 / 2&gt;/dev/null | sort -n | tail -15 # Drill down into the worst one sudo du --inodes -x -d 1 /var 2&gt;/dev/null | sort -n | tail -15 Repeat the drill down until you find a directory with hundreds of thousands of entries. On older coreutils without --inodes, this works too: sudo find /var -xdev -type d -print0 \ | xargs -0 -I{} sh -c 'echo "$(find "{}" -maxdepth 1 | wc -l) {}"' \ | sort -n | tail -15 It is slow on a big tree, but it does not need anything installed. Cleaning up without making it worse rm -rf /var/lib/php/sessions/* fails with “Argument list too long” once the glob expands past the kernel’s argument limit. Let find do the deletion itself: # Delete session files older than two days, one filesystem only sudo find /var/lib/php/sessions -xdev -type f -mtime +2 -delete For a mail queue, use the MTA’s own tooling (postsuper -d ALL deferred) rather than deleting files under its feet. And fix the cause before you clean up, or the slots will be gone again by morning. Making it stay fixed Cleanup in the middle of an incident is not a fix. Two things make it one. First, put the cleanup under systemd-tmpfiles so it runs on a schedule you already trust: # /etc/tmpfiles.d/app-sessions.conf # type path mode user group age d /var/lib/app/sessions 0770 www-data www-data 2d systemd-tmpfiles-clean.timer runs daily on most distributions and will age out files older than two days. Check it with systemctl list-timers systemd-tmpfiles-clean.timer. Second, monitor inodes the same way you monitor bytes. If you run node_exporter, the metrics are already there; most teams just never wrote the alert: ( node_filesystem_files_free{fstype=~"ext4|xfs"} / node_filesystem_files{fstype=~"ext4|xfs"} ) &lt; 0.10 and node_filesystem_readonly == 0 Alert at 10% free, give it a for: 15m, and attach the du --inodes one-liner to the runbook. Planning for it at mkfs time If you know a volume will hold huge numbers of small files (a mail spool, a cache, an artifact store), size the inode table when you create it: # One inode per 4 KiB instead of the default ratio sudo mkfs.ext4 -i 4096 /dev/vg0/spool # Check what an existing filesystem got sudo tune2fs -l /dev/vg0/spool | grep -Ei 'inode count|inodes per group' You cannot add inodes to an existing ext4 filesystem in place, except by growing it. XFS allocates inodes dynamically up to a percentage limit (imaxpct), so it runs out far less often, though it can still happen on a nearly full filesystem. Btrfs has no fixed inode table at all. That is a reasonable argument for XFS on volumes where you can’t predict file counts. Why this matters Every team I have worked with has lost an hour to this exactly once, because the first instinct is df -h and the number looks fine. The fix is cheap: one alert expression, one tmpfiles entry per known small-file producer, and df -i added to the disk-full runbook next to df -h. The incident it prevents is the confusing kind, where the obvious tool tells you everything is healthy while services fail around you. Those are the ones that run long at night.]]></summary></entry><entry><title type="html">Inventory and trim the SUID binaries on your servers</title><link href="https://blog.bogovic.dev/2026/11/18/suid-binary-inventory.html" rel="alternate" type="text/html" title="Inventory and trim the SUID binaries on your servers" /><published>2026-11-18T00:00:00+01:00</published><updated>2026-11-18T00:00:00+01:00</updated><id>https://blog.bogovic.dev/2026/11/18/suid-binary-inventory</id><content type="html" xml:base="https://blog.bogovic.dev/2026/11/18/suid-binary-inventory.html"><![CDATA[<p>Every post-exploitation checklist has the same early step: <code class="language-plaintext highlighter-rouge">find / -perm -4000</code>. An attacker with a low-privilege shell lists every setuid-root binary on the box and checks each one against known escape techniques. Most of the fleets I’ve looked at fail this check in the same way. Nobody chose those binaries. They came in with the base image, a package someone needed once, or a vendor agent, and they never got reviewed again.</p>

<p>The fix isn’t exotic. Know what is setuid or setgid, decide which of those binaries you actually need, strip the rest, and alert when the list changes.</p>

<h2 id="take-the-inventory">Take the inventory</h2>

<p>Start with a list you can diff. Limit the search to local filesystems so it doesn’t wander into NFS mounts, and include setgid binaries, since a setgid binary that grants the <code class="language-plaintext highlighter-rouge">shadow</code> or <code class="language-plaintext highlighter-rouge">disk</code> group is nearly as dangerous as setuid root.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/usr/bin/env bash</span>
<span class="c"># suid-inventory.sh - list setuid/setgid files with owner, mode and package</span>
<span class="nb">set</span> <span class="nt">-euo</span> pipefail

find / <span class="nt">-xdev</span> <span class="se">\(</span> <span class="nt">-perm</span> <span class="nt">-4000</span> <span class="nt">-o</span> <span class="nt">-perm</span> <span class="nt">-2000</span> <span class="se">\)</span> <span class="nt">-type</span> f <span class="nt">-print0</span> 2&gt;/dev/null |
  <span class="k">while </span><span class="nv">IFS</span><span class="o">=</span> <span class="nb">read</span> <span class="nt">-r</span> <span class="nt">-d</span> <span class="s1">''</span> f<span class="p">;</span> <span class="k">do
    </span><span class="nv">mode</span><span class="o">=</span><span class="si">$(</span><span class="nb">stat</span> <span class="nt">-c</span> <span class="s1">'%a %U:%G'</span> <span class="s2">"</span><span class="nv">$f</span><span class="s2">"</span><span class="si">)</span>
    <span class="nv">pkg</span><span class="o">=</span><span class="si">$(</span>dpkg <span class="nt">-S</span> <span class="s2">"</span><span class="nv">$f</span><span class="s2">"</span> 2&gt;/dev/null | <span class="nb">cut</span> <span class="nt">-d</span>: <span class="nt">-f1</span> <span class="o">||</span> <span class="nb">true</span><span class="si">)</span>
    <span class="nb">printf</span> <span class="s1">'%s\t%s\t%s\n'</span> <span class="s2">"</span><span class="nv">$f</span><span class="s2">"</span> <span class="s2">"</span><span class="nv">$mode</span><span class="s2">"</span> <span class="s2">"</span><span class="k">${</span><span class="nv">pkg</span><span class="k">:-</span><span class="nv">UNOWNED</span><span class="k">}</span><span class="s2">"</span>
  <span class="k">done</span> | <span class="nb">sort</span>
</code></pre></div></div>

<p>On RHEL-family systems, replace <code class="language-plaintext highlighter-rouge">dpkg -S</code> with <code class="language-plaintext highlighter-rouge">rpm -qf</code>. Pay attention to the package column. If a setuid file shows up as <code class="language-plaintext highlighter-rouge">UNOWNED</code>, no package manager put it there. It could be a manual install, a leftover from a vendor tarball, or something worse. Investigate every one of these before you look at anything else.</p>

<p>Note that <code class="language-plaintext highlighter-rouge">-xdev</code> skips other mounts, so run the script once for each local filesystem if <code class="language-plaintext highlighter-rouge">/usr</code>, <code class="language-plaintext highlighter-rouge">/opt</code> or <code class="language-plaintext highlighter-rouge">/var</code> are mounted separately.</p>

<h2 id="decide-what-stays">Decide what stays</h2>

<p>A typical minimal Debian server ends up with something like <code class="language-plaintext highlighter-rouge">passwd</code>, <code class="language-plaintext highlighter-rouge">chsh</code>, <code class="language-plaintext highlighter-rouge">chfn</code>, <code class="language-plaintext highlighter-rouge">gpasswd</code>, <code class="language-plaintext highlighter-rouge">newgrp</code>, <code class="language-plaintext highlighter-rouge">su</code>, <code class="language-plaintext highlighter-rouge">sudo</code>, <code class="language-plaintext highlighter-rouge">mount</code>, <code class="language-plaintext highlighter-rouge">umount</code> and <code class="language-plaintext highlighter-rouge">unix_chkpwd</code>. That’s a short list, but plenty of it is unnecessary on a server where nobody logs in interactively and identity comes from a directory:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">chsh</code> and <code class="language-plaintext highlighter-rouge">chfn</code> let users change their shell and GECOS fields. Servers rarely need that, and these two have a long history of bugs.</li>
  <li><code class="language-plaintext highlighter-rouge">newgrp</code> and <code class="language-plaintext highlighter-rouge">gpasswd</code> only matter if you use group passwords. You almost certainly don’t.</li>
  <li><code class="language-plaintext highlighter-rouge">mount</code> and <code class="language-plaintext highlighter-rouge">umount</code> only need setuid for user-mountable entries in fstab. Without those entries, root can mount without the bit.</li>
  <li>Anything installed by tooling, such as old <code class="language-plaintext highlighter-rouge">pkexec</code>, legacy <code class="language-plaintext highlighter-rouge">ping</code> on distributions that haven’t moved to file capabilities, or helpers from X11 or desktop packages pulled in by a careless dependency.</li>
</ul>

<p>Removing the package is better than stripping the bit. If the package has to stay, use <code class="language-plaintext highlighter-rouge">dpkg-statoverride</code> so an upgrade doesn’t quietly put the bit back. A plain <code class="language-plaintext highlighter-rouge">chmod u-s</code> lasts until the next upgrade of that package.</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Persistently drop setuid on chfn/chsh across package upgrades (Debian/Ubuntu)</span>
<span class="k">for </span>b <span class="k">in</span> /usr/bin/chfn /usr/bin/chsh /usr/bin/newgrp /usr/bin/gpasswd<span class="p">;</span> <span class="k">do
  </span>dpkg-statoverride <span class="nt">--update</span> <span class="nt">--add</span> root root 0755 <span class="s2">"</span><span class="nv">$b</span><span class="s2">"</span>
<span class="k">done
</span>dpkg-statoverride <span class="nt">--list</span>
</code></pre></div></div>

<p>On RHEL, the equivalent is to manage the mode in your configuration management run and have it enforced on every run. Where a binary needs one privilege and not full root, replace the setuid bit with a file capability. <code class="language-plaintext highlighter-rouge">ping</code> needing <code class="language-plaintext highlighter-rouge">cap_net_raw</code> is the classic case:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">chmod </span>u-s /usr/bin/ping
setcap cap_net_raw+ep /usr/bin/ping
getcap /usr/bin/ping
</code></pre></div></div>

<h2 id="mount-options-do-the-rest">Mount options do the rest</h2>

<p>Data and scratch filesystems should never honour setuid at all. Mount <code class="language-plaintext highlighter-rouge">/tmp</code>, <code class="language-plaintext highlighter-rouge">/var/tmp</code>, <code class="language-plaintext highlighter-rouge">/home</code> and any application data volumes with <code class="language-plaintext highlighter-rouge">nosuid</code> (and <code class="language-plaintext highlighter-rouge">nodev</code>). Then a binary an attacker drops into a writable path is just a binary.</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>tmpfs        /tmp      tmpfs  defaults,nosuid,nodev,noexec  0 0
/dev/vg0/data /srv/data ext4   defaults,nosuid,nodev         0 2
</code></pre></div></div>

<p>Test <code class="language-plaintext highlighter-rouge">noexec</code> on <code class="language-plaintext highlighter-rouge">/tmp</code> before you roll it out, because some installers and build tools break on it. <code class="language-plaintext highlighter-rouge">nosuid</code> almost never causes problems.</p>

<h2 id="make-it-a-drift-check">Make it a drift check</h2>

<p>A one-off cleanup decays. Commit the approved list and compare against it on a schedule. Anything new gets flagged:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/usr/bin/env bash</span>
<span class="nb">set</span> <span class="nt">-euo</span> pipefail
<span class="nv">baseline</span><span class="o">=</span>/etc/security/suid-baseline.txt
<span class="nv">current</span><span class="o">=</span><span class="si">$(</span><span class="nb">mktemp</span><span class="si">)</span>
/usr/local/sbin/suid-inventory.sh | <span class="nb">cut</span> <span class="nt">-f1</span>,2 <span class="o">&gt;</span> <span class="s2">"</span><span class="nv">$current</span><span class="s2">"</span>
<span class="k">if</span> <span class="o">!</span> diff <span class="nt">-u</span> <span class="s2">"</span><span class="nv">$baseline</span><span class="s2">"</span> <span class="s2">"</span><span class="nv">$current</span><span class="s2">"</span><span class="p">;</span> <span class="k">then
  </span>logger <span class="nt">-p</span> authpriv.warning <span class="nt">-t</span> suid-drift <span class="s2">"SUID/SGID set changed on </span><span class="si">$(</span><span class="nb">hostname</span><span class="si">)</span><span class="s2">"</span>
  <span class="nb">exit </span>1
<span class="k">fi</span>
</code></pre></div></div>

<p>Run it from a systemd timer or your existing compliance job. Ship the warning to wherever your other security events go. A nonzero exit after a package upgrade is usually harmless, but it should still be a decision someone reviews: either approve the new binary and update the baseline, or override it. If you already run auditd, also watch <code class="language-plaintext highlighter-rouge">chmod</code> and <code class="language-plaintext highlighter-rouge">fchmodat</code> calls that set mode bits 04000. That catches the change as it happens, while the timer catches it on the next run.</p>

<h2 id="why-this-matters">Why this matters</h2>

<p>Local privilege escalation bugs in setuid helpers keep turning up, and every one of them is only exploitable on hosts where the helper is installed and setuid. In incident reviews, the painful question is rarely “why did we have the bug?” It’s “why was that binary setuid on a database server in the first place?” A short reviewed list, <code class="language-plaintext highlighter-rouge">nosuid</code> on writable mounts and a drift check that fires on change remove a whole class of escalation paths, and the work takes about an afternoon per image. It also turns the next “patch now” advisory for a setuid helper into a quick check: either the binary is on your list, or the advisory doesn’t apply to you.</p>]]></content><author><name>Ivan Bogović</name></author><category term="Security" /><summary type="html"><![CDATA[Every post-exploitation checklist has the same early step: find / -perm -4000. An attacker with a low-privilege shell lists every setuid-root binary on the box and checks each one against known escape techniques. Most of the fleets I’ve looked at fail this check in the same way. Nobody chose those binaries. They came in with the base image, a package someone needed once, or a vendor agent, and they never got reviewed again. The fix isn’t exotic. Know what is setuid or setgid, decide which of those binaries you actually need, strip the rest, and alert when the list changes. Take the inventory Start with a list you can diff. Limit the search to local filesystems so it doesn’t wander into NFS mounts, and include setgid binaries, since a setgid binary that grants the shadow or disk group is nearly as dangerous as setuid root. #!/usr/bin/env bash # suid-inventory.sh - list setuid/setgid files with owner, mode and package set -euo pipefail find / -xdev \( -perm -4000 -o -perm -2000 \) -type f -print0 2&gt;/dev/null | while IFS= read -r -d '' f; do mode=$(stat -c '%a %U:%G' "$f") pkg=$(dpkg -S "$f" 2&gt;/dev/null | cut -d: -f1 || true) printf '%s\t%s\t%s\n' "$f" "$mode" "${pkg:-UNOWNED}" done | sort On RHEL-family systems, replace dpkg -S with rpm -qf. Pay attention to the package column. If a setuid file shows up as UNOWNED, no package manager put it there. It could be a manual install, a leftover from a vendor tarball, or something worse. Investigate every one of these before you look at anything else. Note that -xdev skips other mounts, so run the script once for each local filesystem if /usr, /opt or /var are mounted separately. Decide what stays A typical minimal Debian server ends up with something like passwd, chsh, chfn, gpasswd, newgrp, su, sudo, mount, umount and unix_chkpwd. That’s a short list, but plenty of it is unnecessary on a server where nobody logs in interactively and identity comes from a directory: chsh and chfn let users change their shell and GECOS fields. Servers rarely need that, and these two have a long history of bugs. newgrp and gpasswd only matter if you use group passwords. You almost certainly don’t. mount and umount only need setuid for user-mountable entries in fstab. Without those entries, root can mount without the bit. Anything installed by tooling, such as old pkexec, legacy ping on distributions that haven’t moved to file capabilities, or helpers from X11 or desktop packages pulled in by a careless dependency. Removing the package is better than stripping the bit. If the package has to stay, use dpkg-statoverride so an upgrade doesn’t quietly put the bit back. A plain chmod u-s lasts until the next upgrade of that package. # Persistently drop setuid on chfn/chsh across package upgrades (Debian/Ubuntu) for b in /usr/bin/chfn /usr/bin/chsh /usr/bin/newgrp /usr/bin/gpasswd; do dpkg-statoverride --update --add root root 0755 "$b" done dpkg-statoverride --list On RHEL, the equivalent is to manage the mode in your configuration management run and have it enforced on every run. Where a binary needs one privilege and not full root, replace the setuid bit with a file capability. ping needing cap_net_raw is the classic case: chmod u-s /usr/bin/ping setcap cap_net_raw+ep /usr/bin/ping getcap /usr/bin/ping Mount options do the rest Data and scratch filesystems should never honour setuid at all. Mount /tmp, /var/tmp, /home and any application data volumes with nosuid (and nodev). Then a binary an attacker drops into a writable path is just a binary. tmpfs /tmp tmpfs defaults,nosuid,nodev,noexec 0 0 /dev/vg0/data /srv/data ext4 defaults,nosuid,nodev 0 2 Test noexec on /tmp before you roll it out, because some installers and build tools break on it. nosuid almost never causes problems. Make it a drift check A one-off cleanup decays. Commit the approved list and compare against it on a schedule. Anything new gets flagged: #!/usr/bin/env bash set -euo pipefail baseline=/etc/security/suid-baseline.txt current=$(mktemp) /usr/local/sbin/suid-inventory.sh | cut -f1,2 &gt; "$current" if ! diff -u "$baseline" "$current"; then logger -p authpriv.warning -t suid-drift "SUID/SGID set changed on $(hostname)" exit 1 fi Run it from a systemd timer or your existing compliance job. Ship the warning to wherever your other security events go. A nonzero exit after a package upgrade is usually harmless, but it should still be a decision someone reviews: either approve the new binary and update the baseline, or override it. If you already run auditd, also watch chmod and fchmodat calls that set mode bits 04000. That catches the change as it happens, while the timer catches it on the next run. Why this matters Local privilege escalation bugs in setuid helpers keep turning up, and every one of them is only exploitable on hosts where the helper is installed and setuid. In incident reviews, the painful question is rarely “why did we have the bug?” It’s “why was that binary setuid on a database server in the first place?” A short reviewed list, nosuid on writable mounts and a drift check that fires on change remove a whole class of escalation paths, and the work takes about an afternoon per image. It also turns the next “patch now” advisory for a setuid helper into a quick check: either the binary is on your list, or the advisory doesn’t apply to you.]]></summary></entry><entry><title type="html">Validate config files before Ansible writes them</title><link href="https://blog.bogovic.dev/2026/11/17/ansible-validate-before-write.html" rel="alternate" type="text/html" title="Validate config files before Ansible writes them" /><published>2026-11-17T00:00:00+01:00</published><updated>2026-11-17T00:00:00+01:00</updated><id>https://blog.bogovic.dev/2026/11/17/ansible-validate-before-write</id><content type="html" xml:base="https://blog.bogovic.dev/2026/11/17/ansible-validate-before-write.html"><![CDATA[<p>A template change goes out to forty hosts. The Jinja renders fine, the task reports <code class="language-plaintext highlighter-rouge">changed</code>, the handler restarts the service, and on every one of those hosts the daemon refuses to start because of a missing semicolon on line 212. Ansible worked as designed. It put the file where you told it to and restarted the service when you told it to. Nothing in that chain checked whether the file was valid.</p>

<p>Most config-managing modules already have a fix for this, and people still don’t use it much: the <code class="language-plaintext highlighter-rouge">validate</code> parameter.</p>

<h2 id="what-validate-actually-does">What validate actually does</h2>

<p><code class="language-plaintext highlighter-rouge">template</code>, <code class="language-plaintext highlighter-rouge">copy</code>, <code class="language-plaintext highlighter-rouge">lineinfile</code>, <code class="language-plaintext highlighter-rouge">blockinfile</code> and <code class="language-plaintext highlighter-rouge">replace</code> all accept <code class="language-plaintext highlighter-rouge">validate</code>. Ansible writes the new content to a temporary file, runs your command against it with <code class="language-plaintext highlighter-rouge">%s</code> replaced by the temp path, and only moves it into place if the command exits 0. If validation fails, the task fails, the original file stays where it was, and the handler never fires.</p>

<p>That ordering matters. The usual alternative is a separate “check config” task after the write, and by the time that runs the broken file is already live. If anything reloads the service in between (a timer, logrotate, someone running <code class="language-plaintext highlighter-rouge">systemctl reload</code> by hand) you have an outage.</p>

<h2 id="a-working-set-of-validators">A working set of validators</h2>

<p>These are the ones I use most. Every one takes a file path and returns non-zero on a parse error.</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Render sshd drop-in</span>
  <span class="na">ansible.builtin.template</span><span class="pi">:</span>
    <span class="na">src</span><span class="pi">:</span> <span class="s">10-hardening.conf.j2</span>
    <span class="na">dest</span><span class="pi">:</span> <span class="s">/etc/ssh/sshd_config.d/10-hardening.conf</span>
    <span class="na">mode</span><span class="pi">:</span> <span class="s2">"</span><span class="s">0600"</span>
    <span class="na">validate</span><span class="pi">:</span> <span class="s">/usr/sbin/sshd -t -f %s</span>
  <span class="na">notify</span><span class="pi">:</span> <span class="s">Reload sshd</span>

<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Render sudoers fragment</span>
  <span class="na">ansible.builtin.template</span><span class="pi">:</span>
    <span class="na">src</span><span class="pi">:</span> <span class="s">ops.sudoers.j2</span>
    <span class="na">dest</span><span class="pi">:</span> <span class="s">/etc/sudoers.d/ops</span>
    <span class="na">mode</span><span class="pi">:</span> <span class="s2">"</span><span class="s">0440"</span>
    <span class="na">validate</span><span class="pi">:</span> <span class="s">/usr/sbin/visudo -cf %s</span>

<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Render nginx site</span>
  <span class="na">ansible.builtin.template</span><span class="pi">:</span>
    <span class="na">src</span><span class="pi">:</span> <span class="s">site.conf.j2</span>
    <span class="na">dest</span><span class="pi">:</span> <span class="s">/etc/nginx/conf.d/site.conf</span>
    <span class="na">validate</span><span class="pi">:</span> <span class="s">/usr/sbin/nginx -t -c /etc/nginx/nginx.conf -q</span>
  <span class="na">notify</span><span class="pi">:</span> <span class="s">Reload nginx</span>

<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Render nftables ruleset</span>
  <span class="na">ansible.builtin.template</span><span class="pi">:</span>
    <span class="na">src</span><span class="pi">:</span> <span class="s">nftables.conf.j2</span>
    <span class="na">dest</span><span class="pi">:</span> <span class="s">/etc/nftables.conf</span>
    <span class="na">validate</span><span class="pi">:</span> <span class="s">/usr/sbin/nft -c -f %s</span>
  <span class="na">notify</span><span class="pi">:</span> <span class="s">Reload nftables</span>

<span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Render chrony config</span>
  <span class="na">ansible.builtin.template</span><span class="pi">:</span>
    <span class="na">src</span><span class="pi">:</span> <span class="s">chrony.conf.j2</span>
    <span class="na">dest</span><span class="pi">:</span> <span class="s">/etc/chrony/chrony.conf</span>
    <span class="na">validate</span><span class="pi">:</span> <span class="s">/usr/sbin/chronyd -p -f %s</span>
  <span class="na">notify</span><span class="pi">:</span> <span class="s">Restart chrony</span>
</code></pre></div></div>

<p>Before you copy these, there are two traps.</p>

<p><strong>sshd and drop-ins.</strong> <code class="language-plaintext highlighter-rouge">sshd -t -f %s</code> checks the fragment as if it were the whole config. A drop-in containing only <code class="language-plaintext highlighter-rouge">PasswordAuthentication no</code> passes. A drop-in containing a <code class="language-plaintext highlighter-rouge">Match</code> block also passes, but you’re testing it in isolation, so you won’t catch conflicts with the main file. That’s fine for syntax and not enough for semantics.</p>

<p><strong>nginx ignores %s.</strong> The example above validates the existing tree, which doesn’t contain the new file yet, so it proves nothing. Ansible also refuses a <code class="language-plaintext highlighter-rouge">validate</code> string without <code class="language-plaintext highlighter-rouge">%s</code>. The honest version builds a throwaway main config that includes the temp file:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/bin/sh</span>
<span class="c"># /usr/local/bin/nginx-validate-site &lt;tmpfile&gt;</span>
<span class="nb">set</span> <span class="nt">-eu</span>
<span class="nv">tmpdir</span><span class="o">=</span><span class="si">$(</span><span class="nb">mktemp</span> <span class="nt">-d</span><span class="si">)</span>
<span class="nb">trap</span> <span class="s1">'rm -rf "$tmpdir"'</span> EXIT
<span class="nb">cat</span> <span class="o">&gt;</span> <span class="s2">"</span><span class="nv">$tmpdir</span><span class="s2">/nginx.conf"</span> <span class="o">&lt;&lt;</span><span class="no">EOF</span><span class="sh">
events {}
http {
    include /etc/nginx/mime.types;
    include </span><span class="nv">$1</span><span class="sh">;
}
</span><span class="no">EOF
</span>/usr/sbin/nginx <span class="nt">-t</span> <span class="nt">-q</span> <span class="nt">-c</span> <span class="s2">"</span><span class="nv">$tmpdir</span><span class="s2">/nginx.conf"</span> <span class="nt">-p</span> <span class="s2">"</span><span class="nv">$tmpdir</span><span class="s2">"</span>
</code></pre></div></div>

<p>Then use <code class="language-plaintext highlighter-rouge">validate: /usr/local/bin/nginx-validate-site %s</code>. Ship the script with the same role so it is always present.</p>

<h2 id="when-there-is-no-validator">When there is no validator</h2>

<p>Some daemons have no check mode. In that case, validate the format instead. For YAML or JSON consumed by an internal service:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Render service config</span>
  <span class="na">ansible.builtin.template</span><span class="pi">:</span>
    <span class="na">src</span><span class="pi">:</span> <span class="s">app.yaml.j2</span>
    <span class="na">dest</span><span class="pi">:</span> <span class="s">/etc/app/app.yaml</span>
    <span class="na">validate</span><span class="pi">:</span> <span class="s">python3 -c "import sys, yaml; yaml.safe_load(open(sys.argv[1]))" %s</span>
</code></pre></div></div>

<p>That won’t catch a wrong key name, but it does catch the most common template failure: indentation broken by a loop that rendered one level too deep. For anything stricter, write a small script that loads the file against a JSON Schema and exits 1 on failure. It costs about twenty lines and you write it once.</p>

<h2 id="validate-is-not-a-health-check">Validate is not a health check</h2>

<p><code class="language-plaintext highlighter-rouge">validate</code> answers one question: will this file parse? It won’t tell you whether the service comes back healthy after the reload. Keep that as a separate step. Flush handlers, then poll the port or the status endpoint with <code class="language-plaintext highlighter-rouge">wait_for</code> or <code class="language-plaintext highlighter-rouge">uri</code>, and run the play with <code class="language-plaintext highlighter-rouge">serial</code> so a bad change stops after the first batch. Validation catches syntax before the write, and the health check catches behaviour after the reload. You want both, but only validation keeps a broken file off the disk in the first place.</p>

<p>One more operational detail: <code class="language-plaintext highlighter-rouge">validate</code> runs on the target host with the target’s binary version. That’s what you want. A config that parses on your laptop’s nginx 1.27 can fail on a fleet still running 1.22, and validating on the target catches that.</p>

<h2 id="why-this-matters">Why this matters</h2>

<p>Most config-push outages I’ve had to clean up weren’t logic errors. They were typos, a missing brace, or a template variable that rendered empty and left a dangling directive. Every one of them would have been stopped by a one-line <code class="language-plaintext highlighter-rouge">validate</code> on the task that wrote the file. It costs a few hundred milliseconds per host. The sudoers case alone justifies it: a broken file in <code class="language-plaintext highlighter-rouge">/etc/sudoers.d</code> can lock out the same automation account you’d use to fix it. Make <code class="language-plaintext highlighter-rouge">validate</code> mandatory in code review for any task that writes a file a daemon parses, and treat a missing one like a missing test.</p>]]></content><author><name>Ivan Bogović</name></author><category term="Automation" /><summary type="html"><![CDATA[A template change goes out to forty hosts. The Jinja renders fine, the task reports changed, the handler restarts the service, and on every one of those hosts the daemon refuses to start because of a missing semicolon on line 212. Ansible worked as designed. It put the file where you told it to and restarted the service when you told it to. Nothing in that chain checked whether the file was valid. Most config-managing modules already have a fix for this, and people still don’t use it much: the validate parameter. What validate actually does template, copy, lineinfile, blockinfile and replace all accept validate. Ansible writes the new content to a temporary file, runs your command against it with %s replaced by the temp path, and only moves it into place if the command exits 0. If validation fails, the task fails, the original file stays where it was, and the handler never fires. That ordering matters. The usual alternative is a separate “check config” task after the write, and by the time that runs the broken file is already live. If anything reloads the service in between (a timer, logrotate, someone running systemctl reload by hand) you have an outage. A working set of validators These are the ones I use most. Every one takes a file path and returns non-zero on a parse error. - name: Render sshd drop-in ansible.builtin.template: src: 10-hardening.conf.j2 dest: /etc/ssh/sshd_config.d/10-hardening.conf mode: "0600" validate: /usr/sbin/sshd -t -f %s notify: Reload sshd - name: Render sudoers fragment ansible.builtin.template: src: ops.sudoers.j2 dest: /etc/sudoers.d/ops mode: "0440" validate: /usr/sbin/visudo -cf %s - name: Render nginx site ansible.builtin.template: src: site.conf.j2 dest: /etc/nginx/conf.d/site.conf validate: /usr/sbin/nginx -t -c /etc/nginx/nginx.conf -q notify: Reload nginx - name: Render nftables ruleset ansible.builtin.template: src: nftables.conf.j2 dest: /etc/nftables.conf validate: /usr/sbin/nft -c -f %s notify: Reload nftables - name: Render chrony config ansible.builtin.template: src: chrony.conf.j2 dest: /etc/chrony/chrony.conf validate: /usr/sbin/chronyd -p -f %s notify: Restart chrony Before you copy these, there are two traps. sshd and drop-ins. sshd -t -f %s checks the fragment as if it were the whole config. A drop-in containing only PasswordAuthentication no passes. A drop-in containing a Match block also passes, but you’re testing it in isolation, so you won’t catch conflicts with the main file. That’s fine for syntax and not enough for semantics. nginx ignores %s. The example above validates the existing tree, which doesn’t contain the new file yet, so it proves nothing. Ansible also refuses a validate string without %s. The honest version builds a throwaway main config that includes the temp file: #!/bin/sh # /usr/local/bin/nginx-validate-site &lt;tmpfile&gt; set -eu tmpdir=$(mktemp -d) trap 'rm -rf "$tmpdir"' EXIT cat &gt; "$tmpdir/nginx.conf" &lt;&lt;EOF events {} http { include /etc/nginx/mime.types; include $1; } EOF /usr/sbin/nginx -t -q -c "$tmpdir/nginx.conf" -p "$tmpdir" Then use validate: /usr/local/bin/nginx-validate-site %s. Ship the script with the same role so it is always present. When there is no validator Some daemons have no check mode. In that case, validate the format instead. For YAML or JSON consumed by an internal service: - name: Render service config ansible.builtin.template: src: app.yaml.j2 dest: /etc/app/app.yaml validate: python3 -c "import sys, yaml; yaml.safe_load(open(sys.argv[1]))" %s That won’t catch a wrong key name, but it does catch the most common template failure: indentation broken by a loop that rendered one level too deep. For anything stricter, write a small script that loads the file against a JSON Schema and exits 1 on failure. It costs about twenty lines and you write it once. Validate is not a health check validate answers one question: will this file parse? It won’t tell you whether the service comes back healthy after the reload. Keep that as a separate step. Flush handlers, then poll the port or the status endpoint with wait_for or uri, and run the play with serial so a bad change stops after the first batch. Validation catches syntax before the write, and the health check catches behaviour after the reload. You want both, but only validation keeps a broken file off the disk in the first place. One more operational detail: validate runs on the target host with the target’s binary version. That’s what you want. A config that parses on your laptop’s nginx 1.27 can fail on a fleet still running 1.22, and validating on the target catches that. Why this matters Most config-push outages I’ve had to clean up weren’t logic errors. They were typos, a missing brace, or a template variable that rendered empty and left a dangling directive. Every one of them would have been stopped by a one-line validate on the task that wrote the file. It costs a few hundred milliseconds per host. The sudoers case alone justifies it: a broken file in /etc/sudoers.d can lock out the same automation account you’d use to fix it. Make validate mandatory in code review for any task that writes a file a daemon parses, and treat a missing one like a missing test.]]></summary></entry><entry><title type="html">Protecting the router CPU with control plane policing on IOS XE</title><link href="https://blog.bogovic.dev/2026/11/16/copp-on-ios-xe.html" rel="alternate" type="text/html" title="Protecting the router CPU with control plane policing on IOS XE" /><published>2026-11-16T00:00:00+01:00</published><updated>2026-11-16T00:00:00+01:00</updated><id>https://blog.bogovic.dev/2026/11/16/copp-on-ios-xe</id><content type="html" xml:base="https://blog.bogovic.dev/2026/11/16/copp-on-ios-xe.html"><![CDATA[<p>A distribution switch stops answering SSH, OSPF neighbors start flapping, and the interface counters look normal. The data plane is forwarding fine, but the route processor is at 99 percent. Someone’s misconfigured monitoring host is hammering SNMP, or a broadcast storm is pushing ARP to the CPU, or a scanner found the management address. Whatever the source, all traffic punted to the CPU shares one queue, and routing protocols lose to noise.</p>

<p>Control plane policing (CoPP) fixes this by classifying punted traffic and rate-limiting each class separately. Your BGP and OSPF keep their share of the CPU, and SNMP floods get dropped before they reach the processes that matter.</p>

<h2 id="what-the-platform-already-does">What the platform already does</h2>

<p>On Catalyst 9000 switches, IOS XE ships with a system-defined policy called <code class="language-plaintext highlighter-rouge">system-cpp-policy</code> attached to the control plane. It has sensible defaults per punt queue, and you tune it rather than replace it. On ISR and ASR routers there is no such default for most traffic, so you build your own policy with MQC. The example below is for a router; the classification logic carries over to the switches.</p>

<p>Check what is currently applied before changing anything:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>show policy-map control-plane
show platform hardware qfp active feature qos interface CPP
show platform software infrastructure punt
</code></pre></div></div>

<p>The last command shows what is actually being punted and why. Look at it on a normal day so you know what “normal” means.</p>

<h2 id="build-the-classes">Build the classes</h2>

<p>Start with ACLs that describe traffic you expect. Be specific about sources; a class that matches “any OSPF” also matches spoofed OSPF.</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ip access-list extended COPP-ROUTING
 permit tcp 10.0.0.0 0.0.255.255 any eq bgp
 permit tcp 10.0.0.0 0.0.255.255 eq bgp any
 permit ospf 10.0.0.0 0.0.255.255 any
 permit udp any any eq 3784
!
ip access-list extended COPP-MGMT
 permit tcp 10.50.0.0 0.0.0.255 any eq 22
 permit udp 10.50.0.0 0.0.0.255 any eq snmp
 permit udp any eq ntp any eq ntp
 permit tcp 10.50.0.0 0.0.0.255 any eq 830
!
ip access-list extended COPP-ICMP
 permit icmp any any echo
 permit icmp any any echo-reply
 permit icmp any any ttl-exceeded
 permit icmp any any unreachable
!
class-map match-all CM-COPP-ROUTING
 match access-group name COPP-ROUTING
class-map match-all CM-COPP-MGMT
 match access-group name COPP-MGMT
class-map match-all CM-COPP-ICMP
 match access-group name COPP-ICMP
</code></pre></div></div>

<p>Port 3784 is single-hop BFD control. If you run BFD and forget it here, you will find out the hard way when the default class starts dropping it.</p>

<h2 id="build-the-policy">Build the policy</h2>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>policy-map PM-COPP
 class CM-COPP-ROUTING
  police rate 2000 pps
   conform-action transmit
   exceed-action transmit
 class CM-COPP-MGMT
  police rate 500 pps
   conform-action transmit
   exceed-action drop
 class CM-COPP-ICMP
  police rate 100 pps
   conform-action transmit
   exceed-action drop
 class class-default
  police rate 200 pps
   conform-action transmit
   exceed-action drop
!
control-plane
 service-policy input PM-COPP
</code></pre></div></div>

<p>Two choices here are deliberate. The routing class transmits on exceed: it exists for visibility, not enforcement, because dropping your own BGP keepalives during a convergence event is worse than a busy CPU. And class-default drops on exceed, so anything you did not anticipate gets a small, bounded share.</p>

<p>The rates are starting points, not recommendations. Size them from what you observe. A router with a full table and a few hundred BGP sessions needs a very different routing rate from a branch box with two OSPF neighbors.</p>

<h2 id="roll-it-out-in-monitor-mode-first">Roll it out in monitor mode first</h2>

<p>The classic CoPP outage is an engineer applying a policy that drops something nobody listed: HSRP, LDP, DHCP relay, a TACACS reply, IPsec IKE to the router itself. Avoid it by deploying every class with <code class="language-plaintext highlighter-rouge">exceed-action transmit</code> first, then watching for a week:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>show policy-map control-plane input
</code></pre></div></div>

<p>Look at the exceeded counters per class, and look at what lands in class-default. If class-default is busy, find out what it is before you start dropping it. An embedded packet capture on the control plane helps:</p>

<div class="language-text highlighter-rouge"><div class="highlight"><pre class="highlight"><code>monitor capture CAP control-plane in match any limit duration 60
monitor capture CAP start
show monitor capture CAP buffer brief
monitor capture CAP stop
</code></pre></div></div>

<p>Once the counters stop surprising you, switch the exceed actions to drop class by class, management and default first.</p>

<h2 id="keep-it-consistent">Keep it consistent</h2>

<p>CoPP is exactly the kind of config that drifts: one router gets a new ACL line during an incident and nobody back-ports it. Keep the policy in your templating or config management source, and include <code class="language-plaintext highlighter-rouge">show policy-map control-plane input</code> in whatever you already collect for monitoring, so drop counters become a graph rather than something you discover during an outage. A rising drop count in class-default is often the first sign of a scan or a misbehaving neighbor.</p>

<h2 id="why-this-matters">Why this matters</h2>

<p>Most control plane outages I have dealt with were not attacks. They were a broken monitoring poller, a layer-2 loop pushing ARP, or a neighbor in a flap loop, and the router could not protect its own routing sessions because everything shared one queue. CoPP does not make the box faster; it makes it decide what to sacrifice. Put it in carefully, observe before enforcing, and the next CPU spike costs you some SNMP polls instead of your adjacencies.</p>]]></content><author><name>Ivan Bogović</name></author><category term="Cisco" /><summary type="html"><![CDATA[A distribution switch stops answering SSH, OSPF neighbors start flapping, and the interface counters look normal. The data plane is forwarding fine, but the route processor is at 99 percent. Someone’s misconfigured monitoring host is hammering SNMP, or a broadcast storm is pushing ARP to the CPU, or a scanner found the management address. Whatever the source, all traffic punted to the CPU shares one queue, and routing protocols lose to noise. Control plane policing (CoPP) fixes this by classifying punted traffic and rate-limiting each class separately. Your BGP and OSPF keep their share of the CPU, and SNMP floods get dropped before they reach the processes that matter. What the platform already does On Catalyst 9000 switches, IOS XE ships with a system-defined policy called system-cpp-policy attached to the control plane. It has sensible defaults per punt queue, and you tune it rather than replace it. On ISR and ASR routers there is no such default for most traffic, so you build your own policy with MQC. The example below is for a router; the classification logic carries over to the switches. Check what is currently applied before changing anything: show policy-map control-plane show platform hardware qfp active feature qos interface CPP show platform software infrastructure punt The last command shows what is actually being punted and why. Look at it on a normal day so you know what “normal” means. Build the classes Start with ACLs that describe traffic you expect. Be specific about sources; a class that matches “any OSPF” also matches spoofed OSPF. ip access-list extended COPP-ROUTING permit tcp 10.0.0.0 0.0.255.255 any eq bgp permit tcp 10.0.0.0 0.0.255.255 eq bgp any permit ospf 10.0.0.0 0.0.255.255 any permit udp any any eq 3784 ! ip access-list extended COPP-MGMT permit tcp 10.50.0.0 0.0.0.255 any eq 22 permit udp 10.50.0.0 0.0.0.255 any eq snmp permit udp any eq ntp any eq ntp permit tcp 10.50.0.0 0.0.0.255 any eq 830 ! ip access-list extended COPP-ICMP permit icmp any any echo permit icmp any any echo-reply permit icmp any any ttl-exceeded permit icmp any any unreachable ! class-map match-all CM-COPP-ROUTING match access-group name COPP-ROUTING class-map match-all CM-COPP-MGMT match access-group name COPP-MGMT class-map match-all CM-COPP-ICMP match access-group name COPP-ICMP Port 3784 is single-hop BFD control. If you run BFD and forget it here, you will find out the hard way when the default class starts dropping it. Build the policy policy-map PM-COPP class CM-COPP-ROUTING police rate 2000 pps conform-action transmit exceed-action transmit class CM-COPP-MGMT police rate 500 pps conform-action transmit exceed-action drop class CM-COPP-ICMP police rate 100 pps conform-action transmit exceed-action drop class class-default police rate 200 pps conform-action transmit exceed-action drop ! control-plane service-policy input PM-COPP Two choices here are deliberate. The routing class transmits on exceed: it exists for visibility, not enforcement, because dropping your own BGP keepalives during a convergence event is worse than a busy CPU. And class-default drops on exceed, so anything you did not anticipate gets a small, bounded share. The rates are starting points, not recommendations. Size them from what you observe. A router with a full table and a few hundred BGP sessions needs a very different routing rate from a branch box with two OSPF neighbors. Roll it out in monitor mode first The classic CoPP outage is an engineer applying a policy that drops something nobody listed: HSRP, LDP, DHCP relay, a TACACS reply, IPsec IKE to the router itself. Avoid it by deploying every class with exceed-action transmit first, then watching for a week: show policy-map control-plane input Look at the exceeded counters per class, and look at what lands in class-default. If class-default is busy, find out what it is before you start dropping it. An embedded packet capture on the control plane helps: monitor capture CAP control-plane in match any limit duration 60 monitor capture CAP start show monitor capture CAP buffer brief monitor capture CAP stop Once the counters stop surprising you, switch the exceed actions to drop class by class, management and default first. Keep it consistent CoPP is exactly the kind of config that drifts: one router gets a new ACL line during an incident and nobody back-ports it. Keep the policy in your templating or config management source, and include show policy-map control-plane input in whatever you already collect for monitoring, so drop counters become a graph rather than something you discover during an outage. A rising drop count in class-default is often the first sign of a scan or a misbehaving neighbor. Why this matters Most control plane outages I have dealt with were not attacks. They were a broken monitoring poller, a layer-2 loop pushing ARP, or a neighbor in a flap loop, and the router could not protect its own routing sessions because everything shared one queue. CoPP does not make the box faster; it makes it decide what to sacrifice. Put it in carefully, observe before enforcing, and the next CPU spike costs you some SNMP polls instead of your adjacencies.]]></summary></entry></feed>