From 819e3cb665bf3761d6ba1733a6ae29df47a47e18 Mon Sep 17 00:00:00 2001 From: spektr Date: Thu, 26 Nov 2026 19:00:10 +0100 Subject: [PATCH] CT 103: Disk-Housekeeping gegen volle Root-Platte (Gitea/Keycloak-Assets 0-Byte) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../ct-103-reverse-proxy/ansible/README.md | 15 ++ .../ansible/playbooks/disk-housekeeping.yml | 13 ++ .../ansible/playbooks/site.yml | 1 + .../ansible/playbooks/verify-production.yml | 27 +++ .../reverse_proxy_disk_housekeeping/README.md | 24 +++ .../defaults/main.yml | 26 +++ .../handlers/main.yml | 5 + .../tasks/main.yml | 200 ++++++++++++++++++ 8 files changed, 311 insertions(+) create mode 100644 proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/disk-housekeeping.yml create mode 100644 proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/README.md create mode 100644 proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/defaults/main.yml create mode 100644 proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/handlers/main.yml create mode 100644 proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/tasks/main.yml diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/README.md b/proxmox/lxc/ct-103-reverse-proxy/ansible/README.md index 0494ba5..0ab1402 100644 --- a/proxmox/lxc/ct-103-reverse-proxy/ansible/README.md +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/README.md @@ -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, diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/disk-housekeeping.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/disk-housekeeping.yml new file mode 100644 index 0000000..36d33eb --- /dev/null +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/disk-housekeeping.yml @@ -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 diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/site.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/site.yml index 3eb3e18..e88dfd8 100644 --- a/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/site.yml +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/site.yml @@ -26,3 +26,4 @@ - role: reverse_proxy_oauth2proxy - role: reverse_proxy_research_vhost - role: reverse_proxy_fail2ban + - role: reverse_proxy_disk_housekeeping diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/verify-production.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/verify-production.yml index 25b595b..79897fd 100644 --- a/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/verify-production.yml +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/playbooks/verify-production.yml @@ -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 diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/README.md b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/README.md new file mode 100644 index 0000000..b04375d --- /dev/null +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/README.md @@ -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. diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/defaults/main.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/defaults/main.yml new file mode 100644 index 0000000..4ce5f0e --- /dev/null +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/defaults/main.yml @@ -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) }} diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/handlers/main.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/handlers/main.yml new file mode 100644 index 0000000..0023f05 --- /dev/null +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: Restart systemd-journald + ansible.builtin.systemd_service: + name: systemd-journald + state: restarted diff --git a/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/tasks/main.yml b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/tasks/main.yml new file mode 100644 index 0000000..262e1d3 --- /dev/null +++ b/proxmox/lxc/ct-103-reverse-proxy/ansible/roles/reverse_proxy_disk_housekeeping/tasks/main.yml @@ -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