CT 103: Disk-Housekeeping gegen volle Root-Platte (Gitea/Keycloak-Assets 0-Byte)
Vorfall 2026-11-26: CT 103 (NPM-Reverse-Proxy) Root-fs zu 100% voll, weil die
NPM-Logs unter /opt/nginx-proxy-manager/data/logs nicht rotiert wurden und nginx
im Container gelöschte Inodes offen hielt. NPM lieferte dadurch abgeschnittene
0-Byte-Assets ("Frontend is not initialized" bei Gitea/CT 110, Keycloak ohne CSS).
Neues Role reverse_proxy_disk_housekeeping in site.yml:
- journald-Drop-in (SystemMaxUse=200M, MaxRetentionSec=7d)
- logrotate-Policy für die NPM-Logs mit copytruncate (Pflicht wegen offener FDs)
- selbstheilender Guard: bei Unterschreitung von reverse_proxy_minimum_root_available_bytes
Journal vacumen, NPM-Logs in-place truncaten, NPM-Cache leeren, NPM neu starten,
danach Headroom asserten; Phase 1 (Freiräumen) läuft vor dem Schreiben der Configs,
da bei 0 Byte frei keine neuen Dateien anlegbar sind
- failed-Zustand der durch die volle Platte betroffenen oneshot-Units
(logrotate.service, man-db.service) wird gecleared
Zusätzlich: eigenes Playbook disk-housekeeping.yml, Headroom-Assert und
Drop-in-Prüfung in verify-production.yml, README-Abschnitt.
Verifiziert: site.yml real changed=1 (unrelated Mode-Fix), verify-production ok,
zweiter site.yml --check changed=0; Gitea-JS 661667B und Keycloak-CSS 1158689B
via NPM wieder vollständig, CT 103 Platte 53%, keine failed units.
Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
@@ -55,6 +55,21 @@ The adoption path mirrors CT 100 and keeps the production proxy intact:
|
||||
The production verifier is read-only. A real `site.yml` run enforces the
|
||||
declared state and therefore requires an explicit change authorization.
|
||||
|
||||
## Disk housekeeping (incident 2026-11-26)
|
||||
|
||||
On 2026-11-26 the CT 103 root filesystem filled up: the NPM access logs below
|
||||
`/opt/nginx-proxy-manager/data/logs` had no logrotate policy, and nginx keeps
|
||||
deleted inodes open inside the container. NPM then served truncated 0-byte
|
||||
assets, which surfaced as "Frontend is not initialized" on Gitea (CT 110) and
|
||||
unstyled Keycloak pages behind the proxy. The `reverse_proxy_disk_housekeeping`
|
||||
role (part of `site.yml`) declares the countermeasures: a journald size cap, a
|
||||
`copytruncate` logrotate policy for the NPM logs, and a self-healing guard that
|
||||
vaciums the journal, purges the NPM proxy cache and restarts NPM whenever the
|
||||
root headroom drops below `reverse_proxy_minimum_root_available_bytes`
|
||||
(1 GiB, also asserted by `audit-production.yml` and `verify-production.yml`).
|
||||
The guard makes every `site.yml` run heal a full root disk reproducibly; once
|
||||
the headroom is restored, a second run reports `changed=0`.
|
||||
|
||||
## Declared scope and deliberate non-goals
|
||||
|
||||
- NPM runtime data (SQLite database, keys, Let's Encrypt certificates,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
- name: Apply the CT 103 disk housekeeping countermeasures
|
||||
hosts: reverse_proxy_hosts
|
||||
become: true
|
||||
gather_facts: true
|
||||
gather_subset:
|
||||
- min
|
||||
- hardware
|
||||
- network
|
||||
- virtual
|
||||
|
||||
roles:
|
||||
- role: reverse_proxy_disk_housekeeping
|
||||
@@ -26,3 +26,4 @@
|
||||
- role: reverse_proxy_oauth2proxy
|
||||
- role: reverse_proxy_research_vhost
|
||||
- role: reverse_proxy_fail2ban
|
||||
- role: reverse_proxy_disk_housekeeping
|
||||
|
||||
@@ -65,6 +65,33 @@
|
||||
reverse_proxy_production_services.results |
|
||||
map(attribute='stdout') | unique | list == ['active']
|
||||
|
||||
- name: Require free root filesystem headroom
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- >-
|
||||
ansible_facts['mounts'] |
|
||||
selectattr('mount', 'equalto', '/')
|
||||
| map(attribute='block_available')
|
||||
| map('int') | first * 4096 >= reverse_proxy_minimum_root_available_bytes | int
|
||||
fail_msg: The root filesystem is low on available bytes.
|
||||
|
||||
- name: Verify the disk housekeeping drop-ins exist
|
||||
ansible.builtin.stat:
|
||||
path: "{{ item }}"
|
||||
loop:
|
||||
- /etc/systemd/journald.conf.d/99-ghostnet-limits.conf
|
||||
- /etc/logrotate.d/nginx-proxy-manager
|
||||
register: reverse_proxy_production_housekeeping_files
|
||||
|
||||
- name: Require the disk housekeeping drop-ins to be present
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- reverse_proxy_production_housekeeping_files.results |
|
||||
map(attribute='stat.exists') | unique | list == [true]
|
||||
fail_msg: >-
|
||||
The declared disk housekeeping drop-ins (journald cap, NPM logrotate
|
||||
policy) are missing.
|
||||
|
||||
- name: Require SSH socket activation to be gone
|
||||
ansible.builtin.systemd_service:
|
||||
name: ssh.socket
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
# reverse_proxy_disk_housekeeping
|
||||
|
||||
Durable countermeasures for the 2026-11-26 CT 103 incident: the root
|
||||
filesystem filled up because the NPM access logs below
|
||||
`/opt/nginx-proxy-manager/data/logs` were not rotated (and nginx keeps
|
||||
deleted inodes open inside the container), so NPM served truncated 0-byte
|
||||
assets — visible as "Frontend is not initialized" on Gitea (CT 110) and
|
||||
unstyled Keycloak pages behind the proxy.
|
||||
|
||||
The role declares:
|
||||
|
||||
- a journald drop-in capping the persistent journal (`SystemMaxUse`,
|
||||
`MaxRetentionSec`),
|
||||
- a logrotate policy for the NPM log directory using `copytruncate` (mandatory
|
||||
because of the open file descriptors in the container),
|
||||
- a self-healing guard: whenever the available root bytes drop below
|
||||
`reverse_proxy_minimum_root_available_bytes` (inventory-wide, also asserted
|
||||
by `audit-production.yml`), the role vaciums the journal, purges the NPM
|
||||
proxy cache (`/opt/nginx-proxy-manager/data/nginx/cache`) and restarts the
|
||||
NPM service, then asserts the headroom again.
|
||||
|
||||
The guard is part of `site.yml`, so every convergence run heals a full root
|
||||
filesystem the same reproducible way; a second run reports `changed=0` once
|
||||
the headroom is restored.
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
---
|
||||
# Incident 2026-11-26: the CT 103 root filesystem filled up (NPM access logs
|
||||
# under /opt/nginx-proxy-manager/data/logs are not covered by logrotate and
|
||||
# grow unbounded; nginx keeps deleted inodes open inside the container).
|
||||
# NPM then served truncated 0-byte assets behind the proxy, which surfaced as
|
||||
# "Frontend is not initialized" on Gitea (CT 110) and unstyled Keycloak pages.
|
||||
# This role declares the durable countermeasures and a self-healing guard that
|
||||
# purges the NPM proxy cache and restarts NPM whenever the declared root
|
||||
# headroom is violated.
|
||||
|
||||
reverse_proxy_housekeeping_journald_dropin: /etc/systemd/journald.conf.d/99-ghostnet-limits.conf
|
||||
reverse_proxy_housekeeping_journald_system_max_use: 200M
|
||||
reverse_proxy_housekeeping_journald_max_retention_sec: 7d
|
||||
|
||||
reverse_proxy_housekeeping_logrotate_dropin: /etc/logrotate.d/nginx-proxy-manager
|
||||
reverse_proxy_housekeeping_npm_logs_directory: >-
|
||||
{{ reverse_proxy_npm_data_directory | default('/opt/nginx-proxy-manager/data') }}/logs
|
||||
reverse_proxy_housekeeping_logrotate_rotate: 4
|
||||
|
||||
reverse_proxy_housekeeping_npm_cache_directory: >-
|
||||
{{ reverse_proxy_npm_data_directory | default('/opt/nginx-proxy-manager/data') }}/nginx/cache
|
||||
|
||||
# Reuse the inventory-wide threshold so audit-production.yml and this role
|
||||
# enforce the same headroom.
|
||||
reverse_proxy_housekeeping_root_min_available_bytes: >-
|
||||
{{ reverse_proxy_minimum_root_available_bytes | default(1000000000) }}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Restart systemd-journald
|
||||
ansible.builtin.systemd_service:
|
||||
name: systemd-journald
|
||||
state: restarted
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
---
|
||||
# Phase 1: free space first. With a completely full root filesystem not even
|
||||
# a new directory can be created, so the emergency cleanup must run before
|
||||
# any configuration file is written. Truncating in place (copytruncate
|
||||
# semantics) frees blocks without allocating new ones.
|
||||
|
||||
- name: Read the available bytes on the root filesystem
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- /usr/bin/df
|
||||
- --block-size=1
|
||||
- --output=avail
|
||||
- /
|
||||
check_mode: false
|
||||
changed_when: false
|
||||
register: reverse_proxy_housekeeping_df_before
|
||||
|
||||
- name: Compute the available root filesystem bytes
|
||||
ansible.builtin.set_fact:
|
||||
reverse_proxy_housekeeping_root_available_bytes: >-
|
||||
{{ reverse_proxy_housekeeping_df_before.stdout_lines[1] | int }}
|
||||
|
||||
- name: Vacuum the persistent journal when root headroom is low
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- /usr/bin/journalctl
|
||||
- --vacuum-size={{ reverse_proxy_housekeeping_journald_system_max_use }}
|
||||
changed_when: false
|
||||
when: >-
|
||||
reverse_proxy_housekeeping_root_available_bytes | int <
|
||||
reverse_proxy_housekeeping_root_min_available_bytes | int
|
||||
|
||||
- name: Enumerate NPM log files when root headroom is low
|
||||
ansible.builtin.find:
|
||||
paths: "{{ reverse_proxy_housekeeping_npm_logs_directory }}"
|
||||
file_type: file
|
||||
patterns: "*.log"
|
||||
register: reverse_proxy_housekeeping_big_logs
|
||||
when: >-
|
||||
reverse_proxy_housekeeping_root_available_bytes | int <
|
||||
reverse_proxy_housekeeping_root_min_available_bytes | int
|
||||
|
||||
- name: Truncate NPM log files in place when root headroom is low
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- /usr/bin/truncate
|
||||
- -s
|
||||
- "0"
|
||||
- "{{ item.path }}"
|
||||
loop: "{{ reverse_proxy_housekeeping_big_logs.files | default([]) }}"
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
when: >-
|
||||
reverse_proxy_housekeeping_root_available_bytes | int <
|
||||
reverse_proxy_housekeeping_root_min_available_bytes | int
|
||||
|
||||
- name: Enumerate the NPM proxy cache when root headroom is low
|
||||
ansible.builtin.find:
|
||||
paths: "{{ reverse_proxy_housekeeping_npm_cache_directory }}"
|
||||
recurse: true
|
||||
register: reverse_proxy_housekeeping_cache_files
|
||||
when: >-
|
||||
reverse_proxy_housekeeping_root_available_bytes | int <
|
||||
reverse_proxy_housekeeping_root_min_available_bytes | int
|
||||
|
||||
- name: Purge the NPM proxy cache when root headroom is low
|
||||
ansible.builtin.file:
|
||||
path: "{{ item.path }}"
|
||||
state: absent
|
||||
loop: "{{ reverse_proxy_housekeeping_cache_files.files | default([]) }}"
|
||||
loop_control:
|
||||
label: "{{ item.path }}"
|
||||
when: >-
|
||||
reverse_proxy_housekeeping_root_available_bytes | int <
|
||||
reverse_proxy_housekeeping_root_min_available_bytes | int
|
||||
|
||||
- name: Restart NPM when root headroom is low
|
||||
ansible.builtin.systemd_service:
|
||||
name: "{{ reverse_proxy_npm_service_name }}"
|
||||
state: restarted
|
||||
when: >-
|
||||
reverse_proxy_housekeeping_root_available_bytes | int <
|
||||
reverse_proxy_housekeeping_root_min_available_bytes | int
|
||||
|
||||
# Phase 2: durable declared state (writable again once phase 1 freed space).
|
||||
|
||||
- name: Create the journald drop-in directory
|
||||
ansible.builtin.file:
|
||||
path: "{{ reverse_proxy_housekeeping_journald_dropin | dirname }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0755"
|
||||
|
||||
- name: Install the journald size cap for the CT 103 root filesystem
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
# Managed by Ansible (reverse_proxy_disk_housekeeping).
|
||||
# The persistent journal must not be able to fill the 7.8G root disk.
|
||||
[Journal]
|
||||
SystemMaxUse={{ reverse_proxy_housekeeping_journald_system_max_use }}
|
||||
MaxRetentionSec={{ reverse_proxy_housekeeping_journald_max_retention_sec }}
|
||||
dest: "{{ reverse_proxy_housekeeping_journald_dropin }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
notify: Restart systemd-journald
|
||||
|
||||
- name: Install the logrotate policy for the NPM log directory
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
# Managed by Ansible (reverse_proxy_disk_housekeeping).
|
||||
# NPM writes its access/error logs through the container bind mount, so
|
||||
# copytruncate is mandatory: nginx keeps the file descriptors open and a
|
||||
# rename-based rotation would leave the container writing to deleted
|
||||
# inodes, which never frees disk space.
|
||||
{{ reverse_proxy_housekeeping_npm_logs_directory }}/*.log {
|
||||
weekly
|
||||
rotate {{ reverse_proxy_housekeeping_logrotate_rotate }}
|
||||
compress
|
||||
delaycompress
|
||||
missingok
|
||||
notifempty
|
||||
copytruncate
|
||||
}
|
||||
dest: "{{ reverse_proxy_housekeeping_logrotate_dropin }}"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
|
||||
- name: Validate the logrotate policy without applying it
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- /usr/sbin/logrotate
|
||||
- --debug
|
||||
- "{{ reverse_proxy_housekeeping_logrotate_dropin }}"
|
||||
check_mode: false
|
||||
changed_when: false
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Enable and start the logrotate timer
|
||||
ansible.builtin.systemd_service:
|
||||
name: logrotate.timer
|
||||
enabled: true
|
||||
state: started
|
||||
|
||||
- name: Read the failure state of the oneshot units hit by the full disk
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- /usr/bin/systemctl
|
||||
- is-failed
|
||||
- "{{ item }}"
|
||||
check_mode: false
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
loop:
|
||||
- logrotate.service
|
||||
- man-db.service
|
||||
register: reverse_proxy_housekeeping_failed_units
|
||||
|
||||
- name: Re-run the failed oneshot units so their failed state clears
|
||||
ansible.builtin.systemd_service:
|
||||
name: "{{ item.item }}"
|
||||
state: started
|
||||
loop: "{{ reverse_proxy_housekeeping_failed_units.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.item }}"
|
||||
when: item.stdout == "failed"
|
||||
|
||||
- name: Run logrotate once so the new NPM policy applies immediately
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- /usr/sbin/logrotate
|
||||
- /etc/logrotate.conf
|
||||
changed_when: false
|
||||
|
||||
# Phase 3: verify the headroom after the guard ran.
|
||||
|
||||
- name: Re-read the available bytes on the root filesystem
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- /usr/bin/df
|
||||
- --block-size=1
|
||||
- --output=avail
|
||||
- /
|
||||
check_mode: false
|
||||
changed_when: false
|
||||
register: reverse_proxy_housekeeping_df_after
|
||||
when: not ansible_check_mode
|
||||
|
||||
- name: Require the declared root filesystem headroom
|
||||
ansible.builtin.assert:
|
||||
that: >-
|
||||
(reverse_proxy_housekeeping_df_after.stdout_lines[1] | int) >=
|
||||
(reverse_proxy_housekeeping_root_min_available_bytes | int)
|
||||
fail_msg: >-
|
||||
The root filesystem is still below the declared headroom of
|
||||
{{ reverse_proxy_housekeeping_root_min_available_bytes }} bytes after
|
||||
the housekeeping guard ran.
|
||||
when: not ansible_check_mode
|
||||
Reference in New Issue
Block a user