CT-103: Ansible-Nachbau fuer NPM/Fail2Ban (Adoption 07.11.2026)

Vollstaendiger CT-scoped Sollzustand fuer den Reverse-Proxy-LXC:
Konten/SSH-Drop-in (reverse_proxy_access), nftables (reverse_proxy_firewall),
NPM- und Fail2Ban-Quadlets inkl. Jails/Filter (reverse_proxy_npm,
reverse_proxy_fail2ban), LXC-Baseline sowie preflight/audit/bootstrap/
verify-deploy-access/site/verify-production-Playbooks fuer die Inventare
agent/bootstrap/production. NPM-Runtime-Daten (DB, Zertifikate, Proxyhosts)
bleiben bewusst aussen vor (Restore aus CT-Backup).

Verifiziert am 09.11.2026 gegen den Live-Host: preflight.yml (agent)
ok=15 failed=0; verify-production.yml (production) ok=27 changed=0 failed=0;
site.yml --check changed=0 (konvergent und idempotent). Host-Key-Fingerprint,
Hostname, Debian 13.7, 10.0.0.10, 2 vCPU/1024 MB matchen die Inventory-Safeguards.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-11-09 05:40:35 +01:00
parent 76feaa9549
commit eece53c7bb
48 changed files with 2127 additions and 4 deletions
+5 -4
View File
@@ -2,10 +2,11 @@
Host root for Nginx Proxy Manager and Fail2Ban at `10.0.0.10`.
The current service is documented and hardened, but its complete desired state
has not yet been imported into Ansible. New changes belong in a CT-scoped
Ansible project below this directory; generated NPM files must not be edited as
the authoritative source.
The complete desired state lives in the CT-scoped Ansible project
[`ansible/`](ansible/) (access accounts, SSH baseline, nftables, the NPM and
Fail2Ban Quadlets and the local Fail2Ban jails/filters). Generated NPM files
must not be edited as the authoritative source; NPM runtime data (database,
keys, certificates, proxy hosts) is restored from the CT backup.
See the
[`GNAI-006` operating and security record](../../../docs/platform/proxmox-server/lxc/ct-103-reverse-proxy/GNAI-006-SEC_Reverse-Proxy.md).
@@ -0,0 +1,71 @@
# CT 103 reverse proxy Ansible project
This self-contained host project manages the production reverse proxy LXC
(CT 103, `reverse-proxy`, 10.0.0.10: Nginx Proxy Manager, Fail2Ban, nftables).
It follows the CT 100 Pi-hole and CT 101 Samba project schema, uses the
repository-wide pinned control dependency and the shared `podman_runtime`
role, while all CT 103 inventories, playbooks, keys and service roles remain
inside the CT 103 root.
Create the repository-level control environment once:
```bash
python3 -m venv .venv
.venv/bin/python -m pip install --upgrade pip
.venv/bin/python -m pip install -r shared/ansible/requirements-control.txt
```
Run commands from this directory and always select an inventory explicitly:
```bash
cd proxmox/lxc/ct-103-reverse-proxy/ansible
../../../../.venv/bin/ansible-playbook \
--inventory inventories/agent/hosts.yml \
playbooks/preflight.yml \
--private-key ~/.ssh/id_ed25519_ghostnet_ct103_agent
```
## Adoption sequence for the pre-Ansible CT 103
The LXC was hardened and accepted before this project existed (GNAI-006).
The adoption path mirrors CT 100 and keeps the production proxy intact:
1. `preflight.yml` on the `agent` inventory (read-only, unprivileged,
`--private-key ~/.ssh/id_ed25519_ghostnet_ct103_agent`) proves identity,
service health, listeners and the local NPM admin answer.
2. `audit-production.yml` on the `bootstrap` inventory (read-only, become
through `ghost`, `--ask-become-pass`) deep-audits the root-only state and
reports the known drifts instead of failing on them.
3. `bootstrap.yml` on the `bootstrap` inventory adopts the `ansible-deploy`
account, the NOPASSWD sudo policy and the unified SSH drop-in; keep a
second session or the Proxmox console open while SSH policy changes are
applied.
4. `verify-deploy-access.yml` on the `production` inventory proves the new
deployment boundary
(`--private-key ~/.ssh/id_ed25519_ghostnet_ct103_ansible_deploy`).
5. `site.yml --check --diff` on the `production` inventory previews the
convergence. Expected changes: the SSH drop-in gains `AllowUsers
ansible-deploy`, `AllowStreamLocalForwarding no` and `DisableForwarding
yes`; SSH socket activation is replaced by the classic `ssh.service`;
`/etc/nftables.conf` is rewritten with the managed marker (identical
rules); the two stale Quadlet backups are removed.
6. `site.yml` converges; `verify-production.yml` plus a second
`site.yml --check` run with `changed=0` complete the adoption.
The production verifier is read-only. A real `site.yml` run enforces the
declared state and therefore requires an explicit change authorization.
## Declared scope and deliberate non-goals
- NPM runtime data (SQLite database, keys, Let's Encrypt certificates,
proxy hosts), the Fail2Ban configuration tree and ban database, and the
NPM admin password are backup-restored runtime artifacts. They are never
created, read or transported by these playbooks.
- `postfix.service` is present on the host but outside the GNAI-006 declared
state; this project neither installs nor removes it. The operator decides
whether to retire it.
- The functional Fail2Ban acceptance (GNAI-006 section 12) stays an
operator-run procedure; this project only pins the quadlet, jails and
filters.
- Do not store secret contents, private SSH keys or NPM access-log data in
this repository.
@@ -0,0 +1,12 @@
[defaults]
home = .ansible
host_key_checking = True
interpreter_python = auto_silent
local_tmp = .ansible/tmp
retry_files_enabled = False
roles_path = roles:../../../../shared/ansible/roles
timeout = 15
[ssh_connection]
pipelining = True
ssh_args = -o ControlMaster=auto -o ControlPersist=60s
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBbqc+Gb7tysX5K1R8+mPljlyVoxUlpDUfeP5Y6fem3K ansible-deploy@ct103-reverse-proxy
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKIbKODJqHAk6SVF/IB+L2ucBoTRIn1AUnXxpvVjPade ghost-agent@ct103-reverse-proxy
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEsXLT43P4LsYwKE56+AMz3NiimJhbkt6irZsMaNyA1Y ghost@ct103-reverse-proxy
@@ -0,0 +1,59 @@
---
ansible_become_method: sudo
ansible_python_interpreter: /usr/bin/python3
ansible_ssh_common_args: >-
-o IdentitiesOnly=yes
-o StrictHostKeyChecking=yes
-o UserKnownHostsFile=~/.ssh/known_hosts_ghostnet_ct103
reverse_proxy_expected_distribution: Debian
reverse_proxy_expected_distribution_major_version: "13"
reverse_proxy_expected_hostname: reverse-proxy
reverse_proxy_expected_virtualization_type: lxc
reverse_proxy_minimum_root_available_bytes: 1000000000
reverse_proxy_firewall_management_ipv4: 10.0.0.0/24
reverse_proxy_firewall_ssh_port: 22
reverse_proxy_firewall_admin_tcp_ports:
- 81
reverse_proxy_firewall_public_tcp_ports:
- 80
- 443
reverse_proxy_access_source_networks: 10.0.0.0/24
# Mirrored from the role defaults so that audit-production.yml and
# verify-production.yml can render the templates via lookup and compare them
# with the live files (self-contained inventory):
reverse_proxy_npm_image: docker.io/jc21/nginx-proxy-manager
reverse_proxy_npm_image_tag: "2.15.1"
reverse_proxy_npm_container_name: nginx-proxy-manager
reverse_proxy_npm_service_name: nginx-proxy-manager.service
reverse_proxy_npm_quadlet_path: /etc/containers/systemd/nginx-proxy-manager.container
reverse_proxy_npm_data_directory: /opt/nginx-proxy-manager/data
reverse_proxy_npm_letsencrypt_directory: /opt/nginx-proxy-manager/letsencrypt
reverse_proxy_npm_stale_quadlet_files:
- nginx-proxy-manager.container.bak-2.11.1
reverse_proxy_fail2ban_image: lscr.io/linuxserver/fail2ban
reverse_proxy_fail2ban_image_tag: "1.1.0-r2-ls43"
reverse_proxy_fail2ban_container_name: fail2ban
reverse_proxy_fail2ban_service_name: fail2ban.service
reverse_proxy_fail2ban_quadlet_path: /etc/containers/systemd/fail2ban.container
reverse_proxy_fail2ban_config_directory: /opt/fail2ban/config
reverse_proxy_fail2ban_stale_quadlet_files:
- fail2ban.container.bak-2026-09-16
# Additional mirrors of role defaults used only for template comparison in
# audit-production.yml and verify-production.yml:
reverse_proxy_npm_timezone: Europe/Berlin
reverse_proxy_fail2ban_timezone: Europe/Berlin
reverse_proxy_fail2ban_capabilities:
- NET_ADMIN
- NET_RAW
reverse_proxy_fail2ban_npm_logs_mount: /opt/nginx-proxy-manager/data/logs
reverse_proxy_fail2ban_ignoreip: 127.0.0.1/8 10.0.0.0/24
reverse_proxy_fail2ban_action: 'nftables-multiport[port="80,443", protocol=tcp]'
reverse_proxy_fail2ban_jail_directory: /opt/fail2ban/config/fail2ban/jail.d
reverse_proxy_fail2ban_filter_directory: /opt/fail2ban/config/fail2ban/filter.d
@@ -0,0 +1,7 @@
---
reverse_proxy_ctid: 103
reverse_proxy_expected_ipv4: 10.0.0.10
reverse_proxy_expected_ssh_host_key_fingerprint: >-
SHA256:XtPIUVMsVhvL7kFzsC/cZfo6I9vXCNGdROtoxzeNkdg
reverse_proxy_expected_processor_vcpus: 2
reverse_proxy_minimum_memory_mb: 1024
@@ -0,0 +1,8 @@
---
all:
children:
reverse_proxy_hosts:
hosts:
reverse-proxy-ct103:
ansible_host: 10.0.0.10
ansible_user: ghost-agent
@@ -0,0 +1,59 @@
---
ansible_become_method: sudo
ansible_python_interpreter: /usr/bin/python3
ansible_ssh_common_args: >-
-o IdentitiesOnly=yes
-o StrictHostKeyChecking=yes
-o UserKnownHostsFile=~/.ssh/known_hosts_ghostnet_ct103
reverse_proxy_expected_distribution: Debian
reverse_proxy_expected_distribution_major_version: "13"
reverse_proxy_expected_hostname: reverse-proxy
reverse_proxy_expected_virtualization_type: lxc
reverse_proxy_minimum_root_available_bytes: 1000000000
reverse_proxy_firewall_management_ipv4: 10.0.0.0/24
reverse_proxy_firewall_ssh_port: 22
reverse_proxy_firewall_admin_tcp_ports:
- 81
reverse_proxy_firewall_public_tcp_ports:
- 80
- 443
reverse_proxy_access_source_networks: 10.0.0.0/24
# Mirrored from the role defaults so that audit-production.yml and
# verify-production.yml can render the templates via lookup and compare them
# with the live files (self-contained inventory):
reverse_proxy_npm_image: docker.io/jc21/nginx-proxy-manager
reverse_proxy_npm_image_tag: "2.15.1"
reverse_proxy_npm_container_name: nginx-proxy-manager
reverse_proxy_npm_service_name: nginx-proxy-manager.service
reverse_proxy_npm_quadlet_path: /etc/containers/systemd/nginx-proxy-manager.container
reverse_proxy_npm_data_directory: /opt/nginx-proxy-manager/data
reverse_proxy_npm_letsencrypt_directory: /opt/nginx-proxy-manager/letsencrypt
reverse_proxy_npm_stale_quadlet_files:
- nginx-proxy-manager.container.bak-2.11.1
reverse_proxy_fail2ban_image: lscr.io/linuxserver/fail2ban
reverse_proxy_fail2ban_image_tag: "1.1.0-r2-ls43"
reverse_proxy_fail2ban_container_name: fail2ban
reverse_proxy_fail2ban_service_name: fail2ban.service
reverse_proxy_fail2ban_quadlet_path: /etc/containers/systemd/fail2ban.container
reverse_proxy_fail2ban_config_directory: /opt/fail2ban/config
reverse_proxy_fail2ban_stale_quadlet_files:
- fail2ban.container.bak-2026-09-16
# Additional mirrors of role defaults used only for template comparison in
# audit-production.yml and verify-production.yml:
reverse_proxy_npm_timezone: Europe/Berlin
reverse_proxy_fail2ban_timezone: Europe/Berlin
reverse_proxy_fail2ban_capabilities:
- NET_ADMIN
- NET_RAW
reverse_proxy_fail2ban_npm_logs_mount: /opt/nginx-proxy-manager/data/logs
reverse_proxy_fail2ban_ignoreip: 127.0.0.1/8 10.0.0.0/24
reverse_proxy_fail2ban_action: 'nftables-multiport[port="80,443", protocol=tcp]'
reverse_proxy_fail2ban_jail_directory: /opt/fail2ban/config/fail2ban/jail.d
reverse_proxy_fail2ban_filter_directory: /opt/fail2ban/config/fail2ban/filter.d
@@ -0,0 +1,7 @@
---
reverse_proxy_ctid: 103
reverse_proxy_expected_ipv4: 10.0.0.10
reverse_proxy_expected_ssh_host_key_fingerprint: >-
SHA256:XtPIUVMsVhvL7kFzsC/cZfo6I9vXCNGdROtoxzeNkdg
reverse_proxy_expected_processor_vcpus: 2
reverse_proxy_minimum_memory_mb: 1024
@@ -0,0 +1,8 @@
---
all:
children:
reverse_proxy_hosts:
hosts:
reverse-proxy-ct103:
ansible_host: 10.0.0.10
ansible_user: ghost
@@ -0,0 +1,59 @@
---
ansible_become_method: sudo
ansible_python_interpreter: /usr/bin/python3
ansible_ssh_common_args: >-
-o IdentitiesOnly=yes
-o StrictHostKeyChecking=yes
-o UserKnownHostsFile=~/.ssh/known_hosts_ghostnet_ct103
reverse_proxy_expected_distribution: Debian
reverse_proxy_expected_distribution_major_version: "13"
reverse_proxy_expected_hostname: reverse-proxy
reverse_proxy_expected_virtualization_type: lxc
reverse_proxy_minimum_root_available_bytes: 1000000000
reverse_proxy_firewall_management_ipv4: 10.0.0.0/24
reverse_proxy_firewall_ssh_port: 22
reverse_proxy_firewall_admin_tcp_ports:
- 81
reverse_proxy_firewall_public_tcp_ports:
- 80
- 443
reverse_proxy_access_source_networks: 10.0.0.0/24
# Mirrored from the role defaults so that audit-production.yml and
# verify-production.yml can render the templates via lookup and compare them
# with the live files (self-contained inventory):
reverse_proxy_npm_image: docker.io/jc21/nginx-proxy-manager
reverse_proxy_npm_image_tag: "2.15.1"
reverse_proxy_npm_container_name: nginx-proxy-manager
reverse_proxy_npm_service_name: nginx-proxy-manager.service
reverse_proxy_npm_quadlet_path: /etc/containers/systemd/nginx-proxy-manager.container
reverse_proxy_npm_data_directory: /opt/nginx-proxy-manager/data
reverse_proxy_npm_letsencrypt_directory: /opt/nginx-proxy-manager/letsencrypt
reverse_proxy_npm_stale_quadlet_files:
- nginx-proxy-manager.container.bak-2.11.1
reverse_proxy_fail2ban_image: lscr.io/linuxserver/fail2ban
reverse_proxy_fail2ban_image_tag: "1.1.0-r2-ls43"
reverse_proxy_fail2ban_container_name: fail2ban
reverse_proxy_fail2ban_service_name: fail2ban.service
reverse_proxy_fail2ban_quadlet_path: /etc/containers/systemd/fail2ban.container
reverse_proxy_fail2ban_config_directory: /opt/fail2ban/config
reverse_proxy_fail2ban_stale_quadlet_files:
- fail2ban.container.bak-2026-09-16
# Additional mirrors of role defaults used only for template comparison in
# audit-production.yml and verify-production.yml:
reverse_proxy_npm_timezone: Europe/Berlin
reverse_proxy_fail2ban_timezone: Europe/Berlin
reverse_proxy_fail2ban_capabilities:
- NET_ADMIN
- NET_RAW
reverse_proxy_fail2ban_npm_logs_mount: /opt/nginx-proxy-manager/data/logs
reverse_proxy_fail2ban_ignoreip: 127.0.0.1/8 10.0.0.0/24
reverse_proxy_fail2ban_action: 'nftables-multiport[port="80,443", protocol=tcp]'
reverse_proxy_fail2ban_jail_directory: /opt/fail2ban/config/fail2ban/jail.d
reverse_proxy_fail2ban_filter_directory: /opt/fail2ban/config/fail2ban/filter.d
@@ -0,0 +1,7 @@
---
reverse_proxy_ctid: 103
reverse_proxy_expected_ipv4: 10.0.0.10
reverse_proxy_expected_ssh_host_key_fingerprint: >-
SHA256:XtPIUVMsVhvL7kFzsC/cZfo6I9vXCNGdROtoxzeNkdg
reverse_proxy_expected_processor_vcpus: 2
reverse_proxy_minimum_memory_mb: 1024
@@ -0,0 +1,8 @@
---
all:
children:
reverse_proxy_hosts:
hosts:
reverse-proxy-ct103:
ansible_host: 10.0.0.10
ansible_user: ansible-deploy
@@ -0,0 +1,366 @@
---
- name: Read-only deep audit of the pre-Ansible CT 103 state
hosts: reverse_proxy_hosts
become: true
gather_facts: true
gather_subset:
- min
- hardware
- network
- virtual
vars:
reverse_proxy_audit_ssh_dropin: /etc/ssh/sshd_config.d/99-security.conf
tasks:
- name: Verify the expected guest identity
ansible.builtin.assert:
that:
- inventory_hostname == "reverse-proxy-ct103"
- reverse_proxy_ctid | int == 103
- ansible_facts["hostname"] == reverse_proxy_expected_hostname
- ansible_facts["distribution"] == reverse_proxy_expected_distribution
- >-
ansible_facts["distribution_major_version"] ==
reverse_proxy_expected_distribution_major_version
- >-
ansible_facts["default_ipv4"]["address"] ==
reverse_proxy_expected_ipv4
- >-
ansible_facts["virtualization_type"] ==
reverse_proxy_expected_virtualization_type
- ansible_facts["virtualization_role"] == "guest"
- ansible_facts["service_mgr"] == "systemd"
fail_msg: The connected machine is not the expected CT 103 LXC.
- name: Read failed systemd units
ansible.builtin.command:
argv:
- /usr/bin/systemctl
- --failed
- --no-legend
- --plain
check_mode: false
changed_when: false
register: reverse_proxy_audit_failed_units
- name: Require no failed units
ansible.builtin.assert:
that:
- reverse_proxy_audit_failed_units.stdout | trim == ""
- name: Report the SSH daemon activation mode
ansible.builtin.command:
argv:
- /usr/bin/systemctl
- is-enabled
- "{{ item }}"
check_mode: false
changed_when: false
failed_when: false
loop:
- ssh.socket
- ssh.service
register: reverse_proxy_audit_ssh_activation
- name: Report the known socket activation drift
ansible.builtin.debug:
msg: >-
ssh.socket={{ reverse_proxy_audit_ssh_activation.results[0].stdout }},
ssh.service={{ reverse_proxy_audit_ssh_activation.results[1].stdout }}.
The unified baseline moves CT 103 from ssh.socket activation to the
classic ssh.service managed by reverse_proxy_access.
- name: Read the deployed NPM Quadlet
ansible.builtin.command:
argv:
- /usr/bin/cat
- "{{ reverse_proxy_npm_quadlet_path }}"
check_mode: false
changed_when: false
register: reverse_proxy_audit_npm_quadlet
- name: Verify the live NPM Quadlet already matches the declared template
ansible.builtin.assert:
that:
- >-
reverse_proxy_audit_npm_quadlet.stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_npm/templates/nginx-proxy-manager.container.j2') | trim
fail_msg: The live NPM Quadlet differs from the declared template.
- name: Read the deployed Fail2Ban Quadlet
ansible.builtin.command:
argv:
- /usr/bin/cat
- "{{ reverse_proxy_fail2ban_quadlet_path }}"
check_mode: false
changed_when: false
register: reverse_proxy_audit_fail2ban_quadlet
- name: Verify the live Fail2Ban Quadlet already matches the declared template
ansible.builtin.assert:
that:
- >-
reverse_proxy_audit_fail2ban_quadlet.stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_fail2ban/templates/fail2ban.container.j2') | trim
fail_msg: The live Fail2Ban Quadlet differs from the declared template.
- name: Report the trailing newline normalization
ansible.builtin.debug:
msg: >-
The live Quadlet configuration files end with an extra blank line.
Convergence normalizes them to a single trailing newline; no
configuration content changes.
- name: Read the live local NPM jail and filter files
ansible.builtin.command:
argv:
- /usr/bin/cat
- "{{ item.path }}"
check_mode: false
changed_when: false
loop:
- path: "{{ reverse_proxy_fail2ban_jail_directory }}/npm-scanner.local"
- path: "{{ reverse_proxy_fail2ban_jail_directory }}/npm-badbots.local"
- path: "{{ reverse_proxy_fail2ban_filter_directory }}/npm-scanner.conf"
- path: "{{ reverse_proxy_fail2ban_filter_directory }}/npm-badbots.conf"
register: reverse_proxy_audit_fail2ban_configs
- name: Verify the live NPM jail and filter files match the declared templates
ansible.builtin.assert:
that:
- >-
reverse_proxy_audit_fail2ban_configs.results[0].stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_fail2ban/templates/npm-scanner.local.j2') | trim
- >-
reverse_proxy_audit_fail2ban_configs.results[1].stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_fail2ban/templates/npm-badbots.local.j2') | trim
- >-
reverse_proxy_audit_fail2ban_configs.results[2].stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_fail2ban/templates/npm-scanner.conf.j2') | trim
- >-
reverse_proxy_audit_fail2ban_configs.results[3].stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_fail2ban/templates/npm-badbots.conf.j2') | trim
fail_msg: A live NPM jail or filter file differs from the declared template.
- name: Read and validate the live nftables configuration
ansible.builtin.command:
argv:
- /usr/sbin/nft
- --check
- --file
- /etc/nftables.conf
check_mode: false
changed_when: false
register: reverse_proxy_audit_nftables_check
- name: Report the cosmetic nftables divergence
ansible.builtin.debug:
msg: >-
The live /etc/nftables.conf is semantically the declared policy
(nft --check rc={{ reverse_proxy_audit_nftables_check.rc }}), but it
still carries the pre-Ansible comment header. Convergence rewrites
it with the managed marker; no rule change is expected.
- name: Require the active input chain to carry the declared policy
ansible.builtin.command:
argv:
- /usr/sbin/nft
- list
- chain
- inet
- filter
- input
check_mode: false
changed_when: false
register: reverse_proxy_audit_input_chain
- name: Verify the active input chain semantics
ansible.builtin.assert:
that:
- reverse_proxy_audit_input_chain.stdout is search('policy drop')
- reverse_proxy_audit_input_chain.stdout is search('tcp dport { 80, 443 }')
- reverse_proxy_audit_input_chain.stdout is search('tcp dport { 22, 81 }')
- name: Validate the effective SSH policy
ansible.builtin.command:
argv:
- /usr/sbin/sshd
- -T
check_mode: false
changed_when: false
register: reverse_proxy_audit_effective_sshd
- name: Verify the hardened GNAI-006 SSH core
ansible.builtin.assert:
that:
- "'permitrootlogin no' in reverse_proxy_audit_effective_sshd.stdout_lines"
- "'passwordauthentication no' in reverse_proxy_audit_effective_sshd.stdout_lines"
- >-
'allowusers ghost-agent' in
reverse_proxy_audit_effective_sshd.stdout_lines
- >-
'allowusers ghost' in
reverse_proxy_audit_effective_sshd.stdout_lines
- >-
'allowusers ansible-deploy' not in
reverse_proxy_audit_effective_sshd.stdout_lines
- "'allowtcpforwarding no' in reverse_proxy_audit_effective_sshd.stdout_lines"
- name: Detect the unified baseline SSH drifts to be adopted
ansible.builtin.set_fact:
reverse_proxy_audit_ssh_drifts: >-
{{
[] +
([] if 'allowstreamlocalforwarding no' in reverse_proxy_audit_effective_sshd.stdout_lines else ['AllowStreamLocalForwarding no']) +
([] if 'disableforwarding yes' in reverse_proxy_audit_effective_sshd.stdout_lines else ['DisableForwarding yes']) +
([] if reverse_proxy_audit_effective_sshd.stdout is search('allowusers .*ansible-deploy')
else ['AllowUsers ansible-deploy'])
}}
- name: Report the unified baseline SSH drifts
ansible.builtin.debug:
msg: >-
Expected adoption drifts in the SSH drop-in: {{ reverse_proxy_audit_ssh_drifts | join(', ') }}.
- name: Read the live access account states
ansible.builtin.command:
argv:
- /usr/bin/passwd
- -S
- "{{ item }}"
check_mode: false
changed_when: false
loop:
- ghost-agent
- ghost
register: reverse_proxy_audit_password_states
- name: Require the pre-Ansible account states
ansible.builtin.assert:
that:
- reverse_proxy_audit_password_states.results[0].stdout.split()[1] == "L"
- reverse_proxy_audit_password_states.results[1].stdout.split()[1] == "P"
- name: Stat the hardened NPM runtime paths
ansible.builtin.stat:
path: "{{ item }}"
loop:
- /opt/nginx-proxy-manager/data
- /opt/nginx-proxy-manager/data/logs
- /opt/nginx-proxy-manager/data/database.sqlite
- /opt/nginx-proxy-manager/data/keys.json
register: reverse_proxy_audit_npm_hardening
- name: Verify the accepted NPM file hardening
ansible.builtin.assert:
that:
- reverse_proxy_audit_npm_hardening.results[0].stat.mode == "0750"
- reverse_proxy_audit_npm_hardening.results[1].stat.mode == "0750"
- reverse_proxy_audit_npm_hardening.results[2].stat.mode == "0600"
- reverse_proxy_audit_npm_hardening.results[3].stat.mode == "0600"
- name: Read the active Fail2Ban jail status
ansible.builtin.command:
argv:
- /usr/bin/podman
- exec
- fail2ban
- fail2ban-client
- status
check_mode: false
changed_when: false
failed_when: false
register: reverse_proxy_audit_fail2ban_status
- name: Report the active Fail2Ban jail status
ansible.builtin.debug:
msg: "{{ reverse_proxy_audit_fail2ban_status.stdout | trim | default('unreadable', true) }}"
- name: Enumerate the active Fail2Ban nftables elements
ansible.builtin.command:
argv:
- /usr/sbin/nft
- list
- ruleset
check_mode: false
changed_when: false
register: reverse_proxy_audit_nft_ruleset
- name: Report the active Fail2Ban bans
ansible.builtin.debug:
msg: >-
{% set found = reverse_proxy_audit_nft_ruleset.stdout is search('f2b-table') %}
{% if found %}
Active f2b-table elements detected in the nftables ruleset.
{% else %}
No f2b-table in the ruleset; currently no active Fail2Ban bans.
{% endif %}
- name: Report the postfix observation
ansible.builtin.command:
argv:
- /usr/bin/systemctl
- is-active
- postfix.service
check_mode: false
changed_when: false
failed_when: false
register: reverse_proxy_audit_postfix
- name: Report postfix as out-of-scope drift
ansible.builtin.debug:
msg: >-
postfix.service is {{ reverse_proxy_audit_postfix.stdout }} but is not
part of the GNAI-006 declared state; this project neither installs
nor removes it. The operator decides whether to retire it.
- name: Read the service states
ansible.builtin.command:
argv:
- /usr/bin/systemctl
- is-active
- "{{ item }}"
check_mode: false
changed_when: false
loop:
- ssh.service
- nftables.service
- nginx-proxy-manager.service
- fail2ban.service
- unattended-upgrades.service
register: reverse_proxy_audit_service_states
- name: Require every core service to be active
ansible.builtin.assert:
that:
- >-
reverse_proxy_audit_service_states.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: Report the audit result
ansible.builtin.debug:
msg:
ctid: "{{ reverse_proxy_ctid }}"
hostname: "{{ ansible_facts['hostname'] }}"
ipv4: "{{ ansible_facts.default_ipv4.address }}"
socket_activation_drift: "ssh.socket -> ssh.service"
ssh_dropin_drifts: "{{ reverse_proxy_audit_ssh_drifts }}"
out_of_scope: "postfix.service={{ reverse_proxy_audit_postfix.stdout }}"
trusted_ssh_fingerprint: "{{ reverse_proxy_expected_ssh_host_key_fingerprint }}"
@@ -0,0 +1,12 @@
---
- name: Adopt the CT 103 access bootstrap declaratively
hosts: reverse_proxy_hosts
become: true
gather_facts: true
gather_subset:
- min
- network
- virtual
roles:
- role: reverse_proxy_access
@@ -0,0 +1,171 @@
---
- name: Read-only verification of the CT 103 reverse proxy LXC
hosts: reverse_proxy_hosts
become: false
gather_facts: true
gather_subset:
- min
- hardware
- network
- virtual
tasks:
- name: Verify required inventory safeguards are defined
ansible.builtin.assert:
that:
- reverse_proxy_ctid is defined
- reverse_proxy_expected_hostname is defined
- reverse_proxy_expected_ipv4 is defined
- reverse_proxy_expected_ssh_host_key_fingerprint is defined
- reverse_proxy_expected_distribution is defined
- reverse_proxy_expected_distribution_major_version is defined
- reverse_proxy_expected_virtualization_type is defined
- reverse_proxy_expected_processor_vcpus is defined
- reverse_proxy_minimum_memory_mb is defined
fail_msg: >-
The selected inventory lacks mandatory CT 103 identity safeguards.
Stop before running any configuration playbook.
- name: Verify the expected guest identity
ansible.builtin.assert:
that:
- inventory_hostname == "reverse-proxy-ct103"
- reverse_proxy_ctid | int == 103
- ansible_facts["hostname"] == reverse_proxy_expected_hostname
- ansible_facts["distribution"] == reverse_proxy_expected_distribution
- >-
ansible_facts["distribution_major_version"] ==
reverse_proxy_expected_distribution_major_version
- >-
ansible_facts["default_ipv4"]["address"] ==
reverse_proxy_expected_ipv4
- >-
ansible_facts["virtualization_type"] ==
reverse_proxy_expected_virtualization_type
- ansible_facts["virtualization_role"] == "guest"
- ansible_facts["service_mgr"] == "systemd"
- ansible_facts["python"]["version"]["major"] | int >= 3
fail_msg: >-
The connected machine is not the expected CT 103 reverse proxy LXC.
success_msg: >-
The expected Debian 13 reverse proxy LXC is connected.
- name: Read the connected identity
ansible.builtin.command:
argv:
- /usr/bin/id
- -un
check_mode: false
changed_when: false
register: reverse_proxy_preflight_identity
- name: Require the unprivileged read-only agent account
ansible.builtin.assert:
that:
- reverse_proxy_preflight_identity.stdout == "ghost-agent"
- name: Require the expected compute resources
ansible.builtin.assert:
that:
- ansible_facts["processor_vcpus"] | int >= reverse_proxy_expected_processor_vcpus | int
- ansible_facts["memtotal_mb"] | int >= reverse_proxy_minimum_memory_mb | int
- name: Read failed systemd units
ansible.builtin.command:
argv:
- /usr/bin/systemctl
- --failed
- --no-legend
- --plain
check_mode: false
changed_when: false
register: reverse_proxy_preflight_failed_units
- name: Require no failed units
ansible.builtin.assert:
that:
- reverse_proxy_preflight_failed_units.stdout | trim == ""
- name: Read required service states
ansible.builtin.command:
argv:
- /usr/bin/systemctl
- is-active
- "{{ item }}"
check_mode: false
changed_when: false
loop:
- ssh.service
- nftables.service
- nginx-proxy-manager.service
- fail2ban.service
- unattended-upgrades.service
register: reverse_proxy_preflight_service_states
- name: Require every core service to be active
ansible.builtin.assert:
that:
- >-
reverse_proxy_preflight_service_states.results |
map(attribute='stdout') | unique | list == ['active']
- name: Read the service listeners
ansible.builtin.command:
argv:
- /usr/bin/ss
- -H
- -tuln
check_mode: false
changed_when: false
register: reverse_proxy_preflight_listeners
- name: Require the proxy, admin, backend and SSH listeners
ansible.builtin.assert:
that:
- reverse_proxy_preflight_listeners.stdout is search(':80 ')
- reverse_proxy_preflight_listeners.stdout is search(':81 ')
- reverse_proxy_preflight_listeners.stdout is search(':443 ')
- reverse_proxy_preflight_listeners.stdout is search(':22 ')
- reverse_proxy_preflight_listeners.stdout is search(':3000 ')
fail_msg: >-
The CT 103 service listeners for HTTP, the NPM admin interface,
HTTPS, the NPM backend and SSH are incomplete.
- name: Read the local NPM admin response
ansible.builtin.command:
argv:
- /usr/bin/curl
- -sS
- -o
- /dev/null
- -w
- "%{http_code}"
- http://127.0.0.1:81/
check_mode: false
changed_when: false
register: reverse_proxy_preflight_admin_response
failed_when: false
vars:
ansible_command_timeout: 10
- name: Require the NPM admin interface to answer locally
ansible.builtin.assert:
that:
- reverse_proxy_preflight_admin_response.stdout in ["200", "301", "302"]
fail_msg: The NPM admin interface on port 81 did not answer.
- name: Report the verified CT 103 baseline
ansible.builtin.debug:
msg:
inventory_host: "{{ inventory_hostname }}"
ctid: "{{ reverse_proxy_ctid }}"
hostname: "{{ ansible_facts['hostname'] }}"
operating_system: >-
{{ ansible_facts['distribution'] }}
{{ ansible_facts['distribution_version'] }}
default_ipv4: "{{ ansible_facts['default_ipv4']['address'] }}"
virtualization: >-
{{ ansible_facts['virtualization_type'] }}
{{ ansible_facts['virtualization_role'] }}
memory_mib: "{{ ansible_facts['memtotal_mb'] }}"
trusted_ssh_fingerprint: "{{ reverse_proxy_expected_ssh_host_key_fingerprint }}"
@@ -0,0 +1,26 @@
---
- name: Converge the CT 103 reverse proxy LXC on the declared state
hosts: reverse_proxy_hosts
become: true
gather_facts: true
gather_subset:
- min
- hardware
- network
- virtual
roles:
- role: reverse_proxy_lxc_baseline
vars:
reverse_proxy_lxc_baseline_expected_hostname: "{{ reverse_proxy_expected_hostname }}"
reverse_proxy_lxc_baseline_expected_distribution: "{{ reverse_proxy_expected_distribution }}"
reverse_proxy_lxc_baseline_expected_distribution_major_version: >-
{{ reverse_proxy_expected_distribution_major_version }}
reverse_proxy_lxc_baseline_expected_ipv4: "{{ reverse_proxy_expected_ipv4 }}"
reverse_proxy_lxc_baseline_expected_virtualization_type: >-
{{ reverse_proxy_expected_virtualization_type }}
- role: reverse_proxy_access
- role: podman_runtime
- role: reverse_proxy_firewall
- role: reverse_proxy_npm
- role: reverse_proxy_fail2ban
@@ -0,0 +1,43 @@
---
- name: Verify the CT 103 Ansible deployment boundary
hosts: reverse_proxy_hosts
become: false
gather_facts: false
tasks:
- name: Verify Ansible module execution without privilege escalation
ansible.builtin.ping:
- name: Read the SSH account identity
ansible.builtin.command:
argv:
- /usr/bin/id
- -un
check_mode: false
changed_when: false
register: reverse_proxy_deploy_account_identity
- name: Verify the expected SSH account
ansible.builtin.assert:
that:
- reverse_proxy_deploy_account_identity.stdout == "ansible-deploy"
fail_msg: The SSH connection did not use ansible-deploy.
- name: Read the effective identity through sudo
become: true
ansible.builtin.command:
argv:
- /usr/bin/id
- -u
check_mode: false
changed_when: false
register: reverse_proxy_deploy_root_identity
- name: Verify non-interactive root escalation
ansible.builtin.assert:
that:
- reverse_proxy_deploy_root_identity.stdout == "0"
fail_msg: Non-interactive sudo did not produce effective UID 0.
success_msg: >-
The CT 103 deployment account can connect and escalate privileges
non-interactively.
@@ -0,0 +1,286 @@
---
- name: Read-only verification of the converged CT 103 production state
hosts: reverse_proxy_hosts
become: true
gather_facts: true
gather_subset:
- min
- hardware
- network
- virtual
tasks:
- name: Verify the expected guest identity
ansible.builtin.assert:
that:
- inventory_hostname == "reverse-proxy-ct103"
- reverse_proxy_ctid | int == 103
- ansible_facts["hostname"] == reverse_proxy_expected_hostname
- >-
ansible_facts["default_ipv4"]["address"] ==
reverse_proxy_expected_ipv4
- >-
ansible_facts["virtualization_type"] ==
reverse_proxy_expected_virtualization_type
- ansible_facts["virtualization_role"] == "guest"
- ansible_facts["service_mgr"] == "systemd"
fail_msg: The connected machine is not the expected CT 103 LXC.
- name: Read failed systemd units
ansible.builtin.command:
argv:
- /usr/bin/systemctl
- --failed
- --no-legend
- --plain
check_mode: false
changed_when: false
register: reverse_proxy_production_failed_units
- name: Require no failed units
ansible.builtin.assert:
that:
- reverse_proxy_production_failed_units.stdout | trim == ""
- name: Read required service states
ansible.builtin.command:
argv:
- /usr/bin/systemctl
- is-active
- "{{ item }}"
check_mode: false
changed_when: false
loop:
- ssh.service
- nftables.service
- nginx-proxy-manager.service
- fail2ban.service
- unattended-upgrades.service
register: reverse_proxy_production_services
- name: Require every production service to be active
ansible.builtin.assert:
that:
- >-
reverse_proxy_production_services.results |
map(attribute='stdout') | unique | list == ['active']
- name: Require SSH socket activation to be gone
ansible.builtin.systemd_service:
name: ssh.socket
enabled: false
state: stopped
check_mode: true
register: reverse_proxy_production_ssh_socket
- name: Verify ssh.socket stays disabled and stopped
ansible.builtin.assert:
that:
- not reverse_proxy_production_ssh_socket.changed
- name: Read the service listeners
ansible.builtin.command:
argv:
- /usr/bin/ss
- -H
- -tuln
check_mode: false
changed_when: false
register: reverse_proxy_production_listeners
- name: Require the proxy, admin, backend and SSH listeners
ansible.builtin.assert:
that:
- reverse_proxy_production_listeners.stdout is search(':80 ')
- reverse_proxy_production_listeners.stdout is search(':81 ')
- reverse_proxy_production_listeners.stdout is search(':443 ')
- reverse_proxy_production_listeners.stdout is search(':22 ')
- reverse_proxy_production_listeners.stdout is search(':3000 ')
- name: Validate the effective SSH policy
ansible.builtin.command:
argv:
- /usr/sbin/sshd
- -T
check_mode: false
changed_when: false
register: reverse_proxy_production_effective_sshd
- name: Verify the full effective SSH baseline
ansible.builtin.assert:
that:
- "'permitrootlogin no' in reverse_proxy_production_effective_sshd.stdout_lines"
- "'passwordauthentication no' in reverse_proxy_production_effective_sshd.stdout_lines"
- "'kbdinteractiveauthentication no' in reverse_proxy_production_effective_sshd.stdout_lines"
- "'pubkeyauthentication yes' in reverse_proxy_production_effective_sshd.stdout_lines"
- "'allowtcpforwarding no' in reverse_proxy_production_effective_sshd.stdout_lines"
- "'allowstreamlocalforwarding no' in reverse_proxy_production_effective_sshd.stdout_lines"
- "'disableforwarding yes' in reverse_proxy_production_effective_sshd.stdout_lines"
- "'permittunnel no' in reverse_proxy_production_effective_sshd.stdout_lines"
- "'maxauthtries 3' in reverse_proxy_production_effective_sshd.stdout_lines"
- "'logingracetime 30' in reverse_proxy_production_effective_sshd.stdout_lines"
- "'loglevel VERBOSE' in reverse_proxy_production_effective_sshd.stdout_lines"
- >-
'allowusers ghost-agent' in
reverse_proxy_production_effective_sshd.stdout_lines
- >-
'allowusers ghost' in
reverse_proxy_production_effective_sshd.stdout_lines
- >-
'allowusers ansible-deploy' in
reverse_proxy_production_effective_sshd.stdout_lines
- name: Read account password states
ansible.builtin.command:
argv:
- /usr/bin/passwd
- -S
- "{{ item }}"
check_mode: false
changed_when: false
loop:
- ghost-agent
- ghost
- ansible-deploy
register: reverse_proxy_production_password_states
- name: Verify account password states
ansible.builtin.assert:
that:
- reverse_proxy_production_password_states.results[0].stdout.split()[1] == "L"
- reverse_proxy_production_password_states.results[1].stdout.split()[1] == "P"
- reverse_proxy_production_password_states.results[2].stdout.split()[1] == "L"
- name: Read the deployed NPM Quadlet
ansible.builtin.command:
argv:
- /usr/bin/cat
- "{{ reverse_proxy_npm_quadlet_path }}"
check_mode: false
changed_when: false
register: reverse_proxy_production_npm_quadlet
- name: Require the NPM Quadlet to match the declared template
ansible.builtin.assert:
that:
- >-
reverse_proxy_production_npm_quadlet.stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_npm/templates/nginx-proxy-manager.container.j2') | trim
- name: Read the deployed Fail2Ban Quadlet
ansible.builtin.command:
argv:
- /usr/bin/cat
- "{{ reverse_proxy_fail2ban_quadlet_path }}"
check_mode: false
changed_when: false
register: reverse_proxy_production_fail2ban_quadlet
- name: Require the Fail2Ban Quadlet to match the declared template
ansible.builtin.assert:
that:
- >-
reverse_proxy_production_fail2ban_quadlet.stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_fail2ban/templates/fail2ban.container.j2') | trim
- name: Read the local NPM jail and filter files
ansible.builtin.command:
argv:
- /usr/bin/cat
- "{{ item.path }}"
check_mode: false
changed_when: false
loop:
- path: "{{ reverse_proxy_fail2ban_jail_directory }}/npm-scanner.local"
- path: "{{ reverse_proxy_fail2ban_jail_directory }}/npm-badbots.local"
- path: "{{ reverse_proxy_fail2ban_filter_directory }}/npm-scanner.conf"
- path: "{{ reverse_proxy_fail2ban_filter_directory }}/npm-badbots.conf"
register: reverse_proxy_production_fail2ban_configs
- name: Require the NPM jail and filter files to match the declared templates
ansible.builtin.assert:
that:
- >-
reverse_proxy_production_fail2ban_configs.results[0].stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_fail2ban/templates/npm-scanner.local.j2') | trim
- >-
reverse_proxy_production_fail2ban_configs.results[1].stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_fail2ban/templates/npm-badbots.local.j2') | trim
- >-
reverse_proxy_production_fail2ban_configs.results[2].stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_fail2ban/templates/npm-scanner.conf.j2') | trim
- >-
reverse_proxy_production_fail2ban_configs.results[3].stdout | trim ==
lookup('ansible.builtin.template',
playbook_dir ~ '/../roles/reverse_proxy_fail2ban/templates/npm-badbots.conf.j2') | trim
- name: Require the stale Quadlet backups to be gone
ansible.builtin.stat:
path: "/etc/containers/systemd/{{ item }}"
loop: >-
{{ reverse_proxy_npm_stale_quadlet_files +
reverse_proxy_fail2ban_stale_quadlet_files }}
register: reverse_proxy_production_stale_files
- name: Verify no stale Quadlet backups remain
ansible.builtin.assert:
that:
- >-
reverse_proxy_production_stale_files.results |
map(attribute='stat.exists') | unique | list == [false]
- name: Stat the hardened NPM runtime paths
ansible.builtin.stat:
path: "{{ item }}"
loop:
- /opt/nginx-proxy-manager/data
- /opt/nginx-proxy-manager/data/logs
- /opt/nginx-proxy-manager/data/database.sqlite
- /opt/nginx-proxy-manager/data/keys.json
register: reverse_proxy_production_npm_hardening
- name: Verify the NPM file hardening
ansible.builtin.assert:
that:
- reverse_proxy_production_npm_hardening.results[0].stat.mode == "0750"
- reverse_proxy_production_npm_hardening.results[1].stat.mode == "0750"
- reverse_proxy_production_npm_hardening.results[2].stat.mode == "0600"
- reverse_proxy_production_npm_hardening.results[3].stat.mode == "0600"
- name: Read the local NPM admin response
ansible.builtin.command:
argv:
- /usr/bin/curl
- -sS
- -o
- /dev/null
- -w
- "%{http_code}"
- http://127.0.0.1:81/
check_mode: false
changed_when: false
register: reverse_proxy_production_admin_response
vars:
ansible_command_timeout: 10
- name: Require the NPM admin interface to answer locally
ansible.builtin.assert:
that:
- reverse_proxy_production_admin_response.stdout in ["200", "301", "302"]
- name: Report the verified CT 103 production state
ansible.builtin.debug:
msg:
ctid: "{{ reverse_proxy_ctid }}"
hostname: "{{ ansible_facts['hostname'] }}"
ipv4: "{{ ansible_facts['default_ipv4']['address'] }}"
services: >-
{{ reverse_proxy_production_services.results |
map(attribute='stdout') | unique | list }}
npm_admin_http: "{{ reverse_proxy_production_admin_response.stdout | trim }}"
trusted_ssh_fingerprint: "{{ reverse_proxy_expected_ssh_host_key_fingerprint }}"
@@ -0,0 +1,15 @@
# CT 103 reverse_proxy_access
Adopts the shared LXC access accounts on the CT 103 reverse proxy:
`ghost-agent` (uid 1000, read-only, locked), `ghost` (uid 1001, password-gated
sudo membership) and `ansible-deploy` (uid 1002, NOPASSWD sudo, restricted
deployment key). Installs the hardened SSH drop-in
`/etc/ssh/sshd_config.d/99-security.conf` exactly as accepted in GNAI-006
sections 2.1 and 2.9, plus the two baseline extensions shared with the other
adopted LXCs (`AllowStreamLocalForwarding no`, `DisableForwarding yes`), and
moves the host from `ssh.socket` activation to the classic `ssh.service`
managed by this role.
Private keys never enter this repository; only the public keys below
`files/ssh/` are managed. Interactive secret steps (the `ghost` account
password and sudo password prompts) remain operator-run.
@@ -0,0 +1,28 @@
---
reverse_proxy_access_source_networks: 10.0.0.0/24
reverse_proxy_access_public_key_root: "{{ playbook_dir }}/../files/ssh"
reverse_proxy_access_agent_user: ghost-agent
reverse_proxy_access_agent_uid: 1000
reverse_proxy_access_agent_public_key_file: >-
{{ reverse_proxy_access_public_key_root }}/reverse-proxy-ghost-agent.pub
reverse_proxy_access_admin_user: ghost
reverse_proxy_access_admin_uid: 1001
reverse_proxy_access_admin_public_key_file: >-
{{ reverse_proxy_access_public_key_root }}/reverse-proxy-ghost.pub
reverse_proxy_access_deploy_user: ansible-deploy
reverse_proxy_access_deploy_uid: 1002
reverse_proxy_access_deploy_public_key_file: >-
{{ reverse_proxy_access_public_key_root }}/reverse-proxy-ansible-deploy.pub
reverse_proxy_access_ssh_dropin: /etc/ssh/sshd_config.d/99-security.conf
reverse_proxy_access_sudoers_file: /etc/sudoers.d/90-ghostnet-ansible-deploy
# AllowUsers stays explicit on CT 103: the GNAI-006 hardening set it and every
# login path is covered by the three managed accounts.
reverse_proxy_access_allow_users:
- ghost-agent
- ghost
- ansible-deploy
@@ -0,0 +1,5 @@
---
- name: Restart the classic SSH service
ansible.builtin.systemd_service:
name: ssh.service
state: restarted
@@ -0,0 +1,217 @@
---
- name: Create fixed primary groups for the CT 103 access accounts
ansible.builtin.group:
name: "{{ item.name }}"
gid: "{{ item.uid }}"
state: present
loop:
- name: "{{ reverse_proxy_access_agent_user }}"
uid: "{{ reverse_proxy_access_agent_uid }}"
- name: "{{ reverse_proxy_access_admin_user }}"
uid: "{{ reverse_proxy_access_admin_uid }}"
- name: "{{ reverse_proxy_access_deploy_user }}"
uid: "{{ reverse_proxy_access_deploy_uid }}"
loop_control:
label: "{{ item.name }}"
- name: Create the fixed CT 103 access accounts
ansible.builtin.user:
name: "{{ item.name }}"
uid: "{{ item.uid }}"
group: "{{ item.name }}"
home: "/home/{{ item.name }}"
shell: /bin/bash
create_home: true
state: present
loop:
- name: "{{ reverse_proxy_access_agent_user }}"
uid: "{{ reverse_proxy_access_agent_uid }}"
- name: "{{ reverse_proxy_access_admin_user }}"
uid: "{{ reverse_proxy_access_admin_uid }}"
- name: "{{ reverse_proxy_access_deploy_user }}"
uid: "{{ reverse_proxy_access_deploy_uid }}"
loop_control:
label: "{{ item.name }}"
- name: Keep the read-only agent outside supplementary groups
ansible.builtin.user:
name: "{{ reverse_proxy_access_agent_user }}"
groups: ""
append: false
password_lock: true
- name: Keep the deployment account outside supplementary groups
ansible.builtin.user:
name: "{{ reverse_proxy_access_deploy_user }}"
groups: ""
append: false
password_lock: true
- name: Grant password-gated sudo membership to the administrator
ansible.builtin.user:
name: "{{ reverse_proxy_access_admin_user }}"
groups:
- sudo
append: true
- name: Create protected SSH directories
ansible.builtin.file:
path: "/home/{{ item }}/.ssh"
state: directory
owner: "{{ item }}"
group: "{{ item }}"
mode: "0700"
loop:
- "{{ reverse_proxy_access_agent_user }}"
- "{{ reverse_proxy_access_admin_user }}"
- "{{ reverse_proxy_access_deploy_user }}"
- name: Install the read-only agent key
ansible.builtin.copy:
content: "{{ lookup('ansible.builtin.file', reverse_proxy_access_agent_public_key_file) }}"
dest: "/home/{{ reverse_proxy_access_agent_user }}/.ssh/authorized_keys"
owner: "{{ reverse_proxy_access_agent_user }}"
group: "{{ reverse_proxy_access_agent_user }}"
mode: "0600"
- name: Install the personal administrator key
ansible.builtin.copy:
content: "{{ lookup('ansible.builtin.file', reverse_proxy_access_admin_public_key_file) }}"
dest: "/home/{{ reverse_proxy_access_admin_user }}/.ssh/authorized_keys"
owner: "{{ reverse_proxy_access_admin_user }}"
group: "{{ reverse_proxy_access_admin_user }}"
mode: "0600"
- name: Install the restricted deployment key
ansible.builtin.copy:
content: |
restrict,from="{{ reverse_proxy_access_source_networks }}" {{ lookup('ansible.builtin.file', reverse_proxy_access_deploy_public_key_file) }}
dest: "/home/{{ reverse_proxy_access_deploy_user }}/.ssh/authorized_keys"
owner: "{{ reverse_proxy_access_deploy_user }}"
group: "{{ reverse_proxy_access_deploy_user }}"
mode: "0600"
- name: Install the validated deployment sudo policy
ansible.builtin.copy:
content: |
{{ reverse_proxy_access_deploy_user }} ALL=(root) NOPASSWD: ALL
dest: "{{ reverse_proxy_access_sudoers_file }}"
owner: root
group: root
mode: "0440"
validate: /usr/sbin/visudo -cf %s
- name: Ensure root has no SSH authorization material
ansible.builtin.file:
path: /root/.ssh
state: directory
owner: root
group: root
mode: "0700"
- name: Keep the root authorized keys file empty
ansible.builtin.copy:
content: ""
dest: /root/.ssh/authorized_keys
owner: root
group: root
mode: "0600"
- name: Install the hardened SSH policy
ansible.builtin.template:
src: sshd.conf.j2
dest: "{{ reverse_proxy_access_ssh_dropin }}"
owner: root
group: root
mode: "0644"
validate: /usr/sbin/sshd -t -f %s
notify: Restart the classic SSH service
- name: Disable SSH socket activation
ansible.builtin.systemd_service:
name: ssh.socket
enabled: false
state: stopped
- name: Enable the classic SSH service
ansible.builtin.systemd_service:
name: ssh.service
enabled: true
state: started
- name: Read account password states
ansible.builtin.command:
argv:
- /usr/bin/passwd
- -S
- "{{ item }}"
check_mode: false
changed_when: false
loop:
- "{{ reverse_proxy_access_agent_user }}"
- "{{ reverse_proxy_access_admin_user }}"
- "{{ reverse_proxy_access_deploy_user }}"
register: reverse_proxy_access_password_states
- name: Verify account password states
ansible.builtin.assert:
that:
- reverse_proxy_access_password_states.results[0].stdout.split()[1] == "L"
- reverse_proxy_access_password_states.results[1].stdout.split()[1] == "P"
- reverse_proxy_access_password_states.results[2].stdout.split()[1] == "L"
fail_msg: >-
ghost-agent and ansible-deploy must remain locked, while ghost must keep
the independently assigned password used only for sudo.
- name: Read effective supplementary groups
ansible.builtin.command:
argv:
- /usr/bin/id
- -Gn
- "{{ item }}"
check_mode: false
changed_when: false
loop:
- "{{ reverse_proxy_access_agent_user }}"
- "{{ reverse_proxy_access_deploy_user }}"
register: reverse_proxy_access_restricted_groups
- name: Verify restricted accounts have no supplementary groups
ansible.builtin.assert:
that:
- >-
reverse_proxy_access_restricted_groups.results[0].stdout ==
reverse_proxy_access_agent_user
- >-
reverse_proxy_access_restricted_groups.results[1].stdout ==
reverse_proxy_access_deploy_user
- name: Flush SSH policy handlers before final validation
ansible.builtin.meta: flush_handlers
- name: Validate the effective SSH policy
ansible.builtin.command:
argv:
- /usr/sbin/sshd
- -T
check_mode: false
changed_when: false
register: reverse_proxy_access_effective_sshd
when: not ansible_check_mode
- name: Verify critical effective SSH settings
ansible.builtin.assert:
that:
- "'permitrootlogin no' in reverse_proxy_access_effective_sshd.stdout_lines"
- "'passwordauthentication no' in reverse_proxy_access_effective_sshd.stdout_lines"
- "'kbdinteractiveauthentication no' in reverse_proxy_access_effective_sshd.stdout_lines"
- "'pubkeyauthentication yes' in reverse_proxy_access_effective_sshd.stdout_lines"
- "'allowtcpforwarding no' in reverse_proxy_access_effective_sshd.stdout_lines"
- "'allowstreamlocalforwarding no' in reverse_proxy_access_effective_sshd.stdout_lines"
- "'disableforwarding yes' in reverse_proxy_access_effective_sshd.stdout_lines"
- "'permittunnel no' in reverse_proxy_access_effective_sshd.stdout_lines"
- "'maxauthtries 3' in reverse_proxy_access_effective_sshd.stdout_lines"
- "'logingracetime 30' in reverse_proxy_access_effective_sshd.stdout_lines"
- "'loglevel VERBOSE' in reverse_proxy_access_effective_sshd.stdout_lines"
fail_msg: The effective SSH policy differs from the declared baseline.
when: not ansible_check_mode
@@ -0,0 +1,20 @@
# Managed by Ansible role reverse_proxy_access.
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitEmptyPasswords no
AuthenticationMethods publickey
AllowUsers {{ reverse_proxy_access_allow_users | join(' ') }}
X11Forwarding no
AllowAgentForwarding no
AllowTcpForwarding no
AllowStreamLocalForwarding no
GatewayPorts no
PermitTunnel no
DisableForwarding yes
MaxAuthTries 3
LoginGraceTime 30
LogLevel VERBOSE
@@ -0,0 +1,17 @@
# CT 103 reverse_proxy_fail2ban
Manages the rootful Fail2Ban Quadlet
`/etc/containers/systemd/fail2ban.container` exactly as accepted in GNAI-006
section 4.2: tag-pinned image `lscr.io/linuxserver/fail2ban:1.1.0-r2-ls43`,
host networking, `NET_ADMIN` and `NET_RAW` (never `--privileged`),
persistent `/opt/fail2ban/config` and read-only access to the NPM access
logs. The LinuxServer configuration tree ships with the image; this role owns
only the two local NPM jails (`npm-scanner`, `npm-badbots`) and their filters
under `/opt/fail2ban/config/fail2ban/`, rendered identically to the accepted
GNAI-006 sections 6.2 and 6.3, including the client-IP parser rule (section
5), the LAN `ignoreip` allowlist and the `nftables-multiport` action on
ports 80,443. Files stay owned by the image-internal lsio user (uid/gid 911).
The functional fail2ban acceptance (GNAI-006 section 12) remains open and is
an operator-run procedure; the stale `fail2ban.container.bak-2026-09-16`
edit backup is removed by the explicit stale file list.
@@ -0,0 +1,42 @@
---
reverse_proxy_fail2ban_image: lscr.io/linuxserver/fail2ban
reverse_proxy_fail2ban_image_tag: "1.1.0-r2-ls43"
reverse_proxy_fail2ban_container_name: fail2ban
reverse_proxy_fail2ban_service_name: fail2ban.service
reverse_proxy_fail2ban_quadlet_path: /etc/containers/systemd/fail2ban.container
reverse_proxy_fail2ban_quadlet_mode: "0644"
reverse_proxy_fail2ban_config_directory: /opt/fail2ban/config
reverse_proxy_fail2ban_fail2ban_directory: "{{ reverse_proxy_fail2ban_config_directory }}/fail2ban"
reverse_proxy_fail2ban_jail_directory: "{{ reverse_proxy_fail2ban_fail2ban_directory }}/jail.d"
reverse_proxy_fail2ban_filter_directory: "{{ reverse_proxy_fail2ban_fail2ban_directory }}/filter.d"
reverse_proxy_fail2ban_npm_logs_mount: /opt/nginx-proxy-manager/data/logs
reverse_proxy_fail2ban_timezone: Europe/Berlin
# Never hand out the privileged profile: NET_ADMIN plus NET_RAW are sufficient
# for the nftables action (GNAI-006 section 9.3).
reverse_proxy_fail2ban_capabilities:
- NET_ADMIN
- NET_RAW
reverse_proxy_fail2ban_ignoreip: 127.0.0.1/8 10.0.0.0/24
reverse_proxy_fail2ban_action: 'nftables-multiport[port="80,443", protocol=tcp]'
reverse_proxy_fail2ban_stale_quadlet_files:
- fail2ban.container.bak-2026-09-16
# The persistent configuration tree and the ban database under
# /opt/fail2ban/config are runtime data restored from the CT backup; only the
# four local files below are declared state.
reverse_proxy_fail2ban_config_files:
- path: "{{ reverse_proxy_fail2ban_jail_directory }}/npm-scanner.local"
src: npm-scanner.local.j2
- path: "{{ reverse_proxy_fail2ban_jail_directory }}/npm-badbots.local"
src: npm-badbots.local.j2
- path: "{{ reverse_proxy_fail2ban_filter_directory }}/npm-scanner.conf"
src: npm-scanner.conf.j2
- path: "{{ reverse_proxy_fail2ban_filter_directory }}/npm-badbots.conf"
src: npm-badbots.conf.j2
reverse_proxy_fail2ban_config_owner: "911"
reverse_proxy_fail2ban_config_mode: "0644"
@@ -0,0 +1,10 @@
---
- name: Reload systemd for the CT 103 Fail2Ban service
ansible.builtin.systemd_service:
daemon_reload: true
- name: Restart the CT 103 Fail2Ban service
ansible.builtin.systemd_service:
name: "{{ reverse_proxy_fail2ban_service_name }}"
enabled: true
state: restarted
@@ -0,0 +1,75 @@
---
- name: Require the Fail2Ban image identity to be pinned
ansible.builtin.assert:
that:
- reverse_proxy_fail2ban_image | length > 0
- reverse_proxy_fail2ban_image_tag | length > 0
- reverse_proxy_fail2ban_capabilities | length > 0
fail_msg: >-
Fail2Ban must be deployed from an explicitly pinned image with an
explicit capability list.
- name: Require the NPM log mount to stay read-only for Fail2Ban
ansible.builtin.assert:
that:
- reverse_proxy_fail2ban_npm_logs_mount is match('^/opt/nginx-proxy-manager/')
fail_msg: >-
Fail2Ban may only mount the NPM log tree below /opt/nginx-proxy-manager.
- name: Install the local NPM jail and filter configuration
ansible.builtin.template:
src: "{{ item.src }}"
dest: "{{ item.path }}"
owner: "{{ reverse_proxy_fail2ban_config_owner }}"
group: "{{ reverse_proxy_fail2ban_config_owner }}"
mode: "{{ reverse_proxy_fail2ban_config_mode }}"
loop: "{{ reverse_proxy_fail2ban_config_files }}"
loop_control:
label: "{{ item.path }}"
notify: Restart the CT 103 Fail2Ban service
- name: Install the Fail2Ban Quadlet
ansible.builtin.template:
src: fail2ban.container.j2
dest: "{{ reverse_proxy_fail2ban_quadlet_path }}"
owner: root
group: root
mode: "{{ reverse_proxy_fail2ban_quadlet_mode }}"
notify:
- Reload systemd for the CT 103 Fail2Ban service
- Restart the CT 103 Fail2Ban service
- name: Remove stale Quadlet edit backups
ansible.builtin.file:
path: "/etc/containers/systemd/{{ item }}"
state: absent
loop: "{{ reverse_proxy_fail2ban_stale_quadlet_files }}"
loop_control:
label: "{{ item }}"
- name: Enable and start the Fail2Ban service
ansible.builtin.systemd_service:
name: "{{ reverse_proxy_fail2ban_service_name }}"
enabled: true
state: started
- name: Flush Fail2Ban handlers before verification
ansible.builtin.meta: flush_handlers
- name: Read the Fail2Ban service state
ansible.builtin.command:
argv:
- /usr/bin/systemctl
- is-active
- "{{ reverse_proxy_fail2ban_service_name }}"
check_mode: false
changed_when: false
register: reverse_proxy_fail2ban_service_state
when: not ansible_check_mode
- name: Verify the Fail2Ban service is active
ansible.builtin.assert:
that:
- reverse_proxy_fail2ban_service_state.stdout == "active"
fail_msg: The Fail2Ban Quadlet service did not come up active.
when: not ansible_check_mode
@@ -0,0 +1,26 @@
[Unit]
Description=Fail2Ban
Wants=network-online.target
After=network-online.target
[Container]
Image={{ reverse_proxy_fail2ban_image }}:{{ reverse_proxy_fail2ban_image_tag }}
ContainerName={{ reverse_proxy_fail2ban_container_name }}
Network=host
{% for capability in reverse_proxy_fail2ban_capabilities %}
AddCapability={{ capability }}
{% endfor %}
Volume={{ reverse_proxy_fail2ban_config_directory }}:/config:rw
Volume={{ reverse_proxy_fail2ban_npm_logs_mount }}:/remotelogs/npm:ro
Environment=TZ={{ reverse_proxy_fail2ban_timezone }}
[Service]
Restart=always
TimeoutStartSec=300
[Install]
WantedBy=multi-user.target
@@ -0,0 +1,5 @@
[Definition]
failregex = ^\[.*\] - [0-9]{3} [0-9]{3} - (?:GET|POST|HEAD|OPTIONS) [^ ]+ [^ ]+ "[^"]*" \[Client <HOST>\] .* "[^"]*(?i:sqlmap|nikto|nmap|masscan|zgrab|nessus|openvas|dirbuster|gobuster|wpscan|python-requests|go-http-client|censys|whatweb|acunetix)[^"]*"
ignoreregex =
@@ -0,0 +1,15 @@
[npm-badbots]
enabled = true
filter = npm-badbots
backend = auto
logpath = /remotelogs/npm/proxy-host-*_access.log
findtime = 10m
maxretry = 2
bantime = 24h
ignoreip = {{ reverse_proxy_fail2ban_ignoreip }}
action = {{ reverse_proxy_fail2ban_action }}
@@ -0,0 +1,5 @@
[Definition]
failregex = ^\[.*\] - [0-9]{3} [0-9]{3} - (GET|POST|HEAD) [^ ]+ [^ ]+ "/(?:[^"]*/)?(?:\.env[^"/]*|\.git/[^"]*|\.aws/[^"]*|wp-config\.php[^"]*|wp-login\.php(?:\?[^"]*)?|wp-admin(?:/[^"]*)?|actuator(?:/[^"]*)?|_ignition(?:/[^"]*)?|storage/logs(?:/[^"]*))" \[Client <HOST>\]
ignoreregex =
@@ -0,0 +1,15 @@
[npm-scanner]
enabled = true
filter = npm-scanner
backend = auto
logpath = /remotelogs/npm/proxy-host-*_access.log
findtime = 10m
maxretry = 3
bantime = 1h
ignoreip = {{ reverse_proxy_fail2ban_ignoreip }}
action = {{ reverse_proxy_fail2ban_action }}
@@ -0,0 +1,8 @@
# CT 103 reverse_proxy_firewall
Installs the strict nftables INPUT policy accepted in GNAI-006 section 3 as
the declared state: DROP default, loopback, established/related, ICMP, SSH
and the NPM admin port 81 restricted to the management LAN `10.0.0.0/24`,
and the public reverse proxy ports 80 and 443 open. The active SSH source of
the Ansible run must be inside the management allowlist before the ruleset is
replaced, and the effective policy is verified after reload.
@@ -0,0 +1,8 @@
---
reverse_proxy_firewall_management_ipv4: 10.0.0.0/24
reverse_proxy_firewall_ssh_port: 22
reverse_proxy_firewall_admin_tcp_ports:
- 81
reverse_proxy_firewall_public_tcp_ports:
- 80
- 443
@@ -0,0 +1,6 @@
---
- name: Restart the CT 103 firewall
ansible.builtin.systemd_service:
name: nftables.service
enabled: true
state: restarted
@@ -0,0 +1,79 @@
---
- name: Require an explicit management allowlist
ansible.builtin.assert:
that:
- reverse_proxy_firewall_management_ipv4 | length > 0
- reverse_proxy_firewall_admin_tcp_ports | length > 0
- reverse_proxy_firewall_public_tcp_ports | length > 0
fail_msg: The firewall allowlists must be explicit and non-empty.
- name: Read the active Ansible SSH transport endpoint
become: false
ansible.builtin.command:
argv:
- /usr/bin/printenv
- SSH_CONNECTION
check_mode: false
changed_when: false
register: reverse_proxy_firewall_ssh_connection
- name: Require the active Ansible SSH source in the management allowlist
ansible.builtin.command:
argv: >-
{{
[
'/usr/bin/python3',
'-c',
'import ipaddress,sys; address=ipaddress.ip_address(sys.argv[1]); raise SystemExit(0 if any(address in ipaddress.ip_network(network) for network in sys.argv[2:]) else 1)',
reverse_proxy_firewall_ssh_connection.stdout.split()[0]
] + [reverse_proxy_firewall_management_ipv4]
}}
check_mode: false
changed_when: false
vars:
ansible_command_timeout: 5
- name: Install and validate the CT 103 nftables policy
ansible.builtin.template:
src: nftables.conf.j2
dest: /etc/nftables.conf
owner: root
group: root
mode: "0755"
validate: /usr/sbin/nft --check --file %s
notify: Restart the CT 103 firewall
- name: Enable and start the nftables service
ansible.builtin.systemd_service:
name: nftables.service
enabled: true
state: started
- name: Flush firewall handlers before verification
ansible.builtin.meta: flush_handlers
- name: Read the active input chain policy
ansible.builtin.command:
argv:
- /usr/sbin/nft
- list
- chain
- inet
- filter
- input
check_mode: false
changed_when: false
register: reverse_proxy_firewall_active_input
when: not ansible_check_mode
- name: Verify the active input chain policy
ansible.builtin.assert:
that:
- reverse_proxy_firewall_active_input.stdout is search('policy drop')
- >-
reverse_proxy_firewall_active_input.stdout is
search('tcp dport { 80, 443 }')
- >-
reverse_proxy_firewall_active_input.stdout is
search('tcp dport { 22, 81 }')
when: not ansible_check_mode
@@ -0,0 +1,35 @@
#!/usr/sbin/nft -f
# Managed by Ansible role reverse_proxy_firewall.
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
# Loopback
iifname "lo" accept
# Established and related
ct state invalid drop
ct state established,related accept
# ICMP for diagnostics and correct network operation
ip protocol icmp accept
# SSH and the NPM admin interface only from the local LAN
ip saddr {{ reverse_proxy_firewall_management_ipv4 }} tcp dport { {{ reverse_proxy_firewall_ssh_port }}, {{ reverse_proxy_firewall_admin_tcp_ports | join(', ') }} } accept
# Public reverse proxy ports
tcp dport { {{ reverse_proxy_firewall_public_tcp_ports | join(', ') }} } accept
}
chain forward {
type filter hook forward priority 0; policy accept;
}
chain output {
type filter hook output priority 0; policy accept;
}
}
@@ -0,0 +1,12 @@
# CT 103 reverse_proxy_lxc_baseline
Blocks all state-changing roles until the connected system is proven to be
the CT 103 reverse proxy LXC (`reverse-proxy`, 10.0.0.10, Debian 13, LXC
guest, systemd), then installs the baseline administration packages
(`bind9-dnsutils`, `ca-certificates`, `curl`, `jq`, `nftables`, `openssl`,
`unattended-upgrades`), pins the timezone to Europe/Berlin and creates the
protected `/opt/nginx-proxy-manager` parent directory.
The postfix MTA present on the pre-Ansible host is outside the declared
state (GNAI-006 does not manage mail); this role neither installs nor
removes it.
@@ -0,0 +1,22 @@
---
reverse_proxy_lxc_baseline_expected_hostname: reverse-proxy
reverse_proxy_lxc_baseline_expected_distribution: Debian
reverse_proxy_lxc_baseline_expected_distribution_major_version: "13"
reverse_proxy_lxc_baseline_expected_ipv4: 10.0.0.10
reverse_proxy_lxc_baseline_expected_virtualization_type: lxc
reverse_proxy_lxc_baseline_timezone: Europe/Berlin
reverse_proxy_lxc_baseline_packages:
- bind9-dnsutils
- ca-certificates
- curl
- jq
- nftables
- openssl
- unattended-upgrades
reverse_proxy_lxc_baseline_directories:
- path: /opt/nginx-proxy-manager
owner: root
group: root
mode: "0755"
@@ -0,0 +1,58 @@
---
- name: Verify the CT 103 reverse proxy identity before changing baseline state
ansible.builtin.assert:
that:
- ansible_facts["hostname"] == reverse_proxy_lxc_baseline_expected_hostname
- >-
ansible_facts["distribution"] ==
reverse_proxy_lxc_baseline_expected_distribution
- >-
ansible_facts["distribution_major_version"] ==
reverse_proxy_lxc_baseline_expected_distribution_major_version
- >-
ansible_facts["default_ipv4"]["address"] ==
reverse_proxy_lxc_baseline_expected_ipv4
- >-
ansible_facts["virtualization_type"] ==
reverse_proxy_lxc_baseline_expected_virtualization_type
- ansible_facts["virtualization_role"] == "guest"
- ansible_facts["service_mgr"] == "systemd"
fail_msg: >-
The connected system is not the declared CT 103 reverse proxy LXC. No
baseline changes may be applied.
- name: Install the baseline administration packages
ansible.builtin.apt:
name: "{{ reverse_proxy_lxc_baseline_packages }}"
state: present
update_cache: true
cache_valid_time: 3600
install_recommends: false
- name: Set the local timezone database link
ansible.builtin.file:
src: "/usr/share/zoneinfo/{{ reverse_proxy_lxc_baseline_timezone }}"
dest: /etc/localtime
state: link
owner: root
group: root
force: true
- name: Record the configured timezone
ansible.builtin.copy:
content: "{{ reverse_proxy_lxc_baseline_timezone }}\n"
dest: /etc/timezone
owner: root
group: root
mode: "0644"
- name: Create the protected reverse proxy configuration paths
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
owner: "{{ item.owner }}"
group: "{{ item.group }}"
mode: "{{ item.mode }}"
loop: "{{ reverse_proxy_lxc_baseline_directories }}"
loop_control:
label: "{{ item.path }}"
@@ -0,0 +1,15 @@
# CT 103 reverse_proxy_npm
Manages the rootful Nginx Proxy Manager Quadlet
`/etc/containers/systemd/nginx-proxy-manager.container` exactly as accepted in
GNAI-006 section 4.1: tag-pinned image
`docker.io/jc21/nginx-proxy-manager:2.15.1`, host networking, persistent
`/opt/nginx-proxy-manager/data` and `/opt/nginx-proxy-manager/letsencrypt`,
IPv6 disabled and timezone Europe/Berlin.
The role also enforces the local file hardening accepted on 2026-09-22
(GNAI-006 section 2.3): `data` and its `logs` directory `0750 root:root`,
the SQLite database and key file `0600`, regular log files `0640`, and it
removes the stale `nginx-proxy-manager.container.bak-2.11.1` edit backup.
NPM's database, key file, certificates and proxy hosts are runtime data
restored from the CT backup; they are never stored in this repository.
@@ -0,0 +1,25 @@
---
reverse_proxy_npm_image: docker.io/jc21/nginx-proxy-manager
reverse_proxy_npm_image_tag: "2.15.1"
reverse_proxy_npm_container_name: nginx-proxy-manager
reverse_proxy_npm_service_name: nginx-proxy-manager.service
reverse_proxy_npm_quadlet_path: /etc/containers/systemd/nginx-proxy-manager.container
reverse_proxy_npm_quadlet_mode: "0644"
reverse_proxy_npm_data_directory: /opt/nginx-proxy-manager/data
reverse_proxy_npm_letsencrypt_directory: /opt/nginx-proxy-manager/letsencrypt
reverse_proxy_npm_logs_directory: "{{ reverse_proxy_npm_data_directory }}/logs"
reverse_proxy_npm_timezone: Europe/Berlin
# Deliberate cleanup: leftover edit backups inside the Quadlet directory are
# not configuration and must not accumulate. The generator ignores them, but
# the declared state keeps the directory clean.
reverse_proxy_npm_stale_quadlet_files:
- nginx-proxy-manager.container.bak-2.11.1
# Local hardening accepted in GNAI-006 section 2.3; the files themselves are
# NPM runtime data restored from the CT backup, never stored in this repo.
reverse_proxy_npm_protected_files:
- "{{ reverse_proxy_npm_data_directory }}/database.sqlite"
- "{{ reverse_proxy_npm_data_directory }}/keys.json"
reverse_proxy_npm_log_mode: "0640"
@@ -0,0 +1,10 @@
---
- name: Reload systemd for the CT 103 NPM service
ansible.builtin.systemd_service:
daemon_reload: true
- name: Restart the CT 103 NPM service
ansible.builtin.systemd_service:
name: "{{ reverse_proxy_npm_service_name }}"
enabled: true
state: restarted
@@ -0,0 +1,114 @@
---
- name: Require the NPM image identity to be pinned
ansible.builtin.assert:
that:
- reverse_proxy_npm_image | length > 0
- reverse_proxy_npm_image_tag | length > 0
fail_msg: >-
Nginx Proxy Manager must be deployed from an explicitly pinned image.
- name: Create the hardened NPM data and certificate directories
ansible.builtin.file:
path: "{{ item.path }}"
state: directory
owner: root
group: root
mode: "{{ item.mode }}"
loop:
- path: "{{ reverse_proxy_npm_data_directory }}"
mode: "0750"
- path: "{{ reverse_proxy_npm_letsencrypt_directory }}"
mode: "0755"
- path: "{{ reverse_proxy_npm_logs_directory }}"
mode: "0750"
loop_control:
label: "{{ item.path }}"
- name: Install the NPM Quadlet
ansible.builtin.template:
src: nginx-proxy-manager.container.j2
dest: "{{ reverse_proxy_npm_quadlet_path }}"
owner: root
group: root
mode: "{{ reverse_proxy_npm_quadlet_mode }}"
notify:
- Reload systemd for the CT 103 NPM service
- Restart the CT 103 NPM service
- name: Remove stale Quadlet edit backups
ansible.builtin.file:
path: "/etc/containers/systemd/{{ item }}"
state: absent
loop: "{{ reverse_proxy_npm_stale_quadlet_files }}"
loop_control:
label: "{{ item }}"
- name: Require the protected NPM runtime files to exist
ansible.builtin.stat:
path: "{{ item }}"
loop: "{{ reverse_proxy_npm_protected_files }}"
register: reverse_proxy_npm_protected_state
- name: Verify the protected NPM runtime files exist
ansible.builtin.assert:
that:
- reverse_proxy_npm_protected_state.results | map(attribute='stat.exists') | unique | list == [true]
fail_msg: >-
The declared NPM runtime files are missing; restore the data directory
from the CT backup before converging.
- name: Keep the NPM database and key file private
ansible.builtin.file:
path: "{{ item }}"
state: file
owner: root
group: root
mode: "0600"
loop: "{{ reverse_proxy_npm_protected_files }}"
loop_control:
label: "{{ item }}"
- name: Enumerate the NPM log files
ansible.builtin.find:
paths: "{{ reverse_proxy_npm_logs_directory }}"
file_type: file
recurse: true
register: reverse_proxy_npm_log_files
- name: Keep NPM logs non-world-readable
ansible.builtin.file:
path: "{{ item.path }}"
state: file
owner: root
group: root
mode: "{{ reverse_proxy_npm_log_mode }}"
loop: "{{ reverse_proxy_npm_log_files.files }}"
loop_control:
label: "{{ item.path }}"
- name: Enable and start the NPM service
ansible.builtin.systemd_service:
name: "{{ reverse_proxy_npm_service_name }}"
enabled: true
state: started
- name: Flush NPM handlers before verification
ansible.builtin.meta: flush_handlers
- name: Read the NPM service state
ansible.builtin.command:
argv:
- /usr/bin/systemctl
- is-active
- "{{ reverse_proxy_npm_service_name }}"
check_mode: false
changed_when: false
register: reverse_proxy_npm_service_state
when: not ansible_check_mode
- name: Verify the NPM service is active
ansible.builtin.assert:
that:
- reverse_proxy_npm_service_state.stdout == "active"
fail_msg: The NPM Quadlet service did not come up active.
when: not ansible_check_mode
@@ -0,0 +1,23 @@
[Unit]
Description=Nginx Proxy Manager
Wants=network-online.target
After=network-online.target
[Container]
Image={{ reverse_proxy_npm_image }}:{{ reverse_proxy_npm_image_tag }}
ContainerName={{ reverse_proxy_npm_container_name }}
Network=host
Volume={{ reverse_proxy_npm_data_directory }}:/data:rw
Volume={{ reverse_proxy_npm_letsencrypt_directory }}:/etc/letsencrypt:rw
Environment=DISABLE_IPV6=true
Environment=TZ={{ reverse_proxy_npm_timezone }}
[Service]
Restart=always
TimeoutStartSec=300
[Install]
WantedBy=multi-user.target