<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hécate R.</title>
    <description>The latest articles on DEV Community by Hécate R. (@hecate-regnier).</description>
    <link>https://dev.to/hecate-regnier</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1743124%2F09e1adb2-1ae4-4547-870b-71e5f754d459.jpg</url>
      <title>DEV Community: Hécate R.</title>
      <link>https://dev.to/hecate-regnier</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hecate-regnier"/>
    <language>en</language>
    <item>
      <title>How-to: install a Wazuh agent and get something out of it</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Wed, 25 Nov 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/how-to-install-a-wazuh-agent-and-get-something-out-of-it-5h5f</link>
      <guid>https://dev.to/hecate-regnier/how-to-install-a-wazuh-agent-and-get-something-out-of-it-5h5f</guid>
      <description>&lt;p&gt;Wazuh is an open-source security monitoring platform: a central manager collects and analyses, agents installed on each machine send logs and observations. A single Wazuh agent does the work of several tools once installed separately: log collection, file integrity monitoring (the job of AIDE or Tripwire), configuration audit (Lynis’s), package vulnerability detection (Trivy’s for the system), rootkit hunting.&lt;/p&gt;

&lt;p&gt;This tutorial assumes a Wazuh 4.x manager is already running. It installs an agent on a Rocky Linux server, enrols it properly, makes it watch what really matters, and shows how to write your first rules: one to silence known noise, one to raise an alert that matters. The goal isn’t thousands of alerts, but few, and meaningful.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/how-to-install-a-wazuh-agent-and-get-something-out-of-it_diagram_en.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fejbru65h4sxjoorbkzmd.webp" alt="Diagram of a Wazuh agent talking to the manager on ports 1515 and 1514, with watching, rules and upgrade order" width="800" height="419"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;What the agent sends, what the manager does with it, and how to tune it.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What a Wazuh agent does
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Module&lt;/th&gt;
&lt;th&gt;What it does&lt;/th&gt;
&lt;th&gt;Tuning needed&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;log collection&lt;/td&gt;
&lt;td&gt;sends logs to the manager, which decodes them and applies its rules&lt;/td&gt;
&lt;td&gt;add your application logs&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;file integrity (syscheck)&lt;/td&gt;
&lt;td&gt;detects file creations, changes, deletions&lt;/td&gt;
&lt;td&gt;pick directories, enable real time&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SCA&lt;/td&gt;
&lt;td&gt;checks configuration against the distribution’s CIS benchmark&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;inventory (syscollector)&lt;/td&gt;
&lt;td&gt;lists packages, ports, processes, interfaces&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;vulnerabilities&lt;/td&gt;
&lt;td&gt;the manager matches the inventory against CVE databases&lt;/td&gt;
&lt;td&gt;none on the agent side&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;rootcheck&lt;/td&gt;
&lt;td&gt;looks for known rootkit signs and anomalies&lt;/td&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Step 1: on the manager, getting ready
&lt;/h2&gt;

&lt;p&gt;The agent talks to the manager on two TCP ports: &lt;strong&gt;1514&lt;/strong&gt; for events (encrypted with a key unique to each agent) and &lt;strong&gt;1515&lt;/strong&gt; for enrolment, where the agent obtains that key. Open them only to your machines’ addresses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;firewall-cmd --permanent --new-zone=wazuh-agents
firewall-cmd --permanent --zone=wazuh-agents --add-source=203.0.113.25/32
firewall-cmd --permanent --zone=wazuh-agents --add-source=203.0.113.40/32
firewall-cmd --permanent --zone=wazuh-agents --add-port=1514/tcp --add-port=1515/tcp
firewall-cmd --reload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without an enrolment password, anyone who can reach port 1515 can register a fake agent and send fake events. Turn it on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- /var/ossec/etc/ossec.conf on the manager --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;auth&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;disabled&amp;gt;&lt;/span&gt;no&lt;span class="nt"&gt;&amp;lt;/disabled&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;port&amp;gt;&lt;/span&gt;1515&lt;span class="nt"&gt;&amp;lt;/port&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;use_password&amp;gt;&lt;/span&gt;yes&lt;span class="nt"&gt;&amp;lt;/use_password&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ssl_verify_host&amp;gt;&lt;/span&gt;no&lt;span class="nt"&gt;&amp;lt;/ssl_verify_host&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;purge&amp;gt;&lt;/span&gt;yes&lt;span class="nt"&gt;&amp;lt;/purge&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/auth&amp;gt;&lt;/span&gt;

openssl rand -base64 24 &amp;gt; /var/ossec/etc/authd.pass
chmod 640 /var/ossec/etc/authd.pass &amp;amp;&amp;amp; chown root:wazuh /var/ossec/etc/authd.pass
systemctl restart wazuh-manager
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;purge&lt;/code&gt; lets a reinstalled machine re-enrol under the same name: the old entry is replaced instead of being refused as a duplicate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: install the Wazuh agent, in the right version
&lt;/h2&gt;

&lt;p&gt;Absolute rule: &lt;strong&gt;the agent’s version must never exceed the manager’s&lt;/strong&gt;. A newer agent is refused at connection, with an unhelpful message. Always upgrade the manager first, then the agents, and install a specific version rather than “the latest”:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# /etc/yum.repos.d/wazuh.repo&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;wazuh&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Wazuh
&lt;span class="nv"&gt;baseurl&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://packages.wazuh.com/4.x/yum/
&lt;span class="nv"&gt;gpgcheck&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="nv"&gt;gpgkey&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://packages.wazuh.com/key/GPG-KEY-WAZUH
&lt;span class="nv"&gt;enabled&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1

rpm --import https://packages.wazuh.com/key/GPG-KEY-WAZUH
&lt;span class="nv"&gt;WAZUH_MANAGER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'wazuh.example.org'&lt;/span&gt; \
&lt;span class="nv"&gt;WAZUH_REGISTRATION_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;enrolment password&amp;gt;'&lt;/span&gt; \
&lt;span class="nv"&gt;WAZUH_AGENT_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'web1.example.org'&lt;/span&gt; \
  dnf install wazuh-agent-4.14.9
systemctl daemon-reload
systemctl &lt;span class="nb"&gt;enable&lt;/span&gt; --now wazuh-agent
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The package reads these environment variables during install, writes the manager’s address into &lt;code&gt;ossec.conf&lt;/code&gt;, puts the password in &lt;code&gt;authd.pass&lt;/code&gt; and enrols at first start. To keep a general &lt;code&gt;dnf update&lt;/code&gt; from moving the agent ahead of the manager, exclude it from automatic updates (&lt;code&gt;exclude=wazuh-agent&lt;/code&gt; in the repository file, or the &lt;code&gt;versionlock&lt;/code&gt; plugin) and upgrade it deliberately, after the manager.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: check the Wazuh agent connection
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;grep ^status /var/ossec/var/run/wazuh-agentd.state &lt;span class="c"&gt;# status='connected'&lt;/span&gt;
tail -n 20 /var/ossec/logs/ossec.log
&lt;span class="c"&gt;# on the manager:&lt;/span&gt;
/var/ossec/bin/agent_control -l &lt;span class="c"&gt;# the agent is "Active"&lt;/span&gt;
/var/ossec/bin/agent_control -i 007 &lt;span class="c"&gt;# details: version, last keepalive&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the agent stays “disconnected”: firewall (on either side), wrong enrolment password, name already taken, or a version newer than the manager. &lt;code&gt;ossec.log&lt;/code&gt; on the agent almost always says which.&lt;/p&gt;

&lt;h3&gt;
  
  
  A connected agent, for real
&lt;/h3&gt;

&lt;p&gt;The agent on my web server, 2 November 2026, four hours after a reboot:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# /var/ossec/bin/wazuh-control info&lt;/span&gt;
&lt;span class="nv"&gt;WAZUH_VERSION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"v4.14.9"&lt;/span&gt;
&lt;span class="nv"&gt;WAZUH_TYPE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"agent"&lt;/span&gt;

&lt;span class="c"&gt;# /var/ossec/bin/wazuh-control status&lt;/span&gt;
wazuh-modulesd is running...
wazuh-logcollector is running...
wazuh-syscheckd is running...
wazuh-agentd is running...
wazuh-execd is running...

&lt;span class="c"&gt;# grep "Connected to the server" /var/ossec/logs/ossec.log | tail -1&lt;/span&gt;
2026/11/02 09:06:20 wazuh-agentd: INFO: &lt;span class="o"&gt;(&lt;/span&gt;4102&lt;span class="o"&gt;)&lt;/span&gt;: Connected to the server &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;wazuh.example.org&lt;span class="o"&gt;]&lt;/span&gt;:1514/tcp&lt;span class="o"&gt;)&lt;/span&gt;.

&lt;span class="c"&gt;# grep -E "^(status|last_keepalive|last_ack|msg_count|msg_sent|msg_buffer)" /var/ossec/var/run/wazuh-agentd.state&lt;/span&gt;
&lt;span class="nv"&gt;status&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'connected'&lt;/span&gt;
&lt;span class="nv"&gt;last_keepalive&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'2026-11-02 13:01:20'&lt;/span&gt;
&lt;span class="nv"&gt;last_ack&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'2026-11-02 13:01:20'&lt;/span&gt;
&lt;span class="nv"&gt;msg_count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'117686'&lt;/span&gt;
&lt;span class="nv"&gt;msg_sent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'118393'&lt;/span&gt;
&lt;span class="nv"&gt;msg_buffer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'0'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Five daemons running&lt;/strong&gt; : modulesd (inventory, SCA, vulnerability data), logcollector (reads logs), syscheckd (file integrity), agentd (the connection), execd (active responses). If one is missing, the matching feature is silently off.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Connected less than a minute after boot&lt;/strong&gt; (the machine came up at 09:05:29): the agent starts early and reconnects on its own after a reboot of either side.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;last_keepalive and last_ack&lt;/strong&gt; at the same second: the agent sends, and the manager answers. A keepalive without an ack means the agent talks into the void: firewall on the way back, or a key the manager no longer recognises.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;msg_buffer = 0&lt;/strong&gt; : nothing waiting to be sent. This buffer fills when the manager is unreachable; if it stays high, events are being delayed, and once full they are dropped.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;117 686 messages in four hours&lt;/strong&gt; , about 8 per second for a busy web server: mostly log lines, plus inventory and integrity results. That’s the order of magnitude to plan for when sizing the manager.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 4: make it read the right logs
&lt;/h2&gt;

&lt;p&gt;By default the agent reads the classic system logs. Add your services’ logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- /var/ossec/etc/ossec.conf on the agent --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;localfile&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;log_format&amp;gt;&lt;/span&gt;syslog&lt;span class="nt"&gt;&amp;lt;/log_format&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;location&amp;gt;&lt;/span&gt;/var/log/nginx/error.log&lt;span class="nt"&gt;&amp;lt;/location&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/localfile&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;localfile&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;log_format&amp;gt;&lt;/span&gt;json&lt;span class="nt"&gt;&amp;lt;/log_format&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;location&amp;gt;&lt;/span&gt;/var/log/suricata/eve.json&lt;span class="nt"&gt;&amp;lt;/location&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/localfile&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;localfile&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;log_format&amp;gt;&lt;/span&gt;journald&lt;span class="nt"&gt;&amp;lt;/log_format&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;location&amp;gt;&lt;/span&gt;journald&lt;span class="nt"&gt;&amp;lt;/location&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;filter&lt;/span&gt; &lt;span class="na"&gt;field&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"_SYSTEMD_UNIT"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;^sshd\.service$&lt;span class="nt"&gt;&amp;lt;/filter&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/localfile&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;syslog&lt;/strong&gt; : the classic text format, one line per event, which the manager decodes with its shipped decoders;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;json&lt;/strong&gt; : for structured logs (Suricata, many modern applications). Each field becomes searchable in the dashboard and usable in rules;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;journald&lt;/strong&gt; : reads the systemd journal directly, filtered by unit. Essential for services that write to no file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Don’t make the same agent read the same information through two paths (a file and the systemd journal, for example): each event would be counted twice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: file integrity
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;syscheck&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;frequency&amp;gt;&lt;/span&gt;43200&lt;span class="nt"&gt;&amp;lt;/frequency&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;directories&lt;/span&gt; &lt;span class="na"&gt;realtime&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yes"&lt;/span&gt; &lt;span class="na"&gt;check_all&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yes"&lt;/span&gt; &lt;span class="na"&gt;report_changes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yes"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;/etc/ssh,/etc/sudoers.d,/etc/nginx&lt;span class="nt"&gt;&amp;lt;/directories&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;directories&lt;/span&gt; &lt;span class="na"&gt;realtime&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yes"&lt;/span&gt; &lt;span class="na"&gt;check_all&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yes"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;/etc/passwd,/etc/shadow,/etc/group&lt;span class="nt"&gt;&amp;lt;/directories&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;directories&lt;/span&gt; &lt;span class="na"&gt;check_all&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"yes"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;/usr/bin,/usr/sbin,/usr/local/bin&lt;span class="nt"&gt;&amp;lt;/directories&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ignore&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"sregex"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;\.swp$|~$&lt;span class="nt"&gt;&amp;lt;/ignore&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;nodiff&amp;gt;&lt;/span&gt;/etc/shadow&lt;span class="nt"&gt;&amp;lt;/nodiff&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/syscheck&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;frequency&lt;/strong&gt; : a full scan every twelve hours for directories without real-time monitoring;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;realtime&lt;/strong&gt; : immediate monitoring through inotify, for files whose change must alert right away (SSH configuration, sudo, accounts);&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;report_changes&lt;/strong&gt; : attaches the changed file’s diff to the alert. Precious for configuration; never on secret files, hence &lt;code&gt;nodiff&lt;/code&gt; for &lt;code&gt;/etc/shadow&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;binaries&lt;/strong&gt; (&lt;code&gt;/usr/bin&lt;/code&gt;…): a change outside a package update is a strong sign of compromise. They’re numerous: no real time, the periodic scan is enough;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ignore&lt;/strong&gt; : editor temporary files, which would raise alerts at every edit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every package update produces a burst of integrity alerts on binaries: that’s normal, and the manager ties them to dnf’s logs. What should worry you is a binary change &lt;strong&gt;without&lt;/strong&gt; a matching update.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: SCA and vulnerabilities, for free
&lt;/h2&gt;

&lt;p&gt;Configuration assessment (SCA) applies the distribution’s CIS benchmark every twelve hours and gives a score, with each failed check’s rationale and suggested remediation. Don’t aim for 100%: some checks assume a partitioning scheme or organisation that doesn’t apply to you. Read the list, fix what makes sense, and note why you ignore the rest.&lt;/p&gt;

&lt;p&gt;Vulnerability detection relies on the package inventory the agent sends; the manager matches it against published vulnerability databases. It covers installed RPM packages. It doesn’t see what an application bundles itself: an embedded Node.js, a Python environment, a Go binary built with a vulnerable library. For those, you have to follow each project’s announcements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 7: writing your own rules
&lt;/h2&gt;

&lt;p&gt;The shipped rules cover the essentials, but they need adjusting. Yours go on the manager, in &lt;code&gt;/var/ossec/etc/rules/&lt;/code&gt;, in a file of your own that no update will overwrite, with ids from 100000 up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- /var/ossec/etc/rules/local_tuning.xml (on the manager) --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;group&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"local,tuning,"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;rule&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"100900"&lt;/span&gt; &lt;span class="na"&gt;level&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;if_sid&amp;gt;&lt;/span&gt;550&lt;span class="nt"&gt;&amp;lt;/if_sid&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;field&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;^/var/lib/myapp/cache/&lt;span class="nt"&gt;&amp;lt;/field&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;description&amp;gt;&lt;/span&gt;Known noise: application cache changing all the time&lt;span class="nt"&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/rule&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;rule&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"100901"&lt;/span&gt; &lt;span class="na"&gt;level&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"12"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;if_sid&amp;gt;&lt;/span&gt;550&lt;span class="nt"&gt;&amp;lt;/if_sid&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;field&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;^/etc/sudoers&lt;span class="nt"&gt;&amp;lt;/field&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;description&amp;gt;&lt;/span&gt;sudo configuration changed: $(file)&lt;span class="nt"&gt;&amp;lt;/description&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;group&amp;gt;&lt;/span&gt;privilege_escalation,&lt;span class="nt"&gt;&amp;lt;/group&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/rule&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/group&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Silencing known noise
&lt;/h3&gt;

&lt;p&gt;A rule that shouts all the time makes you ignore all the others. Don’t disable the original rule: add a level-0 &lt;strong&gt;child&lt;/strong&gt; rule (&lt;code&gt;if_sid&lt;/code&gt;) targeting only the known case. Here rule 550 (“checksum changed”) stays active everywhere except for the application’s cache.&lt;/p&gt;

&lt;h3&gt;
  
  
  Raising what matters
&lt;/h3&gt;

&lt;p&gt;Conversely, a change to the sudo configuration deserves more than the default level: rule 100901 lifts it to level 12, enough to trigger an immediate notification. The &lt;code&gt;privilege_escalation&lt;/code&gt; group makes it easy to find in the dashboard.&lt;/p&gt;

&lt;h3&gt;
  
  
  The field name trap
&lt;/h3&gt;

&lt;p&gt;The dashboard and the JSON alerts show the file path as &lt;code&gt;syscheck.path&lt;/code&gt;. But in a rule, and in the description’s &lt;code&gt;$(…)&lt;/code&gt; substitution, you must write &lt;code&gt;file&lt;/code&gt;. With &lt;code&gt;syscheck.path&lt;/code&gt; there’s no error at load time: the rule simply never fires, and the description shows up blank. I shipped two rule files broken this way before understanding it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test before reloading
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/var/ossec/bin/wazuh-analysisd -t &lt;span class="c"&gt;# rule syntax&lt;/span&gt;
/var/ossec/bin/wazuh-logtest &lt;span class="c"&gt;# paste a line: which rules apply?&lt;/span&gt;
systemctl restart wazuh-manager
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;wazuh-logtest&lt;/code&gt; only simulates logs, not integrity events. For a syscheck rule, the test is real: change a file in the target directory on the agent, and look for the alert in &lt;code&gt;/var/ossec/logs/alerts/alerts.json&lt;/code&gt; on the manager.&lt;/p&gt;

&lt;h2&gt;
  
  
  Upgrading the fleet
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;the manager first, indexer and dashboard included, following the release notes;&lt;/li&gt;
&lt;li&gt;check that every agent is still “Active”;&lt;/li&gt;
&lt;li&gt;then the agents, machine by machine, pinning the same version as the manager;&lt;/li&gt;
&lt;li&gt;after each agent, &lt;code&gt;agent_control -i&lt;/code&gt; must show the new version.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Going further
&lt;/h2&gt;

&lt;p&gt;“Active responses” let the manager trigger an action on the agent in response to a rule (banning an address, for example). If CrowdSec or fail2ban already do that, refrain: two systems each banning on their own make unblocking painful. Wazuh is more useful as memory and as a correlation point than as an enforcer.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This post is part of a series of sysadmin tutorials (tag “how-to”).&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Series “How-to”, tutorial 15/77. · &lt;a href="https://hecate.neurozone.fr/?p=623" rel="noopener noreferrer"&gt;← Previous tutorial&lt;/a&gt; · Next tutorial → (coming 30 Nov) · &lt;a href="https://blog.neurozone.fr/?p=2069" rel="noopener noreferrer"&gt;Version française&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Related articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=598" rel="noopener noreferrer"&gt;Installing CrowdSec without banning yourself&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=599" rel="noopener noreferrer"&gt;Suricata as an IPS with NFQUEUE&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=620" rel="noopener noreferrer"&gt;A well-tuned fail2ban with progressive bans&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/25/how-to-install-a-wazuh-agent-and-get-something-out-of-it/" rel="noopener noreferrer"&gt;How-to: install a Wazuh agent and get something out of it&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>security</category>
      <category>sysadminnotebook</category>
      <category>english</category>
      <category>howto</category>
    </item>
    <item>
      <title>Oracle identity columns and sequences: the ISEQ$$ cache and what a crash costs, tested</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Tue, 24 Nov 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/oracle-identity-columns-and-sequences-the-iseq-cache-and-what-a-crash-costs-tested-g0l</link>
      <guid>https://dev.to/hecate-regnier/oracle-identity-columns-and-sequences-the-iseq-cache-and-what-a-crash-costs-tested-g0l</guid>
      <description>&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; I killed the container with &lt;code&gt;podman kill&lt;/code&gt; (SIGKILL): an Oracle identity column went from id 9 to 24 and a plain sequence from 3 to 22, which matches the cache of 20 that both use. A clean restart, by contrast, lost nothing. &lt;code&gt;NEXTVAL&lt;/code&gt; is evaluated once per statement, so two calls in one query return the same value.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Oracle AI Database 26ai Free 23.26.3 in a container, throw-away schema, Rocky Linux 10.2 host. Part 3 of 5. Every output comes from my own test runs.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/oracle-identity-column-sequences-iseq-cache-crash-tested.webp" rel="noopener noreferrer"&gt;&lt;img width="800" height="249" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fhecate.neurozone.fr%2Fwp-content%2Fuploads%2F2026%2F11%2Foracle-identity-column-sequences-iseq-cache-crash-tested.webp" alt="Oracle identity column after a crash: the id jumps from 9 to 24 and a sequence from 3 to 22"&gt;&lt;/a&gt;Oracle 26ai Free: a cache of 20 sits behind the identity column and the sequence.&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;Oracle identity column or sequence as default&lt;/h2&gt;

&lt;pre&gt;CREATE TABLE t_ident (id NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, v VARCHAR2(20));
CREATE SEQUENCE s1;
CREATE TABLE t_seq (id NUMBER DEFAULT s1.NEXTVAL PRIMARY KEY, v VARCHAR2(20));

INSERT INTO t_ident(v) VALUES ('a') RETURNING id INTO :id;   -- 1
INSERT INTO t_seq(v)   VALUES ('a') RETURNING id INTO :id;   -- 1
SELECT s1.CURRVAL FROM dual;                                  -- 1&lt;/pre&gt;

&lt;p&gt;The dictionary shows the link:&lt;/p&gt;

&lt;pre&gt;TABLE_NAME COLUMN_N DATA_DEFAULT
---------- -------- ----------------------------------------
T_IDENT    ID       "SHOP"."ISEQ$$_73219".nextval
T_SEQ      ID       "SHOP"."S1"."NEXTVAL"&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;user_tab_identity_cols&lt;/code&gt; maps each identity column to its hidden sequence and gives &lt;code&gt;ALWAYS&lt;/code&gt; or &lt;code&gt;BY DEFAULT&lt;/code&gt;. Both sequences above report &lt;code&gt;cache_size&lt;/code&gt; 20 in &lt;code&gt;user_sequences&lt;/code&gt;: that is also the default for a plain &lt;code&gt;CREATE SEQUENCE&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;ALWAYS or BY DEFAULT&lt;/h2&gt;

&lt;p&gt;With &lt;code&gt;BY DEFAULT&lt;/code&gt;, Oracle accepts an explicit value but the counter does not move, exactly as in PostgreSQL:&lt;/p&gt;

&lt;pre&gt;INSERT INTO t_by(id, v) VALUES (2, 'explicit 2');                       -- ok
INSERT INTO t_by(v) VALUES ('default 1') RETURNING id INTO :id;         -- 1
INSERT INTO t_by(v) VALUES ('default 2') RETURNING id INTO :id;
ORA-00001: unique constraint (SHOP.SYS_C008690) violated on table SHOP.T_BY columns (ID)
INSERT INTO t_by(v) VALUES ('default 3') RETURNING id INTO :id;         -- 3&lt;/pre&gt;

&lt;p&gt;With &lt;code&gt;ALWAYS&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;ORA-32795: cannot insert into a generated always identity column&lt;/pre&gt;

&lt;h2&gt;Rollback and failed inserts consume values&lt;/h2&gt;

&lt;pre&gt;INSERT INTO t_ident(v) VALUES ('rolled back') RETURNING id INTO :id;    -- 2
ROLLBACK;
INSERT INTO t_ident(v) VALUES ('after rollback') RETURNING id INTO :id; -- 3&lt;/pre&gt;

&lt;p&gt;With a unique violation: id 1, &lt;code&gt;ORA-00001&lt;/code&gt; on the duplicate, then 3.&lt;/p&gt;

&lt;h2&gt;NEXTVAL is evaluated once per statement&lt;/h2&gt;

&lt;pre&gt;SELECT s_cache.NEXTVAL, s_cache.NEXTVAL FROM dual;     -- 1 1&lt;/pre&gt;

&lt;p&gt;Two calls in the same statement return the same value, so one statement cannot hand out two ids.&lt;/p&gt;

&lt;h2&gt;Concurrency: order of ids is not order of commits&lt;/h2&gt;

&lt;pre&gt;A: begin 08:32:11.155        (A inserts first, commits last)
B: begin 08:32:12.658
B got id 2
B: committed 08:32:13.493
A got id 1
A: committed 08:32:15.900&lt;/pre&gt;

&lt;p&gt;B’s row commits and is visible before A’s row, although its id is higher.&lt;/p&gt;

&lt;h2&gt;CACHE belongs to the instance, not to the session&lt;/h2&gt;

&lt;pre&gt;CREATE SEQUENCE s_cache CACHE 10;
same session twice : 1 1
new session        : 2
another new session: 3&lt;/pre&gt;

&lt;p&gt;Unlike PostgreSQL, different sessions get consecutive values: the cache is shared by the instance (observed: consecutive values across sessions). &lt;code&gt;user_sequences.last_number&lt;/code&gt; shows the high-water mark written to the dictionary: 11 for &lt;code&gt;s_cache&lt;/code&gt;, 21 for a cache of 20 after the first call.&lt;/p&gt;

&lt;h2&gt;Limits and CYCLE&lt;/h2&gt;

&lt;pre&gt;ORA-08004: Sequence S_SMALL.NEXTVAL exceeds MAXVALUE and cannot be instantiated.
ALTER SEQUENCE s_small CYCLE;
ORA-04013: The CACHE value may not exceed the CYCLE value.
ALTER SEQUENCE s_small NOCACHE CYCLE;
SELECT s_small.NEXTVAL FROM dual;                      -- 1&lt;/pre&gt;

&lt;p&gt;If the cache is bigger than the cycle length, &lt;code&gt;CYCLE&lt;/code&gt; is refused; &lt;code&gt;NOCACHE&lt;/code&gt; fixes it. An identity on &lt;code&gt;NUMBER(2)&lt;/code&gt; starting at 98 gives 98, 99 and then &lt;code&gt;ORA-01438: value 100 greater than specified precision (2, 0)&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;Restart and crash&lt;/h2&gt;

&lt;p&gt;Three rows inserted, the last deleted, clean restart (&lt;code&gt;podman stop&lt;/code&gt;: SIGTERM, the image runs a &lt;code&gt;SHUTDOWN IMMEDIATE&lt;/code&gt;):&lt;/p&gt;

&lt;pre&gt;id of the row inserted after the clean restart: 4
sequence before the restart: 1 1 1   (one statement, three calls)
sequence after the restart: 2&lt;/pre&gt;

&lt;p&gt;No gap. Five more rows (last id 9), then &lt;code&gt;podman kill&lt;/code&gt; (SIGKILL), instance recovery (the alert log shows &lt;code&gt;Beginning crash recovery of 1 threads&lt;/code&gt;):&lt;/p&gt;

&lt;pre&gt;ids before the crash: 1,2,4,5,6,7,8,9
sequence before the crash: 3 3
id of the row inserted after the crash: 24
ids now: 1,2,4,5,6,7,8,9,24
sequence after the crash: 22&lt;/pre&gt;

&lt;p&gt;The Oracle identity column jumps from 9 to 24, the explicit sequence from 3 to 22, but the clean restart before it had lost nothing. The arithmetic is consistent with the cache of 20 starting at the first value handed out after the clean restart (4 + 20 = 24 and 2 + 20 = 22): after the crash, the instance restarts from the high-water mark stored in the dictionary. However, I did not trace the dictionary updates to confirm the mechanism.&lt;/p&gt;

&lt;h2&gt;Where to read the state&lt;/h2&gt;

&lt;pre&gt;SELECT sequence_name, increment_by, cycle_flag, order_flag, cache_size, last_number FROM user_sequences;
SELECT table_name, column_name, generation_type, sequence_name FROM user_tab_identity_cols;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;last_number&lt;/code&gt; is the next value that would be handed out &lt;em&gt;when the cache is exhausted&lt;/em&gt;, not the last value used.&lt;/p&gt;

&lt;h2&gt;Official documentation&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.oracle.com/database/free/" rel="noopener noreferrer"&gt;Oracle AI Database Free&lt;/a&gt;, the edition used here&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.oracle.com/en/database/oracle/oracle-database/26/sqlrf/CREATE-SEQUENCE.html" rel="noopener noreferrer"&gt;CREATE SEQUENCE&lt;/a&gt;, SQL Language Reference, 26ai&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.oracle.com/en/database/oracle/oracle-database/26/sqlrf/CREATE-TABLE.html" rel="noopener noreferrer"&gt;CREATE TABLE&lt;/a&gt;, identity clause&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.oracle.com/en/database/oracle/oracle-database/26/sqlrf/Pseudocolumns.html" rel="noopener noreferrer"&gt;Pseudocolumns&lt;/a&gt;, &lt;code&gt;CURRVAL&lt;/code&gt; and &lt;code&gt;NEXTVAL&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;*Not tested here: &lt;code&gt;ORDER&lt;/code&gt; and RAC behaviour, &lt;code&gt;NOCACHE&lt;/code&gt; cost, &lt;code&gt;ALTER TABLE ... MODIFY ... RESTART&lt;/code&gt;, &lt;code&gt;SYS_GUID()&lt;/code&gt; as key, shutdown with &lt;code&gt;ABORT&lt;/code&gt; (my crash is a SIGKILL of the container).*&lt;/p&gt;

&lt;h2&gt;All parts of the series&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=4230" rel="noopener noreferrer"&gt;1/5 PostgreSQL&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=4232" rel="noopener noreferrer"&gt;2/5 MariaDB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3/5 Oracle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;4/5 SQL Server (coming 1 Dec)&lt;/span&gt;&lt;/p&gt;

&lt;p&gt;&lt;span&gt;5/5 TL;DR: the four engines compared (coming 8 Dec)&lt;/span&gt;&lt;/p&gt;

&lt;h2&gt;Related articles&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=377" rel="noopener noreferrer"&gt;Inside database data files (1/3): InnoDB, from MySQL to MariaDB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=378" rel="noopener noreferrer"&gt;Inside database data files (2/3): PostgreSQL&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=379" rel="noopener noreferrer"&gt;Inside database data files (3/3): Oracle, and all three side by side&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/24/oracle-identity-column-sequences-iseq-cache-crash-tested/" rel="noopener noreferrer"&gt;Oracle identity columns and sequences: the ISEQ$$ cache and what a crash costs, tested&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>database</category>
      <category>mariadb</category>
      <category>storage</category>
      <category>sysadminnotebook</category>
    </item>
    <item>
      <title>How-to: a blocking WAF with OpenResty and CrowdSec AppSec</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Mon, 23 Nov 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/how-to-a-blocking-waf-with-openresty-and-crowdsec-appsec-109n</link>
      <guid>https://dev.to/hecate-regnier/how-to-a-blocking-waf-with-openresty-and-crowdsec-appsec-109n</guid>
      <description>&lt;p&gt;The firewall and CrowdSec’s bans stop addresses that have already misbehaved. They can do nothing against the &lt;em&gt;first&lt;/em&gt; malicious request from an unknown address: the one looking for a forgotten &lt;code&gt;.env&lt;/code&gt; file, an exposed &lt;code&gt;.git&lt;/code&gt; repository, or exploiting a vulnerability published yesterday in a WordPress plugin. That’s the job of a web application firewall (WAF): inspect every HTTP request and block those that look like an attack.&lt;/p&gt;

&lt;p&gt;CrowdSec provides one, the &lt;strong&gt;AppSec&lt;/strong&gt; engine, with “virtual patching” rules for known vulnerabilities, updated like the rest of the hub. To block, the web server must submit each request to it before serving it. With nginx, the official bouncer does that in Lua, hence &lt;strong&gt;OpenResty&lt;/strong&gt; : an nginx distribution with LuaJIT built in. This tutorial covers migrating from nginx to OpenResty without changing any site configuration, wiring in the engine, an observation period, then switching to blocking.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/how-to-a-blocking-waf-with-openresty-and-crowdsec-appsec_diagram_en.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6n5fpevjmbp1qxbnf7i9.webp" alt="Diagram of the layers of the CrowdSec WAF setup and the three-step rollout from OpenResty to blocking"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Each layer looks at something different; the rollout observes before blocking.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The three layers
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Layer&lt;/th&gt;
&lt;th&gt;What it sees&lt;/th&gt;
&lt;th&gt;What it blocks&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;firewall bouncer (nftables)&lt;/td&gt;
&lt;td&gt;IP addresses&lt;/td&gt;
&lt;td&gt;already banned addresses, before the TCP connection&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OpenResty bouncer, decisions part&lt;/td&gt;
&lt;td&gt;each HTTP request’s address&lt;/td&gt;
&lt;td&gt;banned addresses, with an explanation page&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AppSec engine&lt;/td&gt;
&lt;td&gt;each request’s contents (path, parameters, headers, body)&lt;/td&gt;
&lt;td&gt;requests matching a known attack, from the very first one&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;An address that triggers the AppSec engine several times ends up banned by a scenario, and then moves to the earlier, cheaper layers.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: OpenResty instead of nginx, same configuration
&lt;/h2&gt;

&lt;p&gt;OpenResty publishes EL9 packages; there are none for EL10 as I write, but the EL9 ones work on Rocky Linux 10. Install them next to nginx, removing nothing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dnf install openresty openresty-opm
opm get ledgetech/lua-resty-http=0.17.1
/usr/local/openresty/nginx/sbin/nginx -V 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1 &lt;span class="o"&gt;|&lt;/span&gt; head -3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;lua-resty-http&lt;/code&gt; library, which the bouncer needs, is normally installed by the bouncer package’s script, but silently and not always. Install it explicitly, pinning the version.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keeping the “nginx” identity
&lt;/h3&gt;

&lt;p&gt;The safest way not to break anything is to change &lt;strong&gt;only the binary&lt;/strong&gt;. The service stays &lt;code&gt;nginx.service&lt;/code&gt; (monitoring, scripts, logrotate, fail2ban and CrowdSec keep working), the configuration stays in &lt;code&gt;/etc/nginx&lt;/code&gt;, the logs in &lt;code&gt;/var/log/nginx&lt;/code&gt;, and the process runs as the &lt;code&gt;nginx&lt;/code&gt; user. A systemd override replaces the commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight systemd"&gt;&lt;code&gt;&lt;span class="c1"&gt;# /etc/systemd/system/nginx.service.d/openresty.conf
&lt;/span&gt;&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;ExecStartPre&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="na"&gt;ExecStartPre&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;openresty&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;sbin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;conf&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;t&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;openresty&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;sbin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;conf&lt;/span&gt;
&lt;span class="na"&gt;ExecReload&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="na"&gt;ExecReload&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;openresty&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;sbin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;nginx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;conf&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="n"&gt;reload&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-p /etc/nginx/&lt;/code&gt; sets the prefix: relative paths in the configuration (&lt;code&gt;include mime.types;&lt;/code&gt;, for example) resolve as with the original nginx. Also check that the dynamic modules your configuration loads (&lt;code&gt;load_module&lt;/code&gt;) exist in OpenResty too: otherwise remove them or find their equivalent.&lt;/p&gt;

&lt;h3&gt;
  
  
  SELinux
&lt;/h3&gt;

&lt;p&gt;The OpenResty binary must run in the same domain as nginx (&lt;code&gt;httpd_t&lt;/code&gt;), or it won’t have access to site files, certificates or PHP-FPM sockets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;semanage fcontext -a -t httpd_exec_t &lt;span class="s1"&gt;'/usr/local/openresty/nginx/sbin/nginx'&lt;/span&gt;
restorecon -v /usr/local/openresty/nginx/sbin/nginx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Testing before switching
&lt;/h3&gt;

&lt;p&gt;Before touching the service, run OpenResty &lt;strong&gt;side by side&lt;/strong&gt; with a copy of the configuration listening on other ports, and compare each site’s HTTP code between the two servers. When everything matches, apply the override and restart. Keep the nginx package installed for a few days: rolling back is then just removing the override.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: the AppSec engine
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;cscli collections install crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules&lt;/span&gt;

&lt;span class="c1"&gt;# /etc/crowdsec/acquis.d/appsec.yaml
&lt;/span&gt;&lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;appsec&lt;/span&gt;
&lt;span class="na"&gt;listen_addr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;127.0.0.1:7422&lt;/span&gt;
&lt;span class="na"&gt;appsec_configs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s"&gt;crowdsecurity/appsec-default&lt;/span&gt;
&lt;span class="na"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;appsec&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;listen_addr&lt;/strong&gt; : the engine listens locally only; only the web server talks to it;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;appsec-default&lt;/strong&gt; : the shipped configuration, which loads the virtual patching rules in blocking mode;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;appsec-generic-rules&lt;/strong&gt; : broader rules (directory traversal, common injections). More useful, but more prone to false positives: that’s where observation matters most.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl restart crowdsec
ss -ltnp &lt;span class="o"&gt;|&lt;/span&gt; grep 7422
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: observe before blocking
&lt;/h2&gt;

&lt;p&gt;Plugging a WAF straight into blocking means risking breaking a site without noticing: an application sending unusual JSON, an editor posting HTML, a form containing a file path. Start with an observation period using nginx’s &lt;code&gt;mirror&lt;/code&gt; directive, which sends a &lt;em&gt;copy&lt;/em&gt; of each request to the engine and ignores its answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="c1"&gt;# /etc/nginx/snippets/server.d/crowdsec-appsec-mirror.conf (in each server)
&lt;/span&gt;&lt;span class="n"&gt;mirror&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;_crowdsec_appsec_mirror&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;mirror_request_body&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="na"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;_crowdsec_appsec_mirror&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;internal&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_pass&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//127.0.0.1:7422/;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_connect_timeout&lt;/span&gt; &lt;span class="mi"&gt;200ms&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_send_timeout&lt;/span&gt; &lt;span class="mi"&gt;1s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_read_timeout&lt;/span&gt; &lt;span class="mi"&gt;1s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Crowdsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Appsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Ip&lt;/span&gt; $&lt;span class="n"&gt;remote_addr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Crowdsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Appsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Uri&lt;/span&gt; $&lt;span class="n"&gt;request_uri&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Crowdsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Appsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Host&lt;/span&gt; $&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Crowdsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Appsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Verb&lt;/span&gt; $&lt;span class="n"&gt;request_method&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Crowdsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Appsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;User&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Agent&lt;/span&gt; $&lt;span class="n"&gt;http_user_agent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;proxy_set_header&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Crowdsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Appsec&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Api&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nc"&gt;Key&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;bouncer&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By construction, this mode can neither block nor alter real traffic: nginx doesn’t wait for the mirror’s answer to reply to the client. The short timeouts keep a slow engine from holding connections. At the same time, put the AppSec scenarios in simulation (&lt;code&gt;cscli simulation enable&lt;/code&gt;) so no address gets banned during this phase.&lt;/p&gt;

&lt;p&gt;Let it run for two to seven days, then read what the engine would have blocked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cscli alerts list --since 72h &lt;span class="o"&gt;|&lt;/span&gt; grep -i appsec
cscli alerts inspect &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;id&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; -d &lt;span class="c"&gt;# the request, the rule, the address&lt;/span&gt;
cscli metrics show appsec
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For each match, ask two questions: is the address mine or a legitimate user’s? Is the path a normal function of an application? Fix before blocking: whitelist addresses (your own servers), exempt a whole site, or disable one specific rule.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: switching to blocking
&lt;/h2&gt;

&lt;p&gt;Create a key for the bouncer (&lt;code&gt;cscli bouncers add openresty-bouncer&lt;/code&gt;), then configure it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight conf"&gt;&lt;code&gt;&lt;span class="c1"&gt;# /etc/crowdsec/bouncers/crowdsec-openresty-bouncer.conf (excerpt)
&lt;/span&gt;&lt;span class="na"&gt;API_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//127.0.0.1:8081&lt;/span&gt;
&lt;span class="na"&gt;API_KEY&lt;/span&gt;&lt;span class="o"&gt;=&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="n"&gt;generated&lt;/span&gt; &lt;span class="n"&gt;by&lt;/span&gt; &lt;span class="n"&gt;cscli&lt;/span&gt; &lt;span class="n"&gt;bouncers&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="na"&gt;MODE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;stream&lt;/span&gt;
&lt;span class="na"&gt;UPDATE_FREQUENCY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="na"&gt;FALLBACK_REMEDIATION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ban&lt;/span&gt;
&lt;span class="na"&gt;BAN_TEMPLATE_PATH&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;crowdsec&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lua&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;templates&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ban&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;
&lt;span class="na"&gt;APPSEC_URL&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//127.0.0.1:7422&lt;/span&gt;
&lt;span class="na"&gt;APPSEC_FAILURE_ACTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;passthrough&lt;/span&gt;
&lt;span class="na"&gt;APPSEC_CONNECT_TIMEOUT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="na"&gt;APPSEC_SEND_TIMEOUT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;200&lt;/span&gt;
&lt;span class="na"&gt;APPSEC_PROCESS_TIMEOUT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;
&lt;span class="na"&gt;ALWAYS_SEND_TO_APPSEC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MODE=stream&lt;/strong&gt; : the bouncer fetches all decisions every 10 seconds and keeps them in shared memory, instead of asking the local API on every request;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;FALLBACK_REMEDIATION=ban&lt;/strong&gt; : a decision of an unknown type is treated as a ban;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;APPSEC_FAILURE_ACTION=passthrough&lt;/strong&gt; : if the engine doesn’t answer, the request goes through. A deliberate choice: a WAF that takes every site offline when it fails is worse than no WAF. The trade-off is that you must monitor the engine;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;timeouts&lt;/strong&gt; (in milliseconds): 100 to connect, 200 to send, 500 for the answer. A local engine answers in a few milliseconds; these values only bound the worst case;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ALWAYS_SEND_TO_APPSEC=false&lt;/strong&gt; : an already banned address is rejected directly, without calling the engine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then the nginx wiring, at &lt;code&gt;http&lt;/code&gt; level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight nginx"&gt;&lt;code&gt;&lt;span class="c1"&gt;# /etc/nginx/conf.d/crowdsec-openresty.conf (http level)
&lt;/span&gt;&lt;span class="n"&gt;lua_package_path&lt;/span&gt; &lt;span class="s1"&gt;'/usr/local/openresty/lualib/plugins/crowdsec/?.lua;;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;lua_shared_dict&lt;/span&gt; &lt;span class="n"&gt;crowdsec_cache&lt;/span&gt; &lt;span class="mi"&gt;50m&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;lua_ssl_trusted_certificate&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;pki&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;tls&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;certs&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;ca&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;bundle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;crt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;init_by_lua_block&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;jit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;off&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="na"&gt;cs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;require&lt;/span&gt; &lt;span class="s2"&gt;"crowdsec"&lt;/span&gt;
    &lt;span class="na"&gt;local ok, err&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"/etc/crowdsec/bouncers/crowdsec-openresty-bouncer.conf"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="s2"&gt;"crowdsec-openresty-bouncer/v1.2.3"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="na"&gt;if ok&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;nil&lt;/span&gt; &lt;span class="n"&gt;then&lt;/span&gt;
        &lt;span class="n"&gt;ngx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ngx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;ERR&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"[Crowdsec] "&lt;/span&gt; &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="kt"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;end&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;map&lt;/span&gt; $&lt;span class="n"&gt;host&lt;/span&gt; $&lt;span class="n"&gt;crowdsec_appsec_bypass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;cloud&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;org&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;# large uploads, WebDAV&lt;/span&gt;
    &lt;span class="n"&gt;audio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;org&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;# audio file uploads&lt;/span&gt;
    &lt;span class="n"&gt;vault&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;example&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;org&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;# secrets store&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;access_by_lua_block&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;if ngx.var.crowdsec_appsec_bypass&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt; &lt;span class="n"&gt;then&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;
    &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"crowdsec"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Allow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ngx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remote_addr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The two traps
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;jit.off()&lt;/strong&gt;. LuaJIT’s just-in-time compiler needs memory pages that are both writable and executable. SELinux denies them to the &lt;code&gt;httpd_t&lt;/code&gt; domain (the &lt;code&gt;httpd_execmem&lt;/code&gt; boolean is off, and it’s better left off). Without this line, nginx dies at startup with “runtime code generation failed”. And &lt;code&gt;nginx -t&lt;/code&gt; doesn’t see it, because the configuration test doesn’t run &lt;code&gt;init_by_lua&lt;/code&gt;: the test passes, the restart fails. The interpreter is plenty for the bouncer’s few calls per request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Large uploads&lt;/strong&gt;. The engine caps the size of request bodies it inspects. Sites that receive large files (online storage, WebDAV, audio transcription) then see every upload refused with a 403, with no explanation for the user. Those sites go into the &lt;code&gt;map $host&lt;/code&gt; exemption table. Same for streaming applications (websockets) and a secrets store, whose requests are encrypted and look like nothing. Exempted sites keep the firewall bouncer’s protection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nginx -t &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; systemctl restart nginx
journalctl -u nginx -n 20 --no-pager &lt;span class="o"&gt;|&lt;/span&gt; grep -i crowdsec &lt;span class="c"&gt;# "Initialisation done"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: check
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -s -o /dev/null -w &lt;span class="s1"&gt;'%{http_code}\n'&lt;/span&gt; https://www.example.org/.env &lt;span class="c"&gt;# 403&lt;/span&gt;
curl -s -o /dev/null -w &lt;span class="s1"&gt;'%{http_code}\n'&lt;/span&gt; https://www.example.org/.git/config &lt;span class="c"&gt;# 403&lt;/span&gt;
curl -s -o /dev/null -w &lt;span class="s1"&gt;'%{http_code}\n'&lt;/span&gt; https://www.example.org/ &lt;span class="c"&gt;# 200&lt;/span&gt;
curl -s -o /dev/null -w &lt;span class="s1"&gt;'%{http_code}\n'&lt;/span&gt; https://cloud.example.org/.env &lt;span class="c"&gt;# not 403: exempted site&lt;/span&gt;
cscli metrics show appsec
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then test each application’s sensitive functions: login, file upload, publishing an article, saving an admin form. An unexpected 403 is diagnosed with &lt;code&gt;cscli alerts list&lt;/code&gt;: the alert gives the rule and the request.&lt;/p&gt;

&lt;h3&gt;
  
  
  Four hours of a real WAF
&lt;/h3&gt;

&lt;p&gt;On my web server, 2 November 2026 (OpenResty 1.31.8.1, CrowdSec AppSec), four hours after a reboot. First the quick tests:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;403&lt;/span&gt;
&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;wp&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bak&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;
&lt;span class="na"&gt;GET /?id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="s1"&gt;' OR 1=1-- -&amp;gt; 200
&lt;/span&gt;&lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 403 on &lt;code&gt;/.env&lt;/code&gt; is a virtual patch blocking. The 404 is the application: no rule needed to fire, the file doesn’t exist. The 200 on a textbook SQL injection is the honest part: the virtual patches block known exploits, not attack &lt;em&gt;families&lt;/em&gt;. Generic SQL injection is the job of the OWASP Core Rule Set, which on this server only logs for now (the subject of a later post). Then what the engine saw:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# cscli metrics show appsec (excerpt)
| Appsec Engine | Processed | Blocked |
| nginx-appsec-mirror | 69.85k | 434 |

| Rule ID | Triggered |
| crowdsecurity/vpatch-CVE-2025-29927 | 283 |
| crowdsecurity/experimental-no-user-agent | 148 |
| crowdsecurity/vpatch-env-access | 142 |
| crowdsecurity/vpatch-symfony-profiler | 3 |
| crowdsecurity/vpatch-git-config | 1 |
| 949110 | 733 |
| 901340 | 876 |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;vpatch-CVE-2025-29927: 283&lt;/strong&gt; : probes for a Next.js authorisation bypass, on a server that runs no Next.js at all. Scanners don’t check what you run; they try everything everywhere. That’s why blocking them costs nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;vpatch-env-access: 142&lt;/strong&gt; : requests for &lt;code&gt;.env&lt;/code&gt; files, the most common secret hunt on the web.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rule numbers in 9xxxxx&lt;/strong&gt; are the Core Rule Set. &lt;code&gt;949110&lt;/code&gt; (“inbound anomaly score exceeded”) is the line that says “CRS would have blocked this request”: 733 times in four hours. Those are the requests to review before ever switching CRS to blocking, because some are legitimate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;901340: 876&lt;/strong&gt; isn’t an attack: it’s a CRS setup rule that turns on request body inspection, and it fires on many requests that have a body. Counters per rule only make sense once you know what each rule does.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Operating it
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;monitor the engine&lt;/strong&gt; : since it fails open, a stopped engine breaks nothing visible. A probe checking that &lt;code&gt;/.env&lt;/code&gt; really returns 403 detects that it no longer protects;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;document every exemption&lt;/strong&gt; : for each exempted site, note why. In six months, the question “why isn’t this site protected?” will have an answer;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;hub updates&lt;/strong&gt; bring new virtual patches: schedule &lt;code&gt;cscli hub update &amp;amp;&amp;amp; cscli hub upgrade&lt;/code&gt; daily, followed by a CrowdSec reload;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;OpenResty upgrades&lt;/strong&gt; : run &lt;code&gt;nginx -t&lt;/code&gt;, then a real restart, and check for the “Initialisation done” line in the log.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What a WAF doesn’t do
&lt;/h2&gt;

&lt;p&gt;A WAF blocks known, crude attacks. It doesn’t replace application updates, removing unused plugins, strong passwords or two-factor authentication. It buys time between a vulnerability’s publication and the patch being installed, and it clears most bot noise from the logs. That’s already a lot.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This post is part of a series of sysadmin tutorials (tag “how-to”).&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Series “How-to”, tutorial 14/77. · &lt;a href="https://hecate.neurozone.fr/?p=622" rel="noopener noreferrer"&gt;← Previous tutorial&lt;/a&gt; · Next tutorial → (coming 25 Nov) · &lt;a href="https://blog.neurozone.fr/?p=2068" rel="noopener noreferrer"&gt;Version française&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Related articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=598" rel="noopener noreferrer"&gt;Installing CrowdSec without banning yourself&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=102" rel="noopener noreferrer"&gt;CrowdSec 1.8 on Debian&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=599" rel="noopener noreferrer"&gt;Suricata as an IPS with NFQUEUE&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/23/how-to-a-blocking-waf-with-openresty-and-crowdsec-appsec/" rel="noopener noreferrer"&gt;How-to: a blocking WAF with OpenResty and CrowdSec AppSec&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>sysadminnotebook</category>
      <category>webservers</category>
      <category>crowdsec</category>
      <category>english</category>
    </item>
    <item>
      <title>VPN up, internal names dead: Android Private DNS, a profile with no DNS and the Pi-hole firewall</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Sun, 22 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/vpn-up-internal-names-dead-android-private-dns-a-profile-with-no-dns-and-the-pi-hole-firewall-2iml</link>
      <guid>https://dev.to/hecate-regnier/vpn-up-internal-names-dead-android-private-dns-a-profile-with-no-dns-and-the-pi-hole-firewall-2iml</guid>
      <description>&lt;p&gt;I was at a conference, phone in hand, and needed my Git forge, the one that runs at home and is only reachable from the local network. That’s exactly why I have a WireGuard tunnel on the phone: I switch it on, I’m “at home”, and I type &lt;code&gt;https://forge.example.net&lt;/code&gt;. That day, the browser told me the site couldn’t be found. Yet the tunnel was connected, the key icon right there at the top of the screen.&lt;/p&gt;

&lt;p&gt;The story is worth telling because there were three causes, each hidden behind the one before, and none was where I expected it. Two were on the phone: an Android setting I had forgotten, and a WireGuard profile with no DNS server. The third was a firewall, on my own server, doing exactly what I had asked it to do months earlier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/vpn_dns_two_walls_en.png" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8g8dsfh421scjttdugqy.png" alt="Three walls on the path of the phone's DNS query: Android Private DNS (AdGuard) leaving the tunnel, a WireGuard profile with no DNS leaving the carrier's DNS, then the Pi-hole firewall dropping queries from the tunnel; after the fixes, the internal name resolves and the forge opens" width="799" height="522"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Each wall hid the next: no query could reach the Pi-hole’s firewall while the phone was asking elsewhere.&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  A name that only exists at home
&lt;/h3&gt;

&lt;p&gt;First, what the phone is asking for. &lt;code&gt;forge.example.net&lt;/code&gt; has &lt;strong&gt;no record in public DNS&lt;/strong&gt;. That’s on purpose: the service is only reachable from inside, and publishing its name, even pointing to a private address, would tell anyone looking that it exists. The name only exists in the home Pi-hole, which serves DNS to the local network and answers &lt;code&gt;192.168.10.17&lt;/code&gt;, the address of the server hosting the forge.&lt;/p&gt;

&lt;p&gt;That’s split-horizon DNS in its simplest form: inside, the name has an answer; outside, it has none. It works perfectly as long as the question reaches the right server. The whole problem that day was right there: the question never reached the Pi-hole.&lt;/p&gt;
&lt;h3&gt;
  
  
  Separating the tunnel from DNS
&lt;/h3&gt;

&lt;p&gt;Faced with “site not found over the VPN”, there are two suspects, and they need separating before touching anything. Either the tunnel doesn’t carry traffic, and nothing reaches home. Or the tunnel works, but the name doesn’t resolve. The deciding test is simple: open a home IP address through the tunnel, with no name at all. If it answers, the tunnel is fine and everything happens in DNS.&lt;/p&gt;

&lt;p&gt;On the conference Wi-Fi, even the IP address didn’t answer. On mobile data, it came up immediately. Event Wi-Fi very often blocks outbound UDP to unusual ports, and WireGuard only speaks UDP; I couldn’t verify it on that particular network, but the behaviour fits. I already had a plan B for places like that, an SSH tunnel carried over HTTPS on port 443, but it only serves SSH, not browsing a forge. That left DNS, on mobile data.&lt;/p&gt;

&lt;p&gt;I didn’t want to trust my phone, so I looked for proof on the server side. The home web server’s log does show the phone’s requests, with its tunnel address:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# on the home server: did anything from the phone's tunnel address ever arrive?&lt;/span&gt;
grep -h &lt;span class="s1"&gt;'^10\.99\.0\.'&lt;/span&gt; /var/log/nginx/*.log &lt;span class="o"&gt;|&lt;/span&gt; tail

10.99.0.10 - - &lt;span class="o"&gt;[&lt;/span&gt;17/Nov/2026:12:42:56 +0100&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="s2"&gt;"GET / HTTP/1.1"&lt;/span&gt; 301 166 &lt;span class="s2"&gt;"-"&lt;/span&gt; &lt;span class="s2"&gt;"Mozilla/5.0 (Android 16; Mobile ...)"&lt;/span&gt;
10.99.0.10 - - &lt;span class="o"&gt;[&lt;/span&gt;17/Nov/2026:12:43:07 +0100&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="s2"&gt;"GET /api/v2/receivers HTTP/2.0"&lt;/span&gt; 200 37 &lt;span class="s2"&gt;"https://192.168.10.17/"&lt;/span&gt; ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the tunnel was cleared. And looking further back, no request from &lt;code&gt;10.99.0.x&lt;/code&gt; had ever reached the forge, or any other home site, before that IP test. The phone had never managed to find the forge’s address.&lt;/p&gt;

&lt;h3&gt;
  
  
  First wall: Android’s “Private DNS”
&lt;/h3&gt;

&lt;p&gt;Since version 9, Android has a “Private DNS” setting. It encrypts DNS queries with DNS-over-TLS to a chosen provider. I had set AdGuard there long ago, to filter ads everywhere, and forgotten about it. The setting has three positions. Off, the phone uses the DNS the network announces. Automatic, it first tries TLS to that announced DNS, and falls back to classic DNS if it can’t. With a provider hostname, it sends &lt;strong&gt;all&lt;/strong&gt; its queries to that provider, and only to it.&lt;/p&gt;

&lt;p&gt;That last mode is the problem: it takes priority over the DNS announced by the VPN. The WireGuard profile can name the home Pi-hole all it likes; Android ignores it and keeps asking AdGuard. And AdGuard, which only knows public DNS, honestly answers that &lt;code&gt;forge.example.net&lt;/code&gt; doesn’t exist. The browser doesn’t even try to connect.&lt;/p&gt;

&lt;p&gt;The proof, again, is on the server side. Pi-hole keeps every query in an SQLite database. Debian doesn’t ship the &lt;code&gt;sqlite3&lt;/code&gt; client on that machine, but FTL, Pi-hole’s DNS engine, embeds one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# on the Pi-hole (Debian ships no sqlite3: FTL embeds one)&lt;/span&gt;
pihole-FTL sqlite3 /etc/pihole/pihole-FTL.db \
  &lt;span class="s2"&gt;"SELECT client, COUNT(*) FROM queries
   WHERE client LIKE '10.99.0.%' AND timestamp &amp;gt; strftime('%s','now','-30 days')
   GROUP BY client;"&lt;/span&gt;
&lt;span class="c"&gt;# -&amp;gt; nothing at all&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In thirty days, not a single query from the phone’s tunnel. The only clients that had asked for the forge’s name were my PC and the home server itself. So I switched Private DNS off and tried again. The name still didn’t resolve, and the Pi-hole’s log stayed empty.&lt;/p&gt;

&lt;h3&gt;
  
  
  Second wall, on the server: the Pi-hole’s firewall
&lt;/h3&gt;

&lt;p&gt;An empty log reads two ways: either the question doesn’t leave for home, or it arrives and something stops it before the DNS server. A query that reaches FTL, even a refused one, leaves a trace in its log. Rather than guess on the phone side, I re-read the path on the server side, and that’s where I found a wall nobody had hit yet.&lt;/p&gt;

&lt;p&gt;Pi-hole filters its clients in two places, and both must agree. The first is FTL itself, with its &lt;code&gt;dns.listeningMode&lt;/code&gt; setting. By default, &lt;code&gt;LOCAL&lt;/code&gt;, it only answers machines on subnets directly attached to its interfaces, and ignores anything arriving routed, such as a VPN client. Mine was already on &lt;code&gt;ALL&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pihole-FTL --config dns.listeningMode
ALL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second is the machine’s firewall. The Pi-hole runs on Debian, protected by ufw, and port 53 is only open to a list of sources. That list held the local network and my servers’ tunnel, but not the phone’s:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ufw status | grep '^53/'
53/tcp ALLOW 192.168.10.0/24
53/udp ALLOW 192.168.10.0/24
53/tcp ALLOW 10.98.0.0/24
53/udp ALLOW 10.98.0.0/24
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So a packet from &lt;code&gt;10.99.0.10&lt;/code&gt; would have been dropped by the kernel before reaching FTL, and FTL would never have known. It’s the worst kind of network failure: no error, no log, just a timeout on the client side. The most annoying part is that I had fallen into exactly the same trap three months earlier, with the servers’ tunnel. I had even left a comment in the configuration warning that both filters must allow a source. The phone had simply never been added.&lt;/p&gt;

&lt;h3&gt;
  
  
  The fix, in Ansible and not by hand
&lt;/h3&gt;

&lt;p&gt;The list of allowed sources is a variable of the Pi-hole’s Ansible role, and the task that opens the firewall loops over it, for TCP and for UDP. Fixing it means adding one line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# roles/pihole/defaults/main.yml
&lt;/span&gt;&lt;span class="na"&gt;pihole_dns_allowed_sources&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"192.168.10.0/24"&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"10.98.0.0/24"&lt;/span&gt; &lt;span class="c1"&gt;# servers' tunnel
&lt;/span&gt;  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"10.99.0.0/24"&lt;/span&gt; &lt;span class="c1"&gt;# phone's tunnel &amp;lt;- the missing line
&lt;/span&gt;
&lt;span class="c1"&gt;# roles/pihole/tasks/firewall.yml
&lt;/span&gt;&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Allow DNS from the allowed sources&lt;/span&gt;
  &lt;span class="na"&gt;community.general.ufw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;rule&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;allow&lt;/span&gt;
    &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"53"&lt;/span&gt;
    &lt;span class="na"&gt;proto&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"{{ item.1 }}"&lt;/span&gt;
    &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"{{ item.0 }}"&lt;/span&gt;
  &lt;span class="na"&gt;loop&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"{{ pihole_dns_allowed_sources | product(['tcp', 'udp']) | list }}"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before applying, I always do a dry run limited to that part of the role. It must show that only the two new rules change, and that the others are already in place. A rule added by hand on the machine would have worked at once, but would have vanished or drifted at the next Ansible run; the configuration has to carry the fix, not the machine.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ansible-playbook -i hosts.ini playbooks/pihole.yml --tags pihole-firewall --check --diff
&lt;span class="c"&gt;# ok: 10.98.0.0/24/tcp, 10.98.0.0/24/udp&lt;/span&gt;
&lt;span class="c"&gt;# changed: 10.99.0.0/24/tcp, 10.99.0.0/24/udp &amp;lt;- only these two&lt;/span&gt;
ansible-playbook -i hosts.ini playbooks/pihole.yml --tags pihole-firewall
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There was a workaround without touching the server: give the phone the router as DNS instead of the Pi-hole. The router answers DNS on its tunnel address and forwards the question to the Pi-hole from its own local-network address, which the firewall accepts. That’s handy to get unstuck in five minutes from a conference room, but it only hides the problem.&lt;/p&gt;

&lt;p&gt;Another fix is tempting and I rejected it: publishing the forge’s name in public DNS, pointing to its private address. It would have worked even with AdGuard. But it announces the name of an internal service to the world, to work around a phone setting.&lt;/p&gt;

&lt;h3&gt;
  
  
  Third wall: the WireGuard profile had no DNS
&lt;/h3&gt;

&lt;p&gt;With the firewall fixed, the forge still didn’t open, and the new rule’s counter stayed at zero packets: nothing reached it. So the question still wasn’t leaving for home. Opening the phone’s WireGuard profile gave the answer: the interface’s DNS servers field was empty. Without it, the app pushes no DNS to Android, which keeps the network’s, here the mobile carrier’s. Which, like AdGuard, doesn’t know my internal name.&lt;/p&gt;

&lt;p&gt;It’s the simplest of the three traps, and the one AdGuard hid best: as long as Private DNS sent everything elsewhere, that field made no difference. The tunnel then has to be turned off and on, because the DNS is only applied when it connects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Checking
&lt;/h3&gt;

&lt;p&gt;With &lt;code&gt;192.168.10.19&lt;/code&gt; in the profile and the tunnel restarted, the forge opened on the phone. Both logs confirm it, twelve seconds apart: the Pi-hole answered the question coming from the tunnel, then the forge served the dashboard to the same address.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Pi-hole, 12:56:19: the phone's query, answered from the home DNS
query[A] forge.example.net from 10.99.0.10
config forge.example.net is &amp;lt;CNAME&amp;gt;
/etc/pihole/hosts/custom.list homeserver.example.lan is 192.168.10.17
# the ufw rule added at 12:50, counter on the UDP line
counter packets 79 ... accept

# the home server, 12:56:31: the forge serves the phone's dashboard
10.99.0.10 - - [17/Nov/2026:12:56:31 +0100] "GET /repo/search?sort=updated&amp;amp;order=desc&amp;amp;uid=1 ... HTTP/2.0" 200 ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The counter on the ufw rule added at 12:50 had already let 79 packets through. Without that fix, those queries would have been dropped silently, and removing the third wall would have changed nothing: all three fixes were needed, and none was enough on its own. I then ran the counter-test: Private DNS switched back to AdGuard, the Pi-hole still set as DNS in the WireGuard profile. The forge became unreachable again. Android’s setting really does win over the VPN’s DNS, even when the profile names one.&lt;/p&gt;

&lt;h3&gt;
  
  
  What I take away
&lt;/h3&gt;

&lt;p&gt;When something doesn’t work “over the VPN”, the first question isn’t “is the VPN connected?”, but “what actually goes through it?”. Opening an IP address through the tunnel separates transport from DNS in ten seconds, and the server’s logs tell the truth when the phone says nothing.&lt;/p&gt;

&lt;p&gt;An encrypted DNS resolver set on the phone wins over the VPN’s DNS: with a provider hostname in “Private DNS”, internal names will never work through the tunnel. And a VPN profile with no DNS server leaves the phone on the carrier’s DNS. And on the server, the absence of any trace in Pi-hole’s log is a clue in itself: it means the packet never arrived, so a firewall stopped it first. Every new VPN subnet must be added to the list of allowed DNS sources, in both filters. This time I wrote the procedure down, so as not to fall into the same hole a third time.&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/22/vpn-up-internal-names-dead-android-private-dns-a-profile-with-no-dns-and-the-pi-hole-firewall/" rel="noopener noreferrer"&gt;VPN up, internal names dead: Android Private DNS, a profile with no DNS and the Pi-hole firewall&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>networking</category>
      <category>sysadminnotebook</category>
      <category>android</category>
      <category>dns</category>
    </item>
    <item>
      <title>Systemd capabilities: from root to one single privilege, with a tested lab</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Sat, 21 Nov 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/systemd-capabilities-from-root-to-one-single-privilege-with-a-tested-lab-1k04</link>
      <guid>https://dev.to/hecate-regnier/systemd-capabilities-from-root-to-one-single-privilege-with-a-tested-lab-1k04</guid>
      <description>&lt;p&gt;Systemd capabilities decide which privileges a service really keeps. Most services start as root, so they hold far more power than they need. This third part of the series “Systemd hardening, directive by directive” shows how to cut that power down, one directive at a time, with a lab you can rebuild in half an hour.&lt;/p&gt;

&lt;p&gt;Every output below comes from a real run on a test machine, so you can compare it with your own results. When a result differs from what the manual leads you to expect, the text says so. The article covers &lt;code&gt;User=&lt;/code&gt;, &lt;code&gt;Group=&lt;/code&gt;, &lt;code&gt;SupplementaryGroups=&lt;/code&gt;, &lt;code&gt;DynamicUser=&lt;/code&gt;, &lt;code&gt;NoNewPrivileges=&lt;/code&gt;, &lt;code&gt;CapabilityBoundingSet=&lt;/code&gt;, &lt;code&gt;AmbientCapabilities=&lt;/code&gt;, &lt;code&gt;SecureBits=&lt;/code&gt; and &lt;code&gt;RestrictSUIDSGID=&lt;/code&gt;. The directive &lt;code&gt;PAMName=&lt;/code&gt; belongs to the same family, but it was not tested, so it only gets a short note.&lt;/p&gt;

&lt;h2&gt;
  
  
  Before you start
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Level:&lt;/strong&gt; you can write a unit file and read a journal. You do not need to know systemd capabilities yet.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Machine:&lt;/strong&gt; a test machine or a virtual machine that runs systemd. Never run this lab on a production server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rights:&lt;/strong&gt; root access through &lt;code&gt;sudo&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tools:&lt;/strong&gt; &lt;code&gt;systemctl&lt;/code&gt;, &lt;code&gt;journalctl&lt;/code&gt;, &lt;code&gt;systemd-analyze&lt;/code&gt;, &lt;code&gt;python3&lt;/code&gt; and the libcap tools (&lt;code&gt;capsh&lt;/code&gt;, &lt;code&gt;getpcaps&lt;/code&gt;, &lt;code&gt;getcap&lt;/code&gt;, &lt;code&gt;setcap&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Time:&lt;/strong&gt; about 30 minutes for the whole lab, and about 5 minutes if you only read.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Part 1 of the series&lt;/strong&gt; explains how to measure a unit with &lt;code&gt;systemd-analyze security&lt;/code&gt;. Here, that score is only a thermometer.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Tested on Rocky Linux 10.2, systemd 257, WSL2 kernel 6.18.54.1-microsoft-standard-WSL2. SELinux is not available on that bench (the selinuxfs file system is absent), so no result below involves SELinux. On a native kernel with SELinux enforcing, some results can differ.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The words you need
&lt;/h2&gt;

&lt;p&gt;Systemd capabilities have their own vocabulary, so a short glossary comes first. Read this table once. Then come back to it when a term feels unclear.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Term&lt;/th&gt;
&lt;th&gt;Plain meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;UID 0 / root&lt;/td&gt;
&lt;td&gt;The administrator account. Historically, the kernel gives it every privilege.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Capability&lt;/td&gt;
&lt;td&gt;One slice of root’s power. For example &lt;code&gt;CAP_NET_BIND_SERVICE&lt;/code&gt; allows ports below 1024, and &lt;code&gt;CAP_CHOWN&lt;/code&gt; allows changing a file owner. The full list is in the &lt;code&gt;capabilities(7)&lt;/code&gt; manual page.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Bounding set&lt;/td&gt;
&lt;td&gt;The ceiling. A capability outside this set cannot be used by the process or by anything it starts.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ambient set&lt;/td&gt;
&lt;td&gt;Capabilities that a non-root process keeps when it runs another program. It is the way to give an unprivileged service one privilege.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Set-user-ID file&lt;/td&gt;
&lt;td&gt;A program that runs with the identity of its owner, usually root (&lt;code&gt;sudo&lt;/code&gt; and &lt;code&gt;passwd&lt;/code&gt; are examples).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;File capability&lt;/td&gt;
&lt;td&gt;A capability stored on the program file itself, with &lt;code&gt;setcap&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;no_new_privs&lt;/td&gt;
&lt;td&gt;A kernel flag. Once set, &lt;code&gt;execve()&lt;/code&gt; can never give the process more privileges. &lt;code&gt;NoNewPrivileges=&lt;/code&gt; sets it.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Drop-in&lt;/td&gt;
&lt;td&gt;A small file named &lt;code&gt;unit.service.d/something.conf&lt;/code&gt; that overrides part of a unit. It survives package updates.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exposure level&lt;/td&gt;
&lt;td&gt;The score of &lt;code&gt;systemd-analyze security&lt;/code&gt;, from 0 to 10. A higher number means a more exposed service.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  How systemd capabilities fit together: who limits, who grants, who blocks
&lt;/h2&gt;

&lt;p&gt;Nine directives look like a lot, but they play only four roles, and the picture below shows them side by side.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-capabilities-user-nonewprivileges-ambient-lab-1.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm95tvu97zlgm931c55dv.webp" alt="Systemd capabilities map: identity, limit, grant and block directives and what each one controls" width="799" height="409"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Who limits, who grants, who blocks.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Identity:&lt;/strong&gt; &lt;code&gt;User=&lt;/code&gt;, &lt;code&gt;Group=&lt;/code&gt;, &lt;code&gt;SupplementaryGroups=&lt;/code&gt; and &lt;code&gt;DynamicUser=&lt;/code&gt; choose who the service is.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Limit:&lt;/strong&gt; &lt;code&gt;CapabilityBoundingSet=&lt;/code&gt; sets the ceiling of what the service can ever hold.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Grant:&lt;/strong&gt; &lt;code&gt;AmbientCapabilities=&lt;/code&gt; gives a non-root service the few capabilities it needs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block:&lt;/strong&gt; &lt;code&gt;NoNewPrivileges=&lt;/code&gt; and &lt;code&gt;RestrictSUIDSGID=&lt;/code&gt; stop the service from climbing back up. &lt;code&gt;SecureBits=&lt;/code&gt; fine-tunes how root and capabilities interact.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the recipe is short: first pick an identity, then grant only what is needed, set the ceiling, and finally close the doors that lead back to root. The sections below test each step in that order.&lt;/p&gt;
&lt;h2&gt;
  
  
  Build the lab
&lt;/h2&gt;

&lt;p&gt;The lab uses one harmless probe script that runs under different settings. The probe does four things. First, it tries to bind port 80 on the loopback address. Second, it tries to hand a file to another owner. Third, it tries to set the set-user-ID bit on its own file. Finally, it runs a root-owned set-user-ID helper. It also prints the capability masks of its own process. Nothing leaves the machine, because the probe only touches a private temporary directory.&lt;/p&gt;

&lt;p&gt;Every name starts with &lt;code&gt;demo-hardening-sd3-&lt;/code&gt;, and the account is called &lt;code&gt;sd3demo&lt;/code&gt;. As a result, the cleanup at the end of the article removes exactly what the lab created. Save the script below as &lt;code&gt;lab-setup.sh&lt;/code&gt; and run it as root.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# Creates the harmless demo files and units of the lab (all named demo-hardening-*).&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -e

&lt;span class="c"&gt;# A dedicated system account for the demo (removed by the cleanup script).&lt;/span&gt;
id sd3demo &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1 &lt;span class="o"&gt;||&lt;/span&gt; useradd --system --no-create-home --shell /usr/sbin/nologin sd3demo

cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /usr/local/bin/demo-hardening-sd3-probe.sh &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# Harmless probe: binds only to loopback, touches only a private temporary directory.&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"identity: uid=$(id -u) user=$(id -un) groups=$(id -G)"&lt;/span&gt;
grep -E &lt;span class="s1"&gt;'^(NoNewPrivs|CapInh|CapPrm|CapEff|CapBnd|CapAmb):'&lt;/span&gt; /proc/self/status
&lt;span class="nv"&gt;d&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;mktemp -d&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; python3 -c &lt;span class="s1"&gt;'import socket; s=socket.socket(); s.bind(("127.0.0.1", 80)); s.close()'&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"probe bind-80: allowed"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"probe bind-80: refused"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"$(id -u)"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 0&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="nv"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;nobody&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="nv"&gt;target&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;root&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;fi&lt;/span&gt;
touch &lt;span class="s2"&gt;"$d/owned"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; chown &lt;span class="s2"&gt;"$target"&lt;/span&gt; &lt;span class="s2"&gt;"$d/owned"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"probe chown-to-$target: allowed"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"probe chown-to-$target: refused"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
touch &lt;span class="s2"&gt;"$d/suid"&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; chmod u+s &lt;span class="s2"&gt;"$d/suid"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"probe chmod-u+s: allowed"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"probe chmod-u+s: refused"&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"probe setuid-helper effective uid: $(/usr/local/bin/demo-hardening-sd3-setuid-id -u)"&lt;/span&gt;
rm -rf &lt;span class="s2"&gt;"$d"&lt;/span&gt;
EOF
chmod 755 /usr/local/bin/demo-hardening-sd3-probe.sh

&lt;span class="c"&gt;# A copy of id(1) owned by root with the set-user-ID bit: it only prints IDs.&lt;/span&gt;
cp /usr/bin/id /usr/local/bin/demo-hardening-sd3-setuid-id
chown root:root /usr/local/bin/demo-hardening-sd3-setuid-id
chmod u+s,a+rx /usr/local/bin/demo-hardening-sd3-setuid-id

cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/systemd/system/demo-hardening-sd3-caps.service &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Unit&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Demo hardening: what may an unprivileged service do?

&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;oneshot
&lt;span class="nv"&gt;User&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sd3demo
&lt;span class="nv"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/local/bin/demo-hardening-sd3-probe.sh
&lt;span class="nv"&gt;StandardOutput&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;journal
EOF

cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/systemd/system/demo-hardening-sd3-root.service &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Unit&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Demo hardening: what may a root service do?

&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;oneshot
&lt;span class="nv"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/local/bin/demo-hardening-sd3-probe.sh
&lt;span class="nv"&gt;StandardOutput&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;journal
EOF

cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /etc/systemd/system/demo-hardening-sd3-dynamic.service &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Unit&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;Description&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Demo hardening: dynamic user

&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;oneshot
&lt;span class="nv"&gt;DynamicUser&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yes
&lt;span class="nv"&gt;StateDirectory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;demo-hardening-sd3-dynamic
&lt;span class="nv"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/bin/id -u
&lt;span class="nv"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/bin/id -un
&lt;span class="nv"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/bin/touch /var/lib/demo-hardening-sd3-dynamic/created-by-the-service
&lt;span class="nv"&gt;StandardOutput&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;journal
EOF

&lt;span class="c"&gt;# Helper used by the following scripts: restart a unit, then print its own journal lines.&lt;/span&gt;
cat &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /usr/local/bin/demo-hardening-sd3-run &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c"&gt;# Restart a unit, then print only the lines this run wrote to the journal.&lt;/span&gt;
&lt;span class="nv"&gt;unit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"$1"&lt;/span&gt;
&lt;span class="nv"&gt;since&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;date &lt;span class="s1"&gt;'+%Y-%m-%d %H:%M:%S'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
systemctl daemon-reload
systemctl restart &lt;span class="s2"&gt;"$unit"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1 &lt;span class="o"&gt;|&lt;/span&gt; sed &lt;span class="s1"&gt;'s/^/restart: /'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
sleep 1
journalctl -u &lt;span class="s2"&gt;"$unit"&lt;/span&gt; -o cat --no-pager --since &lt;span class="s2"&gt;"$since"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; grep -vE &lt;span class="s1"&gt;'^(Starting |Finished |.*: Deactivated successfully)'&lt;/span&gt;
EOF
chmod 755 /usr/local/bin/demo-hardening-sd3-run

systemctl daemon-reload

sudo bash lab-setup.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The helper &lt;code&gt;demo-hardening-sd3-run&lt;/code&gt; reloads systemd, restarts one unit, and prints only the journal lines of that run. Because the units are one-shot, the probe output lands in the journal, and the helper shows it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Baseline: a dedicated user and a root service, with no hardening
&lt;/h3&gt;

&lt;p&gt;First, run the probe twice with no hardening at all. One unit uses the dedicated account. The other one uses the default identity, which is root.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-caps.service
sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-root.service

identity: uid=990 user=sd3demo groups=990
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 000001ffffffffff
CapAmb: 0000000000000000
NoNewPrivs: 0
probe bind-80: refused
probe chown-to-root: refused
probe chmod-u+s: allowed
probe setuid-helper effective uid: 0

identity: uid=0 user=root groups=0
CapInh: 0000000000000000
CapPrm: 000001ffffffffff
CapEff: 000001ffffffffff
CapBnd: 000001ffffffffff
CapAmb: 0000000000000000
NoNewPrivs: 0
probe bind-80: allowed
probe chown-to-nobody: allowed
probe chmod-u+s: allowed
probe setuid-helper effective uid: 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read the output from top to bottom. First, &lt;code&gt;CapBnd&lt;/code&gt; is the bounding set. The value &lt;code&gt;000001ffffffffff&lt;/code&gt; has 41 bits set, so the service may use any of the 41 capabilities of this kernel. Then &lt;code&gt;CapEff&lt;/code&gt; is what the process can use right now. For root it equals the full set, while for the dedicated user it is empty.&lt;/p&gt;

&lt;p&gt;The probes confirm it: the root service passes all four tests, while the dedicated user cannot bind port 80 and cannot give a file to root. However, look at the last two lines for that user. Setting the set-user-ID bit on its own file is allowed, because that is normal for a file owner. Worse, the root-owned helper reports an effective UID of 0. So a set-user-ID program hands root back to a service that was meant to be unprivileged. The systemd capabilities directives below exist to close that hole.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose the identity: User=, Group= and SupplementaryGroups=
&lt;/h2&gt;

&lt;p&gt;The first hardening step costs nothing: do not run as root. &lt;code&gt;User=&lt;/code&gt; names the account. &lt;code&gt;Group=&lt;/code&gt; replaces its primary group. &lt;code&gt;SupplementaryGroups=&lt;/code&gt; adds groups, for example to read a log directory. Then the next test starts from the dedicated account and changes the groups.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;d&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/etc/systemd/system/demo-hardening-sd3-caps.service.d
sudo mkdir -p &lt;span class="nv"&gt;$d&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'[Service]\nSupplementaryGroups=adm\n'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sudo tee &lt;span class="nv"&gt;$d&lt;/span&gt;/10-groups.conf
sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-caps.service &lt;span class="o"&gt;|&lt;/span&gt; head -1
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'[Service]\nGroup=adm\n'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sudo tee &lt;span class="nv"&gt;$d&lt;/span&gt;/10-groups.conf
sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-caps.service &lt;span class="o"&gt;|&lt;/span&gt; head -1
sudo rm -rf &lt;span class="nv"&gt;$d&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; sudo systemctl daemon-reload

identity: &lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990 &lt;span class="nv"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sd3demo &lt;span class="nv"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990
identity: &lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990 &lt;span class="nv"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sd3demo &lt;span class="nv"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990 4
identity: &lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990 &lt;span class="nv"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sd3demo &lt;span class="nv"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These three lines come from three runs of the same unit. The first line is the baseline of the previous section, with no group directive. The second line comes from the first run above: &lt;code&gt;SupplementaryGroups=adm&lt;/code&gt; added group 4 to the list. The third line comes from the second run above, where &lt;code&gt;Group=adm&lt;/code&gt; replaced the primary group, so group 990 disappeared. The last command removes the drop-in, so the next tests start clean. The rule is simple: use &lt;code&gt;SupplementaryGroups=&lt;/code&gt; to add access, and use &lt;code&gt;Group=&lt;/code&gt; only when the service must own its files with another group.&lt;/p&gt;

&lt;p&gt;Next, see what happens if the account does not exist. Because the user was never created, the unit below must fail.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight systemd"&gt;&lt;code&gt;&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;oneshot&lt;/span&gt;
&lt;span class="na"&gt;User&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;nosuchuser&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save it as &lt;code&gt;/etc/systemd/system/demo-hardening-sd3-baduser.service&lt;/code&gt;, then run &lt;code&gt;sudo systemctl daemon-reload&lt;/code&gt;, &lt;code&gt;sudo systemctl start demo-hardening-sd3-baduser.service&lt;/code&gt; and &lt;code&gt;journalctl -u demo-hardening-sd3-baduser.service -o cat --no-pager -n 6&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[...]
Result=exit-code
ExecMainStatus=217
Starting demo-hardening-sd3-baduser.service...
demo-hardening-sd3-baduser.service: Failed to determine user credentials: No such process
demo-hardening-sd3-baduser.service: Failed at step USER spawning /usr/bin/true: No such process
demo-hardening-sd3-baduser.service: Main process exited, code=exited, status=217/USER
demo-hardening-sd3-baduser.service: Failed with result 'exit-code'.
Failed to start demo-hardening-sd3-baduser.service.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exit status is 217, and systemd names the step &lt;code&gt;USER&lt;/code&gt;. Yet the message says &lt;code&gt;No such process&lt;/code&gt;, which does not mention a missing account. So when you see &lt;code&gt;status=217/USER&lt;/code&gt;, check that the account exists with &lt;code&gt;getent passwd NAME&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  DynamicUser=: an account that exists only while the service runs
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;DynamicUser=yes&lt;/code&gt; (since systemd 232) goes one step further. Systemd creates a throw-away account when the unit starts, and then releases it when the unit stops. The numeric ID comes from a reserved range, 61184 to 65519. The setting also switches on several protections, so it is a strong choice for small services. The unit below combines it with &lt;code&gt;StateDirectory=&lt;/code&gt;, which gives the service one writable place.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight systemd"&gt;&lt;code&gt;&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;oneshot&lt;/span&gt;
&lt;span class="na"&gt;DynamicUser&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;yes&lt;/span&gt;
&lt;span class="na"&gt;StateDirectory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dynamic&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;un&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;touch&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dynamic&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;created&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;by&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;
&lt;span class="na"&gt;StandardOutput&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;journal&lt;/span&gt;

&lt;span class="mi"&gt;62604&lt;/span&gt;
&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dynamic&lt;/span&gt;
&lt;span class="o"&gt;---&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="n"&gt;directory&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="n"&gt;from&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;
&lt;span class="n"&gt;lrwxrwxrwx&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="mi"&gt;34&lt;/span&gt; &lt;span class="nc"&gt;Nov&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;57&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dynamic&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;private&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dynamic&lt;/span&gt;
&lt;span class="n"&gt;drwxr&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;xr&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="n"&gt;nobody&lt;/span&gt; &lt;span class="n"&gt;nobody&lt;/span&gt; &lt;span class="mi"&gt;4096&lt;/span&gt; &lt;span class="nc"&gt;Nov&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;57&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;private&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;dynamic&lt;/span&gt;
&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;rw&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="mi"&gt;65534&lt;/span&gt; &lt;span class="mi"&gt;65534&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="nc"&gt;Nov&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;57&lt;/span&gt; &lt;span class="n"&gt;created&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;by&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;the&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;
&lt;span class="o"&gt;---&lt;/span&gt; &lt;span class="n"&gt;is&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;dynamic&lt;/span&gt; &lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;in&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;passwd&lt;/span&gt; &lt;span class="n"&gt;after&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="o"&gt;---&lt;/span&gt; &lt;span class="n"&gt;implied&lt;/span&gt; &lt;span class="n"&gt;settings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;as&lt;/span&gt; &lt;span class="n"&gt;systemd&lt;/span&gt; &lt;span class="n"&gt;reports&lt;/span&gt; &lt;span class="n"&gt;them&lt;/span&gt;
&lt;span class="na"&gt;DynamicUser&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;yes&lt;/span&gt;
&lt;span class="na"&gt;RemoveIPC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;yes&lt;/span&gt;
&lt;span class="na"&gt;PrivateTmp&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;yes&lt;/span&gt;
&lt;span class="na"&gt;ProtectHome&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;only&lt;/span&gt;
&lt;span class="na"&gt;ProtectSystem&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;strict&lt;/span&gt;
&lt;span class="na"&gt;NoNewPrivileges&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;yes&lt;/span&gt;
&lt;span class="na"&gt;RestrictSUIDSGID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;yes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The service ran as UID 62604, which sits inside the documented range. Also, the account is named after the unit, and the count of &lt;code&gt;/etc/passwd&lt;/code&gt; lines is 0: the account never exists in the password file. The state directory lives under &lt;code&gt;/var/lib/private&lt;/code&gt;, and &lt;code&gt;/var/lib/demo-hardening-sd3-dynamic&lt;/code&gt; is a symbolic link to it.&lt;/p&gt;

&lt;p&gt;The last block shows what &lt;code&gt;DynamicUser=yes&lt;/code&gt; switches on: &lt;code&gt;RemoveIPC&lt;/code&gt;, &lt;code&gt;PrivateTmp&lt;/code&gt;, &lt;code&gt;ProtectHome=read-only&lt;/code&gt;, &lt;code&gt;ProtectSystem=strict&lt;/code&gt;, &lt;code&gt;NoNewPrivileges&lt;/code&gt; and &lt;code&gt;RestrictSUIDSGID&lt;/code&gt;. One detail surprised me: from the host, the files appear to belong to &lt;code&gt;nobody&lt;/code&gt; (UID 65534), although the service ran as 62604. This bench does not explain why, and the article does not guess.&lt;/p&gt;

&lt;h2&gt;
  
  
  AmbientCapabilities=: give one privilege to a non-root service
&lt;/h2&gt;

&lt;p&gt;An unprivileged service sometimes needs exactly one privilege, and the classic case is a web server on port 80. &lt;code&gt;AmbientCapabilities=&lt;/code&gt; (since systemd 229) grants it. The first test grants &lt;code&gt;CAP_NET_BIND_SERVICE&lt;/code&gt; to the dedicated account.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo mkdir -p /etc/systemd/system/demo-hardening-sd3-caps.service.d
sudo tee /etc/systemd/system/demo-hardening-sd3-caps.service.d/10-ambient.conf &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;AmbientCapabilities&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;CAP_NET_BIND_SERVICE
EOF
sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-caps.service

identity: &lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990 &lt;span class="nv"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sd3demo &lt;span class="nv"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990
CapInh: 0000000000000400
CapPrm: 0000000000000400
CapEff: 0000000000000400
CapBnd: 000001ffffffffff
CapAmb: 0000000000000400
NoNewPrivs: 0
probe bind-80: allowed
probe chown-to-root: refused
probe chmod-u+s: allowed
probe setuid-helper effective uid: 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result matches the goal: port 80 is now allowed, while chown to root is still refused. The ambient capability shows up in four masks at once: &lt;code&gt;CapInh&lt;/code&gt;, &lt;code&gt;CapPrm&lt;/code&gt;, &lt;code&gt;CapEff&lt;/code&gt; and &lt;code&gt;CapAmb&lt;/code&gt; all read &lt;code&gt;0000000000000400&lt;/code&gt;. That value is bit 10, which is &lt;code&gt;CAP_NET_BIND_SERVICE&lt;/code&gt;. But the last line did not change: the set-user-ID helper still returns 0. Granting one capability does not remove the way back to root.&lt;/p&gt;

&lt;p&gt;Next, add a second capability by overwriting the same file. Because the list is separated by spaces, the new value is easy to read.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo mkdir -p /etc/systemd/system/demo-hardening-sd3-caps.service.d
sudo tee /etc/systemd/system/demo-hardening-sd3-caps.service.d/10-ambient.conf &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;AmbientCapabilities&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;CAP_NET_BIND_SERVICE CAP_CHOWN
EOF
sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-caps.service

&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
CapAmb: 0000000000000401
&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
probe bind-80: allowed
probe chown-to-root: allowed
&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The mask becomes &lt;code&gt;0000000000000401&lt;/code&gt;. Bit 0 is &lt;code&gt;CAP_CHOWN&lt;/code&gt;, and the chown probe now succeeds. Therefore the mask is a direct image of your list, and you can decode it at any time (see the inspection section).&lt;/p&gt;

&lt;h2&gt;
  
  
  NoNewPrivileges=: close the way back to root
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;NoNewPrivileges=yes&lt;/code&gt; (since systemd 187) sets the kernel flag no_new_privs on the service process. From then on, the service and everything it starts can never gain privileges through &lt;code&gt;execve()&lt;/code&gt;. Set-user-ID bits and file capabilities stop working. The manual adds that the flag only covers the unit’s own processes and their children, not programs started on its behalf by &lt;code&gt;at&lt;/code&gt;, &lt;code&gt;crontab&lt;/code&gt; or &lt;code&gt;systemd-run&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-capabilities-user-nonewprivileges-ambient-lab-2.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcoqui6aroef99qvwdh4f.webp" alt="Systemd capabilities with NoNewPrivileges=yes: a set-user-ID program no longer raises the effective UID" width="800" height="326"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;NoNewPrivileges=yes blocks the gain through a set-user-ID program.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo mkdir -p /etc/systemd/system/demo-hardening-sd3-caps.service.d
sudo tee /etc/systemd/system/demo-hardening-sd3-caps.service.d/20-nnp.conf &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;NoNewPrivileges&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yes
EOF
sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-caps.service

identity: &lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990 &lt;span class="nv"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sd3demo &lt;span class="nv"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990
CapInh: 0000000000000401
CapPrm: 0000000000000401
CapEff: 0000000000000401
CapBnd: 000001ffffffffff
CapAmb: 0000000000000401
NoNewPrivs: 1
probe bind-80: allowed
probe chown-to-root: allowed
probe chmod-u+s: allowed
probe setuid-helper effective uid: 990
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things changed. First, &lt;code&gt;NoNewPrivs&lt;/code&gt; now reads 1. Second, the helper reports an effective UID of 990 instead of 0, so the set-user-ID bit no longer works for this service. Meanwhile the ambient capabilities stay: bind and chown are still allowed. So the two directives work as a pair. &lt;code&gt;AmbientCapabilities=&lt;/code&gt; grants the privilege, and &lt;code&gt;NoNewPrivileges=&lt;/code&gt; keeps the grant from growing.&lt;/p&gt;

&lt;p&gt;Note the cost, because a service that needs &lt;code&gt;sudo&lt;/code&gt; or another set-user-ID helper stops working. In my earlier article on systemd hardening on real services (coming 17 Sep), the failsec case shows it: an empty bounding set blocked &lt;code&gt;sudo&lt;/code&gt; even with &lt;code&gt;NoNewPrivileges=false&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  RestrictSUIDSGID=: forbid creating set-user-ID files
&lt;/h2&gt;

&lt;p&gt;The helper is no longer dangerous, but the service can still create new set-user-ID files. A later process outside the unit could then use them. &lt;code&gt;RestrictSUIDSGID=yes&lt;/code&gt; (since systemd 242) uses seccomp to refuse that. The default is off, so the directive is opt-in.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo mkdir -p /etc/systemd/system/demo-hardening-sd3-caps.service.d
sudo tee /etc/systemd/system/demo-hardening-sd3-caps.service.d/30-suid.conf &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;RestrictSUIDSGID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yes
EOF
sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-caps.service

identity: &lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990 &lt;span class="nv"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sd3demo &lt;span class="nv"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;990
CapInh: 0000000000200501
CapPrm: 0000000000000401
CapEff: 0000000000000401
CapBnd: 000001ffffffffff
CapAmb: 0000000000000401
NoNewPrivs: 1
probe bind-80: allowed
probe chown-to-root: allowed
probe chmod-u+s: refused
probe setuid-helper effective uid: 990
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The probe &lt;code&gt;chmod-u+s&lt;/code&gt; is now refused. Before this step it was allowed, even with the other directives in place, because a file owner can always set the bit on a file. Therefore only &lt;code&gt;RestrictSUIDSGID=&lt;/code&gt; blocks it.&lt;/p&gt;

&lt;p&gt;One line deserves attention, since &lt;code&gt;CapInh&lt;/code&gt; changed from &lt;code&gt;0000000000000401&lt;/code&gt; to &lt;code&gt;0000000000200501&lt;/code&gt;. Decoding the new value with &lt;code&gt;capsh --decode&lt;/code&gt; gives &lt;code&gt;cap_chown,cap_setpcap,cap_net_bind_service,cap_sys_admin&lt;/code&gt;, so two extra bits appeared: &lt;code&gt;cap_setpcap&lt;/code&gt; and &lt;code&gt;cap_sys_admin&lt;/code&gt;. The permitted, effective and ambient masks did not change. The documentation read for this article does not explain it. The article reports the observation and does not guess a cause.&lt;/p&gt;

&lt;h2&gt;
  
  
  CapabilityBoundingSet=: the ceiling for the whole service
&lt;/h2&gt;

&lt;p&gt;The bounding set limits what a process can ever hold. Because a service that stays root has every capability by default, this directive matters most for root services among all the systemd capabilities settings. So the next tests use the root unit. First, a plain list names the capabilities that stay. Second, a list that starts with &lt;code&gt;~&lt;/code&gt; names the capabilities to remove. Finally, an empty assignment removes everything.&lt;/p&gt;

&lt;p&gt;Each test writes the shown content into &lt;code&gt;10-bounding.conf&lt;/code&gt; in the drop-in directory of the root unit, replaces the previous content, and runs the unit again. The first test spells out the commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;d&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/etc/systemd/system/demo-hardening-sd3-root.service.d
sudo mkdir -p &lt;span class="nv"&gt;$d&lt;/span&gt;
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'[Service]\nCapabilityBoundingSet=\n'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sudo tee &lt;span class="nv"&gt;$d&lt;/span&gt;/10-bounding.conf
sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-root.service

identity: &lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0 &lt;span class="nv"&gt;user&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;root &lt;span class="nv"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000000000000000
CapAmb: 0000000000000000
NoNewPrivs: 0
probe bind-80: refused
probe chown-to-nobody: refused
probe chmod-u+s: allowed
probe setuid-helper effective uid: 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With an empty set, the service runs as UID 0 but holds nothing. Bind and chown are both refused. The manual describes this behaviour for the empty assignment, and the output confirms it: all five masks that matter read zero. A bare &lt;code&gt;~&lt;/code&gt; with no capability name means the full set, according to the manual, but that form was not tested here.&lt;/p&gt;

&lt;p&gt;Now keep only the capability the service needs, then try the inverted form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight systemd"&gt;&lt;code&gt;&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;CapabilityBoundingSet&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;CAP_NET_BIND_SERVICE&lt;/span&gt;

&lt;span class="k"&gt;[...]&lt;/span&gt;
&lt;span class="nc"&gt;CapPrm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0000000000000400&lt;/span&gt;
&lt;span class="nc"&gt;CapEff&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0000000000000400&lt;/span&gt;
&lt;span class="nc"&gt;CapBnd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0000000000000400&lt;/span&gt;
&lt;span class="k"&gt;[...]&lt;/span&gt;
&lt;span class="n"&gt;probe&lt;/span&gt; &lt;span class="n"&gt;bind&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt;
&lt;span class="n"&gt;probe&lt;/span&gt; &lt;span class="n"&gt;chown&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;nobody&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;refused&lt;/span&gt;
&lt;span class="k"&gt;[...]&lt;/span&gt;

&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;CapabilityBoundingSet&lt;/span&gt;&lt;span class="o"&gt;=~&lt;/span&gt;&lt;span class="no"&gt;CAP_CHOWN&lt;/span&gt;

&lt;span class="k"&gt;[...]&lt;/span&gt;
&lt;span class="nc"&gt;CapPrm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;000001fffffffffe&lt;/span&gt;
&lt;span class="nc"&gt;CapEff&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;000001fffffffffe&lt;/span&gt;
&lt;span class="nc"&gt;CapBnd&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;000001fffffffffe&lt;/span&gt;
&lt;span class="k"&gt;[...]&lt;/span&gt;
&lt;span class="n"&gt;probe&lt;/span&gt; &lt;span class="n"&gt;bind&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt;
&lt;span class="n"&gt;probe&lt;/span&gt; &lt;span class="n"&gt;chown&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;nobody&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;refused&lt;/span&gt;
&lt;span class="k"&gt;[...]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Setting&lt;/th&gt;
&lt;th&gt;CapBnd&lt;/th&gt;
&lt;th&gt;Bind port 80&lt;/th&gt;
&lt;th&gt;Chown&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;(nothing)&lt;/td&gt;
&lt;td&gt;000001ffffffffff&lt;/td&gt;
&lt;td&gt;allowed&lt;/td&gt;
&lt;td&gt;allowed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CapabilityBoundingSet=&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0000000000000000&lt;/td&gt;
&lt;td&gt;refused&lt;/td&gt;
&lt;td&gt;refused&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CapabilityBoundingSet=CAP_NET_BIND_SERVICE&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;0000000000000400&lt;/td&gt;
&lt;td&gt;allowed&lt;/td&gt;
&lt;td&gt;refused&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;CapabilityBoundingSet=~CAP_CHOWN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;000001fffffffffe&lt;/td&gt;
&lt;td&gt;allowed&lt;/td&gt;
&lt;td&gt;refused&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The allow-list form (&lt;code&gt;CAP_NET_BIND_SERVICE&lt;/code&gt;) is the safest, because a future kernel can add capabilities, and an allow-list ignores them. The inverted form is shorter to read when you only want to remove a few. The tool &lt;code&gt;systemd-analyze security&lt;/code&gt; prints its checks in the inverted form, for example &lt;code&gt;CapabilityBoundingSet=~CAP_SYS_ADMIN&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Also look at what did not change in all these runs. The chmod probe stayed allowed, and the set-user-ID helper still reported UID 0. That is because a bounding set removes capabilities, but it does not remove the identity of root, and it does not stop a file owner from using file permissions.&lt;/p&gt;

&lt;h3&gt;
  
  
  The bounding set and file capabilities
&lt;/h3&gt;

&lt;p&gt;A file capability is a capability stored on the program, with &lt;code&gt;setcap&lt;/code&gt;. The bounding set interacts with it, so the test copies &lt;code&gt;/usr/bin/true&lt;/code&gt;, gives the copy &lt;code&gt;cap_net_bind_service=ep&lt;/code&gt;, and runs it as the dedicated user under three bounding sets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight systemd"&gt;&lt;code&gt;&lt;span class="n"&gt;sudo&lt;/span&gt; &lt;span class="n"&gt;cp&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;filecap&lt;/span&gt;
&lt;span class="na"&gt;sudo setcap cap_net_bind_service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ep&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;filecap&lt;/span&gt;
&lt;span class="n"&gt;getcap&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;filecap&lt;/span&gt;

&lt;span class="na"&gt;/usr/local/bin/demo-hardening-sd3-filecap cap_net_bind_service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ep&lt;/span&gt;

&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;oneshot&lt;/span&gt;
&lt;span class="na"&gt;User&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sd3demo&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;hardening&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;sd3&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;filecap&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Save this as &lt;code&gt;/etc/systemd/system/demo-hardening-sd3-filecap.service&lt;/code&gt;. Case A has no drop-in. For case B, write &lt;code&gt;CapabilityBoundingSet=&lt;/code&gt; (empty) into a drop-in file &lt;code&gt;demo-hardening-sd3-filecap.service.d/10.conf&lt;/code&gt;, and for case C write &lt;code&gt;CapabilityBoundingSet=CAP_NET_BIND_SERVICE&lt;/code&gt; there. Each time, run &lt;code&gt;sudo systemctl daemon-reload&lt;/code&gt;, then &lt;code&gt;sudo systemctl start demo-hardening-sd3-filecap.service&lt;/code&gt;, then &lt;code&gt;systemctl show -p Result -p ExecMainStatus demo-hardening-sd3-filecap.service&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;--- A: no bounding set directive
Result=success
ExecMainStatus=0
--- B: CapabilityBoundingSet= (empty)
[...]
Result=exit-code
ExecMainStatus=203
demo-hardening-sd3-filecap.service: Failed at step EXEC spawning /usr/local/bin/demo-hardening-sd3-filecap: Operation not permitted
demo-hardening-sd3-filecap.service: Main process exited, code=exited, status=203/EXEC
demo-hardening-sd3-filecap.service: Failed with result 'exit-code'.
Failed to start demo-hardening-sd3-filecap.service.
--- C: CapabilityBoundingSet=CAP_NET_BIND_SERVICE
Result=success
ExecMainStatus=0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In case B, the program never starts: systemd reports &lt;code&gt;203/EXEC&lt;/code&gt; and &lt;code&gt;Operation not permitted&lt;/code&gt;. The file asks for a capability that the ceiling forbids, so the kernel refuses to run it. In case C, however, the ceiling allows exactly that capability, and the program runs. Therefore, when a service ships a binary with file capabilities, run &lt;code&gt;getcap&lt;/code&gt; on it before you write the bounding set. In my SFTPGo article, removing &lt;code&gt;cap_net_bind_service&lt;/code&gt; from the bounding set produced a crash loop about every 40 seconds, and &lt;code&gt;getcap&lt;/code&gt; found the cause.&lt;/p&gt;

&lt;h2&gt;
  
  
  SecureBits= and PAMName=
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;SecureBits=&lt;/code&gt; sets kernel flags that change how UID 0 and capabilities interact. The systemd.exec page lists the flag names, and the kernel meaning is in &lt;code&gt;capabilities(7)&lt;/code&gt;. The test below applies two of them to the root unit and then observes the result. It does not claim more than what the output shows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;d&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/etc/systemd/system/demo-hardening-sd3-root.service.d
sudo rm -f &lt;span class="nv"&gt;$d&lt;/span&gt;/10-bounding.conf
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'[Service]\nSecureBits=noroot\n'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sudo tee &lt;span class="nv"&gt;$d&lt;/span&gt;/20-securebits.conf
sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-root.service
&lt;span class="nb"&gt;printf&lt;/span&gt; &lt;span class="s1"&gt;'[Service]\nSecureBits=keep-caps\n'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sudo tee &lt;span class="nv"&gt;$d&lt;/span&gt;/20-securebits.conf
sudo /usr/local/bin/demo-hardening-sd3-run demo-hardening-sd3-root.service
sudo rm -rf &lt;span class="nv"&gt;$d&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; sudo systemctl daemon-reload

&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 000001ffffffffff
&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
probe bind-80: refused
&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;

&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
CapPrm: 000001ffffffffff
CapEff: 000001ffffffffff
CapBnd: 000001ffffffffff
&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
probe bind-80: allowed
&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;SecureBits=noroot&lt;/code&gt;, the root service starts with empty permitted and effective sets, although the bounding set stays full. The bind probe is refused. By contrast, with &lt;code&gt;SecureBits=keep-caps&lt;/code&gt;, the output equals the baseline for a service that already runs as root. In short, the second flag shows no effect in this test, and the effect of the first flag is visible. For most services you will not need either one.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;PAMName=&lt;/code&gt; was not tested. It attaches the service to a PAM session, and the lab has no PAM service to observe, so the article gives no result for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open a low port without root: three designs
&lt;/h2&gt;

&lt;p&gt;Binding a port below 1024 is the most common reason for running as root. Three designs solve it, and the picture below compares them. Among the systemd capabilities options, the middle design is the one to learn first.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/systemd-capabilities-user-nonewprivileges-ambient-lab-3.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fod45nzi9yuv7wnsq3exd.webp" alt="Systemd capabilities for ports below 1024: root, a dedicated user with one capability, or a reverse proxy" width="800" height="279"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Three ways to serve port 80, from the widest privilege to none.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Design A, root:&lt;/strong&gt; simple, but the service holds every capability. This is the baseline of the lab.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design B, dedicated user with one capability:&lt;/strong&gt; &lt;code&gt;User=&lt;/code&gt;, &lt;code&gt;AmbientCapabilities=CAP_NET_BIND_SERVICE&lt;/code&gt;, &lt;code&gt;CapabilityBoundingSet=CAP_NET_BIND_SERVICE&lt;/code&gt; and &lt;code&gt;NoNewPrivileges=yes&lt;/code&gt;. This is the combination tested above.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Design C, high port behind a reverse proxy:&lt;/strong&gt; the service listens on a port such as 8080, and the proxy owns port 80. The service needs no capability at all.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Design C removes the need for any capability, so choose it when a proxy already exists. If there is no proxy, design B fits. In my earlier article, the mox mail server follows design B: &lt;code&gt;NoNewPrivileges=true&lt;/code&gt; with &lt;code&gt;AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_SETUID CAP_SETGID CAP_CHOWN&lt;/code&gt;. When I removed &lt;code&gt;CAP_DAC_OVERRIDE&lt;/code&gt;, the service needed &lt;code&gt;CAP_DAC_READ_SEARCH&lt;/code&gt; and &lt;code&gt;SupplementaryGroups=mox&lt;/code&gt; to keep reading its files. Etherpad, finally, shows the minimal end: a dedicated user, no capability, and an exposure level of 1.5.&lt;/p&gt;
&lt;h2&gt;
  
  
  Read the result: five ways to inspect systemd capabilities
&lt;/h2&gt;

&lt;p&gt;Never trust a drop-in until you have read what systemd loaded. Therefore these five checks work on any unit, and each one answers a different question.&lt;/p&gt;
&lt;h3&gt;
  
  
  1. systemctl show
&lt;/h3&gt;

&lt;p&gt;The first check reads the properties that systemd holds for the unit. The manual page for &lt;code&gt;systemctl&lt;/code&gt; does not promise that exec settings appear there, but in this test they do.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemctl show -p User -p SupplementaryGroups -p CapabilityBoundingSet -p AmbientCapabilities -p NoNewPrivileges -p RestrictSUIDSGID -p SecureBits demo-hardening-sd3-caps.service

SecureBits=0
CapabilityBoundingSet=cap_net_bind_service
AmbientCapabilities=cap_net_bind_service
User=sd3demo
SupplementaryGroups=
NoNewPrivileges=yes
RestrictSUIDSGID=yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Names come back in lower case, and an empty value means the setting is missing. Note that &lt;code&gt;SecureBits=0&lt;/code&gt; appears although &lt;code&gt;AmbientCapabilities=&lt;/code&gt; is set. I did not look further into that.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. systemd-analyze capability
&lt;/h3&gt;

&lt;p&gt;The second check lists the capability names with their numbers, or filters them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemd-analyze capability cap_net_bind_service cap_chown

NAME NUMBER
cap_chown 0
cap_net_bind_service 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Decode a mask
&lt;/h3&gt;

&lt;p&gt;To turn a mask from &lt;code&gt;/proc&lt;/code&gt; into names, give it to &lt;code&gt;systemd-analyze capability -m&lt;/code&gt; or to &lt;code&gt;capsh --decode&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;systemd-analyze capability -m 0000000000000401

NAME NUMBER
cap_chown 0
cap_net_bind_service 10

capsh --decode=0000000000000401

0x0000000000000401=cap_chown,cap_net_bind_service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. The process itself
&lt;/h3&gt;

&lt;p&gt;The most reliable check reads the live process. First, a transient unit, started by &lt;code&gt;systemd-run&lt;/code&gt;, sleeps for two minutes. Then the test reads its status file and runs &lt;code&gt;getpcaps&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo systemd-run --unit=demo-hardening-sd3-sleep -p &lt;span class="nv"&gt;User&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;sd3demo -p &lt;span class="nv"&gt;AmbientCapabilities&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;CAP_NET_BIND_SERVICE -p &lt;span class="nv"&gt;NoNewPrivileges&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yes /usr/bin/sleep 120
&lt;span class="nv"&gt;pid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;systemctl show -p MainPID --value demo-hardening-sd3-sleep.service&lt;span class="o"&gt;)&lt;/span&gt;
grep -E &lt;span class="s1"&gt;'^(CapInh|CapPrm|CapEff|CapBnd|CapAmb|NoNewPrivs):'&lt;/span&gt; /proc/&lt;span class="nv"&gt;$pid&lt;/span&gt;/status
getpcaps &lt;span class="nv"&gt;$pid&lt;/span&gt;

CapInh: 0000000000000400
CapPrm: 0000000000000400
CapEff: 0000000000000400
CapBnd: 000001ffffffffff
CapAmb: 0000000000000400
NoNewPrivs: 1
--- getpcaps
6192: &lt;span class="nv"&gt;cap_net_bind_service&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;eip
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In &lt;code&gt;getpcaps&lt;/code&gt; output, &lt;code&gt;cap_net_bind_service=eip&lt;/code&gt; means the capability is effective, inherited and permitted at the same time.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. systemd-analyze security
&lt;/h3&gt;

&lt;p&gt;The last check is the score. Since the same unit scores differently with and without the four directives of this article, the numbers show their effect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[without the drop-in]
→ Overall exposure level for demo-hardening-sd3-caps.service: 9.2 UNSAFE ![😨](https://s.w.org/images/core/emoji/17.0.2/72x72/1f628.png)

[with User=, AmbientCapabilities=CAP_NET_BIND_SERVICE, CapabilityBoundingSet=CAP_NET_BIND_SERVICE,
 NoNewPrivileges=yes and RestrictSUIDSGID=yes]
→ Overall exposure level for demo-hardening-sd3-caps.service: 6.5 MEDIUM ![😐](https://s.w.org/images/core/emoji/17.0.2/72x72/1f610.png)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exposure level moves from 9.2 UNSAFE to 6.5 MEDIUM with these directives alone. The rest of the score depends on the file system, the kernel and the system calls, which parts 2, 4, 5, 6 and 7 cover. Here are some of the lines of the second report:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[...]
✓ User=/DynamicUser= Service runs under a static non-root user identity
✓ NoNewPrivileges= Service processes cannot acquire new privileges
✗ AmbientCapabilities= Service process receives ambient capabilities 0.1
✓ SupplementaryGroups= Service has no supplementary groups
✓ CapabilityBoundingSet=~CAP_SYS_ADMIN Service has no administrator privileges
✗ CapabilityBoundingSet=~CAP_NET_(BIND_SERVICE|BROADCAST|RAW) Service has elevated networking privileges 0.1
✓ CapabilityBoundingSet=~CAP_SET(UID|GID|PCAP) Service cannot change UID/GID identities/capabilities
✓ RestrictSUIDSGID= SUID/SGID file creation by service is restricted
[...]
→ Overall exposure level for demo-hardening-sd3-caps.service: 6.5 MEDIUM ![😐](https://s.w.org/images/core/emoji/17.0.2/72x72/1f610.png)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two lines cost 0.1 each: &lt;code&gt;AmbientCapabilities=&lt;/code&gt; and the networking capabilities. They are the price of the one privilege that the service really needs, and that price is small.&lt;/p&gt;

&lt;h2&gt;
  
  
  Complete drop-ins to copy
&lt;/h2&gt;

&lt;p&gt;Use these drop-ins for systemd capabilities as a starting point. First, replace &lt;code&gt;app01&lt;/code&gt; and &lt;code&gt;appuser&lt;/code&gt; with your own names. The first drop-in is the combination measured above. Also keep the comments, because they help the next person who reads the file.&lt;/p&gt;

&lt;h3&gt;
  
  
  Drop-in 1: a dedicated user with one privilege
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo useradd --system --no-create-home --shell /usr/sbin/nologin appuser

sudo mkdir -p /etc/systemd/system/app01.service.d
sudo tee /etc/systemd/system/app01.service.d/10-privileges.conf &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="c"&gt;# Identity: never root.&lt;/span&gt;
&lt;span class="nv"&gt;User&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;appuser
&lt;span class="c"&gt;# Grant: the only privilege this service needs (bind ports below 1024).&lt;/span&gt;
&lt;span class="nv"&gt;AmbientCapabilities&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;CAP_NET_BIND_SERVICE
&lt;span class="c"&gt;# Limit: nothing else can ever be held, even through a file capability.&lt;/span&gt;
&lt;span class="nv"&gt;CapabilityBoundingSet&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;CAP_NET_BIND_SERVICE
&lt;span class="c"&gt;# Block: no gain through set-user-ID bits or file capabilities.&lt;/span&gt;
&lt;span class="nv"&gt;NoNewPrivileges&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yes
&lt;span class="c"&gt;# Block: the service cannot create set-user-ID or set-group-ID files.&lt;/span&gt;
&lt;span class="nv"&gt;RestrictSUIDSGID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yes
EOF

sudo systemctl daemon-reload
sudo systemctl restart app01.service
systemd-analyze security app01.service &lt;span class="o"&gt;|&lt;/span&gt; tail -1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Drop-in 2: no fixed account at all
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo mkdir -p /etc/systemd/system/app01.service.d
sudo tee /etc/systemd/system/app01.service.d/10-privileges.conf &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="c"&gt;# Identity: a temporary account, created at start and released at stop.&lt;/span&gt;
&lt;span class="nv"&gt;DynamicUser&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yes
&lt;span class="c"&gt;# The only place the service may write (becomes /var/lib/app01).&lt;/span&gt;
&lt;span class="nv"&gt;StateDirectory&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;app01
&lt;span class="c"&gt;# DynamicUser=yes already implies NoNewPrivileges and RestrictSUIDSGID.&lt;/span&gt;
EOF

sudo systemctl daemon-reload
sudo systemctl restart app01.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Drop-in 3: a service that must stay root
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sudo mkdir -p /etc/systemd/system/app01.service.d
sudo tee /etc/systemd/system/app01.service.d/10-privileges.conf &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /dev/null &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="s1"&gt;'EOF'&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;Service&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="c"&gt;# The service still runs as root, but it keeps only one capability.&lt;/span&gt;
&lt;span class="nv"&gt;CapabilityBoundingSet&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;CAP_NET_BIND_SERVICE
&lt;span class="nv"&gt;NoNewPrivileges&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;yes
EOF

sudo systemctl daemon-reload
sudo systemctl restart app01.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Of these three, the lab measured the first one in full. The second was tested for the account, the state directory and the implied settings. The third one was tested for the bounding set only, without &lt;code&gt;NoNewPrivileges=yes&lt;/code&gt;. Always read &lt;code&gt;systemctl show&lt;/code&gt; after a change, then test the real service.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes with systemd capabilities
&lt;/h2&gt;

&lt;p&gt;These mistakes come from the lab itself, so each one has a real output.&lt;/p&gt;

&lt;h3&gt;
  
  
  A typo in a capability name is silent
&lt;/h3&gt;

&lt;p&gt;The unit below misspells the name with an extra S.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight systemd"&gt;&lt;code&gt;&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;AmbientCapabilities&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="no"&gt;CAP_NET_BIND_SERVICES&lt;/span&gt;

&lt;span class="na"&gt;AmbientCapabilities&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;
&lt;span class="na"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;success&lt;/span&gt;
&lt;span class="na"&gt;ExecMainStatus&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="o"&gt;---&lt;/span&gt; &lt;span class="n"&gt;journal&lt;/span&gt; &lt;span class="n"&gt;search&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;the&lt;/span&gt; &lt;span class="n"&gt;misspelled&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;whole&lt;/span&gt; &lt;span class="n"&gt;boot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="n"&gt;of&lt;/span&gt; &lt;span class="n"&gt;journal&lt;/span&gt; &lt;span class="n"&gt;search&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;---&lt;/span&gt; &lt;span class="n"&gt;systemd&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;analyze&lt;/span&gt; &lt;span class="n"&gt;verify&lt;/span&gt;
&lt;span class="n"&gt;verify&lt;/span&gt; &lt;span class="n"&gt;exit&lt;/span&gt; &lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Systemd loads the unit without any message. Instead, the property is simply empty, and the unit starts with &lt;code&gt;Result=success&lt;/code&gt;. A search of the whole boot journal for the wrong name finds nothing, and &lt;code&gt;systemd-analyze verify&lt;/code&gt; prints nothing and exits with code 0. The only visible sign is the empty property. Therefore, always run &lt;code&gt;systemctl show -p AmbientCapabilities UNIT&lt;/code&gt; after an edit. On the other hand, the lower-case form &lt;code&gt;cap_net_bind_service&lt;/code&gt; is accepted.&lt;/p&gt;

&lt;h3&gt;
  
  
  A drop-in without the [Service] header
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AmbientCapabilities=
/etc/systemd/system/demo-hardening-sd3-caps.service.d/10-noheader.conf:1: Assignment outside of section. Ignoring.
/etc/systemd/system/demo-hardening-sd3-caps.service.d/10-noheader.conf:1: Assignment outside of section. Ignoring.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The warning is clear: &lt;code&gt;Assignment outside of section. Ignoring.&lt;/code&gt; It appeared twice in the journal. It only showed up after &lt;code&gt;daemon-reload&lt;/code&gt; and after the unit was loaded by a &lt;code&gt;systemctl show&lt;/code&gt;, so run a command that loads the unit before you search the journal.&lt;/p&gt;

&lt;h3&gt;
  
  
  A drop-in file that does not end in .conf
&lt;/h3&gt;

&lt;p&gt;The file &lt;code&gt;10-ambient.txt&lt;/code&gt; was ignored, because &lt;code&gt;AmbientCapabilities=&lt;/code&gt; stayed empty. However, the journal was not searched for a message in this case.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other mistakes with clear symptoms
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Missing account:&lt;/strong&gt; &lt;code&gt;status=217/USER&lt;/code&gt; and the odd text &lt;code&gt;No such process&lt;/code&gt; (shown earlier).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Empty bounding set with a file-capability binary:&lt;/strong&gt; &lt;code&gt;status=203/EXEC&lt;/code&gt; and &lt;code&gt;Operation not permitted&lt;/code&gt; (shown earlier).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ambient capability without &lt;code&gt;NoNewPrivileges=yes&lt;/code&gt;:&lt;/strong&gt; the set-user-ID helper still returns UID 0 (step A).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Too much hardening on a service that calls &lt;code&gt;sudo&lt;/code&gt;:&lt;/strong&gt; it fails with &lt;code&gt;NoNewPrivileges=yes&lt;/code&gt; or an empty bounding set.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Forgotten &lt;code&gt;systemctl daemon-reload&lt;/code&gt;:&lt;/strong&gt; systemd keeps the old unit, and the new file seems to do nothing.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Final checklist for systemd capabilities
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Does the service need root? If not, set &lt;code&gt;User=&lt;/code&gt; (or &lt;code&gt;DynamicUser=yes&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Does it need a privilege? Name exactly one capability in &lt;code&gt;AmbientCapabilities=&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Is the ceiling set? Write the same list in &lt;code&gt;CapabilityBoundingSet=&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Is &lt;code&gt;NoNewPrivileges=yes&lt;/code&gt; set, and does the service run without &lt;code&gt;sudo&lt;/code&gt;?&lt;/li&gt;
&lt;li&gt;Is &lt;code&gt;RestrictSUIDSGID=yes&lt;/code&gt; set, unless the service creates set-user-ID files on purpose?&lt;/li&gt;
&lt;li&gt;Does a binary of the service carry file capabilities? Run &lt;code&gt;getcap&lt;/code&gt; before you set the ceiling.&lt;/li&gt;
&lt;li&gt;After every edit, run &lt;code&gt;systemctl daemon-reload&lt;/code&gt;, then &lt;code&gt;systemctl show -p&lt;/code&gt; for each directive.&lt;/li&gt;
&lt;li&gt;Read the live process: &lt;code&gt;/proc/PID/status&lt;/code&gt; and &lt;code&gt;getpcaps&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Measure with &lt;code&gt;systemd-analyze security&lt;/code&gt; and keep the number in the change record.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What this lab did not test
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;PAMName=&lt;/code&gt; was not tested.&lt;/li&gt;
&lt;li&gt;SELinux is not available on the bench, so the interaction between systemd capabilities and SELinux policy is outside this article.&lt;/li&gt;
&lt;li&gt;A bare &lt;code&gt;CapabilityBoundingSet=~&lt;/code&gt; (the full set, according to the manual) was not tested.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SecureBits=&lt;/code&gt; was only observed on a root service. Its flags were not tested with &lt;code&gt;User=&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The extra bits in &lt;code&gt;CapInh&lt;/code&gt; after &lt;code&gt;RestrictSUIDSGID=yes&lt;/code&gt; are an observation without an explanation.&lt;/li&gt;
&lt;li&gt;The ownership of the dynamic user’s state directory (UID 65534 from the host) is an observation without an explanation.&lt;/li&gt;
&lt;li&gt;The results come from a WSL2 kernel, so a native kernel can differ.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Clean up the lab
&lt;/h2&gt;

&lt;p&gt;Run the script below as root. It removes only the units, drop-ins, files and the account that the lab created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; u &lt;span class="k"&gt;in&lt;/span&gt; demo-hardening-sd3-caps demo-hardening-sd3-root demo-hardening-sd3-dynamic demo-hardening-sd3-baduser demo-hardening-sd3-filecap demo-hardening-sd3-sleep&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  systemctl stop &lt;span class="s2"&gt;"$u.service"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
  systemctl reset-failed &lt;span class="s2"&gt;"$u.service"&lt;/span&gt; 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
  rm -rf &lt;span class="s2"&gt;"/etc/systemd/system/$u.service"&lt;/span&gt; &lt;span class="s2"&gt;"/etc/systemd/system/$u.service.d"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
rm -f /usr/local/bin/demo-hardening-sd3-probe.sh /usr/local/bin/demo-hardening-sd3-setuid-id /usr/local/bin/demo-hardening-sd3-run /usr/local/bin/demo-hardening-sd3-filecap
rm -rf /var/lib/demo-hardening-sd3-dynamic /var/lib/private/demo-hardening-sd3-dynamic
id sd3demo &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1 &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; userdel sd3demo
systemctl daemon-reload
ls -d /etc/systemd/system/*sd3* /usr/local/bin/*sd3* /var/lib/*sd3* 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null&lt;span class="o"&gt;;&lt;/span&gt; getent passwd sd3demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The two last commands must print nothing, and that was the case on the test bench after cleanup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html" rel="noopener noreferrer"&gt;systemd.exec(5)&lt;/a&gt;: the directives &lt;code&gt;User=&lt;/code&gt;, &lt;code&gt;DynamicUser=&lt;/code&gt;, &lt;code&gt;NoNewPrivileges=&lt;/code&gt;, &lt;code&gt;CapabilityBoundingSet=&lt;/code&gt;, &lt;code&gt;AmbientCapabilities=&lt;/code&gt;, &lt;code&gt;SecureBits=&lt;/code&gt;, &lt;code&gt;RestrictSUIDSGID=&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://man7.org/linux/man-pages/man7/capabilities.7.html" rel="noopener noreferrer"&gt;capabilities(7)&lt;/a&gt;: the list of capabilities and the rules for each set.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.freedesktop.org/software/systemd/man/latest/systemd-analyze.html" rel="noopener noreferrer"&gt;systemd-analyze(1)&lt;/a&gt;: the &lt;code&gt;security&lt;/code&gt; and &lt;code&gt;capability&lt;/code&gt; commands.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Earlier in this series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=3481" rel="noopener noreferrer"&gt;Systemd hardening, directive by directive: measuring with systemd-analyze security&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=3491" rel="noopener noreferrer"&gt;Systemd filesystem protection: hardening part 2, directive by directive&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Systemd sandboxing in practice: the drop-ins I use and what each one broke (coming 17 Sep)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=620" rel="noopener noreferrer"&gt;How-to: a well-tuned fail2ban, with progressive bans&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;How-to: install a Wazuh agent and get something out of it (coming 25 Nov)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/21/systemd-capabilities-user-nonewprivileges-ambient-lab/" rel="noopener noreferrer"&gt;Systemd capabilities: from root to one single privilege, with a tested lab&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>linux</category>
      <category>security</category>
      <category>sysadminnotebook</category>
      <category>english</category>
    </item>
    <item>
      <title>How-to: change the DNS servers of a MikroTik router without bypassing Pi-hole</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Fri, 20 Nov 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/how-to-change-the-dns-servers-of-a-mikrotik-router-without-bypassing-pi-hole-3dco</link>
      <guid>https://dev.to/hecate-regnier/how-to-change-the-dns-servers-of-a-mikrotik-router-without-bypassing-pi-hole-3dco</guid>
      <description>&lt;p&gt;To change the MikroTik DNS servers of my home router, I replaced a list of two resolvers with a single one: my Pi-hole. The router answers DNS queries for my WireGuard peers and for the IPv6 clients of my LAN, so a second public resolver in its list let filtered domains slip through. Here is the procedure I follow, step by step, with RouterOS Safe Mode as a safety net.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick answer&lt;/strong&gt; — make a RouterOS 7 router resolve only through Pi-hole.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# In a Winbox terminal or over SSH, press Ctrl+X first (Safe Mode)
/ip dns set servers=192.168.88.19
/ip dns cache flush
/ip dns print
# Test from a LAN host, then press Ctrl+X again to keep the change
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Details, explanations and checks follow below. Addresses are examples.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a second resolver breaks the filter
&lt;/h2&gt;

&lt;p&gt;My router is not only a gateway. It also answers DNS queries for two groups of clients. First, the WireGuard peers: my phone uses one WireGuard interface, and my servers use another. Second, the IPv6 clients of the LAN, because the router advertises itself as their DNS server in router advertisements (&lt;code&gt;/ipv6 nd&lt;/code&gt; with &lt;code&gt;advertise-dns=yes&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Until October 2026, the list of MikroTik DNS servers contained my Pi-hole and Quad9 (&lt;code&gt;servers=192.168.88.19,9.9.9.9&lt;/code&gt;). Because of that second entry, domains that Pi-hole blocks were resolved by Quad9 instead, so the filtering was bypassed. The fix is simple: leave only the Pi-hole in the list.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/mikrotik-dns-servers-before-after_en.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc5efjkg5qijrdzgb7b5t.webp" alt="MikroTik DNS servers before and after: a second public resolver bypasses Pi-hole, one server keeps the filter" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Before, the router had two resolvers and the second one bypassed the filter. After, it has only the Pi-hole.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Before you start
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A router that runs RouterOS 7. Mine is not managed by Ansible.&lt;/li&gt;
&lt;li&gt;A recent copy of its configuration. Mine comes from a nightly backup of the router configuration.&lt;/li&gt;
&lt;li&gt;A terminal on the router: a Winbox New Terminal, or SSH as &lt;code&gt;admin&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The address of your Pi-hole. In this article the router is 192.168.88.1 and the Pi-hole is 192.168.88.19, which are example values.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then learn Safe Mode, because it protects you if you cut your own access. In the CLI, you press Ctrl+X to enter it. While it is active, RouterOS tracks your changes. If the connection drops, the router undoes them, and the RouterOS documentation says this happens after the TCP timeout, which it gives as 9 minutes. When everything works, you press Ctrl+X again to leave Safe Mode and keep the changes.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: enter Safe Mode
&lt;/h2&gt;

&lt;p&gt;Open the terminal and press Ctrl+X. From this moment, a dropped session rolls everything back.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: change the MikroTik DNS servers
&lt;/h2&gt;

&lt;p&gt;Run the four commands below. The first one sets the single server, then the second one empties the cache so that the router stops answering from the old entries. The third one shows the result. The last one checks that the WAN DHCP client adds no DNS server from the provider.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Only the Pi-hole answers from now on
/ip dns set servers=192.168.88.19
# Empty the router's DNS cache
/ip dns cache flush
# Show the result
/ip dns print
# The WAN DHCP client must not add DNS servers from the ISP (look for use-peer-dns=no)
/ip dhcp-client print detail where interface=&amp;lt;your-wan-interface&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: test from a LAN host
&lt;/h2&gt;

&lt;p&gt;Before you leave Safe Mode, query the router from another machine. Three answers tell you that the chain works.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# A domain blocked by Pi-hole: 0.0.0.0 means the query went through Pi-hole&lt;/span&gt;
dig +short doubleclick.net @192.168.88.1
&lt;span class="c"&gt;# A normal domain: a real address&lt;/span&gt;
dig +short example.com @192.168.88.1
&lt;span class="c"&gt;# A name of one of my WireGuard peers: the router can still resolve it&lt;/span&gt;
dig +short peer01.example.net @192.168.88.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the blocked domain returns a real address, the filter is still bypassed, so stay in Safe Mode and look at the list again. If the third name fails, the router lost the link with its peers, so do not keep the change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: keep the change
&lt;/h2&gt;

&lt;p&gt;When the three tests pass, press Ctrl+X again. RouterOS leaves Safe Mode and keeps your changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: confirm it the next morning
&lt;/h2&gt;

&lt;p&gt;The next morning, I open the nightly backup of the router configuration. It shows the new &lt;code&gt;/ip dns&lt;/code&gt; section, which proves that the change survived and that it is recorded.&lt;/p&gt;

&lt;h2&gt;
  
  
  If something goes wrong
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;If your session drops during the change, the router rolls everything back by itself, thanks to Safe Mode.&lt;/li&gt;
&lt;li&gt;If the Pi-hole goes down, the router resolves nothing new. The existing WireGuard tunnels survive.&lt;/li&gt;
&lt;li&gt;The proper fallback is a second Pi-hole, never a public resolver, because a public resolver brings back the bypass.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I take away
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A router that answers DNS for other clients must follow the same filter as the LAN.&lt;/li&gt;
&lt;li&gt;Check the MikroTik DNS servers on every router that relays queries, not only on the clients.&lt;/li&gt;
&lt;li&gt;Use Safe Mode for every remote change, and test before you press Ctrl+X the second time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://help.mikrotik.com/docs/spaces/ROS/pages/37748767/DNS" rel="noopener noreferrer"&gt;MikroTik documentation: DNS&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://help.mikrotik.com/docs/spaces/ROS/pages/328155/Configuration+Management" rel="noopener noreferrer"&gt;MikroTik documentation: Configuration Management (Safe Mode)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=595" rel="noopener noreferrer"&gt;How-to: install and configure WireGuard between a server and home&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=599" rel="noopener noreferrer"&gt;How-to: Suricata as an IPS with NFQUEUE, without breaking your server&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=102" rel="noopener noreferrer"&gt;CrowdSec 1.8 on Debian: leaving the distro package, the postinst trap and a protection checklist&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/20/how-to-change-mikrotik-dns-servers-pihole-safe-mode/" rel="noopener noreferrer"&gt;How-to: change the DNS servers of a MikroTik router without bypassing Pi-hole&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>networking</category>
      <category>sysadminnotebook</category>
      <category>dns</category>
      <category>english</category>
    </item>
    <item>
      <title>Inside database data files (5/3+2): Cassandra</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Thu, 19 Nov 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/inside-database-data-files-532-cassandra-gg5</link>
      <guid>https://dev.to/hecate-regnier/inside-database-data-files-532-cassandra-gg5</guid>
      <description>&lt;p&gt;The first three parts of this series looked at engines that edit fixed-size pages in place, or next to their old versions. Apache Cassandra takes another road, because it never edits a file. Every write ends up in a Cassandra SSTable, a sorted file that is written once and never changed. This bonus part (5/3+2 in the series numbering, after SQLite) opens a real node to show what that looks like on disk.&lt;/p&gt;

&lt;p&gt;I don’t run Cassandra at home. Everything below comes from a one-node lab built for this post (Rocky Linux 10.2 on WSL2, Apache Cassandra 5.0.9, Temurin Java 17.0.21) and from the Apache documentation. The outputs are real: I only cut lines, and I mark each cut with &lt;code&gt;[...]&lt;/code&gt;. With one node there is no replication, no repair and no streaming, so I say when that matters.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Cassandra data directory
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/inside-database-data-files-cassandra-sstable-commit-log-compaction-1.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fvcsjie01yenedsqsqwtz.webp" alt="Cassandra data directory: commitlog, data, hints and saved_caches, with the eight files of one SSTable" width="800" height="391"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The directories of a Cassandra node and the files of one SSTable.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A node keeps its files in four directories. Their location comes from &lt;code&gt;cassandra.yaml&lt;/code&gt;, and when you install from the tarball, they sit under &lt;code&gt;data/&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;commitlog/&lt;/code&gt;: the commit log, cut into segments of 32 MiB, the documented default. A fresh node already had two of them, each exactly 33,554,432 bytes.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;data/&lt;/code&gt;: the SSTables. The layout is &lt;code&gt;data/&amp;lt;keyspace&amp;gt;/&amp;lt;table&amp;gt;-&amp;lt;table id&amp;gt;/&lt;/code&gt;. My table landed in &lt;code&gt;demo/readings-b5b8f990…&lt;/code&gt;. The system keyspaces (&lt;code&gt;system&lt;/code&gt;, &lt;code&gt;system_schema&lt;/code&gt;…) sit next to it, and they also use the same format.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;hints/&lt;/code&gt;: where writes wait for a node that is down. The reference ties it to &lt;code&gt;max_hint_window&lt;/code&gt;, the time during which a dead host gets hints. It stayed empty.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;saved_caches/&lt;/code&gt;: the key, row and counter caches, saved so that a restart does not start cold. Empty too.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the previous parts, a database was a directory, but here a keyspace is a directory, and each table is a directory inside it, with a long suffix that identifies the table.&lt;/p&gt;
&lt;h2&gt;
  
  
  The write path: commit log, memtable, flush
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/inside-database-data-files-cassandra-sstable-commit-log-compaction-2.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F0odg6kwyytsu6sbyu49o.webp" alt="Cassandra write path: commit log and memtable, a flush to immutable SSTables, then compaction" width="800" height="382"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;A write goes to the commit log and the memtable; flushes create SSTables.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A write goes to two places. First, the commit log: Cassandra appends the change to a segment on disk, so that it survives a crash. Second, the memtable, a sorted structure in memory, usually one per table. By default the log is synced every 10 seconds (&lt;code&gt;commitlog_sync: periodic&lt;/code&gt;, &lt;code&gt;commitlog_sync_period: 10000ms&lt;/code&gt;), so a write is acknowledged before it is on disk. The alternative, &lt;code&gt;batch&lt;/code&gt;, waits for the sync.&lt;/p&gt;

&lt;p&gt;In the lab, I inserted seven rows into a new table and looked before flushing. At that point the table directory was empty, but seven cells sat in the memtable, and the commit log held their only copy on disk:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SSTable count: 0
Old SSTable count: 0
Memtable cell count: 7
Memtable data size: 367
Memtable switch count: 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The commit log is not compressed unless you ask for it, so the keys are readable in a segment. I looked with &lt;code&gt;strings&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;strings CommitLog-7-*.log &lt;span class="o"&gt;|&lt;/span&gt; grep -E &lt;span class="s2"&gt;"sensor-[abc]"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; head -5
sensor-a
sensor-a
sensor-a
sensor-b
sensor-b
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A flush turns the memtable into an SSTable. It happens when memory runs short, when the commit log nears its limit, or on demand. I ran &lt;code&gt;nodetool flush demo readings&lt;/code&gt; and eight files appeared:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -l | awk '{print $5, $9}'
47 nb-1-big-CompressionInfo.db
123 nb-1-big-Data.db
10 nb-1-big-Digest.crc32
16 nb-1-big-Filter.db
36 nb-1-big-Index.db
4855 nb-1-big-Statistics.db
68 nb-1-big-Summary.db
92 nb-1-big-TOC.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the flush, the two commit log segments were still there. The documentation says a segment can be deleted or recycled only once all its data is flushed to SSTables, and the segments are shared by all the tables, so I did not see one disappear.&lt;/p&gt;

&lt;h2&gt;
  
  
  Anatomy of a Cassandra SSTable
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/inside-database-data-files-cassandra-sstable-commit-log-compaction-3.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F458z8ddafgw2xvrn6kq0.webp" alt="The eight components of a Cassandra SSTable and the order in which a read uses them" width="800" height="409"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Component sizes from the lab, and the four steps of a read.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Because each file has one job, a Cassandra SSTable is a set of files that share a prefix. In the lab, &lt;code&gt;nb-1-big-&lt;/code&gt; reads as a format version (&lt;code&gt;nb&lt;/code&gt;), a generation number, and the format name (&lt;code&gt;big&lt;/code&gt;, the default). The documentation does not spell this pattern out, so that is my reading of the names. It also describes a trie-based format whose index lives in &lt;code&gt;Partitions.db&lt;/code&gt; and &lt;code&gt;Rows.db&lt;/code&gt; instead of &lt;code&gt;Index.db&lt;/code&gt;; I did not test it. The file &lt;code&gt;TOC.txt&lt;/code&gt; lists the components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat nb-1-big-TOC.txt
CompressionInfo.db
Data.db
Digest.crc32
Filter.db
Index.db
Statistics.db
Summary.db
TOC.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Data.db&lt;/code&gt; (123 bytes): the rows, grouped by partition and compressed in chunks. The default compressor is LZ4, and the compression ratio was 0.68.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Index.db&lt;/code&gt; (36 bytes): partition keys and their positions in &lt;code&gt;Data.db&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Summary.db&lt;/code&gt; (68 bytes): a sample of the index, every 128th entry by default.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Filter.db&lt;/code&gt; (16 bytes): the Bloom filter of the partition keys.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;CompressionInfo.db&lt;/code&gt; (47 bytes): offsets and lengths of the compressed chunks.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Statistics.db&lt;/code&gt; (4,855 bytes): metadata such as timestamps, tombstones and TTLs. It is the biggest file here, and &lt;code&gt;sstablemetadata&lt;/code&gt; prints histograms read from it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Digest.crc32&lt;/code&gt; (10 bytes): a CRC-32 digest of &lt;code&gt;Data.db&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A read does not scan these files. Instead, for a partition key, Cassandra asks the Bloom filter first. A negative answer is final, while a positive one can be wrong (the table’s false-positive chance was 0.01). Then it narrows the search with the summary, finds the exact position in the index, and decompresses the chunk. After two flushes, &lt;code&gt;nodetool getsstables&lt;/code&gt; tells which files can hold a key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nodetool getsstables demo readings sensor-a
data/data/demo/readings-b5b8f990d6fb11f197b7370581990151/nb-1-big-Data.db
data/data/demo/readings-b5b8f990d6fb11f197b7370581990151/nb-2-big-Data.db
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Partitions, rows and cells in Data.db
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/inside-database-data-files-cassandra-sstable-commit-log-compaction-4.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdqqs6bmc19kjw7o2l3vi.webp" alt="Inside a Cassandra SSTable: Index.db positions and the partition, row and cell layout of Data.db" width="800" height="400"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Index.db and Data.db read through hexdump and sstabledump.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Inside &lt;code&gt;Data.db&lt;/code&gt;, rows are grouped by partition. Partitions come in token order, the hash of the partition key, while rows inside a partition follow the clustering key. That is why my three sensors are not in alphabetical order: &lt;code&gt;sensor-b&lt;/code&gt; comes first, then &lt;code&gt;sensor-c&lt;/code&gt;, then &lt;code&gt;sensor-a&lt;/code&gt;. &lt;code&gt;sstabledump&lt;/code&gt; prints a partition like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="n"&gt;sstabledump&lt;/span&gt; &lt;span class="n"&gt;nb&lt;/span&gt;&lt;span class="mi"&gt;-1&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;big&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Data&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"partition"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"key"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sensor-b"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"rows"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"liveness_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"tstamp"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:26:44.439221Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"temp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;37&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"liveness_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"tstamp"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:26:44.441834Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"temp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each row carries the timestamp of its &lt;code&gt;INSERT&lt;/code&gt; in &lt;code&gt;liveness_info&lt;/code&gt;, and each cell can also carry its own timestamp. The metadata tool confirms the token order, the compression and the absence of tombstones:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sstablemetadata nb-1-big-Data.db
Partitioner: org.apache.cassandra.dht.Murmur3Partitioner
Bloom Filter FP chance: 0.01
Compressor: org.apache.cassandra.io.compress.LZ4Compressor
Compression ratio: 0.68
First token: -2257014703785893100 (sensor-b)
Last token: 6459236691210746121 (sensor-a)
Covered clusterings: [1, 3]
Estimated droppable tombstones: 0.0
totalRows: 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The index file is small, so I read it by hand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;xxd nb-1-big-Index.db
00000000: 0008 7365 6e73 6f72 2d62 0000 0008 7365 ..sensor-b....se
00000010: 6e73 6f72 2d63 3500 0008 7365 6e73 6f72 nsor-c5...sensor
00000020: 2d61 6c00 -al.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each entry is a two-byte length (&lt;code&gt;0008&lt;/code&gt;), the key, a position and a zero, so the positions are &lt;code&gt;00&lt;/code&gt;, &lt;code&gt;35&lt;/code&gt; and &lt;code&gt;6c&lt;/code&gt;: 0, 53 and 108 in the uncompressed data stream. &lt;code&gt;sstabledump&lt;/code&gt; reports 22, 75 and 130 for the first row of each partition, which is 22 bytes after each start. That matches a header made of a two-byte key length, the eight-byte key, and a twelve-byte deletion time. The documentation does not describe the byte layout of &lt;code&gt;Data.db&lt;/code&gt;, so treat this decoding as my reading of the output, not as a specification.&lt;/p&gt;

&lt;h2&gt;
  
  
  An UPDATE or a DELETE is a new write
&lt;/h2&gt;

&lt;p&gt;Nothing in a Cassandra SSTable is ever edited, so to see it, I changed one value, added a row, deleted a row, deleted a whole partition, and flushed again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;readings&lt;/span&gt; &lt;span class="k"&gt;SET&lt;/span&gt; &lt;span class="k"&gt;temp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'sensor-a'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;readings&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;temp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;VALUES&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'sensor-a'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;readings&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'sensor-b'&lt;/span&gt; &lt;span class="k"&gt;AND&lt;/span&gt; &lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;DELETE&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;readings&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;device&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'sensor-c'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a result, the second SSTable, &lt;code&gt;nb-2&lt;/code&gt;, contains only these changes. The update is a cell with its own timestamp, and the deletes are tombstones, one for a row and one for a whole partition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="n"&gt;sstabledump&lt;/span&gt; &lt;span class="n"&gt;nb&lt;/span&gt;&lt;span class="mi"&gt;-2&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;big&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Data&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"partition"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"key"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sensor-b"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"rows"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"deletion_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"marked_deleted"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29.783855Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"local_delete_time"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"partition"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"key"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sensor-c"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;57&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"deletion_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"marked_deleted"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29.787731Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"local_delete_time"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"rows"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"partition"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"key"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sensor-a"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"rows"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"temp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"tstamp"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29.773920Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;94&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"liveness_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"tstamp"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29.779577Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"temp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The old values, 21 and 16 and the rows of &lt;code&gt;sensor-c&lt;/code&gt;, are still in &lt;code&gt;nb-1&lt;/code&gt;, untouched. A read then merges both files and keeps the newest answer: the &lt;code&gt;SELECT&lt;/code&gt; returned five rows with &lt;code&gt;temp = 25&lt;/code&gt;. The documentation puts it simply: Cassandra treats a deletion as an insertion.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compaction rewrites the files
&lt;/h2&gt;

&lt;p&gt;If left alone, SSTables pile up, and every read has to look into more of them. Compaction merges them into a new Cassandra SSTable and drops what is out of date. In the lab I disabled automatic compaction on the table, so I could run it by hand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nodetool compact demo readings
141 nb-3-big-Data.db

nodetool compactionhistory
Compaction History: 
id keyspace_name columnfamily_name compacted_at bytes_in bytes_out rows_merged compaction_properties             
f61913d0-d6fb-11f1-97b7-370581990151 demo readings 2026-11-02T21:28:28.031 213 132 {2:3} {compaction_type:Major compaction}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After the compaction, two SSTables of 123 and 90 bytes had become one of 141 bytes. In the history, &lt;code&gt;rows_merged {2:3}&lt;/code&gt; should mean that three partitions were found in two SSTables each (my reading). The history reports 132 bytes written while the &lt;code&gt;Data.db&lt;/code&gt; file is 141 bytes; I did not dig into the gap. The merged file kept the update (25 replaced 21) and dropped the values covered by tombstones, but the tombstones themselves are still there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="n"&gt;sstabledump&lt;/span&gt; &lt;span class="n"&gt;nb&lt;/span&gt;&lt;span class="mi"&gt;-3&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;big&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="n"&gt;Data&lt;/span&gt;&lt;span class="err"&gt;.&lt;/span&gt;&lt;span class="n"&gt;db&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"partition"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"key"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sensor-b"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"rows"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"liveness_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"tstamp"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:26:44.439221Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"temp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;37&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"deletion_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"marked_deleted"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29.783855Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"local_delete_time"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"partition"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"key"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sensor-c"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;74&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"deletion_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"marked_deleted"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29.787731Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"local_delete_time"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"rows"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"partition"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;"key"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"sensor-a"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;97&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"rows"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;97&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"liveness_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"tstamp"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:26:44.426582Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"temp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;111&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"liveness_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"tstamp"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:26:44.432537Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"temp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"tstamp"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29.773920Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;130&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"liveness_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"tstamp"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:26:44.435827Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"temp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;22&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nl"&gt;"type"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"row"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"position"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;145&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"clustering"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"liveness_info"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"tstamp"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T20:27:29.779577Z"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nl"&gt;"cells"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;"name"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"temp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default strategy is size-tiered (STCS), which is what the table used. The documentation also describes leveled (LCS), time-window (TWCS) and unified (UCS) compaction, and recommends UCS for new workloads, but I only ran STCS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the files do not shrink at once
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/inside-database-data-files-cassandra-sstable-commit-log-compaction-5.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8podd78l9fpfvpisoqqr.webp" alt="Cassandra SSTable sizes after a bulk load, deletes, compaction and garbage collection of tombstones" width="800" height="418"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Data.db bytes at each step, and the SSTables of the small test.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A tombstone has to outlive the data it covers, so that every replica learns about the deletion. This is the job of &lt;code&gt;gc_grace_seconds&lt;/code&gt;, ten days by default. The documentation adds that a tombstone is removed only by a compaction after that delay, and only if all the SSTables holding older data take part in the same compaction.&lt;/p&gt;

&lt;p&gt;To see the effect on size, I loaded 60,000 rows into a second table (100 partitions of 600 rows), deleted 90 partitions, and measured the &lt;code&gt;Data.db&lt;/code&gt; files at each step:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;Data.db bytes&lt;/th&gt;
&lt;th&gt;SSTables&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Loaded and flushed&lt;/td&gt;
&lt;td&gt;6,206,495&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After deleting 90 partitions and flushing&lt;/td&gt;
&lt;td&gt;6,207,388&lt;/td&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After nodetool compact&lt;/td&gt;
&lt;td&gt;621,829&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;After gc_grace_seconds = 0 and garbagecollect&lt;/td&gt;
&lt;td&gt;620,584&lt;/td&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The delete made the directory bigger, from 6,221,956 to 6,229,063 bytes, because tombstones are new data. Then the compaction gave the space back, and the data fell from about 6.2 MB to 0.62 MB. The last step removed 1,245 more bytes, which fits the 90 partition tombstones. I did it in the lab like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bulk&lt;/span&gt; &lt;span class="k"&gt;WITH&lt;/span&gt; &lt;span class="n"&gt;gc_grace_seconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;nodetool&lt;/span&gt; &lt;span class="n"&gt;garbagecollect&lt;/span&gt; &lt;span class="n"&gt;demo&lt;/span&gt; &lt;span class="n"&gt;bulk&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do not copy that on a real cluster. If a replica was down while the tombstone existed and the tombstone is purged before that replica comes back, the deleted data can reappear. The documentation calls these zombies. On one node, however, it is safe.&lt;/p&gt;

&lt;p&gt;One detail about the tools: &lt;code&gt;sstablemetadata&lt;/code&gt; estimates droppable tombstones with a grace period of zero unless you pass &lt;code&gt;--gc_grace_seconds&lt;/code&gt;, so it printed 0.0136 by default, and 0.0 when I passed 864000, the real setting of the table.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cassandra next to the three engines
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;InnoDB&lt;/th&gt;
&lt;th&gt;PostgreSQL&lt;/th&gt;
&lt;th&gt;Oracle&lt;/th&gt;
&lt;th&gt;Cassandra&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Unit on disk&lt;/td&gt;
&lt;td&gt;16 KB page&lt;/td&gt;
&lt;td&gt;8 KB page&lt;/td&gt;
&lt;td&gt;8 KB block by default&lt;/td&gt;
&lt;td&gt;an immutable Cassandra SSTable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UPDATE&lt;/td&gt;
&lt;td&gt;in place, old version in undo&lt;/td&gt;
&lt;td&gt;a new tuple version in the table&lt;/td&gt;
&lt;td&gt;in place, before-image in undo&lt;/td&gt;
&lt;td&gt;a new cell with a newer timestamp, in a new SSTable&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;DELETE&lt;/td&gt;
&lt;td&gt;record marked, purged later&lt;/td&gt;
&lt;td&gt;tuple left in place until VACUUM&lt;/td&gt;
&lt;td&gt;row removed in the block, high water mark stays&lt;/td&gt;
&lt;td&gt;a tombstone, a new write&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space comes back with&lt;/td&gt;
&lt;td&gt;a table rebuild&lt;/td&gt;
&lt;td&gt;VACUUM&lt;/td&gt;
&lt;td&gt;SHRINK SPACE or MOVE&lt;/td&gt;
&lt;td&gt;compaction, after gc_grace_seconds&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;None of these choices is better in absolute terms. Cassandra pays for fast, sequential writes with background work: every update leaves an old version behind, and compaction has to clean up later. When you know that, a growing data directory after a big delete stops being a surprise.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This post is part of a series of sysadmin notes (tag “sysadmin notebook”).&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Series “Inside database data files”, part 5/3+2 (bonus). · &lt;a href="https://hecate.neurozone.fr/?p=379" rel="noopener noreferrer"&gt;Part 3/3 and the comparison&lt;/a&gt; · &lt;a href="https://blog.neurozone.fr/?p=5465" rel="noopener noreferrer"&gt;Version française&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Apache Cassandra 5.0 documentation: &lt;a href="https://cassandra.apache.org/doc/5.0/cassandra/architecture/storage-engine.html" rel="noopener noreferrer"&gt;storage engine&lt;/a&gt; (commit log, memtable, SSTable components), &lt;a href="https://cassandra.apache.org/doc/5.0/cassandra/managing/operating/compaction/overview.html" rel="noopener noreferrer"&gt;compaction overview&lt;/a&gt; (strategies, tombstones, &lt;code&gt;gc_grace_seconds&lt;/code&gt;) and the &lt;a href="https://cassandra.apache.org/doc/5.0/cassandra/managing/configuration/cass_yaml_file.html" rel="noopener noreferrer"&gt;&lt;code&gt;cassandra.yaml&lt;/code&gt; reference&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The lab: Rocky Linux 10.2, Apache Cassandra 5.0.9, Temurin Java 17.0.21, WSL2, one node. Tested on one node only.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Related articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=377" rel="noopener noreferrer"&gt;Inside database data files (1/3): InnoDB, from MySQL to MariaDB&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=378" rel="noopener noreferrer"&gt;Inside database data files (2/3): PostgreSQL&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=379" rel="noopener noreferrer"&gt;Inside database data files (3/3): Oracle, and all three side by side&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/19/inside-database-data-files-cassandra-sstable-commit-log-compaction/" rel="noopener noreferrer"&gt;Inside database data files (5/3+2): Cassandra&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>database</category>
      <category>mariadb</category>
      <category>storage</category>
      <category>sysadminnotebook</category>
    </item>
    <item>
      <title>How-to: test your restores automatically every week</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Wed, 18 Nov 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/how-to-test-your-restores-automatically-every-week-4m23</link>
      <guid>https://dev.to/hecate-regnier/how-to-test-your-restores-automatically-every-week-4m23</guid>
      <description>&lt;p&gt;Backups that run every night, logs that say “OK”, an all-green dashboard: none of that proves you’ll be able to restore. Failure causes are many and silent: a configuration file left out of the backup, a hole in the transaction log archive, a major version that changed in the meantime, wrong permissions, a lost encryption key. The only proof a backup works is a successful restore. This article shows how to test restores automatically, once a week.&lt;/p&gt;

&lt;p&gt;This tutorial automates that proof: every week, the latest PostgreSQL backup (pgBackRest) and the latest MariaDB backup (mariadb-backup) are restored into a throwaway Podman container, the instance is started, each database is queried, then everything is destroyed. A message arrives either way. Production is never touched.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/how-to-test-your-restores-automatically-every-week_diagram_en.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fu08gkrhofy9ss9v1y023.webp" alt="Diagram of the weekly restore test: timer, script, Podman container, restore, check, PASSED or FAILED message" width="800" height="419"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The weekly test restores, queries and destroys, and always sends a message.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The rules of the game
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Rule&lt;/th&gt;
&lt;th&gt;Why&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;never touch production&lt;/td&gt;
&lt;td&gt;restore into a scratch directory, container destroyed at the end whatever happens, repository mounted read-only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;the same packages as production&lt;/td&gt;
&lt;td&gt;a physical backup only restores into the same major version, with the same paths&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;a message either way&lt;/td&gt;
&lt;td&gt;a silent test is soon forgotten; a test that fails silently is worse than no test&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;one test at a time&lt;/td&gt;
&lt;td&gt;two simultaneous restores saturate the disk and trip over each other&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;check the contents, not just startup&lt;/td&gt;
&lt;td&gt;an instance that starts on empty databases isn’t a backup&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;h2&gt;
  
  
  Why test restores in a container
&lt;/h2&gt;

&lt;p&gt;You could restore into a directory on the machine and start a second instance on another port. The container adds three things: full isolation (no risk of a test instance writing into production’s files or answering on its port), an environment identical from one week to the next, and cleanup guaranteed by a simple &lt;code&gt;podman rm -f&lt;/code&gt;. Podman runs without a daemon and integrates well with systemd and SELinux.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: images faithful to production
&lt;/h2&gt;

&lt;p&gt;Don’t use the official &lt;code&gt;postgres&lt;/code&gt; or &lt;code&gt;mariadb&lt;/code&gt; images from Docker Hub: they’re built on Debian, with other paths, other build options, sometimes another minor version. The test must use exactly the server’s packages: start from &lt;code&gt;rockylinux:10&lt;/code&gt; and copy &lt;strong&gt;the machine’s own repository files&lt;/strong&gt; rather than rewriting them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Containerfile.postgres&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; rockylinux:10
&lt;span class="k"&gt;COPY&lt;/span&gt; repos/pgdg-redhat-all.repo /etc/yum.repos.d/
&lt;span class="k"&gt;RUN&lt;/span&gt; dnf -y install postgresql18-server pgbackrest &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; dnf clean all
&lt;span class="k"&gt;ENV&lt;/span&gt; &lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/pgsql-18/bin:&lt;span class="nv"&gt;$PATH&lt;/span&gt;

&lt;span class="c"&gt;# Containerfile.mariadb&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; rockylinux:10
&lt;span class="k"&gt;COPY&lt;/span&gt; repos/MariaDB.repo /etc/yum.repos.d/MariaDB.repo
&lt;span class="k"&gt;RUN&lt;/span&gt; dnf -y install MariaDB-server MariaDB-backup MariaDB-client MariaDB-common \
    &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; dnf clean all

podman build -t localhost/restore-test-postgres:18 -f Containerfile.postgres .
podman build -t localhost/restore-test-mariadb:12.3 -f Containerfile.mariadb .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Rebuild the images after every major upgrade of the server, and preferably monthly to track minor versions. A test that restores a PostgreSQL 18 backup into a 17 binary will fail, and that’s good: it caught a gap.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: the common skeleton
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="nb"&gt;set&lt;/span&gt; -uo pipefail
&lt;span class="nv"&gt;DATE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;date +%Y%m%d_%H%M%S&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;SCRATCH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/data/restore-test-scratch/pg-&lt;span class="nv"&gt;$DATE&lt;/span&gt;-&lt;span class="nv"&gt;$$&lt;/span&gt;
&lt;span class="nv"&gt;NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;restore-test-pg-&lt;span class="nv"&gt;$DATE&lt;/span&gt;-&lt;span class="nv"&gt;$$&lt;/span&gt;
&lt;span class="nv"&gt;LOCK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/run/lock/restore-test-pg.lock

notify&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; /usr/local/bin/notify.sh backups &lt;span class="s2"&gt;"PostgreSQL restore test"&lt;/span&gt; &lt;span class="s2"&gt;"$1"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
fail&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; notify &lt;span class="s2"&gt;"FAILED: $1"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; 1&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
cleanup&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; podman rm -f &lt;span class="s2"&gt;"$NAME"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null 2&lt;span class="o"&gt;&amp;gt;&amp;amp;&lt;/span&gt;1 &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; rm -rf &lt;span class="s2"&gt;"$SCRATCH"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;trap&lt;/span&gt; cleanup EXIT INT TERM

&lt;span class="nb"&gt;exec&lt;/span&gt; 9&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;"$LOCK"&lt;/span&gt;
flock -n 9 &lt;span class="o"&gt;||&lt;/span&gt; fail &lt;span class="s2"&gt;"another test is already running"&lt;/span&gt;
mkdir -p &lt;span class="s2"&gt;"$SCRATCH/data"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;set -uo pipefail&lt;/strong&gt; without &lt;code&gt;-e&lt;/code&gt;: we want to handle each error explicitly to send a clear message, not let the script die silently;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;trap cleanup EXIT INT TERM&lt;/strong&gt; : the container and scratch directory are removed whatever happens, including if systemd stops the service at its timeout;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;flock&lt;/strong&gt; : a lock keeps two tests from running at once, for example when a manual run crosses the scheduled one;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;a unique name&lt;/strong&gt; per run (date and process number): an orphan container from a previous test doesn’t block the next.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 3: the PostgreSQL test
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;podman run -d --name &lt;span class="s2"&gt;"$NAME"&lt;/span&gt; \
  -v /data/backup/pgbackrest:/data/backup/pgbackrest:ro,Z \
  -v /etc/pgbackrest/pgbackrest.conf:/etc/pgbackrest/pgbackrest.conf:ro,Z \
  -v &lt;span class="s2"&gt;"$SCRATCH/data"&lt;/span&gt;:/var/lib/pgsql/data:Z \
  localhost/restore-test-postgres:18 sleep infinity &lt;span class="o"&gt;||&lt;/span&gt; fail &lt;span class="s2"&gt;"container start"&lt;/span&gt;

podman &lt;span class="nb"&gt;exec&lt;/span&gt; -u root &lt;span class="s2"&gt;"$NAME"&lt;/span&gt; chown -R postgres:postgres /var/lib/pgsql/data
podman &lt;span class="nb"&gt;exec&lt;/span&gt; -u postgres &lt;span class="s2"&gt;"$NAME"&lt;/span&gt; pgbackrest --stanza=main \
  --pg1-path=/var/lib/pgsql/data --archive-mode=off restore &lt;span class="o"&gt;||&lt;/span&gt; fail &lt;span class="s2"&gt;"pgbackrest restore"&lt;/span&gt;
podman &lt;span class="nb"&gt;exec&lt;/span&gt; -u postgres &lt;span class="s2"&gt;"$NAME"&lt;/span&gt; pg_ctl -D /var/lib/pgsql/data -w -t 900 \
  -o &lt;span class="s2"&gt;"-c archive_mode=off -c port=5432"&lt;/span&gt; start &lt;span class="o"&gt;||&lt;/span&gt; fail &lt;span class="s2"&gt;"PostgreSQL won't start"&lt;/span&gt;

&lt;span class="nv"&gt;dbs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;podman &lt;span class="nb"&gt;exec&lt;/span&gt; -u postgres &lt;span class="s2"&gt;"$NAME"&lt;/span&gt; psql -Atc \
  &lt;span class="s2"&gt;"select datname from pg_database where not datistemplate and datname &amp;lt;&amp;gt; 'postgres'"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;-n &lt;span class="s2"&gt;"$dbs"&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; fail &lt;span class="s2"&gt;"no database restored"&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; db &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$dbs&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nv"&gt;n&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;podman &lt;span class="nb"&gt;exec&lt;/span&gt; -u postgres &lt;span class="s2"&gt;"$NAME"&lt;/span&gt; psql -d &lt;span class="s2"&gt;"$db"&lt;/span&gt; -Atc \
      &lt;span class="s2"&gt;"select count(*) from pg_class c join pg_namespace n on n.oid=c.relnamespace
       where c.relkind='r' and n.nspname not in ('pg_catalog','information_schema')"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
  &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"${n:-0}"&lt;/span&gt; -gt 0&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; fail &lt;span class="s2"&gt;"database $db empty"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
notify &lt;span class="s2"&gt;"PASSED: $(echo $dbs | wc -w) databases restored and checked"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The tricky points
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;read-only repository&lt;/strong&gt; (&lt;code&gt;:ro&lt;/code&gt;): the test can’t damage the backups, even by mistake;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;–archive-mode=off&lt;/strong&gt; on restore and &lt;code&gt;archive_mode=off&lt;/code&gt; at startup: the test instance must never archive its own WAL into the production repository, which would create a stray timeline;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pg_ctl -w -t 900&lt;/strong&gt; : waits up to fifteen minutes for PostgreSQL to replay WAL and accept connections. The time depends on the WAL volume since the last backup; tune it from the first tests’ real duration;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;the checks&lt;/strong&gt; : each database must exist and contain tables. A database with no table after restore is suspect. You can go further with one business query per application (“does the articles table hold at least a thousand rows?”);&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SELinux and volumes&lt;/strong&gt; : the &lt;code&gt;:Z&lt;/code&gt; suffix relabels the directory for the container. Never use it on a directory shared with a service on the machine, it would change its label; in that case, &lt;code&gt;--security-opt label=disable&lt;/code&gt; on that one container is the reasonable option.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 4: the MariaDB test
&lt;/h2&gt;

&lt;p&gt;The principle is the same with a physical &lt;code&gt;mariadb-backup&lt;/code&gt; backup, with a few differences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;prepare before starting&lt;/strong&gt; : a MariaDB physical backup must go through &lt;code&gt;mariadb-backup --prepare&lt;/code&gt;, which applies the redo log copied during the backup. If your backup procedure already does this (preferable), the test starts directly; otherwise the test must do it, on a copy;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;copy, don’t mount&lt;/strong&gt; : MariaDB writes to its files as soon as it starts. So copy the backup into the scratch directory (&lt;code&gt;cp -a&lt;/code&gt;) instead of mounting it read-only;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;the same configuration&lt;/strong&gt; : mount a copy of production’s &lt;code&gt;my.cnf&lt;/code&gt;. If production puts its undo tablespaces (&lt;code&gt;innodb_undo_directory&lt;/code&gt;), binlogs or logs in separate directories, recreate them in the scratch directory and move the matching files there, or InnoDB will refuse to start;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;the mysql user’s id&lt;/strong&gt; : it isn’t necessarily the same in the image and on the machine. Read it from the image (&lt;code&gt;podman run --rm image id -u mysql&lt;/code&gt;) and give it the files;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;the checks&lt;/strong&gt; : &lt;code&gt;mariadb-admin ping&lt;/code&gt; in a loop until the server answers, then for each non-system database, the number of tables and an estimated row count from &lt;code&gt;information_schema.TABLES&lt;/code&gt;. A database with no table or no row fails the test.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 5: schedule
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight systemd"&gt;&lt;code&gt;&lt;span class="c1"&gt;# /etc/systemd/system/restore-test-pgbackrest.timer
&lt;/span&gt;&lt;span class="k"&gt;[Timer]&lt;/span&gt;
&lt;span class="na"&gt;OnCalendar&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nc"&gt;Sun&lt;/span&gt; &lt;span class="o"&gt;*-*-*&lt;/span&gt; &lt;span class="mi"&gt;05&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;
&lt;span class="na"&gt;RandomizedDelaySec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;15min&lt;/span&gt;
&lt;span class="na"&gt;Persistent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="k"&gt;[Install]&lt;/span&gt;
&lt;span class="na"&gt;WantedBy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;timers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;target&lt;/span&gt;

&lt;span class="c1"&gt;# /etc/systemd/system/restore-test-pgbackrest.service
&lt;/span&gt;&lt;span class="k"&gt;[Unit]&lt;/span&gt;
&lt;span class="na"&gt;After&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;pgbackrest&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;full&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;
&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;oneshot&lt;/span&gt;
&lt;span class="na"&gt;ExecStart&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="n"&gt;usr&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;bin&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;restore&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;pgbackrest&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sh&lt;/span&gt;
&lt;span class="na"&gt;TimeoutStartSec&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3h&lt;/span&gt;
&lt;span class="na"&gt;Nice&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="na"&gt;IOSchedulingClass&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;idle&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Sunday 5 am&lt;/strong&gt; : after Sunday’s full backup, to test the freshest one;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persistent=true&lt;/strong&gt; : catches up a missed test if the machine was off;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TimeoutStartSec=3h&lt;/strong&gt; : a stuck test is eventually killed, and the &lt;code&gt;trap&lt;/code&gt; cleans up;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nice and IOSchedulingClass=idle&lt;/strong&gt; : the test yields priority to services. It takes longer, but nobody notices.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Step 6: the notification
&lt;/h2&gt;

&lt;p&gt;The message must arrive in both cases and say something useful: which backup was tested, how many databases, and on failure, the failing step and the log path. A &lt;code&gt;notify.sh&lt;/code&gt; script shared by all services (email, Mattermost, ntfy, whatever) avoids duplicating that code. A test that passes every Sunday ends up as background noise: that’s intended. The day the message is missing, or says something else, you notice.&lt;/p&gt;

&lt;p&gt;Add a monitoring alert on the absence of a recent success: if no “PASSED” message has arrived in ten days, something is wrong even if no failure was reported (timer disabled, machine off, script deleted).&lt;/p&gt;

&lt;h3&gt;
  
  
  Last Sunday’s run
&lt;/h3&gt;

&lt;p&gt;The two tests as they ran on Sunday 1 November 2026 on my home server, from their log files (excerpts; pgBackRest logs in UTC, the script in local time, hence the one-hour gap):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[2026-11-01 05:00:04] Starting pgbackrest restore-test for stanza 'main'
[2026-11-01 05:00:04] Stanza 'main' has 25 backup(s) on record — proceeding with restore
04:00:05.311 P00 INFO: repo1: restore backup set 20261101-010003F, recovery will start at 2026-11-01 00:00:03
04:05:51.113 P00 INFO: restore size = 93.5MB, file total = 5756
04:05:51.114 P00 INFO: restore command end: completed successfully (345892ms)
[2026-11-01 05:05:57] PostgreSQL is ready (took ~6s)
[2026-11-01 05:05:57] Found 4 database(s): forgejo semaphore paperless netbox
[2026-11-01 05:05:58] forgejo: 131 table(s) — OK
[2026-11-01 05:05:58] netbox: 208 table(s) — OK
[2026-11-01 05:05:58] pgbackrest restore-test PASSED — 4 database(s) restored and verified non-empty

[2026-11-01 06:30:26] blog_flo_wp: 93 table(s), ~568925 row(s) — OK
[2026-11-01 06:30:32] piwigo: 35 table(s), ~1008323 row(s) — OK
[2026-11-01 06:30:38] wiki: 41 table(s), ~1440630 row(s) — OK
[2026-11-01 06:30:38] MariaDB restore-test PASSED — 21 database(s) restored and verified non-empty (backup: 20261101_020001)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The restore took 5 min 46 s for 93.5 MB&lt;/strong&gt; : that’s the useful number: it’s roughly what a real restore of that database would cost, measured every week instead of guessed on the day.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PostgreSQL ready in 6 s&lt;/strong&gt; : the restored cluster replayed its WAL and accepted connections, which is the real proof the backup is consistent, not just complete.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tables counted per database&lt;/strong&gt; : an empty or truncated database fails the test even if the restore itself “succeeded”.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Row counts with a tilde&lt;/strong&gt; on the MariaDB side: they come from the statistics (&lt;code&gt;information_schema&lt;/code&gt;), fast but approximate. Good enough to catch an empty table, not to compare two backups exactly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What the test proves, and what it doesn’t
&lt;/h2&gt;

&lt;p&gt;It proves the backup is complete and readable, that the log archive is continuous up to the backup, that an instance of the right version starts on it, and that each database holds data. That’s already a lot: most backups that fail on the day fail on one of these points.&lt;/p&gt;

&lt;p&gt;It doesn’t prove that the application works on that data, that point-in-time recovery lands at the right moment, or that you can run the procedure under pressure at 3 am. For that, nothing replaces a full manual drill once or twice a year: restore onto a blank machine, reconnect an application, stopwatch in hand, following the written documentation. The gaps in the documentation always show up then.&lt;/p&gt;

&lt;h2&gt;
  
  
  What about other data?
&lt;/h2&gt;

&lt;p&gt;The same principle applies to application files (attachments, media, Git repositories): once a month, extract the latest archive into a temporary directory, check it isn’t truncated, that the expected files are there and that their number hasn’t suddenly dropped. Less spectacular than a database, but just as valuable.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This post is part of a series of sysadmin tutorials (tag “how-to”).&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Series “How-to”, tutorial 13/77. · &lt;a href="https://hecate.neurozone.fr/?p=621" rel="noopener noreferrer"&gt;← Previous tutorial&lt;/a&gt; · Next tutorial → (coming 23 Nov) · &lt;a href="https://blog.neurozone.fr/?p=2067" rel="noopener noreferrer"&gt;Version française&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Related articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=621" rel="noopener noreferrer"&gt;PostgreSQL backups with pgBackRest&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=596" rel="noopener noreferrer"&gt;The MariaDB settings that really matter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=378" rel="noopener noreferrer"&gt;PostgreSQL data files, from the inside&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/18/how-to-test-your-restores-automatically-every-week/" rel="noopener noreferrer"&gt;How-to: test your restores automatically every week&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>backup</category>
      <category>sysadminnotebook</category>
      <category>english</category>
      <category>howto</category>
    </item>
    <item>
      <title>How-to: back up PostgreSQL with pgBackRest and restore to the second</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Mon, 16 Nov 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/how-to-back-up-postgresql-with-pgbackrest-and-restore-to-the-second-1i90</link>
      <guid>https://dev.to/hecate-regnier/how-to-back-up-postgresql-with-pgbackrest-and-restore-to-the-second-1i90</guid>
      <description>&lt;p&gt;pgBackRest combines physical copies of the PostgreSQL files with continuous archiving of the WAL, so you can restore the instance to any second between the oldest backup kept and now. This tutorial sets it up on PostgreSQL 18 (PGDG repository, Rocky Linux), schedules it, then walks through a real point-in-time restore.&lt;/p&gt;

&lt;p&gt;A nightly pg_dump is better than nothing, but it has two serious flaws: it can lose up to twenty-four hours of data, and it can’t take you back to "just before the DELETE without WHERE at 2:59 pm". On a large database it’s also slow to produce and very slow to reload, indexes included.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/how-to-back-up-postgresql-with-pgbackrest-and-restore-to-the-second_diagram_en.webp" rel="noopener noreferrer"&gt;&lt;img width="799" height="409" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fhecate.neurozone.fr%2Fwp-content%2Fuploads%2F2026%2F11%2Fhow-to-back-up-postgresql-with-pgbackrest-and-restore-to-the-second_diagram_en.webp" alt="Diagram of pgBackRest: PostgreSQL archives WAL to a repository, then a four-step restore to 2:59 pm"&gt;&lt;/a&gt;Backups plus continuous WAL archiving let you restore to any second.&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;The principle in two sentences&lt;/h2&gt;

&lt;p&gt;PostgreSQL writes every change to the WAL before applying it to the data files. If you have a copy of the files taken at time T and all the WAL produced since, you can replay that WAL onto the copy and stop wherever you like.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Contents&lt;/th&gt;
&lt;th&gt;To restore you need&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;full&lt;/td&gt;
&lt;td&gt;every file of the instance&lt;/td&gt;
&lt;td&gt;this backup + WAL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;differential (diff)&lt;/td&gt;
&lt;td&gt;files changed since the last full&lt;/td&gt;
&lt;td&gt;the full + this diff + WAL&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;incremental (incr)&lt;/td&gt;
&lt;td&gt;files changed since the last backup of any kind&lt;/td&gt;
&lt;td&gt;the full + the whole chain + WAL&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Incrementals are smaller but make the chain fragile: losing one link makes all the following ones unusable. A full a week and a differential a day is a good balance for a database of a few tens of gigabytes.&lt;/p&gt;

&lt;h2&gt;Step 1: install&lt;/h2&gt;

&lt;pre&gt;dnf install pgbackrest            # from the PGDG repository, like PostgreSQL
pgbackrest version
install -d -o postgres -g postgres -m 750 /data/backup/pgbackrest /var/log/pgbackrest&lt;/pre&gt;

&lt;p&gt;pgBackRest runs as the &lt;code&gt;postgres&lt;/code&gt; user: the repository and log directory must belong to it. Under SELinux, if the repository is outside the usual paths, check that PostgreSQL (the &lt;code&gt;postgresql_t&lt;/code&gt; domain) may write there during archiving: a SELinux denial blocks archiving with no other symptom than a growing &lt;code&gt;pg_wal&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;Step 2: pgBackRest’s configuration&lt;/h2&gt;

&lt;pre&gt;# /etc/pgbackrest/pgbackrest.conf
[global]
repo1-path=/data/backup/pgbackrest
repo1-retention-full=2
repo1-retention-diff=14
compress-type=lz4
compress-level=6
log-level-console=warn
log-level-file=info
log-path=/var/log/pgbackrest
start-fast=y
delta=y

[main]
pg1-path=/data/postgresql/18/data
pg1-port=5432&lt;/pre&gt;

&lt;h3&gt;The [global] section&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;repo1-path&lt;/strong&gt;: the repository, here on a local disk. pgBackRest can also write straight to S3, Azure, GCS or another server over SFTP; to start, a local disk copied elsewhere every night will do;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;repo1-retention-full=2&lt;/strong&gt;: keep two full backups. When a third one completes successfully, the oldest is removed, with its differentials and the WAL only it needed. The restore window is therefore one to two weeks;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;repo1-retention-diff=14&lt;/strong&gt;: the number of differentials kept; it must cover at least the interval between two fulls;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;compress-type=lz4&lt;/strong&gt;: lz4 compresses a little less than zstd but much faster, which shortens both backup and restore;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;log-level-console / log-level-file&lt;/strong&gt;: little noise on screen, details in &lt;code&gt;/var/log/pgbackrest&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;start-fast=y&lt;/strong&gt;: triggers an immediate checkpoint at the start of the backup instead of waiting for the next one, which may be minutes away;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;delta=y&lt;/strong&gt;: on restore, pgBackRest compares the files present with the backup’s (by checksum) and only copies those that differ. On a large instance, that’s the difference between an hour and a few minutes.&lt;/p&gt;

&lt;h3&gt;The [main] section&lt;/h3&gt;

&lt;p&gt;That’s the &lt;strong&gt;stanza&lt;/strong&gt;: one PostgreSQL instance to back up, under a name of your choice. &lt;code&gt;pg1-path&lt;/code&gt; is its data directory, &lt;code&gt;pg1-port&lt;/code&gt; its port. Several instances on the same machine make several stanzas.&lt;/p&gt;

&lt;h2&gt;Step 3: wiring in WAL archiving&lt;/h2&gt;

&lt;pre&gt;# postgresql.conf
wal_level        = replica
archive_mode     = on
archive_command  = 'pgbackrest --stanza=main archive-push %p'
archive_timeout  = 300
max_wal_senders  = 3&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;wal_level = replica&lt;/strong&gt;: the WAL holds enough information to rebuild the instance (the default in recent versions);&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;archive_mode = on&lt;/strong&gt;: turns archiving on. This setting needs a restart;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;archive_command&lt;/strong&gt;: the command run for each completed WAL segment (16 MB). &lt;code&gt;%p&lt;/code&gt; is the segment’s path;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;archive_timeout = 300&lt;/strong&gt;: forces a segment switch every five minutes even if the segment isn’t full. On a quiet database, without it, the last transactions can sit for hours in an unarchived segment: that much data lost if the server disappears.&lt;/p&gt;

&lt;p&gt;If archiving fails, PostgreSQL loses nothing: it keeps the segment and retries. But &lt;code&gt;pg_wal/&lt;/code&gt; then grows until it fills the disk, and the instance stops. &lt;strong&gt;That’s the failure to watch first&lt;/strong&gt;, for example with the &lt;code&gt;pg_stat_archiver&lt;/code&gt; view:&lt;/p&gt;

&lt;pre&gt;SELECT archived_count, last_archived_time, failed_count, last_failed_time, last_failed_wal
FROM pg_stat_archiver;&lt;/pre&gt;

&lt;p&gt;An alert on a too-old &lt;code&gt;last_archived_time&lt;/code&gt; (over ten minutes with &lt;code&gt;archive_timeout = 300&lt;/code&gt;) or a growing &lt;code&gt;failed_count&lt;/code&gt; warns you long before the disk is full.&lt;/p&gt;

&lt;h2&gt;Step 4: create the stanza and check&lt;/h2&gt;

&lt;pre&gt;systemctl restart postgresql-18
sudo -u postgres pgbackrest --stanza=main stanza-create
sudo -u postgres pgbackrest --stanza=main check
sudo -u postgres pgbackrest --stanza=main --type=full backup
sudo -u postgres pgbackrest info&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;check&lt;/code&gt; forces a segment switch and waits to see it land in the repository: it’s the end-to-end archiving test. &lt;code&gt;info&lt;/code&gt; shows the backups, their size and the available WAL range:&lt;/p&gt;

&lt;pre&gt;stanza: main
    status: ok
    wal archive min/max (18): 000000010000002A00000031/000000010000002C0000009E

    full backup: 20261101-010002F
        timestamp start/stop: 2026-11-01 01:00:02+01 / 2026-11-01 01:12:47+01
        database size: 41.2GB, database backup size: 41.2GB
        repo1: backup size: 9.8GB&lt;/pre&gt;

&lt;h3&gt;A real repository, two months in&lt;/h3&gt;

&lt;p&gt;The repository of my web server’s PostgreSQL 18 on 2 November 2026, summarised from &lt;code&gt;pgbackrest info --output=json&lt;/code&gt; (the text output lists every backup, oldest first):&lt;/p&gt;

&lt;pre&gt;status ok | wal 000000010000010C00000079 -&amp;gt; 000000010000010F000000DF
label                               type  start        took  db size  changed   stored
20261025-010001F_20261030-020003D   diff  10-30 02:00  128 s  6.6 GB   36.8 MB   12.4 MB
20261025-010001F_20261031-020002D   diff  10-31 02:00  136 s  6.6 GB   39.0 MB   12.9 MB
20261101-010006F                    full  11-01 01:00  370 s  6.6 GB  6710.8 MB  455.5 MB
20261101-010006F_20261102-020003D   diff  11-02 02:00  131 s  6.6 GB   32.0 MB   11.6 MB
backups in repo: 11

# time sudo -u postgres pgbackrest --stanza=main check
real    0m0.500s&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;6.6 GB of database, 455 MB in the repository&lt;/strong&gt; for a full backup: compression divides the size by about fifteen here; PostgreSQL data files, full of page headers and partly empty pages, compress very well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Differential backups of 32–39 MB&lt;/strong&gt;, stored as 12 MB: only the files changed since the last full are copied. Each diff depends on one full only, never on another diff, so losing one diff costs nothing else.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The label tells the lineage&lt;/strong&gt;: &lt;code&gt;20261101-010006F_20261102-020003D&lt;/code&gt; is a diff (D) taken on 2 November, based on the full (F) of 1 November.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The WAL range&lt;/strong&gt; goes back to the oldest backup kept: any point between 25 October and now can be restored, to the second.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;check in half a second&lt;/strong&gt;, silent, exit code 0: the archive command works and the repository answers. Put it in monitoring, not just in the installation notes.&lt;/p&gt;

&lt;h2&gt;Step 5: schedule&lt;/h2&gt;

&lt;pre&gt;# /etc/systemd/system/pgbackrest-full.service
[Unit]
Description=pgBackRest full backup
After=postgresql-18.service
[Service]
Type=oneshot
User=postgres
ExecStart=/usr/bin/pgbackrest --stanza=main --type=full backup

# /etc/systemd/system/pgbackrest-full.timer
[Timer]
OnCalendar=Sun *-*-* 01:00:00
Persistent=true
[Install]
WantedBy=timers.target

# pgbackrest-diff.service / .timer : identical with --type=diff
# and OnCalendar=Mon..Sat *-*-* 02:00:00&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;Persistent=true&lt;/code&gt; catches up a missed backup if the server was off at the scheduled time. Add a failure notification (&lt;code&gt;OnFailure=&lt;/code&gt; pointing to a unit that sends a message): a backup that fails silently for three weeks is an unpleasant discovery on the day you need it.&lt;/p&gt;

&lt;h2&gt;Step 6: getting the repository off the server&lt;/h2&gt;

&lt;p&gt;A repository on the same server protects against human and software mistakes, not against losing the server. Copy it elsewhere every night, after the backup: an &lt;code&gt;rsync&lt;/code&gt; to another machine, or a second pgBackRest repository (&lt;code&gt;repo2-…&lt;/code&gt;) on object storage. The second repository is more elegant: pgBackRest archives WAL to it in parallel and handles retention itself.&lt;/p&gt;

&lt;h2&gt;Step 7: restoring to just before the mistake&lt;/h2&gt;

&lt;p&gt;Scenario: at 3:00 pm, someone notices that a query run at 2:59 and a few seconds emptied a table. We want to go back to 2:59 sharp.&lt;/p&gt;

&lt;pre&gt;systemctl stop postgresql-18
sudo -u postgres pgbackrest --stanza=main --delta \
    --type=time "--target=2026-11-12 14:59:00+01" \
    --target-action=pause restore
systemctl start postgresql-18
sudo -u postgres psql -c "SELECT pg_is_in_recovery(), now()"
# check the data, then:
sudo -u postgres psql -c "SELECT pg_wal_replay_resume()"&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;–type=time&lt;/strong&gt; and &lt;strong&gt;–target&lt;/strong&gt;: the restore target. &lt;strong&gt;Always give the time zone&lt;/strong&gt;: without it, the time is read in the session’s zone, and a one- or two-hour shift either replays the mistake or loses the morning’s work;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;–target-action=pause&lt;/strong&gt;: PostgreSQL stops at the target, read-only. You can calmly check that the table is back and nothing legitimate is missing, then open the instance with &lt;code&gt;pg_wal_replay_resume()&lt;/code&gt;. &lt;code&gt;promote&lt;/code&gt; opens it straight away, without that check;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;–delta&lt;/strong&gt;: only copies changed files, so the restore is much faster;&lt;/p&gt;

&lt;p&gt;pgBackRest picks the starting backup itself (the latest one before the target); PostgreSQL then replays WAL up to the target, and starts a new &lt;em&gt;timeline&lt;/em&gt;: WAL produced after the mistake stays in the repository but will never be replayed on this new branch.&lt;/p&gt;

&lt;p&gt;Other possible targets: &lt;code&gt;--type=xid&lt;/code&gt; (a transaction number), &lt;code&gt;--type=lsn&lt;/code&gt; (an exact WAL position), &lt;code&gt;--type=name&lt;/code&gt; (a named point created before a risky operation with &lt;code&gt;SELECT pg_create_restore_point('before_migration')&lt;/code&gt;). Get into the habit of creating a named point before every schema migration: restoring becomes trivial.&lt;/p&gt;

&lt;h2&gt;Recovering a single database, or a single table&lt;/h2&gt;

&lt;p&gt;pgBackRest restores a whole instance. To recover a single database without touching production, restore onto another machine, or into another directory on another port (&lt;code&gt;--pg1-path=/srv/restore&lt;/code&gt; and &lt;code&gt;port = 5499&lt;/code&gt; in its &lt;code&gt;postgresql.conf&lt;/code&gt;), at the desired time. Then extract the database or table with &lt;code&gt;pg_dump -t&lt;/code&gt; and load it into production. It takes longer, but production is never stopped.&lt;/p&gt;

&lt;h2&gt;Common failures&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;“archive-push” failing&lt;/strong&gt;: repository permissions, full disk, or a SELinux denial. &lt;code&gt;pg_stat_archiver&lt;/code&gt; and &lt;code&gt;/var/log/pgbackrest/main-archive-push-async.log&lt;/code&gt; tell you;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“WAL segment … not found” on restore&lt;/strong&gt;: a hole in the archive, often because archiving was disabled for a while. Only the latest full backup taken after the hole is safe; run one immediately;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;restore that doesn’t stop at the right time&lt;/strong&gt;: the time zone, again. Compare with &lt;code&gt;SHOW timezone&lt;/code&gt;;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“stanza-upgrade” after a PostgreSQL major upgrade&lt;/strong&gt;: pgBackRest refuses to go on until told about the new version. Run &lt;code&gt;stanza-upgrade&lt;/code&gt;, then a full backup immediately.&lt;/p&gt;

&lt;p&gt;And above all: test restores regularly, automatically if possible. That’s the subject of the next tutorial in the series. A backup that has never been restored is only a hypothesis.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;This post is part of a series of sysadmin tutorials (tag “how-to”).&lt;/em&gt;&lt;br&gt;Series “How-to”, tutorial 12/77. · &lt;a href="https://hecate.neurozone.fr/?p=620" rel="noopener noreferrer"&gt;← Previous tutorial&lt;/a&gt; · &lt;span&gt;Next tutorial → (coming 18 Nov)&lt;/span&gt; · &lt;a href="https://blog.neurozone.fr/?p=2066" rel="noopener noreferrer"&gt;Version française&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Official documentation&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://pgbackrest.org/" rel="noopener noreferrer"&gt;pgBackRest&lt;/a&gt;, project site&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pgbackrest.org/user-guide-rhel.html" rel="noopener noreferrer"&gt;pgBackRest user guide for RHEL&lt;/a&gt;, install, backup and restore&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pgbackrest.org/configuration.html" rel="noopener noreferrer"&gt;pgBackRest configuration reference&lt;/a&gt;, every option&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.postgresql.org/docs/18/continuous-archiving.html" rel="noopener noreferrer"&gt;Continuous archiving and point-in-time recovery&lt;/a&gt;, PostgreSQL 18 documentation&lt;/p&gt;

&lt;h2&gt;Related articles&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=378" rel="noopener noreferrer"&gt;PostgreSQL data files, from the inside&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=596" rel="noopener noreferrer"&gt;The MariaDB settings that really matter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=377" rel="noopener noreferrer"&gt;InnoDB data files, from MySQL to MariaDB&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/16/how-to-back-up-postgresql-with-pgbackrest-and-restore-to-the-second/" rel="noopener noreferrer"&gt;How-to: back up PostgreSQL with pgBackRest and restore to the second&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>backup</category>
      <category>sysadminnotebook</category>
      <category>english</category>
      <category>howto</category>
    </item>
    <item>
      <title>How-to: Suricata as an IPS with NFQUEUE, without breaking your server</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Mon, 09 Nov 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/how-to-suricata-as-an-ips-with-nfqueue-without-breaking-your-server-3hf5</link>
      <guid>https://dev.to/hecate-regnier/how-to-suricata-as-an-ips-with-nfqueue-without-breaking-your-server-3hf5</guid>
      <description>&lt;p&gt;Start Suricata in IDS mode, and move to IPS with NFQUEUE only once you can read its alerts and have removed the noisiest false positives. In IPS mode Suricata sits in the path of every packet, and one of the failures described below silently blocked local connections for weeks. This tutorial installs it as an IPS on an Internet-facing Rocky Linux server.&lt;/p&gt;

&lt;p&gt;Suricata is a network intrusion detection engine: it examines packets entering and leaving a machine, reassembles connections, understands protocols (HTTP, TLS, DNS, SSH…) and matches the whole against tens of thousands of rules describing known attacks. In IPS mode it can also block: a packet that matches a drop rule never reaches its destination.&lt;/p&gt;

&lt;p&gt;NFQUEUE is the most useful mode on a standalone server, and also the most delicate, so I describe in detail the failures I ran into.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/how-to-suricata-as-an-ips-on-rocky-linux-without-breaking-yo_diagram_en.webp" rel="noopener noreferrer"&gt;&lt;img width="800" height="391" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fhecate.neurozone.fr%2Fwp-content%2Fuploads%2F2026%2F11%2Fhow-to-suricata-as-an-ips-on-rocky-linux-without-breaking-yo_diagram_en.webp" alt="Packet path through firewalld, NFQUEUE and Suricata, four key settings and the loopback lesson"&gt;&lt;/a&gt;The path of a packet, the settings that matter, and the loopback lesson.&lt;p&gt;&lt;/p&gt;

&lt;h2&gt;IDS or IPS&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;&lt;tr&gt;
&lt;th&gt;Mode&lt;/th&gt;
&lt;th&gt;How it works&lt;/th&gt;
&lt;th&gt;Risk&lt;/th&gt;
&lt;/tr&gt;&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;IDS (af-packet)&lt;/td&gt;
&lt;td&gt;Suricata gets a &lt;em&gt;copy&lt;/em&gt; of packets and alerts&lt;/td&gt;
&lt;td&gt;none for traffic: at worst, missed alerts&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;IPS (NFQUEUE)&lt;/td&gt;
&lt;td&gt;the kernel &lt;em&gt;hands&lt;/em&gt; each packet to Suricata, which accepts or drops it&lt;/td&gt;
&lt;td&gt;Suricata is in the path: a mistake blocks traffic&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;Step 1: install&lt;/h2&gt;

&lt;pre&gt;dnf install epel-release
dnf install suricata
suricata --build-info | grep -E 'NFQueue|AF_PACKET'   # both must be "yes"&lt;/pre&gt;

&lt;p&gt;Two kernel modules are needed for NFQUEUE: &lt;code&gt;nfnetlink_queue&lt;/code&gt; (the queue itself) and &lt;code&gt;xt_NFQUEUE&lt;/code&gt; (the target used by the firewall rules). The second is often forgotten: the rule then fails with an unclear message about a missing module. Load them and make them permanent:&lt;/p&gt;

&lt;pre&gt;modprobe nfnetlink_queue
modprobe xt_NFQUEUE
printf 'nfnetlink_queue\nxt_NFQUEUE\n' &amp;gt; /etc/modules-load.d/nfqueue.conf&lt;/pre&gt;

&lt;h2&gt;Step 2: suricata.yaml, the essentials&lt;/h2&gt;

&lt;pre&gt;# /etc/suricata/suricata.yaml (excerpts)
vars:
  address-groups:
    HOME_NET: "[203.0.113.25/32,2001:db8::25/128]"
    EXTERNAL_NET: "!$HOME_NET"

nfq:
  mode: accept
  fail-open: yes

flow-timeouts:
  tcp:
    established: 7200

stream:
  memcap: 256mb
  midstream: true
  reassembly:
    memcap: 512mb
    depth: 1mb

outputs:
  - eve-log:
      enabled: yes
      filename: eve.json
      types: [alert, drop, anomaly, stats]&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;HOME_NET&lt;/strong&gt;: the addresses you protect. Many rules depend on it (“traffic from outside to HOME_NET”); a wrong value gives both false positives and missed attacks;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;nfq.mode: accept&lt;/strong&gt;: Suricata gives its verdict (accept or drop) and the packet then continues its normal path through the firewall;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;fail-open: yes&lt;/strong&gt;: if the queue overflows because Suricata can’t keep up, packets pass instead of being dropped. On a standalone server, better to let a few packets through uninspected than cut the service;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;flow-timeouts.tcp.established: 7200&lt;/strong&gt;: the point that cost me the most, detailed below. By default Suricata forgets an idle TCP connection after an hour; a connection that stays open longer without traffic sees its next packets treated as “out of connection”, and sometimes dropped;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;midstream: true&lt;/strong&gt;: Suricata agrees to pick up a connection whose start it didn’t see, for example after its own restart. Without it, every connection established before startup is considered invalid;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;memcap&lt;/strong&gt;: memory ceilings for flow tracking and data reassembly. Too low, and Suricata gives up inspecting connections under load; watch the &lt;code&gt;memcap&lt;/code&gt; counters in the statistics;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;eve.json&lt;/strong&gt;: the structured log, one JSON line per event. This is the file you ship to a SIEM.&lt;/p&gt;

&lt;h2&gt;Step 3: rules&lt;/h2&gt;

&lt;pre&gt;suricata-update                      # downloads the ET Open set (free)
suricata-update list-sources
suricata-update enable-source et/open
ls -l /var/lib/suricata/rules/suricata.rules&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;suricata-update&lt;/code&gt; assembles every rule into one file, applying your modification files. Two of them are essential in IPS mode:&lt;/p&gt;

&lt;pre&gt;# /etc/suricata/drop.conf : these rule families block instead of alerting
re:classtype:trojan-activity
re:classtype:command-and-control
re:classtype:domain-c2
re:classtype:exploit-kit
re:classtype:coin-mining

# /etc/suricata/disable.conf : industrial protocols not present here
re:dnp3
re:modbus&lt;/pre&gt;

&lt;p&gt;By default every rule only &lt;strong&gt;alerts&lt;/strong&gt;. &lt;code&gt;drop.conf&lt;/code&gt; turns into blocks the rules whose category leaves no doubt: command-and-control traffic, trojans, cryptocurrency mining. Don’t turn everything into a block: a generic “suspicious traffic” rule triggered by a legitimate application cuts that application without warning. &lt;code&gt;disable.conf&lt;/code&gt; removes useless rules, saving memory and CPU.&lt;/p&gt;

&lt;p&gt;Schedule a daily update with a systemd timer that runs &lt;code&gt;suricata-update&lt;/code&gt;, then asks Suricata to reload its rules without restarting (&lt;code&gt;suricatasc -c reload-rules&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;Step 4: sending traffic to Suricata&lt;/h2&gt;

&lt;p&gt;The service reads queue 0:&lt;/p&gt;

&lt;pre&gt;# /etc/systemd/system/suricata.service.d/ips.conf
[Service]
ExecStart=
ExecStart=/usr/sbin/suricata -c /etc/suricata/suricata.yaml -q 0 --pidfile /var/run/suricata.pid&lt;/pre&gt;

&lt;p&gt;Then the firewall rules, with firewalld in “direct” mode:&lt;/p&gt;

&lt;pre&gt;# 1. loopback never goes through Suricata (priority -1: before anything)
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT  -1 -i lo -j ACCEPT
firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT -1 -o lo -j ACCEPT
# 2. everything else is handed to queue 0; --queue-bypass: if Suricata is stopped, traffic flows
firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT   0 -j NFQUEUE --queue-num 0 --queue-bypass
firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT  0 -j NFQUEUE --queue-num 0 --queue-bypass
firewall-cmd --permanent --direct --add-rule ipv4 filter FORWARD 0 -j NFQUEUE --queue-num 0 --queue-bypass
# same rules for ipv6
firewall-cmd --reload&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;–queue-bypass&lt;/strong&gt;: without it, if Suricata is stopped or crashes, no packet passes at all, SSH included. With it, the kernel lets traffic through when nobody listens on the queue. That’s the line that saves you from calling the provider’s rescue console;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;loopback excluded&lt;/strong&gt;: the most expensive lesson of this tutorial, detailed below;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;order&lt;/strong&gt;: direct rules with priority -1 go before priority 0.&lt;/p&gt;

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

&lt;p&gt;For six weeks, a service on my server (a task queue talking to Redis on &lt;code&gt;127.0.0.1&lt;/code&gt;) froze at irregular intervals, always for exactly 31 minutes and 40 seconds, then recovered. The application’s logs showed nothing, nor did Redis’s. The cause: Suricata was also inspecting loopback traffic. A long idle connection outlived the flow-tracking timeout; when it woke up, its packets belonged to no connection Suricata knew, so it dropped them, and you had to wait for TCP to give up and reconnect.&lt;/p&gt;

&lt;p&gt;The diagnosis came from &lt;code&gt;eve.json&lt;/code&gt;: every dropped packet appears there with its reason.&lt;/p&gt;

&lt;pre&gt;jq -c 'select(.event_type=="drop") | {timestamp, src_ip, dest_ip, dest_port, reason: .drop.reason}' /var/log/suricata/eve.json | tail&lt;/pre&gt;

&lt;p&gt;Three fixes, all needed: exclude loopback (traffic between processes on the same machine has no business in an IPS), raise the TCP timeout to two hours, and enable &lt;code&gt;midstream&lt;/code&gt;. Remember the symptom: a long connection that freezes for a fixed, reproducible time with no error anywhere is almost always a middlebox (firewall, IPS, address translation) that forgot the connection.&lt;/p&gt;

&lt;h2&gt;The network card trap&lt;/h2&gt;

&lt;p&gt;Modern cards and drivers merge several packets into one “superpacket” before handing them to the kernel (GRO, LRO). Suricata then sees packets bigger than the network’s real size, which skews its connection reassembly. Turn these optimisations off on the monitored interface, permanently, through NetworkManager rather than a plain &lt;code&gt;ethtool -K&lt;/code&gt; that would be undone at the next reconnect:&lt;/p&gt;

&lt;pre&gt;nmcli connection modify eth0 ethtool.feature-gro off ethtool.feature-lro off \
    ethtool.feature-gso off ethtool.feature-tso off
nmcli connection up eth0
ethtool -k eth0 | grep -E 'generic-receive|large-receive'&lt;/pre&gt;

&lt;h2&gt;Step 5: start and check&lt;/h2&gt;

&lt;pre&gt;suricata -T -c /etc/suricata/suricata.yaml        # test configuration and rules
systemctl enable --now suricata
tail -f /var/log/suricata/suricata.log            # "engine started"
curl -s http://testmynids.org/uid/index.html      # must fire alert 2100498
jq -c 'select(.event_type=="alert") | .alert.signature' /var/log/suricata/eve.json | tail -3&lt;/pre&gt;

&lt;p&gt;Also check that normal traffic still flows: new SSH connection, website, sending mail, DNS resolution. Then watch the statistics for a few days:&lt;/p&gt;

&lt;pre&gt;jq -c 'select(.event_type=="stats") | .stats | {drop: .ips.blocked, memcap: .tcp.ssn_memcap_drop, kernel: .capture}' /var/log/suricata/eve.json | tail -1&lt;/pre&gt;

&lt;h2&gt;The same counters on a production server&lt;/h2&gt;

&lt;p&gt;Suricata 8.0.8 in IPS mode on my web server, read through the control socket on 2 November 2026 after 75 minutes of uptime. &lt;code&gt;suricatasc&lt;/code&gt; gives the live counters without waiting for the next stats line in eve.json:&lt;/p&gt;

&lt;pre&gt;# suricatasc -c iface-list
{"message": {"count": 1, "ifaces": ["NFQ#0"]}, "return": "OK"}

# suricatasc -c ruleset-stats
[{"id": 0, "rules_loaded": 53325, "rules_failed": 0, "rules_skipped": 0}]

# suricatasc -c dump-counters | jq '.message | {uptime, ips, alerts: .detect.alert}'
uptime        4544 s
ips.accepted  2 076 277
ips.blocked   771
  drop_reason.stream_error    769
  drop_reason.applayer_error  2
  drop_reason.rules           0
alerts        23&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;NFQ#0&lt;/strong&gt;: Suricata is attached to netfilter queue 0, so it sees packets inline and can drop them. In IDS mode this list would show a network interface instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;53 325 rules loaded, 0 failed&lt;/strong&gt;: a non-zero &lt;em&gt;rules_failed&lt;/em&gt; usually means a rule needs a keyword your version doesn’t know, after an update of either the rules or the engine.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;771 packets blocked, 769 for stream_error, 0 by rules&lt;/strong&gt;: that’s the normal picture on a web server. Rule drops are rare; most drops are packets that make no sense for the TCP stream they claim to belong to (retransmissions after the connection closed, bad sequence numbers, invalid checksums). If this number climbs suddenly, look at the &lt;code&gt;drop&lt;/code&gt; events in eve.json: the loopback lesson above started as exactly that kind of spike.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;23 alerts&lt;/strong&gt; in 75 minutes, none of them blocking: protocol anomalies (excessive SYNs on one handshake, mismatched application protocols, invalid timestamps) logged for the SIEM. Yet 23 665 of the loaded rules are set to drop, by class (trojans, command-and-control, exploit kits, miners…) through &lt;code&gt;drop.conf&lt;/code&gt;: in this hour, none of them matched. A drop rule that never fires is the expected state, not a sign it’s broken.&lt;/p&gt;

&lt;h2&gt;Silencing a false positive&lt;/h2&gt;

&lt;p&gt;A rule that fires on legitimate traffic is neutralised from the most precise to the broadest: threshold or suppression for one address in &lt;code&gt;threshold.config&lt;/code&gt;, then disabling the rule by its number in &lt;code&gt;disable.conf&lt;/code&gt;. Never edit the rules file directly: the next update would overwrite it.&lt;/p&gt;

&lt;pre&gt;# /etc/suricata/threshold.config
suppress gen_id 1, sig_id 2210045, track by_src, ip 203.0.113.40&lt;/pre&gt;

&lt;h2&gt;Sending alerts to the SIEM&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;eve.json&lt;/code&gt; can be read by Wazuh, Elastic, Graylog and most SIEMs. With a Wazuh agent, a few lines are enough (format &lt;code&gt;json&lt;/code&gt;, file path) and Suricata’s alerts show up next to the system logs, so you can tie a network alert to an SSH login or a file change. Mind rotation: &lt;code&gt;eve.json&lt;/code&gt; grows fast, and logrotate must signal Suricata to reopen the file.&lt;/p&gt;

&lt;h2&gt;Upgrading Suricata&lt;/h2&gt;

&lt;p&gt;After each package update, run &lt;code&gt;suricata -T&lt;/code&gt; again before restarting: a renamed option or an incompatible rule prevents startup, and thanks to &lt;code&gt;--queue-bypass&lt;/code&gt; traffic then flows &lt;em&gt;uninspected&lt;/em&gt;, with nothing visibly broken. That’s the flip side of failing safe: monitor the service’s state, not just the traffic.&lt;/p&gt;





&lt;p&gt;&lt;em&gt;This post is part of a series of sysadmin tutorials (tag “how-to”).&lt;/em&gt;&lt;br&gt;Series “How-to”, tutorial 10/77. · &lt;a href="https://hecate.neurozone.fr/?p=598" rel="noopener noreferrer"&gt;← Previous tutorial&lt;/a&gt; · &lt;span&gt;Next tutorial → (coming 11 Nov)&lt;/span&gt; · &lt;a href="https://blog.neurozone.fr/?p=2047" rel="noopener noreferrer"&gt;Version française&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Official documentation&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://suricata.io/" rel="noopener noreferrer"&gt;Suricata&lt;/a&gt;, project site&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.suricata.io/" rel="noopener noreferrer"&gt;Suricata documentation&lt;/a&gt;, configuration, rules, IPS mode&lt;/p&gt;

&lt;h2&gt;Related articles&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=598" rel="noopener noreferrer"&gt;Installing CrowdSec at the firewall&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=102" rel="noopener noreferrer"&gt;CrowdSec 1.8 on Debian&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/?p=595" rel="noopener noreferrer"&gt;WireGuard between a server and home&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/09/how-to-suricata-as-an-ips-on-rocky-linux-without-breaking-your-server/" rel="noopener noreferrer"&gt;How-to: Suricata as an IPS with NFQUEUE, without breaking your server&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>security</category>
      <category>sysadminnotebook</category>
      <category>english</category>
      <category>firewalld</category>
    </item>
    <item>
      <title>Sharing an article about databases files in MariaDB</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Thu, 05 Nov 2026 09:50:12 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/sharing-an-article-about-databases-files-in-mariadb-50fd</link>
      <guid>https://dev.to/hecate-regnier/sharing-an-article-about-databases-files-in-mariadb-50fd</guid>
      <description>&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/2026/10/23/inside-database-data-files-1-3-innodb-from-mysql-to-mariadb/" rel="noopener noreferrer"&gt;https://hecate.neurozone.fr/2026/10/23/inside-database-data-files-1-3-innodb-from-mysql-to-mariadb/&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;I hope I can have some feedback !&lt;/p&gt;

</description>
    </item>
    <item>
      <title>How-to: the MariaDB settings that really matter, and how to check them</title>
      <dc:creator>Hécate R.</dc:creator>
      <pubDate>Sun, 01 Nov 2026 14:00:00 +0000</pubDate>
      <link>https://dev.to/hecate-regnier/how-to-the-mariadb-settings-that-really-matter-and-how-to-check-them-5h25</link>
      <guid>https://dev.to/hecate-regnier/how-to-the-mariadb-settings-that-really-matter-and-how-to-check-them-5h25</guid>
      <description>&lt;p&gt;The Internet is full of hundred-line &lt;code&gt;my.cnf&lt;/code&gt; files, copied from server to server, where nobody remembers why each line is there. Most of MariaDB’s defaults are sensible; only about ten MariaDB settings make a real difference. This tutorial goes through them using a real server: MariaDB 12.3 on Rocky Linux, about thirty sites (WordPress, Matomo, Piwigo…), 32 GB of RAM shared with PHP, nginx and other services, spinning disks.&lt;/p&gt;

&lt;p&gt;For each MariaDB setting: what it does, how to choose the value, and above all how to &lt;strong&gt;check&lt;/strong&gt; it’s right. A MariaDB setting you can’t measure is a setting you shouldn’t touch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://hecate.neurozone.fr/wp-content/uploads/2026/11/how-to-the-mariadb-settings-that-really-matter_diagram_en.webp" rel="noopener noreferrer"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fupy74r5gaq217dokx129.webp" alt="Eight MariaDB settings with how to choose each and how to check it, plus a real check after a restart" width="800" height="391"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Eight settings, how to choose them, and how to measure each one.&lt;/em&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Where the configuration lives, and how to read the real value
&lt;/h2&gt;

&lt;p&gt;MariaDB reads &lt;code&gt;/etc/my.cnf&lt;/code&gt; then the files in &lt;code&gt;/etc/my.cnf.d/&lt;/code&gt;. MariaDB settings go in a &lt;code&gt;[mariadb]&lt;/code&gt; section (read only by MariaDB) or &lt;code&gt;[mysqld]&lt;/code&gt; (also read by MySQL-compatible tools). The classic trap: the same variable defined in two files, the last one read wins. Two commands tell the truth:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mariadbd &lt;span class="nt"&gt;--print-defaults&lt;/span&gt; &lt;span class="c"&gt;# what the server will read at next start&lt;/span&gt;
mariadb &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"SHOW GLOBAL VARIABLES LIKE 'innodb_buffer_pool_size'"&lt;/span&gt; &lt;span class="c"&gt;# the current value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A misspelt variable in the file is ignored with a mere warning in the error log. Always compare the current value with the one you think you set.&lt;/p&gt;

&lt;h2&gt;
  
  
  The whole file
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ini"&gt;&lt;code&gt;&lt;span class="nn"&gt;[mariadb]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c"&gt;# --- Memory -------------------------------------------------------------
&lt;/span&gt;&lt;span class="py"&gt;innodb_buffer_pool_size&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;12G&lt;/span&gt;
&lt;span class="py"&gt;innodb_log_file_size&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;2G&lt;/span&gt;
&lt;span class="py"&gt;innodb_log_buffer_size&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;256M&lt;/span&gt;
&lt;span class="py"&gt;tmp_table_size&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;256M&lt;/span&gt;
&lt;span class="py"&gt;max_heap_table_size&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;256M&lt;/span&gt;
&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c"&gt;# --- Durability ----------------------------------------------------------
&lt;/span&gt;&lt;span class="py"&gt;innodb_flush_log_at_trx_commit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;
&lt;span class="py"&gt;sync_binlog&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;
&lt;span class="py"&gt;innodb_flush_method&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;O_DIRECT&lt;/span&gt;
&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c"&gt;# --- I/O (spinning disks) ----------------------------------
&lt;/span&gt;&lt;span class="py"&gt;innodb_io_capacity&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;200&lt;/span&gt;
&lt;span class="py"&gt;innodb_io_capacity_max&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;400&lt;/span&gt;
&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c"&gt;# --- Connexions ----------------------------------------------------------
&lt;/span&gt;&lt;span class="py"&gt;max_connections&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;400&lt;/span&gt;
&lt;span class="py"&gt;thread_cache_size&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;64&lt;/span&gt;
&lt;span class="py"&gt;wait_timeout&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;28800&lt;/span&gt;
&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c"&gt;# --- Tables et fichiers --------------------------------------------------
&lt;/span&gt;&lt;span class="py"&gt;table_open_cache&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;4096&lt;/span&gt;
&lt;span class="py"&gt;table_open_cache_instances&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;8&lt;/span&gt;
&lt;span class="py"&gt;table_definition_cache&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;4096&lt;/span&gt;
&lt;span class="py"&gt;open_files_limit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;68000&lt;/span&gt;
&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c"&gt;# --- Binlogs, replication ------------------------------------------------
&lt;/span&gt;&lt;span class="py"&gt;server_id&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;10&lt;/span&gt;
&lt;span class="py"&gt;log_bin&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;/data/mysql/binlogs/logbin&lt;/span&gt;
&lt;span class="py"&gt;binlog_format&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;ROW&lt;/span&gt;
&lt;span class="py"&gt;binlog_expire_logs_seconds&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;432000&lt;/span&gt;
&lt;span class="py"&gt;max_binlog_size&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;512M&lt;/span&gt;
&lt;span class="py"&gt;log_slave_updates&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;ON&lt;/span&gt;
&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c"&gt;# --- Hygiene -------------------------------------------------------------
&lt;/span&gt;&lt;span class="py"&gt;character_set_server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;utf8mb4&lt;/span&gt;
&lt;span class="py"&gt;collation_server&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;utf8mb4_uca1400_ai_ci&lt;/span&gt;
&lt;span class="py"&gt;transaction_isolation&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;READ-COMMITTED&lt;/span&gt;
&lt;span class="py"&gt;skip_name_resolve&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;ON&lt;/span&gt;
&lt;span class="py"&gt;local_infile&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;OFF&lt;/span&gt;
&lt;span class="py"&gt;max_allowed_packet&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;256M&lt;/span&gt;
&lt;span class="py"&gt;slow_query_log&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;ON&lt;/span&gt;
&lt;span class="py"&gt;long_query_time&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;5&lt;/span&gt;
&lt;span class="py"&gt;log_slow_verbosity&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;query_plan,explain&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Memory
&lt;/h2&gt;

&lt;h3&gt;
  
  
  innodb_buffer_pool_size, the setting that matters most
&lt;/h3&gt;

&lt;p&gt;It’s the cache where InnoDB keeps table and index pages. As long as the data actually used fits, reads don’t touch the disk, which is often a factor of a hundred in response time. The usual rule: 60 to 75% of RAM on a server dedicated to the database, 30 to 40% on a server that also runs the application and the web server. Here, 12 GB out of 32.&lt;/p&gt;

&lt;p&gt;To know whether it’s enough, measure the share of reads served by the cache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;ROUND&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;hit_ratio_pct&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;VARIABLE_VALUE&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;information_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GLOBAL_STATUS&lt;/span&gt;
      &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;VARIABLE_NAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Innodb_buffer_pool_reads'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
     &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;VARIABLE_VALUE&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;information_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GLOBAL_STATUS&lt;/span&gt;
      &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;VARIABLE_NAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Innodb_buffer_pool_read_requests'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above 99% over a normal day, memory isn’t your problem. Below 95%, every query that touches cold data reads the disk: grow the cache if RAM allows, or look for queries that scan whole tables. Since MariaDB 10.5 there’s no need to split the cache into &lt;code&gt;innodb_buffer_pool_instances&lt;/code&gt;: it’s handled internally.&lt;/p&gt;

&lt;h3&gt;
  
  
  innodb_log_file_size: sizing the redo log
&lt;/h3&gt;

&lt;p&gt;Every change is first written to the redo log, then the modified pages are written to the data files in the background. A redo log that’s too small forces InnoDB to flush pages in a hurry when it fills up, which causes latency spikes. A good size covers about an hour of writes. Measure it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;VARIABLE_VALUE&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;information_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GLOBAL_STATUS&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;VARIABLE_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'Innodb_lsn_current'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;SLEEP&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3600&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;VARIABLE_VALUE&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt; &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;information_schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GLOBAL_STATUS&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;VARIABLE_NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'Innodb_lsn_current'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;ROUND&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="o"&gt;@&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;redo_mb_per_hour&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the result is 400 MB per hour, a 512 MB to 1 GB log is enough; here 2 GB leaves room for imports. A bigger log only lengthens crash recovery, from seconds to a few minutes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Per-connection memory: the multiplication trap
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;sort_buffer_size&lt;/code&gt;, &lt;code&gt;join_buffer_size&lt;/code&gt;, &lt;code&gt;read_buffer_size&lt;/code&gt;, &lt;code&gt;read_rnd_buffer_size&lt;/code&gt; are allocated &lt;strong&gt;per connection&lt;/strong&gt; , sometimes several times per query. A 64 MB &lt;code&gt;join_buffer_size&lt;/code&gt; looks harmless, but multiplied by 400 connections it could in theory claim 25 GB. Keep the defaults unless a measurement says otherwise, and raise them only for one session (&lt;code&gt;SET SESSION&lt;/code&gt;) during a heavy job.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tmp_table_size&lt;/code&gt; and &lt;code&gt;max_heap_table_size&lt;/code&gt; go together: the smaller of the two sets the maximum size of an in-memory temporary table before it moves to disk. Watch the ratio of &lt;code&gt;Created_tmp_disk_tables&lt;/code&gt; to &lt;code&gt;Created_tmp_tables&lt;/code&gt;: above 10 to 20%, some queries sort or group large volumes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Durability
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;innodb_flush_log_at_trx_commit = 1&lt;/code&gt; writes and syncs the redo log at every commit; &lt;code&gt;sync_binlog = 1&lt;/code&gt; does the same for the binlog. Together they guarantee that a power cut loses no committed transaction and that the replica stays consistent with the primary. Values 2 or 0 reduce synchronous writes, at the cost of up to one second of lost transactions if the system crashes: acceptable on a replica you can rebuild, never on the primary.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;innodb_flush_method = O_DIRECT&lt;/code&gt; makes InnoDB write straight to disk without going through the system cache: data isn’t cached twice (in InnoDB’s cache and in the kernel’s). It’s the default in recent versions; check it rather than assume it.&lt;/p&gt;

&lt;h2&gt;
  
  
  I/O
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;innodb_io_capacity&lt;/code&gt; tells InnoDB how many operations per second the storage can absorb for background work (page flushing, purge). The default suits SSDs. On spinning disks, 200 keeps InnoDB from saturating the disk at the expense of queries; &lt;code&gt;innodb_io_capacity_max&lt;/code&gt; sets the ceiling when it falls behind. To check: &lt;code&gt;iostat -x 5&lt;/code&gt; during a busy period; the &lt;code&gt;%util&lt;/code&gt; column must not stay stuck at 100.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connections
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;max_connections&lt;/code&gt; should cover the sum of connections the applications can open, with a margin, no more: each connection uses memory, and raising this limit to “fix” &lt;em&gt;Too many connections&lt;/em&gt; errors often hides an application that doesn’t close its connections. Look at the real peak:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SHOW&lt;/span&gt; &lt;span class="k"&gt;GLOBAL&lt;/span&gt; &lt;span class="n"&gt;STATUS&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'Max_used_connections'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SHOW&lt;/span&gt; &lt;span class="k"&gt;GLOBAL&lt;/span&gt; &lt;span class="n"&gt;STATUS&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'Aborted_c%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;SHOW&lt;/span&gt; &lt;span class="k"&gt;GLOBAL&lt;/span&gt; &lt;span class="n"&gt;STATUS&lt;/span&gt; &lt;span class="k"&gt;LIKE&lt;/span&gt; &lt;span class="s1"&gt;'Threads_created'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;thread_cache_size&lt;/code&gt; keeps threads ready for reuse: if &lt;code&gt;Threads_created&lt;/code&gt; grows quickly, raise it. &lt;code&gt;wait_timeout&lt;/code&gt; closes idle connections; 8 hours suits web applications, which reconnect on their own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tables and files
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;table_open_cache&lt;/code&gt; keeps tables open between queries; it’s split into &lt;code&gt;table_open_cache_instances&lt;/code&gt; to limit contention between threads. If &lt;code&gt;Opened_tables&lt;/code&gt; keeps growing, the cache is too small.&lt;/p&gt;

&lt;p&gt;The trap that cost me time: this cache depends on how many files the process may open. MariaDB computes its limits from &lt;code&gt;open_files_limit&lt;/code&gt;, but systemd imposes its own (&lt;code&gt;LimitNOFILE&lt;/code&gt;). If systemd’s is lower, MariaDB &lt;strong&gt;silently&lt;/strong&gt; shrinks its caches at startup: I found a server set to 8 instances that was only using 3. The fix is a systemd override file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight systemd"&gt;&lt;code&gt;&lt;span class="c"&gt;# /etc/systemd/system/mariadb.service.d/limits.conf&lt;/span&gt;
&lt;span class="k"&gt;[Service]&lt;/span&gt;
&lt;span class="nt"&gt;LimitNOFILE&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;68000

&lt;span class="err"&gt;systemctl&lt;/span&gt; &lt;span class="err"&gt;daemon-reload&lt;/span&gt; &lt;span class="err"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="err"&gt;systemctl&lt;/span&gt; &lt;span class="err"&gt;restart&lt;/span&gt; &lt;span class="err"&gt;mariadb&lt;/span&gt;
&lt;span class="err"&gt;mariadb&lt;/span&gt; &lt;span class="err"&gt;-e&lt;/span&gt; &lt;span class="err"&gt;"SHOW&lt;/span&gt; &lt;span class="err"&gt;GLOBAL&lt;/span&gt; &lt;span class="err"&gt;VARIABLES&lt;/span&gt; &lt;span class="err"&gt;WHERE&lt;/span&gt; &lt;span class="err"&gt;Variable_name&lt;/span&gt; &lt;span class="err"&gt;IN&lt;/span&gt; &lt;span class="err"&gt;('open_files_limit','table_open_cache_instances')"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Binlogs and replication
&lt;/h2&gt;

&lt;p&gt;The binlog records every change; it serves replication and point-in-time recovery. &lt;code&gt;binlog_format = ROW&lt;/code&gt; records the changed rows rather than the statements: bigger, but unambiguous (a statement with &lt;code&gt;NOW()&lt;/code&gt; or &lt;code&gt;RAND()&lt;/code&gt; doesn’t give the same result replayed elsewhere). &lt;code&gt;binlog_expire_logs_seconds&lt;/code&gt; purges old files: keep at least the interval between two full backups, or point-in-time recovery becomes impossible for the period in between. &lt;code&gt;server_id&lt;/code&gt; must be unique across the whole replication topology, and &lt;code&gt;log_slave_updates&lt;/code&gt; lets a replica act as a source itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hygiene
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;utf8mb4&lt;/strong&gt; : real 4-byte UTF-8, emoji included. The historical &lt;code&gt;utf8&lt;/code&gt; set is limited to 3 bytes and truncates some characters;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;collation_server&lt;/strong&gt; : recent versions offer UCA 14.0 collations (&lt;code&gt;utf8mb4_uca1400_ai_ci&lt;/code&gt;), more accurate for comparisons and sorting;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;READ-COMMITTED&lt;/strong&gt; : fewer locks than the default REPEATABLE-READ, a good fit for web applications;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;skip_name_resolve&lt;/strong&gt; : no DNS lookup on every connection (slow DNS would mean slow connections), and grants are given by IP address;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;local_infile = OFF&lt;/strong&gt; : closes a door that lets a client make the server read files;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;max_allowed_packet&lt;/strong&gt; : the maximum size of a query or a row; too small, and imports and large contents fail;&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;the slow query log&lt;/strong&gt; : beyond 5 seconds, with the execution plan. Read it every week: it’s the best optimisation source there is.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The method for any MariaDB setting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;change &lt;strong&gt;one&lt;/strong&gt; setting at a time, and note the measurement before and after;&lt;/li&gt;
&lt;li&gt;many variables can be changed live (&lt;code&gt;SET GLOBAL&lt;/code&gt;) for a trial; then write them to the file, or they vanish at restart;&lt;/li&gt;
&lt;li&gt;those that need a restart (redo log size, &lt;code&gt;open_files_limit&lt;/code&gt;) get scheduled;&lt;/li&gt;
&lt;li&gt;keep the configuration under version control, with the reason for each non-default value as a comment. In six months, that comment will be worth more than the value itself.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Checks after a change
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;systemctl restart mariadb &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; systemctl is-active mariadb
journalctl &lt;span class="nt"&gt;-u&lt;/span&gt; mariadb &lt;span class="nt"&gt;-n&lt;/span&gt; 30 &lt;span class="nt"&gt;--no-pager&lt;/span&gt; | &lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-iE&lt;/span&gt; &lt;span class="s1"&gt;'warn|error'&lt;/span&gt;
mariadb &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"SHOW GLOBAL VARIABLES"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; /tmp/vars.after
diff &amp;lt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sort&lt;/span&gt; /tmp/vars.before&lt;span class="o"&gt;)&lt;/span&gt; &amp;lt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sort&lt;/span&gt; /tmp/vars.after&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a Prometheus exporter watches the database, compare over a few days the cache hit ratio, on-disk temporary tables, connections and query latency. A MariaDB setting is only good if those curves confirm it.&lt;/p&gt;

&lt;h2&gt;
  
  
  A real check, 75 minutes after a restart
&lt;/h2&gt;

&lt;p&gt;To show what these checks give on a real server, here is my web server’s MariaDB 12.3 on 2 November 2026, read with the monitoring account (which only needs to read variables and counters). The machine had rebooted 75 minutes earlier, which makes the numbers more instructive, not less.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;@@&lt;/span&gt;&lt;span class="n"&gt;innodb_buffer_pool_size&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;buffer_pool_gb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="o"&gt;@@&lt;/span&gt;&lt;span class="n"&gt;innodb_log_file_size&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="n"&gt;redo_mb&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
       &lt;span class="o"&gt;@@&lt;/span&gt;&lt;span class="n"&gt;max_connections&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;@@&lt;/span&gt;&lt;span class="n"&gt;innodb_flush_log_at_trx_commit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;@@&lt;/span&gt;&lt;span class="n"&gt;sync_binlog&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;----------------+---------+-------------------+---------------------------------+---------------+&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;buffer_pool_gb&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;redo_mb&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="o"&gt;@@&lt;/span&gt;&lt;span class="n"&gt;max_connections&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="o"&gt;@@&lt;/span&gt;&lt;span class="n"&gt;innodb_flush_log_at_trx_commit&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="o"&gt;@@&lt;/span&gt;&lt;span class="n"&gt;sync_binlog&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;----------------+---------+-------------------+---------------------------------+---------------+&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;31&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;2048&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="c1"&gt;----------------+---------+-------------------+---------------------------------+---------------+&lt;/span&gt;

&lt;span class="k"&gt;SHOW&lt;/span&gt; &lt;span class="k"&gt;GLOBAL&lt;/span&gt; &lt;span class="n"&gt;STATUS&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;Variable_name&lt;/span&gt; &lt;span class="k"&gt;IN&lt;/span&gt; &lt;span class="p"&gt;(...);&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Uptime&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;4487&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Innodb_buffer_pool_read_requests&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;5163358&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Innodb_buffer_pool_reads&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;121600&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Innodb_log_waits&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Max_used_connections&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;61&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Threads_created&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;61&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Connections&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;11846&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Created_tmp_tables&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;37637&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;Created_tmp_disk_tables&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="mi"&gt;5223&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;How I read it, line by line:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Buffer pool hit ratio&lt;/strong&gt; : 1 − 121 600 / 5 163 358 = &lt;strong&gt;97.6 %&lt;/strong&gt;. On a server that has been up for weeks I expect above 99.9 %. Here the cache is still filling: every page read from disk since the restart counts as a miss. That’s why the ratio must be compared over days, never right after a restart, and why a restart is followed by a slow first hour.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Innodb_log_waits = 0&lt;/strong&gt; : no transaction had to wait for room in the log buffer. With a 2 GB redo log, even the start-up traffic didn’t saturate it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Max_used_connections = 61&lt;/strong&gt; out of 400 allowed, and &lt;strong&gt;Threads_created = 61&lt;/strong&gt; for 11 846 connections: the thread cache reuses threads instead of creating one per connection. If Threads_created grew almost as fast as Connections, thread_cache_size would be too small.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Temporary tables on disk&lt;/strong&gt; : 5 223 out of 37 637, i.e. 14 %. That’s mostly WordPress queries sorting text columns, which go to disk regardless of tmp_table_size. Above 25 %, it’s worth looking for the queries responsible before raising any limit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;innodb_flush_log_at_trx_commit = 1 and sync_binlog = 1&lt;/strong&gt; : full durability on the primary. The replica runs with 2 and 0, the reasons are in the MariaDB series.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Total time: two queries, one minute. Run them before and after every change, and keep the outputs: that’s what turns “it feels faster” into a measurement.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;This post is part of a series of sysadmin tutorials (tag “how-to”).&lt;/em&gt;&lt;br&gt;&lt;br&gt;
Series “How-to”, tutorial 6/77. · &lt;a href="https://hecate.neurozone.fr/?p=595" rel="noopener noreferrer"&gt;← Previous tutorial&lt;/a&gt; · &lt;a href="https://hecate.neurozone.fr/?p=1531" rel="noopener noreferrer"&gt;Next tutorial →&lt;/a&gt; · &lt;a href="https://blog.neurozone.fr/?p=2044" rel="noopener noreferrer"&gt;Version française&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Related articles
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=377" rel="noopener noreferrer"&gt;How InnoDB stores data on disk&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=53" rel="noopener noreferrer"&gt;MySQL export without lock tables&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://hecate.neurozone.fr/?p=379" rel="noopener noreferrer"&gt;Oracle and the three engines side by side&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The post &lt;a href="https://hecate.neurozone.fr/2026/11/01/how-to-the-mariadb-settings-that-really-matter/" rel="noopener noreferrer"&gt;How-to: the MariaDB settings that really matter, and how to check them&lt;/a&gt; appeared first on &lt;a href="https://hecate.neurozone.fr" rel="noopener noreferrer"&gt;Hécate Regnier - Neurozone&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>database</category>
      <category>sysadminnotebook</category>
      <category>english</category>
      <category>howto</category>
    </item>
  </channel>
</rss>
