diff --git a/docs/GNAI-000-DOC_Index.md b/docs/GNAI-000-DOC_Index.md index a44f934..cbe559c 100644 --- a/docs/GNAI-000-DOC_Index.md +++ b/docs/GNAI-000-DOC_Index.md @@ -41,6 +41,7 @@ jeweiligen Fachdokumenten. Die priorisierte weitere Umsetzung beschreibt der | [CT 101 / GNAI-017](platform/proxmox-server/lxc/ct-101-samba/GNAI-017-PLAN_Samba-NFS-Export.md) | Samba-Dateiserver `10.0.0.9`: Aufnahme ins Repository, NFS-Export und Encoding-Shares | | [CT 101 / GNAI-018](platform/proxmox-server/lxc/ct-101-samba/GNAI-018-REQ_Encoding-Pipeline-Integration.md) | Requirements der Encoding-Pipeline an CT 101 — Übergabe an den Ansible-Rebuild | | [CT 101 / GNAI-019](platform/proxmox-server/lxc/ct-101-samba/GNAI-019-DEC_Ansible-Migration.md) | Entwurfsentscheidungen der CT-101-Ansible-Migration: natives Samba, NFS-Ganesha als Quadlet, Fresh-State-Rebuild | +| [CT 114 / GNAI-024](platform/proxmox-server/lxc/ct-114-litecoin-wallet/GNAI-024-PLAN_Litecoin-Wallet-LXC.md) | geplanter Litecoin-Wallet-LXC `ltc-node` (`10.0.0.61`): Prüfung der Research-Dokumente, Tor-only Cold Node, Ansible-Projekt und Provisioning — noch nicht angelegt (Plan 25.11.2026) | ### KI und Deployment diff --git a/docs/platform/proxmox-server/README.md b/docs/platform/proxmox-server/README.md index e728163..a0887ee 100644 --- a/docs/platform/proxmox-server/README.md +++ b/docs/platform/proxmox-server/README.md @@ -19,7 +19,9 @@ Hypervisors selbst. | [GNAI-018 / CT 101](lxc/ct-101-samba/GNAI-018-REQ_Encoding-Pipeline-Integration.md) | Requirements der Encoding-Pipeline an CT 101 für den Ansible-Rebuild (Übergabe) | | [GNAI-019 / CT 101](lxc/ct-101-samba/GNAI-019-DEC_Ansible-Migration.md) | Entwurfsentscheidungen der Ansible-Migration: natives Samba, NFS-Ganesha als Quadlet, Fresh-State-Rebuild | | [CT-101-Automation](../../../proxmox/lxc/ct-101-samba/README.md) | produktives Samba-Ansible-Projekt und CT-spezifische PVE-Helfer | -| [PVE-Host-Automation](../../../proxmox/pve-host/README.md) | Ansible-Verwaltung des PVE-Hosts selbst (`10.0.0.2`): Deploy-Account, Kernel-NFS-Export, LXC-Conf | +| [GNAI-024 / CT 114](lxc/ct-114-litecoin-wallet/GNAI-024-PLAN_Litecoin-Wallet-LXC.md) | `10.0.0.61` (geplant): Litecoin Cold Wallet als Tor-only Full Node; Plan und Forschungsprüfung, CT noch nicht angelegt | +| [CT-114-Automation](../../../proxmox/lxc/ct-114-litecoin-wallet/README.md) | Ansible-Projekt und PVE-Provisioning-Skripte für CT 114 (GNAI-024) | +| [PVE-Host-Automation](../../../proxmox/pve-host/README.md) | Ansible-Verwaltung des PVE-Hosts selbst (`10.0.0.2`): Deploy-Account, Kernel-NFS-Export, LXC-Conf, tägliche CT-114-Snapshots (`pve_lxc_snapshot`) | Die versionierte Quelle für den optionalen, secretfreien Community-Scripts-Post-install-Hook liegt unter diff --git a/docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/GNAI-024-PLAN_Litecoin-Wallet-LXC.md b/docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/GNAI-024-PLAN_Litecoin-Wallet-LXC.md new file mode 100644 index 0000000..cdb7ebf --- /dev/null +++ b/docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/GNAI-024-PLAN_Litecoin-Wallet-LXC.md @@ -0,0 +1,230 @@ +# Litecoin Wallet LXC (CT 114) – Plan, Prüfung der Recherche und Umsetzungsstand + +**Dokumenten-ID:** GNAI-024-PLAN +**Titel:** Litecoin Full Node (Cold Wallet) als gehärteter unprivilegierter LXC CT 114 auf Ghostnet Proxmox +**Status:** Plan vollständig, reviewed; CT 114 noch nicht angelegt — Provisioning und Konvergenz sind Operator-Schritte (Abschnitt 6) +**Geltungsbereich:** neuer LXC CT 114 `ltc-node` (`10.0.0.61`) auf Proxmox `10.0.0.2`; Änderungen am PVE-Host nur über das bestehende `proxmox/pve-host`-Ansible-Projekt +**Referenzen:** [Auftrag/Research `litecoin-lxc-setup.txt`](litecoin-lxc-setup.txt), [Testplan `litecoin-lxc-tests.txt`](litecoin-lxc-tests.txt), [GNAI-011 SSH-Architektur](../../GNAI-011-SEC_LXC-SSH-Architecture.md), [GNAI-007 Adressplan](../ct-105-wireguard/GNAI-007-SEC_VPN.md), [GNAI-016 Ansible-Rebuild CT 102](../../lxc/ct-102-keycloak/GNAI-016-PLAN_Keycloak-Ansible-Rebuild.md), [CT-114-Automation](../../../../../proxmox/lxc/ct-114-litecoin-wallet/ansible/README.md), [CT-114-Skripte](../../../../../proxmox/lxc/ct-114-litecoin-wallet/scripts/README.md), [Doku-Index](../../../../GNAI-000-DOC_Index.md) + +## Änderungsverlauf + +| Datum | Version | Autor | Änderung | +| --- | --- | --- | --- | +| 2026-11-25 | 0.1 | Mistral Vibe | Erstfassung: Prüfung der beiden Research-Dokumente gegen Repo-Konventionen (Abschnitt 2), Zielarchitektur, Zugriffsmodell, Ansible-Projekt, Provisioning-Skripte, Phasenplan, Abnahmetests. | + +## 1. Zweck und Leitentscheidung + +Der Betreiber möchte Litecoin von Bitpanda empfangen und Dienste im Internet +(z. B. Rapidgator) bezahlen — bei bestmöglicher Sicherheit und Privatsphäre. +Leitentscheidung: ein eigener, unprivilegierter LXC **CT 114** betreibt +einen Litecoin Full Node (`litecoind` v0.21.5.8) als Cold Wallet. Der +P2P-Verkehr läuft ausschließlich über Tor (onion-only, `listen=0`), der +RPC ist auf `127.0.0.1:9332` gebunden und nur per SSH-Exec erreichbar. +Kein Port wird nach außen geöffnet; die FRITZ!Box bekommt keinen Forward +für CT 114. + +Die Research-Dokumente (`litecoin-lxc-setup.txt`, `litecoin-lxc-tests.txt`) +werden mit den Befunden in Abschnitt 2 an die etablierten Verfahren des +Repositories angepasst (GNAI-011 SSH-Baseline, nftables statt ufw, +Drei-Inventar-Ansible-Projekte, PVE-Host-Automation, hostunabhängige +Backups, Secret-Regeln). + +## 2. Prüfung der Recherche-Dokumente (Befunde) + +| Nr. | Befund | Entscheidung | +| --- | --- | --- | +| a) | Versionsangabe „v0.21.5.x, mindestens 5.6/5.7/5.8 wegen MWEB-Sicherheitsfixes 2026“ geprüft am 2026-11-25: aktuellstes Release ist **v0.21.5.8** (GitHub, publiziert 2026-09-12); Release-Notes: Maintenance-Release inkl. des nur an Pools verteilten **v0.21.5.7-Sicherheitsfixes** (MWEB-Konsensusregel ab Height 3.172.640), „upgrading strongly recommended“. SHA-256 des x86_64-Tarballs `43200c9f…ab1be9` gegen das signierte `SHA256SUMS.asc` von `download.litecoin.org` verifiziert (Download 2026-11-25, Summe identisch). | Version **0.21.5.8** wird gepinnt; die Rolle `litecoin_core` lädt nur mit `checksum: sha256:43200c9f…` (fail-closed) und assertiert `litecoind --version`. GPG-Verifikation des `SHA256SUMS.asc` mit den Litecoin-Release-Keys bleibt zusätzlicher Operator-Schritt beim manuellen Review. | +| b) | Research schlägt `ufw` vor. Repo-Konvention ist native **nftables** mit eigener `ghostnet_filter`-Tabelle (CT 100/102/103, CT 105). | Rolle `litecoin_firewall` deployt `/etc/nftables.conf`: input policy drop, nur SSH (TCP 22) aus `10.0.0.0/24` + `10.8.0.0/24`, output accept (Tor-Ausgang), forward drop. **Keine** Ports 9333/9332/9050/9051 nach außen. | +| c) | Research nennt `rpcport=8332` — das ist der **Bitcoin**-Port. Litecoin-RPC ist **9332**, P2P 9333. | Korrigiert: `rpcport=9332`, `rpcbind=127.0.0.1`, `rpcallowip=127.0.0.1`. | +| d) | Research empfiehlt RPC-Zugriff per SSH-Tunnel (`ssh -L 8332:...`). Die GNAI-011-Baseline setzt jedoch `AllowTcpForwarding no` **und** `DisableForwarding yes` (CT-102-Dropin, Hook), und die Agenten-Schlüssel sind `restrict`/`no-port-forwarding`. | **Kein SSH-Tunnel.** RPC nur per SSH-Exec: `ssh -F ~/.ssh/config ghostnet-ct114-ghost 'sudo -u litecoin litecoin-cli -conf=/etc/litecoin/litecoin.conf '`; der Agent nutzt den Wrapper `ltc-readonly` (NOPASSWD-Sudo, Kommando-Whitelist, nur Lese-RPCs). | +| e) | Research empfiehlt `rpcauth` (niemals `rpcpassword` im Klartext). | Es wird gar kein RPC-Credential in Dateien abgelegt: **Cookie-Auth** (Default) — `litecoin-cli` läuft als User `litecoin` und nutzt `/var/lib/litecoin/.cookie`. `litecoin.conf` enthält keine Secrets (Mode 0640 root:litecoin). | +| f) | MWEB: Bitpanda und Rapidgator unterstützen keine MWEB-Adressen; `ltcmweb1…` an eine Exchange wäre Verlust. | Wallet erzeugt nur legacy/bech32-Adressen (`getnewaddress "" "bech32"` → `ltc1…`). MWEB bleibt lokal nutzbar (Cake Wallet), wird aber nie an Exchanges/Dienste adressiert. Dokumentiert in `litecoin.conf` und Abschnitt 8. | +| g) | Research nimmt einen „separaten Proxmox Backup Server im LAN“ an, dessen Zugangsdaten der Betreiber liefert. Im Repo existiert **kein PBS**; das etablierte hostunabhängige Backup-Ziel ist der `gn-backup`-Account auf `ghostnet-ki` (`10.0.0.90`, eigene Hardware, Rolle `pve_lxc_backup_sync` / `gn_backup_receiver`). | Default: restic-Repo `sftp:gn-backup@10.0.0.90:/var/lib/ghostnet-ai-backup/ct114/restic` (Inventar-Variable `litecoin_backup_repository`, clientseitig verschlüsselt — das Ziel sieht nur Ciphertext). Falls der Betreiber doch ein PBS betreibt, genügen die PBS-Zugangsdaten als Inventar-Override. **Offener Punkt 11.1.** | +| h) | Research: LXC-Backup „nur Snapshots, kein vzdump“. Repo-Konvention syncet alle `vzdump-lxc-*`-Archive nach ghostnet-ki (`pve_lxc_backup_sync`). | Bewusste, begründete Abweichung: CT 114 wird **nicht** in den vzdump-Job aufgenommen (150 GiB Chain, nächtlich ×4 Archive wären teuer; Chain ist per Neu-Sync rekonstruierbar; `wallet.dat` ist durch restic verschlüsselt **und** durch Snapshots geschützt). Umsetzung: Rolle `pve_lxc_snapshot` (täglich 04:00, 7 Snapshots Retention) + restic aus dem CT. **Operator-Schritt:** CT 114 im PVE-Backup-Job ausschließen (Abschnitt 6, Phase 0). | +| i) | Ressourcen 2 vCPU / 4 GiB / 150 GiB rootfs auf SSD/NVMe. | Übernommen; `local-lvm` (thin, snapshotfähig). Preflight im Provisioning-Skript: `local-lvm` aktiv und ≥ 214 GiB frei. Kein Nesting nötig (kein Podman; `litecoind` als systemd-Service unter User `litecoin`). | +| j) | Debian 13, unprivileged, Key-Only-SSH, fail2ban, unattended-upgrades, dedizierter User `litecoin`. | Übernommen nach Repo-Muster: frischer CT per gepinntem Community-Scripts-`debian.sh` + Bootstrap-Hook (wie CT 102, GNAI-016 Phase D), dann Ansible (`litecoin_lxc_baseline`, `litecoin_access`, `litecoin_fail2ban`, …). `unattended-upgrades` auf Debian-Security eingeschränkt (CT-100/101/102-Konvention). | + +## 3. Zielarchitektur + +| Komponente | Wert | +| --- | --- | +| CT-ID / Hostname | `114` / `ltc-node` | +| IP | `10.0.0.61/24` (statischer Serverbereich bis `.99`; DHCP ab `.100`), GW `10.0.0.1`, DNS `10.0.0.14` (Pi-hole), vmbr0, IPv6 aus | +| OS / Typ | Debian 13, unprivileged, onboot, protection | +| Ressourcen | 2 vCPU, 4096 MiB RAM, 1024 MiB Swap, 150 GiB rootfs `local-lvm` | +| Software | `litecoind` v0.21.5.8 in `/opt/litecoin` (Symlink), `tor` (Client-only, SOCKS 127.0.0.1:9050), nftables, fail2ban, unattended-upgrades, restic | +| Node-Konfig | `proxy=127.0.0.1:9050`, `onlynet=onion`, `listen=0`, `dnsseed=0`, `upnp=0`, `natpmp=0`, RPC `127.0.0.1:9332` Cookie-Auth, `wallet=cold`, `dbcache=2048` | +| Firewall | nftables default-deny; nur SSH 22 aus LAN/WireGuard; kein Forwarding | +| Backups | täglich 04:00 Snapshot auf PVE (Retention 7, Rolle `pve_lxc_snapshot`) + täglich 03:00 `backupwallet` + restic (verschlüsselt) nach `gn-backup@ghostnet-ki`; monatlich `restic check` | +| Monitoring | systemd-Status in `verify-production.yml`/`audit-production.yml`; GNMON-Integration späterer Schritt (11.4) | + +## 4. Zugriffsmodell (GNAI-011) + +| Konto | UID | Rechte | Schlüssel | +| --- | --- | --- | --- | +| `ghost-agent` | 1000 | locked, `restrict,from="10.0.0.0/24,10.8.0.0/24"`, NOPASSWD nur für `/usr/local/bin/ltc-readonly` (Lese-RPCs als `litecoin`) | `~/.ssh/id_ed25519_ghostnet_ct114_agent` (passphrase-los, 2026-11-25 erzeugt), Alias `ghostnet-ct114-agent` | +| `ghost` | 1001 | passwort-gated sudo | `~/.ssh/id_ed25519_ghostnet_ct114_ghost` (**Operator-Schritt: interaktiv mit Passphrase erzeugen**, Abschnitt 6 Phase 0), Alias `ghostnet-ct114-ghost` | +| `ansible-deploy` | 1002 | locked, `NOPASSWD: ALL`, `restrict,from=…` | `~/.ssh/id_ed25519_ghostnet_ct114_ansible_deploy` (passphrase-los), Alias `ghostnet-ct114-ansible-deploy` | +| `litecoin` | 1100 | Service-Account, `nologin`, locked, kein SSH | — | + +Öffentliche Schlüssel liegen in +[`ansible/files/ssh/`](../../../../../proxmox/lxc/ct-114-litecoin-wallet/ansible/files/ssh); +`sshd` härtet per Drop-in (`PermitRootLogin no`, PasswordAuthentication no, +`DisableForwarding yes`, AllowUsers nur die drei Konten). Hostkey-Fingerprint +wird nach dem ersten Boot gepinnt (`litecoin_expected_ssh_host_key_fingerprint`, +aktuell `PENDING`-Platzhalter — fail-closed). Optional: `10.0.0.61` in die +WireGuard-Server-Admin-Ziele auf CT 105 aufnehmen (eigener Change, 11.2). + +## 5. Ansible-Projekt + +`proxmox/lxc/ct-114-litecoin-wallet/ansible/` folgt dem CT-102/CT-100-Schema: + +``` +ansible/ +├── ansible.cfg # roles_path inkl. shared/ansible/roles +├── files/ssh/litecoin-*.pub # nur öffentliche Schlüssel +├── inventories/{agent,bootstrap,production}/ +│ ├── hosts.yml # ghost-agent / ghost / ansible-deploy +│ ├── group_vars/litecoin_hosts.yml # Erwartungen, Firewall, Core-Pin, restic-Ziel +│ └── host_vars/litecoin-ct114.yml # CTID 114, IP, Fingerprint-Pin, Ressourcen +├── playbooks/ +│ ├── preflight.yml # read-only, agent-Inventar, Identitäts- und Leerstands-Gates +│ ├── verify-deploy-access.yml # ansible-deploy-Grenze +│ ├── site.yml # Rollen: baseline → access → firewall → fail2ban → tor → core → backup +│ ├── verify-production.yml # read-only Produktions-Verifikation (Listener, Dienste, Firewall, SSH) +│ └── audit-production.yml # read-only Deep-Audit +└── roles/ + ├── litecoin_lxc_baseline # Pakete, litecoin-User (1100), Zeitzone, unattended-upgrades, Verzeichnisse + ├── litecoin_access # Konten, authorized_keys, sudoers, sshd-Dropin, ltc-readonly + ├── litecoin_firewall # nftables ghostnet_filter (default-deny, SSH only) + ├── litecoin_fail2ban # sshd-Jail, systemd-Backend, nftables-Action + ├── litecoin_tor # Client-only torrc, SOCKS 127.0.0.1:9050 + ├── litecoin_core # gepinnter Download (SHA256), litecoin.conf, systemd-Unit, logrotate + └── litecoin_backup # backupwallet + restic (Timers 03:00 / monatlich check) +``` + +## 6. Phasen und Checkliste (Operator-Schritte hervorgehoben) + +- **Phase 0 — Vorbereitung (Operator, Workstation + PVE):** + 1. `ghost`-Schlüssel interaktiv erzeugen (`ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_ghostnet_ct114_ghost -C "ghost@ghostnet-ct114"`), `.pub` nach `ansible/files/ssh/litecoin-ghost.pub` kopieren; `ADMIN_PUBLIC_KEY`-Platzhalter im Hook ersetzen; Hook-SHA neu pinnen (siehe `scripts/README.md` Schritt 0). + 2. restic-Backup-Key für CT 114 erzeugen und für `gn-backup@ghostnet-ki` quellbeschränkt auf `10.0.0.61` autorisieren; privater Key landet später per Operator auf dem CT unter `/etc/litecoin-backup/.ssh/id_ed25519` (0600) — nie im Repo. + 3. CT 114 im PVE-vzdump-Backup-Job ausschließen (Befund h). + 4. Hooks auf dem PVE installieren und SHAs verifizieren; `provision-ct114-litecoin.sh` als root@pve ausführen (erstellt CT 114, setzt Swap, verifiziert Profil + Hook). + 5. `pct exec 114 -- passwd ghost` (interaktiv); Hostkey-Fingerprint pinnen; FRITZ!Box: sicherstellen, dass **kein** Forward auf 10.0.0.61 existiert. +- **Phase 1 — Agent-Preflight:** `preflight.yml` gegen `inventories/agent` mit `--private-key ~/.ssh/id_ed25519_ghostnet_ct114_agent` (read-only, `ghost-agent`). +- **Phase 2 — Deploy-Grenze:** `verify-deploy-access.yml` gegen `inventories/production`. +- **Phase 3 — Konvergenz (braucht explizites Go des Betreibers):** `site.yml --check --diff`, dann `site.yml` gegen `inventories/production`. Zweiter Lauf muss `changed=0` liefern. +- **Phase 4 — Verifikation:** `verify-production.yml`, `audit-production.yml`; LXC-Neustart-Test über PVE (nie boot_id-Waiter, GNAI-016 §7) und erneute Verifikation. +- **Phase 5 — Wallet-Inbetriebnahme (interaktiv, nie im Playbook):** Node syncen lassen (`ltc-readonly getblockchaininfo` → `initialblockdownload: false`), `sudo -u litecoin litecoin-cli … createwallet "cold"`, sofort `encryptwallet` (Passphrase wird nur interaktiv eingegeben und im Secret-Store des Betreibers abgelegt — nie in Repo/Logs), Empfangsadresse `getnewaddress "" "bech32"`, restic-Repo anlegen (`restic init`) mit dem Operator-Passwort, erstes `backupwallet` + `restic backup` + `restic check`. +- **Phase 6 — Abnahme:** Tests aus Abschnitt 10. + +## 7. Sicherheitsregeln (verbindlich) + +- Nie Seed-Phrase, Wallet-Passphrase, restic-Passwort oder private Schlüssel + in Dateien, Repos, Logs oder Tickets — nur Secret-Store (Vaultwarden) / + interaktive Übergabe. +- Keine Ports nach außen öffnen (kein 9333, kein 9332/9050/9051); `listen=0` + nie „zum Debuggen“ aufheben; P2P nur über Tor (`onlynet=onion`). +- Nur gepinnte, Prüfsummen-verifizierte Software (SHA256-Pin in der Rolle; + GPG-Review des signierten `SHA256SUMS.asc` als Operator-Schritt). +- RPC nur loopback + SSH-Exec; kein Port-Forwarding (GNAI-011). +- Nie MWEB-Adressen (`ltcmweb1…`) an Bitpanda, Rapidgator oder sonstige + externe Dienste; nur `ltc1…`/legacy. +- Zahlungen nur mit kleinen Beträgen nach bestandenem Restore-Test + (Abschnitt 10); Adressen am Bildschirm visuell vergleichen. +- Alle Änderungen dokumentieren (dieses Dokument, Änderungsverlauf). + +## 8. Wallet-Betrieb und Zahlungen (SOP) + +Empfang (Bitpanda → Node): Bitpanda sendet auf die `ltc1…`-Adresse; lokal +`ssh -F ~/.ssh/config ghostnet-ct114-agent 'sudo ltc-readonly getbalance'` / +`listtransactions` (6 Bestätigungen abwarten; zur Prüfung nie öffentliche +Explorer, nur Tor). + +Senden (Node → Bitpanda/Rapidgator): interaktiv als `ghost` oder +`ansible-deploy` per SSH-Exec — kurzes Unlock-Fenster, dann sofort sperren: + +```bash +ssh -F ~/.ssh/config ghostnet-ct114-ghost +sudo -u litecoin /opt/litecoin/bin/litecoin-cli -conf=/etc/litecoin/litecoin.conf walletpassphrase "" 120 +sudo -u litecoin /opt/litecoin/bin/litecoin-cli -conf=/etc/litecoin/litecoin.conf sendtoaddress "" +sudo -u litecoin /opt/litecoin/bin/litecoin-cli -conf=/etc/litecoin/litecoin.conf walletlock +``` + +Die Passphrase wird nur interaktiv eingegeben (ggf. via `read -s` in einer +One-Shot-Shell), nie in History/Dateien. Der Agent-Account kann über +`ltc-readonly` ausschließlich lesend prüfen (getbalance, getblockchaininfo, +getnetworkinfo, getpeerinfo, getwalletinfo, listtransactions, …). + +## 9. Backup- und Restore-Konzept + +- **Snapshot (PVE-Host):** täglich 04:00, Retention 7 — Rolle + `pve_lxc_snapshot` im `proxmox/pve-host`-Projekt (Befund h). +- **Wallet-Backup (im CT):** täglich 03:00 `backupwallet` als `litecoin` + + restic (clientseitig verschlüsselt) nur von `/var/lib/litecoin/backups` + nach `gn-backup@ghostnet-ki` (oder Betreiber-PBS, 11.1); Retention 30 + Tage; monatlich `restic check`. Passwort/Key liegen root-only in + `/etc/litecoin-backup/`. +- **Restore:** Snapshot in PVE zurückspielen **oder** frischer CT 114 per + `provision-ct114-litecoin.sh` + Ansible, Chain neu syncen, `wallet.dat` + aus restic zurückspielen, `walletpassphrase` → fertig. Restore-Test + vor dem ersten nennenswerten Betrag (Abschnitt 10, Phase 1). + +## 10. Abnahmetests (aus `litecoin-lxc-tests.txt`, an Repo-Verfahren angepasst) + +- **Phase 0 (vor dem ersten Euro):** Node gesynct (`initialblockdownload: + false`); `getnetworkinfo` nur `onion`; Wallet verschlüsselt + (`getwalletinfo.unlocked_until` nur nach `walletpassphrase`); `nmap` von + einem anderen LAN-Gerät gegen `10.0.0.61` → keine offenen Ports außer + SSH-aus-dem-LAN-Ergebnis; Snapshot-Liste auf PVE; `restic snapshots` und + `restic check` fehlerfrei; `verify-production.yml` + `audit-production.yml` + bestanden; `site.yml`-Zweitlauf `changed=0`. +- **Phase 1 (Restore zuerst):** Snapshot-Restore auf einen Scratch-CT + (wie CT 150 bei CT 100) testen; `wallet.dat` aus restic auf Test-CT + einspielen, mit `walletpassphrase` öffnen, `getbalance` zeigt Test-Coins; + Seed/Metall-Backup physisch prüfen. +- **Phase 2 (kleine echte Beträge):** Bitpanda → `ltc1…` (kleinster Betrag, + 6 Bestätigungen, `listtransactions`); Node → Bitpanda zurück; Node → + Cake Wallet; Cake → extern. Nie über öffentlichen Explorer prüfen. +- **Phase 3 (MWEB, klein):** peg-in/peg-out in Cake Wallet; nie MWEB an + Bitpanda/Rapidgator. +- **Phase 4 (Notfall):** Server aus → Cake Wallet unabhängig; Handy weg → + Cake-Seed auf zweitem Gerät; `walletlock` → Senden ohne Passphrase schlägt + fehl. +- **Bericht an den Betreiber:** CT-ID, IP, Core-Version + SHA-256, + Sync-Status, Snapshot-/restic-Listen, Firewall-Regeln, RPC-Variante + (SSH-Exec, Befund d), Doku-Link. + +## 11. Offene Punkte / Entscheidungen des Betreibers + +1. **Backup-Ziel:** Default `gn-backup@ghostnet-ki` (Befund g). Falls ein + separater PBS im LAN existiert: Zugangsdaten liefern, Inventar-Variable + `litecoin_backup_repository` überschreiben und Ziel-Hostkey pinnen. +2. **WireGuard-Zugriff:** `10.0.0.61` auf CT 105 in die Server-Admin-Ziele + aufnehmen? (Default: nein, LAN-SSH genügt.) +3. **vzdump-Ausschluss CT 114** im PVE-Backup-Job bestätigen (Befund h). +4. **GNMON-Monitoring** für CT 114 (Node synced, Backup-Timer) als Folge-Schritt. +5. **IP/CT-ID bestätigen:** CT 114 / `10.0.0.61` waren am 2026-11-25 frei + (dokumentiertes Inventar: CT 100–105, 110, 116; IPs .2–.90 belegt, .61 + frei). Vor Provisioning live gegen `pct list` prüfen — das + Provisioning-Skript fail-closed bei belegter ID. + +## 12. Implementierungsstand 2026-11-25 + +- Branch `lxc/ct-114-gnai-024-litecoin-wallet` (keine Kollision mit + `main` oder anderen Feature-Branches). +- Angelegt: Ansible-Projekt `proxmox/lxc/ct-114-litecoin-wallet/ansible/` + (3 Inventare, 5 Playbooks, 7 Rollen), PVE-Host-Skripte + (`provision-ct114-litecoin.sh` mit gepinnten Community-Scripts-SHAs, + `ghostnet-litecoin-ansible-bootstrap-hook.sh`), Rolle `pve_lxc_snapshot` + im `pve-host`-Projekt, READMEs. +- Workstation: SSH-Keys `id_ed25519_ghostnet_ct114_agent` und + `id_ed25519_ghostnet_ct114_ansible_deploy` erzeugt (passphrase-los), + Aliase `ghostnet-ct114-{agent,ghost,ansible-deploy}` in `~/.ssh/config`. + Der `ghost`-Key ist Operator-Schritt (Passphrase interaktiv). +- Verifiziert: Litecoin v0.21.5.8 SHA-256 gegen signiertes `SHA256SUMS.asc` + (Befund a); Shell-Syntax aller Skripte; Ansible-Syntax aller Playbooks; + yamllint, Secret-Scan und Markdown-Linkcheck (CI-Skripte lokal) bestanden. +- **Noch nicht produktiv:** CT 114 existiert nicht; Provisioning, + Ansible-Konvergenz, Wallet-Anlage und Abnahmetests folgen Abschnitt 6/10 + nach explizitem Go des Betreibers. diff --git a/docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/litecoin-lxc-setup.txt b/docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/litecoin-lxc-setup.txt new file mode 100644 index 0000000..d160907 --- /dev/null +++ b/docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/litecoin-lxc-setup.txt @@ -0,0 +1,119 @@ +# Auftrag: Litecoin Full Node (Cold Wallet) als LXC auf Proxmox + +**Ziel:** Ein gehärteter, unprivilegierter LXC auf dem Proxmox-Host betreibt einen eigenen Litecoin Full Node (`litecoind`) als Cold Wallet. P2P-Traffic läuft ausschließlich über Tor, RPC-Zugriff nur lokal per SSH-Tunnel. Backups: tägliche LXC-Snapshots + tägliches verschlüsseltes `wallet.dat`-Backup auf einen separaten Proxmox Backup Server im LAN. + +**Voraussetzungen (vom Auftraggeber vorgegeben):** +- Nur **Litecoin Core** (kein ElectrumX, kein GUI-Client im LXC) +- LXC-Backup: **nur Snapshots**, kein externes/vzdump-Backup des Containers +- Wallet-Backup: **separater Proxmox Backup Server im lokalen Netz** als Ziel (restic, client-seitig verschlüsselt) +- RPC-Zugang: Agent wählt die sicherste praktikable Variante und dokumentiert sie (Empfehlung: `rpcbind=127.0.0.1` + SSH-Tunnel) + +--- + +## 1. LXC anlegen (Proxmox VE) + +- Template: **Debian 13** (aktuelles offizielles Template) +- **Unprivileged** lassen (Default) +- Ressourcen: **2 vCPU, 4096 MB RAM, 150 GB rootfs** auf SSD/NVMe-Storage (Chain ~100 GB + Wachstum; NVMe wegen random I/O) +- Hostname: `ltc-node`; feste LAN-IP oder DHCP-Reservierung (nächste freie ID wählen, im Router reservieren) +- Kein Port-Forwarding, keine Bridge-Exposure außer LAN + +## 2. Container härten + +- SSH: Key-Only (`PasswordAuthentication no`, `PermitRootLogin no`), `fail2ban` installieren +- `unattended-upgrades` aktivieren (Security-Updates automatisch) +- Firewall `ufw`: default **deny incoming**, default allow outgoing; **keine Ports öffnen** (weder 9333 P2P noch 8332/8333 RPC) +- Dedizierter User `litecoin` (nicht root) für `litecoind`; datadir `/var/lib/litecoin` + +## 3. Tor installieren (im selben LXC) + +- `apt install tor`, Service aktivieren +- `torrc`: SOCKS-Proxy auf `127.0.0.1:9050` (Default), `ControlPort 9051` optional für auto-Onion-Service + +## 4. Litecoin Core installieren (verifiziert) + +- **Neueste stabile Version** herunterladen von `https://download.litecoin.org/` (Stand 2026: Reihe **v0.21.5.x**, mindestens v0.21.5.6/5.7/5.8 wegen der MWEB-Sicherheitsfixes 2026 – nie eine ältere Version) +- **SHA256-Summe prüfen** (aus den offiziellen release notes) **und Signatur verifizieren** (Signing-Key des Litecoin-Projekts, z. B. laanwj) +- Installation nach `/opt/litecoin-`, Symlink `/opt/litecoin` +- systemd-Unit `litecoind.service`: User `litecoin`, `ExecStart=/opt/litecoin/bin/litecoind -datadir=/var/lib/litecoin -conf=/etc/litecoin/litecoin.conf`, Restart=on-failure, Hardening (NoNewPrivileges, ProtectSystem=strict außer datadir, PrivateTmp) + +## 5. litecoin.conf (Kernstück) + +```ini +# Netzwerk: nur Tor, kein Clearnet, kein Inbound +proxy=127.0.0.1:9050 +onlynet=onion +listen=0 +discover=0 +upnp=0 + +# RPC: nur lokal, Agent entscheidet final (Empfehlung: SSH-Tunnel) +server=1 +rpcbind=127.0.0.1 +rpcallowip=127.0.0.1 +# rpcauth=:$ (niemals rpcpassword im Klartext) +rpcport=8332 + +# Performance / Wallet +dbcache=2048 +txindex=0 +wallet=cold +fallbackfee=0.0001 +``` + +## 6. Wallet einrichten + +1. Node starten, Sync abwarten (`litecoin-cli getblockchaininfo` → `initialblockdownload: false`) +2. `litecoin-cli -conf=/etc/litecoin/litecoin.conf createwallet "cold"` +3. **Sofort verschlüsseln:** `encryptwallet ""` – Passwort wird **nie** in Dateien, Logs oder diesem Auftrag gespeichert; Übergabe nur über vom Auftraggeber vorgesehenen Secret-Kanal +4. Empfangsadresse erzeugen und dokumentieren: `getnewaddress "" "bech32"` (nur legacy/bech32 – **Bitpanda unterstützt kein MWEB**, daher nie `ltcmweb1` an Bitpanda) +5. Descriptor/Seed-Infos exportieren und sicher ablegen (siehe Abschnitt 8) + +## 7. Snapshots (LXC-Backup, täglich) + +- Proxmox-Job oder Cron auf dem Host: täglicher **Snapshot** des LXC (Storage mit Snapshot-Support: ZFS oder LVM-thin), Retention z. B. 7 Stück +- Snapshot schützt gegen Korruption – ersetzt **nicht** das Wallet-Backup (Abschnitt 8) + +## 8. Verschlüsseltes wallet.dat-Backup zum separaten PBS im LAN (täglich) + +- `restic` im LXC installieren; Repo auf dem **separaten Proxmox Backup Server im LAN** anlegen (Zugriff per SSH), **client-seitige Verschlüsselung** (restic-Standard) +- Cron täglich 03:00 Uhr im LXC: + - `litecoin-cli backupwallet /var/lib/litecoin/backups/wallet-$(date +%F)` + - `restic backup /var/lib/litecoin/backups` (nur backups/, **nie** die komplette Chain – die wird bei Restore neu gesynct) + - `restic forget --keep-daily 30 --prune` +- Zugangsdaten/Passwörter für restic liegen im Secret-Store des Auftraggebers, nicht in Cron-Files im Klartext (restic nutzt RESTIC_PASSWORD_FILE oder env aus systemd-Credentials) +- Monatlich: `restic check` als Test + +## 9. Monitoring & Doku + +- systemd-Status `litecoind` + `tor` überwachen; Alarm wenn Node nicht synced (`getblockchaininfo`) +- `logrotate` für litecoin debug.log +- Doku im LXC (`/root/README.md`): genutzte Befehle, SSH-Tunnel-Anleitung, Restore-Anleitung: + - Snapshot-Restore in Proxmox **oder** + - frischer LXC + Core neu installieren + Chain neu syncen + `wallet.dat` aus restic zurückspielen + `walletpassphrase` → fertig +- Changelog aller Änderungen pflegen + +## 10. Abnahmetest (muss bestanden werden) + +1. Kleinen LTC-Betrag von Bitpanda auf `getnewaddress` (bech32/legacy) senden → 6 Bestätigungen abwarten → in `listtransactions` sichtbar +2. Test-Sendung kleiner Betrag zurück an Bitpanda → Tx via Tor gebroadcastet (Log/`getnetworkinfo` prüfen: nur onion-Verbindungen, `listen=0`) +3. Snapshot erstellen + auflisten +4. restic-Backup ausführen + `restic snapshots` + `restic check` erfolgreich +5. Firewall verifizieren: von außen kein Port offen (`nmap` vom anderen LAN-Gerät gegen LXC-IP) +6. Bericht an Auftraggeber: LXC-ID, IP, installierte Core-Version + Prüfsumme, Sync-Status, Snapshot-Liste, restic-Snapshot-Liste, Firewall-Regeln, gewählte RPC-Variante + Doku-Link + +## 11. Sicherheitsregeln (verbindlich) + +- **Nie** Seed-Phrase, wallet-Passwort, restic-Passwort, RPC-Credentials in Klartext in Dateien, Repos, Logs oder diesen Auftrag schreiben – nur verschlüsselt/secret +- Keine Ports nach außen öffnen (kein 9333, kein 8332/8333) +- Nur signierte/verifizierte Software-Downloads (SHA256 + GPG) +- Node nur über Tor erreichbar (onion-only); `listen=0` nicht „zum Debuggen“ aufheben +- Bitpanda/Handelsplätze: immer nur legacy/bech32-Adressen, nie MWEB-Adressen an Exchanges +- Alle Änderungen dokumentieren + +## 12. Offene Punkte (Agent entscheidet und dokumentiert) + +- LXC-ID, LAN-IP, Hostname (nächste freie Werte, DHCP-Reservierung vorschlagen) +- Finale RPC-Zugriffsvariante (Empfehlung: `rpcbind=127.0.0.1` + `ssh -L 8332:127.0.0.1:8332 ltc-node` vom Desktop) +- Snapshot-Zeitplan/Retention (Vorschlag: täglich, 7 behalten) +- restic-Repo-Details auf dem PBS (Ziel-URL/SSH-Host werden vom Auftraggeber geliefert) diff --git a/docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/litecoin-lxc-tests.txt b/docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/litecoin-lxc-tests.txt new file mode 100644 index 0000000..0da39e2 --- /dev/null +++ b/docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/litecoin-lxc-tests.txt @@ -0,0 +1,37 @@ +Der wichtigste Test ist nicht „funktioniert eine Zahlung“, sondern **„komme ich an mein Geld, wenn etwas schiefgeht“**. Deshalb in dieser Reihenfolge, immer mit kleinen Beträgen: + +## Phase 0: Setup-Checks (vor dem ersten Euro) +- Node vollständig gesynct: `litecoin-cli getblockchaininfo` → `initialblockdownload: false`, Block-Höhe nahe dem Netzwerk-Top +- Nur Tor: `litecoin-cli getnetworkinfo` → Verbindungen nur `onion`, `listen=0` aktiv +- Wallet verschlüsselt: `litecoin-cli getwalletinfo` → `unlocked_until` nur nach `walletpassphrase`; ohne Passwort keine Sends möglich +- Firewall: von einem anderen LAN-Gerät `nmap ` → keine offenen Ports +- Backups laufen: Snapshot-Liste in Proxmox, `restic snapshots` zeigt Einträge, `restic check` fehlerfrei + +## Phase 1: Restore-Test (das wichtigste zuerst!) +Bevor nennenswert Geld drauf ist: +1. **Snapshot-Restore testen:** Snapshot des LXC in Proxmox zurückspielen (auf Kopie/CT-ID testen), prüfen ob `litecoind` startet und Wallet intakt +2. **Wallet-Restore testen:** `wallet.dat` aus restic auf einem Test-Rechner/Test-CT einspielen, Core mit `walletpassphrase` öffnen, `getbalance` zeigt die Test-Coins → Beweis, dass das Backup funktioniert +3. Seed/Metall-Backup physisch prüfen:Offline-Leseprobe (Wörter lesbar, vollständig) + +## Phase 2: Kleine echte Transaktionen (Cent- bis zweistellige Beträge) +1. **Bitpanda → Node:** kleinsten Betrag auf `getnewaddress "" "bech32"` senden, Adresse doppelt prüfen (kopieren, nicht abtippen), 6 Bestätigungen abwarten, in `listtransactions` prüfen – **nicht über öffentlichen Explorer** (der sieht deine Adresse; wenn doch, nur über Tor) +2. **Node → Bitpanda zurück:** `sendtoaddress` kleiner Betrag, prüfe im Bitpanda-Konto den Eingang; damit ist Ein- und Auszahlung bewiesen +3. **Node → Handy (Cake Wallet):** kleiner Betrag an die Cake-Adresse, warte Bestätigungen, in Cake Wallet sichtbar +4. **Handy → externe Adresse:** von Cake Wallet kleiner Betrag zurück an Node-Adresse oder Bitpanda + +## Phase 3: MWEB-Test (klein) +- In Cake Wallet oder Electrum-LTC: kleiner Betrag peg-in (MWEB-Adresse `ltcmweb1...`), innerhalb MWEB kleine Sendung, dann peg-out zurück auf normale Adresse +- Prüfen: an **Bitpanda/Rapidgator nie MWEB-Adressen** senden (da gehen Coins verloren) + +## Phase 4: Notfall-Übung +- Server ausmachen → Cake Wallet funktioniert unabhängig (Hot Wallet) +- Handy weg/defekt → Cake-Seed auf neuem Gerät wiederherstellen (Test mit zweitem Gerät) +- Node-Wallet-Sperre testen: `walletlock` → Senden ohne `walletpassphrase` muss fehlschlagen + +## Rote Linien währenddessen +- Nie Seed-Phrase irgendwo eingeben – auch nicht „zum Testen“ in Webseiten/Apps +- Nie größere Beträge, bevor Phase 1–3 bestanden sind +- Jede Adresse auf dem Bildschirm visuell vergleichen (bei Hardware-Wallet: auf dem Gerät) +- Logs/Fehler dokumentieren, bevor du weitermachst + +**Faustregel:** Wenn Restore-Test + kleine Ein-/Auszahlung + MWEB-Rundtrip bestanden sind, ist das Setup produktiv. Erst dann größere Beträge von Bitpanda rüberschieben – und auch dann immer erst Testbetrag, dann Rest. diff --git a/proxmox/lxc/ct-114-litecoin-wallet/README.md b/proxmox/lxc/ct-114-litecoin-wallet/README.md new file mode 100644 index 0000000..88f0e02 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/README.md @@ -0,0 +1,20 @@ +# CT 114 – Litecoin wallet node + +Host root for the Litecoin full-node LXC at `10.0.0.61` (`ltc-node`), planned +as a Tor-only cold wallet (GNAI-024). The container does not exist yet; it is +created on the PVE host by the operator with the reviewed helpers in +[`scripts/`](scripts/README.md) and then converged by the self-contained +Ansible project in [`ansible/`](ansible/README.md). + +| Area | Content | +| --- | --- | +| [`ansible/`](ansible/README.md) | inventories (`agent`/`bootstrap`/`production`), playbooks and CT-specific roles | +| [`scripts/`](scripts/README.md) | reviewed PVE provisioning launcher and access bootstrap hook | +| [`../../../docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/GNAI-024-PLAN_Litecoin-Wallet-LXC.md`](../../../docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/GNAI-024-PLAN_Litecoin-Wallet-LXC.md) | design, review of the research documents, decisions, phases and acceptance tests | +| [`../../../docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/litecoin-lxc-setup.txt`](../../../docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/litecoin-lxc-setup.txt) | original research brief (Auftrag) | +| [`../../../docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/litecoin-lxc-tests.txt`](../../../docs/platform/proxmox-server/lxc/ct-114-litecoin-wallet/litecoin-lxc-tests.txt) | original research test plan (Auftrag) | + +Secrets never enter this repository: no wallet passphrase, no seed, no +restic password, no private SSH keys. The wallet passphrase and restic +secret are handled interactively / via the operator's secret store +(Vaultwarden), and only public keys live in `ansible/files/ssh/`. diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/README.md b/proxmox/lxc/ct-114-litecoin-wallet/ansible/README.md new file mode 100644 index 0000000..5e59095 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/README.md @@ -0,0 +1,65 @@ +# CT 114 Litecoin wallet Ansible project + +This self-contained host project manages the CT 114 Litecoin full-node LXC +(`ltc-node`, `10.0.0.61`). It follows the CT 102 Keycloak fresh-rebuild schema +and the CT 100/103 three-inventory convention (`agent`, `bootstrap`, +`production`) and uses the repository-wide pinned control dependency +(`shared/ansible/requirements-control.txt`); all CT 114 inventories, +playbooks, keys and roles remain inside the CT 114 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-114-litecoin-wallet/ansible +../../../../.venv/bin/ansible-playbook \ + --inventory inventories/production/hosts.yml \ + playbooks/verify-production.yml \ + --private-key ~/.ssh/id_ed25519_ghostnet_ct114_ansible_deploy +``` + +## Commissioning sequence for the new CT 114 + +CT 114 does not exist yet; the LXC is created on the PVE host by the operator +with the reviewed helpers in [`../scripts/`](../scripts/) (Community Scripts +launcher + bootstrap hook), following the CT 102 procedure (GNAI-016 Phase D, +GNAI-024 Abschnitt 6): + +0. Operator, on the workstation: generate the three CT 114 key pairs + (`ghost` interactively with passphrase; `ghost-agent`/`ansible-deploy` + passphrase-less), copy the `.pub` files into `files/ssh/`, fill the + `ADMIN_PUBLIC_KEY` placeholder in the bootstrap hook, then create the + restic backup key and the restic password on the target during bootstrap + (secrets never enter this repository). +1. Operator, as root@pve: install the reviewed hooks and run + `../scripts/provision-ct114-litecoin.sh`. +2. Operator: pin the SSH host-key fingerprint from the Proxmox console into + all three `host_vars/litecoin-ct114.yml` files, and add + `10.0.0.61` to the WireGuard server-admin target list on CT 105 if VPN + management access is wanted. +3. `preflight.yml` on the `agent` inventory (read-only, unprivileged, + `--private-key ~/.ssh/id_ed25519_ghostnet_ct114_agent`) proves identity, + resource gates and the empty state. +4. `verify-deploy-access.yml` on the `production` inventory proves the + `ansible-deploy` boundary. +5. `site.yml --check --diff` on the `production` inventory previews the + convergence. A real `site.yml` run enforces the declared state and + therefore requires explicit operator authorization. +6. `verify-production.yml` plus a second `site.yml` run with `changed=0` + complete the commissioning; `audit-production.yml` is the read-only deep + audit. + +The node is started by `site.yml` only on inventories with +`litecoin_service_start_allowed: true` (production). Wallet creation and +`encryptwallet` are interactive operator/agent steps over SSH exec — never +part of a playbook (GNAI-024 Abschnitt 8). + +Do not store the wallet passphrase, the restic password, the restic SSH +private key, any private SSH key or seed material in this repository. diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/ansible.cfg b/proxmox/lxc/ct-114-litecoin-wallet/ansible/ansible.cfg new file mode 100644 index 0000000..b0d9cb1 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/ansible.cfg @@ -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 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/files/ssh/litecoin-ansible-deploy.pub b/proxmox/lxc/ct-114-litecoin-wallet/ansible/files/ssh/litecoin-ansible-deploy.pub new file mode 100644 index 0000000..4124aec --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/files/ssh/litecoin-ansible-deploy.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILfqlYvqesJK9bhMmfv6tRp5pXPFDu13xmYbV+58fopV ansible-deploy@ghostnet-ct114 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/files/ssh/litecoin-ghost-agent.pub b/proxmox/lxc/ct-114-litecoin-wallet/ansible/files/ssh/litecoin-ghost-agent.pub new file mode 100644 index 0000000..99d0744 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/files/ssh/litecoin-ghost-agent.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMvQR56yADYULrpThnXROAa8GxKWfb+xcnIVLVDVX6Yy ghost-agent@ghostnet-ct114 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/agent/group_vars/litecoin_hosts.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/agent/group_vars/litecoin_hosts.yml new file mode 100644 index 0000000..2466eba --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/agent/group_vars/litecoin_hosts.yml @@ -0,0 +1,32 @@ +--- +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_ct114 + +litecoin_expected_distribution: Debian +litecoin_expected_distribution_major_version: "13" +litecoin_expected_hostname: ltc-node +litecoin_expected_virtualization_type: lxc + +litecoin_firewall_management_ipv4: + - 10.0.0.0/24 + - 10.8.0.0/24 +litecoin_firewall_ssh_port: 22 + +litecoin_access_source_networks: 10.0.0.0/24,10.8.0.0/24 + +litecoin_core_version: 0.21.5.8 +litecoin_core_tarball_name: "litecoin-{{ litecoin_core_version }}-x86_64-linux-gnu.tar.gz" +litecoin_core_base_url: "https://download.litecoin.org/litecoin-{{ litecoin_core_version }}/linux" +# SHA-256 aus dem signierten SHA256SUMS.asc von download.litecoin.org +# (Release v0.21.5.8 vom 2026-09-12, enthaelt den 0.21.5.7-Sicherheitsfix), +# am 2026-11-25 gegen den offiziellen Download geprueft (GNAI-024 Abschnitt 2). +litecoin_core_tarball_sha256: >- + 43200c9f9d65ebc126ea5833ca9429e144c4b3273da6bb9f4e89fd7450ab1be9 + +# Read-only access only; the agent inventory must never converge state. +litecoin_service_start_allowed: false +litecoin_service_production_enabled: false diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/agent/host_vars/litecoin-ct114.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/agent/host_vars/litecoin-ct114.yml new file mode 100644 index 0000000..557bb33 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/agent/host_vars/litecoin-ct114.yml @@ -0,0 +1,11 @@ +--- +litecoin_ctid: 114 +litecoin_expected_ipv4: 10.0.0.61 +# Wird nach dem ersten Boot des CT vom Operator aus der Proxmox-Konsole +# uebernommen (ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub via pct exec) +# und hier gepinnt. Der Platzhalter muss vor dem ersten Lauf ersetzt werden. +litecoin_expected_ssh_host_key_fingerprint: "SHA256:PENDING-operator-pins-after-first-boot" +litecoin_expected_processor_vcpus: 2 +litecoin_minimum_memory_mb: 3800 +litecoin_minimum_root_size_bytes: 150000000000 +litecoin_minimum_root_available_bytes: 20000000000 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/agent/hosts.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/agent/hosts.yml new file mode 100644 index 0000000..48b1d08 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/agent/hosts.yml @@ -0,0 +1,8 @@ +--- +all: + children: + litecoin_hosts: + hosts: + litecoin-ct114: + ansible_host: 10.0.0.61 + ansible_user: ghost-agent diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/bootstrap/group_vars/litecoin_hosts.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/bootstrap/group_vars/litecoin_hosts.yml new file mode 100644 index 0000000..5d8faa7 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/bootstrap/group_vars/litecoin_hosts.yml @@ -0,0 +1,29 @@ +--- +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_ct114 + +litecoin_expected_distribution: Debian +litecoin_expected_distribution_major_version: "13" +litecoin_expected_hostname: ltc-node +litecoin_expected_virtualization_type: lxc + +litecoin_firewall_management_ipv4: + - 10.0.0.0/24 + - 10.8.0.0/24 +litecoin_firewall_ssh_port: 22 + +litecoin_access_source_networks: 10.0.0.0/24,10.8.0.0/24 + +litecoin_core_version: 0.21.5.8 +litecoin_core_tarball_name: "litecoin-{{ litecoin_core_version }}-x86_64-linux-gnu.tar.gz" +litecoin_core_base_url: "https://download.litecoin.org/litecoin-{{ litecoin_core_version }}/linux" +litecoin_core_tarball_sha256: >- + 43200c9f9d65ebc126ea5833ca9429e144c4b3273da6bb9f4e89fd7450ab1be9 + +# Bootstrap converges configuration but must not start the node yet. +litecoin_service_start_allowed: false +litecoin_service_production_enabled: false diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/bootstrap/host_vars/litecoin-ct114.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/bootstrap/host_vars/litecoin-ct114.yml new file mode 100644 index 0000000..ce93607 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/bootstrap/host_vars/litecoin-ct114.yml @@ -0,0 +1,8 @@ +--- +litecoin_ctid: 114 +litecoin_expected_ipv4: 10.0.0.61 +litecoin_expected_ssh_host_key_fingerprint: "SHA256:PENDING-operator-pins-after-first-boot" +litecoin_expected_processor_vcpus: 2 +litecoin_minimum_memory_mb: 3800 +litecoin_minimum_root_size_bytes: 150000000000 +litecoin_minimum_root_available_bytes: 20000000000 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/bootstrap/hosts.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/bootstrap/hosts.yml new file mode 100644 index 0000000..c746a6e --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/bootstrap/hosts.yml @@ -0,0 +1,8 @@ +--- +all: + children: + litecoin_hosts: + hosts: + litecoin-ct114: + ansible_host: 10.0.0.61 + ansible_user: ghost diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/production/group_vars/litecoin_hosts.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/production/group_vars/litecoin_hosts.yml new file mode 100644 index 0000000..2aded07 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/production/group_vars/litecoin_hosts.yml @@ -0,0 +1,37 @@ +--- +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_ct114 + +litecoin_expected_distribution: Debian +litecoin_expected_distribution_major_version: "13" +litecoin_expected_hostname: ltc-node +litecoin_expected_virtualization_type: lxc + +litecoin_firewall_management_ipv4: + - 10.0.0.0/24 + - 10.8.0.0/24 +litecoin_firewall_ssh_port: 22 + +litecoin_access_source_networks: 10.0.0.0/24,10.8.0.0/24 + +litecoin_core_version: 0.21.5.8 +litecoin_core_tarball_name: "litecoin-{{ litecoin_core_version }}-x86_64-linux-gnu.tar.gz" +litecoin_core_base_url: "https://download.litecoin.org/litecoin-{{ litecoin_core_version }}/linux" +# SHA-256 aus dem signierten SHA256SUMS.asc von download.litecoin.org +# (Release v0.21.5.8 vom 2026-09-12, enthaelt den 0.21.5.7-Sicherheitsfix), +# am 2026-11-25 gegen den offiziellen Download geprueft (GNAI-024 Abschnitt 2). +litecoin_core_tarball_sha256: >- + 43200c9f9d65ebc126ea5833ca9429e144c4b3273da6bb9f4e89fd7450ab1be9 + +# restic-Ziel auf dem hostunabhaengigen Backup-Ziel ghostnet-ki (10.0.0.90), +# Konto gn-backup; clientseitige Verschluesselung ist restic-Standard. +# Alternativ liefert der Betreiber die Zugangsdaten eines separaten PBS im LAN. +litecoin_backup_repository: "sftp:gn-backup@10.0.0.90:/var/lib/ghostnet-ai-backup/ct114/restic" +litecoin_backup_keep_daily: 30 + +litecoin_service_start_allowed: true +litecoin_service_production_enabled: true diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/production/host_vars/litecoin-ct114.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/production/host_vars/litecoin-ct114.yml new file mode 100644 index 0000000..f6e2ee2 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/production/host_vars/litecoin-ct114.yml @@ -0,0 +1,11 @@ +--- +litecoin_ctid: 114 +litecoin_expected_ipv4: 10.0.0.61 +# Wird nach dem ersten Boot des CT vom Operator aus der Proxmox-Konsole +# uebernommen (pct exec 114 -- ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub) +# und hier gepinnt. Der Platzhalter muss vor dem ersten Lauf ersetzt werden. +litecoin_expected_ssh_host_key_fingerprint: "SHA256:PENDING-operator-pins-after-first-boot" +litecoin_expected_processor_vcpus: 2 +litecoin_minimum_memory_mb: 3800 +litecoin_minimum_root_size_bytes: 150000000000 +litecoin_minimum_root_available_bytes: 20000000000 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/production/hosts.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/production/hosts.yml new file mode 100644 index 0000000..7d5815f --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/inventories/production/hosts.yml @@ -0,0 +1,8 @@ +--- +all: + children: + litecoin_hosts: + hosts: + litecoin-ct114: + ansible_host: 10.0.0.61 + ansible_user: ansible-deploy diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/audit-production.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/audit-production.yml new file mode 100644 index 0000000..de90e03 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/audit-production.yml @@ -0,0 +1,181 @@ +--- +- name: Read-only deep audit of the CT 114 production state + hosts: litecoin_hosts + become: true + gather_facts: true + gather_subset: + - min + - network + - virtual + + tasks: + - name: Require the production inventory safeguards + ansible.builtin.assert: + that: + - litecoin_ctid | int == 114 + - inventory_hostname == "litecoin-ct114" + - >- + litecoin_expected_ssh_host_key_fingerprint is + match('^SHA256:[A-Za-z0-9+/]{43}$') + + - name: Read the account inventory + ansible.builtin.command: + argv: [/usr/bin/getent, passwd] + check_mode: false + changed_when: false + register: litecoin_audit_passwd + + - name: Require exactly the managed accounts with their fixed UIDs + ansible.builtin.assert: + that: + - litecoin_audit_passwd.stdout is search('(?m)^ghost-agent:x:1000:1000:') + - litecoin_audit_passwd.stdout is search('(?m)^ghost:x:1001:1001:') + - litecoin_audit_passwd.stdout is search('(?m)^ansible-deploy:x:1002:1002:') + - litecoin_audit_passwd.stdout is search('(?m)^litecoin:x:1100:1100:') + + - name: Read the password states of the managed accounts + ansible.builtin.command: + argv: [/usr/bin/passwd, -S, "{{ item }}"] + check_mode: false + changed_when: false + register: litecoin_audit_password_states + loop: + - ghost-agent + - ghost + - ansible-deploy + - litecoin + loop_control: + label: "{{ item }}" + + - name: Require locked or password-gated states only + ansible.builtin.assert: + that: + - item.stdout.split()[1] in ["L", "P"] + loop: "{{ litecoin_audit_password_states.results }}" + loop_control: + label: "{{ item.item }}" + + - name: Read the sudoers drop-ins + ansible.builtin.command: + argv: [/usr/bin/cat, /etc/sudoers.d/90-ghostnet-ansible-deploy, /etc/sudoers.d/91-ghostnet-litecoin-readonly] + check_mode: false + changed_when: false + register: litecoin_audit_sudoers + + - name: Require the validated sudo policies + ansible.builtin.assert: + that: + - litecoin_audit_sudoers.stdout is search('ansible-deploy ALL=\\(root\\) NOPASSWD: ALL') + - litecoin_audit_sudoers.stdout is search('ghost-agent ALL=\\(root\\) NOPASSWD: /usr/local/bin/ltc-readonly') + + - name: Verify the sudoers files pass visudo + ansible.builtin.command: + argv: [/usr/sbin/visudo, -c, -f, "{{ item }}"] + check_mode: false + changed_when: false + loop: + - /etc/sudoers.d/90-ghostnet-ansible-deploy + - /etc/sudoers.d/91-ghostnet-litecoin-readonly + loop_control: + label: "{{ item }}" + + - name: Read the effective SSH configuration + ansible.builtin.command: + argv: [/usr/sbin/sshd, -T] + check_mode: false + changed_when: false + register: litecoin_audit_sshd + + - name: Require the GNAI-011 SSH baseline + ansible.builtin.assert: + that: + - litecoin_audit_sshd.stdout is search('(?m)^permitrootlogin no$') + - litecoin_audit_sshd.stdout is search('(?m)^passwordauthentication no$') + - litecoin_audit_sshd.stdout is search('(?m)^kbdinteractiveauthentication no$') + - litecoin_audit_sshd.stdout is search('(?m)^allowtcpforwarding no$') + - litecoin_audit_sshd.stdout is search('(?m)^disableforwarding yes$') + - litecoin_audit_sshd.stdout is search('(?m)^allowusers ghost-agent ghost ansible-deploy$') + + - name: Read the fail2ban jail list + ansible.builtin.command: + argv: [/usr/bin/fail2ban-client, status] + check_mode: false + changed_when: false + register: litecoin_audit_fail2ban + + - name: Require the sshd jail + ansible.builtin.assert: + that: + - litecoin_audit_fail2ban.stdout is search('sshd') + + - name: Read the active nftables ruleset + ansible.builtin.command: + argv: [/usr/sbin/nft, list, ruleset] + check_mode: false + changed_when: false + register: litecoin_audit_nft + + - name: Require the Ghostnet filter table in the ruleset + ansible.builtin.assert: + that: + - litecoin_audit_nft.stdout is search('table inet ghostnet_filter') + + - name: Read the Tor client configuration + ansible.builtin.command: + argv: [/usr/bin/tor, --verify-config, -f, /etc/tor/torrc] + check_mode: false + changed_when: false + register: litecoin_audit_tor_config + + - name: Require the Tor config to verify + ansible.builtin.assert: + that: + - litecoin_audit_tor_config.rc == 0 + + - name: Read the litecoind network state via the read-only wrapper path + become: false + ansible.builtin.command: + argv: [/usr/bin/sudo, -n, -u, litecoin, /opt/litecoin/bin/litecoin-cli, -conf=/etc/litecoin/litecoin.conf, getnetworkinfo] + check_mode: false + changed_when: false + register: litecoin_audit_networkinfo + when: not ansible_check_mode + + - name: Require onion-only networking when the node is running + ansible.builtin.assert: + that: + - >- + '"onion"' in litecoin_audit_networkinfo.stdout + - >- + litecoin_audit_networkinfo.stdout is not + search('"name": "(ipv4|ipv6)"') + when: + - not ansible_check_mode + - litecoin_service_start_allowed | bool + + - name: Read the litecoind datadir usage + ansible.builtin.command: + argv: [/usr/bin/du, -sb, /var/lib/litecoin] + check_mode: false + changed_when: false + register: litecoin_audit_datadir_usage + + - name: Read the wallet backup directory state + ansible.builtin.stat: + path: /var/lib/litecoin/backups + register: litecoin_audit_backup_dir + + - name: Require the protected wallet backup directory + ansible.builtin.assert: + that: + - litecoin_audit_backup_dir.stat.exists + - litecoin_audit_backup_dir.stat.mode == "0700" + - litecoin_audit_backup_dir.stat.pw_name == "litecoin" + + - name: Report the CT 114 audit summary + ansible.builtin.debug: + msg: + ctid: "{{ litecoin_ctid }}" + ssh_fingerprint: "{{ litecoin_expected_ssh_host_key_fingerprint }}" + datadir_bytes: "{{ litecoin_audit_datadir_usage.stdout.split()[0] }}" + fail2ban_jails: "{{ litecoin_audit_fail2ban.stdout_lines }}" diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/preflight.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/preflight.yml new file mode 100644 index 0000000..0770359 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/preflight.yml @@ -0,0 +1,175 @@ +--- +- name: Read-only verification of the fresh CT 114 Litecoin LXC + hosts: litecoin_hosts + become: false + gather_facts: true + gather_subset: + - min + - hardware + - network + - virtual + + tasks: + - name: Verify required inventory safeguards are defined + ansible.builtin.assert: + that: + - litecoin_ctid is defined + - litecoin_expected_hostname is defined + - litecoin_expected_ipv4 is defined + - litecoin_expected_ssh_host_key_fingerprint is defined + - litecoin_expected_distribution is defined + - litecoin_expected_distribution_major_version is defined + - litecoin_expected_virtualization_type is defined + - litecoin_minimum_memory_mb is defined + - litecoin_minimum_root_size_bytes is defined + fail_msg: >- + The selected inventory lacks mandatory CT 114 identity safeguards. + Stop before running any configuration playbook. + + - name: Verify the expected guest identity + ansible.builtin.assert: + that: + - inventory_hostname == "litecoin-ct114" + - litecoin_ctid | int == 114 + - ansible_facts["hostname"] == litecoin_expected_hostname + - ansible_facts["distribution"] == litecoin_expected_distribution + - >- + ansible_facts["distribution_major_version"] == + litecoin_expected_distribution_major_version + - >- + ansible_facts["default_ipv4"]["address"] == + litecoin_expected_ipv4 + - >- + ansible_facts["virtualization_type"] == + litecoin_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 114 Litecoin LXC. + Stop before using any privileged playbook. + success_msg: The expected Debian 13 CT 114 Litecoin LXC is connected. + + - name: Verify the pinned SSH host key fingerprint + ansible.builtin.assert: + that: + - litecoin_expected_ssh_host_key_fingerprint is + match('^SHA256:[A-Za-z0-9+/]{43}$') + fail_msg: >- + litecoin_expected_ssh_host_key_fingerprint still contains the + PENDING placeholder. Pin the real fingerprint from the Proxmox + console after the first boot (GNAI-024 Abschnitt 6). + + - name: Read the unprivileged SSH identity + ansible.builtin.command: + argv: + - /usr/bin/id + - -un + check_mode: false + changed_when: false + register: litecoin_preflight_ssh_identity + + - name: Verify the agent account was used on the agent inventory + ansible.builtin.assert: + that: + - litecoin_preflight_ssh_identity.stdout == "ghost-agent" + fail_msg: >- + The agent inventory must connect through the unprivileged + ghost-agent account. + when: ansible_user is defined and ansible_user == "ghost-agent" + + - name: Read failed systemd units + ansible.builtin.command: + argv: + - /usr/bin/systemctl + - --failed + - --no-legend + - --plain + check_mode: false + changed_when: false + register: litecoin_preflight_failed_units + + - name: Read the listening TCP ports + ansible.builtin.command: + argv: + - /usr/bin/ss + - -H + - -lnt + check_mode: false + changed_when: false + register: litecoin_preflight_listeners + + - name: Read the effective processor count + ansible.builtin.command: + argv: + - /usr/bin/nproc + check_mode: false + changed_when: false + register: litecoin_preflight_nproc + + - name: Read root filesystem capacity + ansible.builtin.command: + argv: + - /usr/bin/findmnt + - --bytes + - --noheadings + - --output + - SIZE,AVAIL + - --target + - / + check_mode: false + changed_when: false + register: litecoin_preflight_root_capacity + + - name: Check that no Litecoin installation exists yet + ansible.builtin.stat: + path: /opt/litecoin + register: litecoin_preflight_opt_symlink + + - name: Verify the fresh-LXC commissioning gates + ansible.builtin.assert: + that: + - >- + litecoin_preflight_nproc.stdout | int == + litecoin_expected_processor_vcpus | int + - >- + ansible_facts["memtotal_mb"] | int >= + litecoin_minimum_memory_mb | int + - >- + litecoin_preflight_root_capacity.stdout.split()[0] | int >= + litecoin_minimum_root_size_bytes | int + - >- + litecoin_preflight_root_capacity.stdout.split()[1] | int >= + litecoin_minimum_root_available_bytes | int + - litecoin_preflight_failed_units.stdout | trim == "" + - >- + litecoin_preflight_listeners.stdout is search('\\b22\\b') or + litecoin_preflight_listeners.stdout | trim == "" + - not litecoin_preflight_opt_symlink.stat.exists + fail_msg: >- + The target is not the expected healthy, empty CT 114. Stop before + creating configuration, services or wallets. + success_msg: >- + CT 114 is healthy, empty and ready for declarative configuration. + + - name: Report the verified Litecoin commissioning baseline + ansible.builtin.debug: + msg: + inventory_host: "{{ inventory_hostname }}" + ctid: "{{ litecoin_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'] }} + effective_processor_count: "{{ litecoin_preflight_nproc.stdout }}" + memory_mib: "{{ ansible_facts['memtotal_mb'] }}" + root_size_bytes: >- + {{ litecoin_preflight_root_capacity.stdout.split()[0] }} + root_available_bytes: >- + {{ litecoin_preflight_root_capacity.stdout.split()[1] }} + trusted_ssh_fingerprint: >- + {{ litecoin_expected_ssh_host_key_fingerprint }} diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/site.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/site.yml new file mode 100644 index 0000000..20dec22 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/site.yml @@ -0,0 +1,29 @@ +--- +- name: Converge the CT 114 Litecoin wallet LXC on the declared state + hosts: litecoin_hosts + become: true + gather_facts: true + gather_subset: + - min + - hardware + - network + - virtual + + roles: + - role: litecoin_lxc_baseline + vars: + litecoin_lxc_baseline_expected_hostname: >- + {{ litecoin_expected_hostname }} + litecoin_lxc_baseline_expected_distribution: >- + {{ litecoin_expected_distribution }} + litecoin_lxc_baseline_expected_distribution_major_version: >- + {{ litecoin_expected_distribution_major_version }} + litecoin_lxc_baseline_expected_ipv4: "{{ litecoin_expected_ipv4 }}" + litecoin_lxc_baseline_expected_virtualization_type: >- + {{ litecoin_expected_virtualization_type }} + - role: litecoin_access + - role: litecoin_firewall + - role: litecoin_fail2ban + - role: litecoin_tor + - role: litecoin_core + - role: litecoin_backup diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/verify-deploy-access.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/verify-deploy-access.yml new file mode 100644 index 0000000..c4166fc --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/verify-deploy-access.yml @@ -0,0 +1,43 @@ +--- +- name: Verify the CT 114 Ansible deployment boundary + hosts: litecoin_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: litecoin_deploy_account_identity + + - name: Verify the expected SSH account + ansible.builtin.assert: + that: + - litecoin_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: litecoin_deploy_root_identity + + - name: Verify non-interactive root escalation + ansible.builtin.assert: + that: + - litecoin_deploy_root_identity.stdout == "0" + fail_msg: Non-interactive sudo did not produce effective UID 0. + success_msg: >- + The CT 114 deployment account can connect and escalate privileges + non-interactively. diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/verify-production.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/verify-production.yml new file mode 100644 index 0000000..92924ea --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/playbooks/verify-production.yml @@ -0,0 +1,213 @@ +--- +- name: Read-only verification of the converged CT 114 production state + hosts: litecoin_hosts + become: true + gather_facts: true + gather_subset: + - min + - network + - virtual + + tasks: + - name: Require the production inventory safeguards + ansible.builtin.assert: + that: + - litecoin_ctid | int == 114 + - inventory_hostname == "litecoin-ct114" + - >- + litecoin_expected_ssh_host_key_fingerprint is + match('^SHA256:[A-Za-z0-9+/]{43}$') + + - name: Verify the expected guest identity + ansible.builtin.assert: + that: + - ansible_facts["hostname"] == litecoin_expected_hostname + - ansible_facts["distribution"] == litecoin_expected_distribution + - >- + ansible_facts["distribution_major_version"] == + litecoin_expected_distribution_major_version + - >- + ansible_facts["default_ipv4"]["address"] == + litecoin_expected_ipv4 + - >- + ansible_facts["virtualization_type"] == + litecoin_expected_virtualization_type + - ansible_facts["virtualization_role"] == "guest" + fail_msg: The connected machine is not the declared CT 114. + + - name: Read failed systemd units + ansible.builtin.command: + argv: [/usr/bin/systemctl, --failed, --no-legend, --plain] + check_mode: false + changed_when: false + register: litecoin_production_failed_units + + - name: Require no failed units + ansible.builtin.assert: + that: + - litecoin_production_failed_units.stdout | trim == "" + + - name: Read the deployment account identity + become: false + ansible.builtin.command: + argv: [/usr/bin/id, -un] + check_mode: false + changed_when: false + register: litecoin_production_ssh_identity + + - name: Require the deployment account + ansible.builtin.assert: + that: + - litecoin_production_ssh_identity.stdout == "ansible-deploy" + + - name: Read the required service states + ansible.builtin.command: + argv: + - /usr/bin/systemctl + - is-active + - ssh.service + - nftables.service + - fail2ban.service + - tor.service + - unattended-upgrades.service + check_mode: false + changed_when: false + register: litecoin_production_services + + - name: Require all management services active + ansible.builtin.assert: + that: + - litecoin_production_services.stdout_lines | select('!=', 'active') | list | length == 0 + + - name: Read the litecoind service state + ansible.builtin.command: + argv: [/usr/bin/systemctl, is-active, litecoind.service] + check_mode: false + changed_when: false + register: litecoin_production_litecoind + + - name: Require litecoind active when the inventory allows starting it + ansible.builtin.assert: + that: + - litecoin_production_litecoind.stdout == "active" + when: litecoin_service_start_allowed | bool + + - name: Read the listening TCP sockets + ansible.builtin.command: + argv: [/usr/bin/ss, -H, -lnt] + check_mode: false + changed_when: false + register: litecoin_production_listeners + + - name: Require SSH as the only externally bound listener + ansible.builtin.assert: + that: + - litecoin_production_listeners.stdout is search('0.0.0.0:22\\b|\\[::\\]:22\\b') + - not (litecoin_production_listeners.stdout is search('0.0.0.0:(9332|9333|9050|9051)\\b')) + - not (litecoin_production_listeners.stdout is search('\\[::\\]:(9332|9333|9050|9051)\\b')) + fail_msg: >- + Unexpected externally bound listener. RPC 9332, SOCKS 9050, + ControlPort 9051 and P2P 9333 must be loopback-only or absent. + + - name: Require loopback-only RPC and Tor listeners + ansible.builtin.assert: + that: + - litecoin_production_listeners.stdout is search('127.0.0.1:9332\\b') + - litecoin_production_listeners.stdout is search('127.0.0.1:9050\\b') + - not (litecoin_production_listeners.stdout is search('9333')) + fail_msg: >- + litecoind must bind RPC to 127.0.0.1:9332 only and must not listen + on P2P 9333 (listen=0, onion-only). + + - name: Read the litecoind version + ansible.builtin.command: + argv: [/opt/litecoin/bin/litecoind, --version] + check_mode: false + changed_when: false + register: litecoin_production_version + + - name: Require the pinned Litecoin Core version + ansible.builtin.assert: + that: + - ('Litecoin Core version v' ~ litecoin_core_version) in litecoin_production_version.stdout + fail_msg: "Unexpected litecoind version: {{ litecoin_production_version.stdout }}" + + - name: Read the active Ghostnet nftables table + ansible.builtin.command: + argv: [/usr/sbin/nft, list, table, inet, ghostnet_filter] + check_mode: false + changed_when: false + register: litecoin_production_nft + + - name: Require the default-deny firewall + ansible.builtin.assert: + that: + - litecoin_production_nft.stdout is search('policy drop') + - litecoin_production_nft.stdout is search('SSH management') + - litecoin_production_nft.stdout is search('default input deny') + + - name: Read the effective SSH policy + ansible.builtin.command: + argv: [/usr/sbin/sshd, -T] + check_mode: false + changed_when: false + register: litecoin_production_sshd_effective + + - name: Require the hardened SSH policy + ansible.builtin.assert: + that: + - litecoin_production_sshd_effective.stdout is search('(?m)^permitrootlogin no$') + - litecoin_production_sshd_effective.stdout is search('(?m)^passwordauthentication no$') + - litecoin_production_sshd_effective.stdout is search('(?m)^allowtcpforwarding no$') + - litecoin_production_sshd_effective.stdout is search('(?m)^disableforwarding yes$') + + - name: Read the litecoin.conf permissions + ansible.builtin.stat: + path: /etc/litecoin/litecoin.conf + register: litecoin_production_conf_stat + + - name: Require the protected litecoin.conf + ansible.builtin.assert: + that: + - litecoin_production_conf_stat.stat.mode == "0640" + - litecoin_production_conf_stat.stat.pw_name == "root" + - litecoin_production_conf_stat.stat.gr_name == "litecoin" + + - name: Read the restic password file state without reading its content + ansible.builtin.stat: + path: /etc/litecoin-backup/restic-password + get_checksum: false + register: litecoin_production_restic_password_stat + + - name: Require the operator-provided restic secret with safe permissions + ansible.builtin.assert: + that: + - litecoin_production_restic_password_stat.stat.exists + - litecoin_production_restic_password_stat.stat.mode == "0600" + - litecoin_production_restic_password_stat.stat.pw_name == "root" + fail_msg: >- + /etc/litecoin-backup/restic-password must exist as root:root 0600; + the operator installs it once (GNAI-024 Abschnitt 6 Schritt 0). + + - name: Read the enabled backup timers + ansible.builtin.command: + argv: [/usr/bin/systemctl, list-timers, --no-legend, litecoin-wallet-backup.timer, litecoin-restic-check.timer] + check_mode: false + changed_when: false + register: litecoin_production_timers + + - name: Require both backup timers + ansible.builtin.assert: + that: + - litecoin_production_timers.stdout is search('litecoin-wallet-backup.timer') + - litecoin_production_timers.stdout is search('litecoin-restic-check.timer') + + - name: Report the verified CT 114 production state + ansible.builtin.debug: + msg: + ctid: "{{ litecoin_ctid }}" + ipv4: "{{ ansible_facts['default_ipv4']['address'] }}" + litecoind: "{{ litecoin_production_version.stdout.splitlines()[0] }}" + listeners: "{{ litecoin_production_listeners.stdout_lines }}" + services: "{{ litecoin_production_services.stdout_lines }}" + ssh_fingerprint: "{{ litecoin_expected_ssh_host_key_fingerprint }}" diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/README.md b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/README.md new file mode 100644 index 0000000..5cd1428 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/README.md @@ -0,0 +1,18 @@ +# litecoin_access + +Access model for CT 114, mirroring `keycloak_access` / GNAI-011: + +- `ghost-agent` (1000, locked, no groups): `restrict,from="10.0.0.0/24,10.8.0.0/24"` + key plus a NOPASSWD sudo rule limited to `/usr/local/bin/ltc-readonly`, a + wrapper that whitelists read-only `litecoin-cli` calls and runs them as the + `litecoin` user (cookie auth, no stored RPC credentials). +- `ghost` (1001, password-gated sudo): personal admin key with forwarding + restrictions. +- `ansible-deploy` (1002, locked, `NOPASSWD: ALL`): `restrict,from=...` key. +- Root SSH emptied, `PermitRootLogin no`, password auth off, socket activation + off, and `DisableForwarding yes` — therefore no SSH port forwarding; the + Litecoin RPC (127.0.0.1:9332) is only used via SSH exec, never via tunnel. + +All public keys come from `ansible/files/ssh/`; the role fails closed when a +key file is missing (the `ghost` key is generated interactively by the +operator before the first converge — GNAI-024 Abschnitt 6 Schritt 0). diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/defaults/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/defaults/main.yml new file mode 100644 index 0000000..d95e589 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/defaults/main.yml @@ -0,0 +1,37 @@ +--- +litecoin_access_source_networks: 10.0.0.0/24,10.8.0.0/24 +litecoin_access_public_key_root: "{{ playbook_dir }}/../files/ssh" + +litecoin_access_agent_user: ghost-agent +litecoin_access_agent_uid: 1000 +litecoin_access_agent_public_key_file: >- + {{ litecoin_access_public_key_root }}/litecoin-ghost-agent.pub + +litecoin_access_admin_user: ghost +litecoin_access_admin_uid: 1001 +litecoin_access_admin_public_key_file: >- + {{ litecoin_access_public_key_root }}/litecoin-ghost.pub + +litecoin_access_deploy_user: ansible-deploy +litecoin_access_deploy_uid: 1002 +litecoin_access_deploy_public_key_file: >- + {{ litecoin_access_public_key_root }}/litecoin-ansible-deploy.pub + +litecoin_access_ssh_dropin: /etc/ssh/sshd_config.d/99-ghostnet-litecoin.conf +litecoin_access_sudoers_file: /etc/sudoers.d/90-ghostnet-ansible-deploy +litecoin_access_readonly_sudoers_file: /etc/sudoers.d/91-ghostnet-litecoin-readonly +litecoin_access_readonly_wrapper: /usr/local/bin/ltc-readonly + +# Read-only litecoin-cli calls the agent account may run via the wrapper. +# Sending coins is deliberately not in this list; it stays an interactive +# `sudo -u litecoin litecoin-cli ...` action by ghost/ansible-deploy after an +# explicit walletpassphrase unlock (GNAI-024 Abschnitt 8). +litecoin_access_readonly_commands: + - getbalance + - getblockchaininfo + - getblockcount + - getmempoolinfo + - getnetworkinfo + - getpeerinfo + - getwalletinfo + - listtransactions diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/handlers/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/handlers/main.yml new file mode 100644 index 0000000..f67d8e5 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: Restart the classic SSH service + ansible.builtin.systemd_service: + name: ssh.service + state: restarted diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/tasks/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/tasks/main.yml new file mode 100644 index 0000000..b04e3b0 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/tasks/main.yml @@ -0,0 +1,225 @@ +--- +- name: Require all three role-specific public keys in files/ssh + ansible.builtin.stat: + path: "{{ item }}" + loop: + - "{{ litecoin_access_agent_public_key_file }}" + - "{{ litecoin_access_admin_public_key_file }}" + - "{{ litecoin_access_deploy_public_key_file }}" + register: litecoin_access_public_keys + +- name: Fail with a clear message when a public key is missing + ansible.builtin.fail: + msg: >- + Missing public key {{ item.item }}. The operator generates the CT 114 + key pairs (the ghost key interactively with passphrase) and copies the + .pub files into ansible/files/ssh/ before converging (GNAI-024 + Abschnitt 6, Schritt 0). + when: not item.stat.exists + loop: "{{ litecoin_access_public_keys.results }}" + loop_control: + label: "{{ item.item }}" + +- name: Validate the public key files are real OpenSSH keys + ansible.builtin.command: + argv: + - /usr/bin/ssh-keygen + - -l + - -f + - "{{ item }}" + check_mode: false + changed_when: false + loop: + - "{{ litecoin_access_agent_public_key_file }}" + - "{{ litecoin_access_admin_public_key_file }}" + - "{{ litecoin_access_deploy_public_key_file }}" + loop_control: + label: "{{ item }}" + +- name: Create fixed primary groups for Litecoin access accounts + ansible.builtin.group: + name: "{{ item.name }}" + gid: "{{ item.uid }}" + state: present + loop: + - name: "{{ litecoin_access_agent_user }}" + uid: "{{ litecoin_access_agent_uid }}" + - name: "{{ litecoin_access_admin_user }}" + uid: "{{ litecoin_access_admin_uid }}" + - name: "{{ litecoin_access_deploy_user }}" + uid: "{{ litecoin_access_deploy_uid }}" + loop_control: + label: "{{ item.name }}" + +- name: Create fixed Litecoin 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: "{{ litecoin_access_agent_user }}" + uid: "{{ litecoin_access_agent_uid }}" + - name: "{{ litecoin_access_admin_user }}" + uid: "{{ litecoin_access_admin_uid }}" + - name: "{{ litecoin_access_deploy_user }}" + uid: "{{ litecoin_access_deploy_uid }}" + loop_control: + label: "{{ item.name }}" + +- name: Keep the read-only agent outside supplementary groups + ansible.builtin.user: + name: "{{ litecoin_access_agent_user }}" + groups: "" + append: false + password_lock: true + +- name: Keep the deployment account outside supplementary groups + ansible.builtin.user: + name: "{{ litecoin_access_deploy_user }}" + groups: "" + append: false + password_lock: true + +- name: Grant password-gated sudo membership to the administrator + ansible.builtin.user: + name: "{{ litecoin_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: + - "{{ litecoin_access_agent_user }}" + - "{{ litecoin_access_admin_user }}" + - "{{ litecoin_access_deploy_user }}" + +- name: Install the restricted read-only agent key + ansible.builtin.copy: + content: | + restrict,from="{{ litecoin_access_source_networks }}" {{ lookup('ansible.builtin.file', litecoin_access_agent_public_key_file) }} + dest: "/home/{{ litecoin_access_agent_user }}/.ssh/authorized_keys" + owner: "{{ litecoin_access_agent_user }}" + group: "{{ litecoin_access_agent_user }}" + mode: "0600" + +- name: Install the restricted personal administrator key + ansible.builtin.copy: + content: | + from="{{ litecoin_access_source_networks }}",no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc {{ lookup('ansible.builtin.file', litecoin_access_admin_public_key_file) }} + dest: "/home/{{ litecoin_access_admin_user }}/.ssh/authorized_keys" + owner: "{{ litecoin_access_admin_user }}" + group: "{{ litecoin_access_admin_user }}" + mode: "0600" + +- name: Install the restricted deployment key + ansible.builtin.copy: + content: | + restrict,from="{{ litecoin_access_source_networks }}" {{ lookup('ansible.builtin.file', litecoin_access_deploy_public_key_file) }} + dest: "/home/{{ litecoin_access_deploy_user }}/.ssh/authorized_keys" + owner: "{{ litecoin_access_deploy_user }}" + group: "{{ litecoin_access_deploy_user }}" + mode: "0600" + +- name: Install validated deployment sudo policy + ansible.builtin.copy: + content: | + {{ litecoin_access_deploy_user }} ALL=(root) NOPASSWD: ALL + dest: "{{ litecoin_access_sudoers_file }}" + owner: root + group: root + mode: "0440" + validate: /usr/sbin/visudo -cf %s + +- name: Install the read-only wrapper for the agent account + ansible.builtin.template: + src: ltc-readonly.sh.j2 + dest: "{{ litecoin_access_readonly_wrapper }}" + owner: root + group: root + mode: "0750" + validate: /bin/bash -n %s + +- name: Install validated read-only sudo policy for the agent account + ansible.builtin.copy: + content: | + {{ litecoin_access_agent_user }} ALL=(root) NOPASSWD: {{ litecoin_access_readonly_wrapper }} + dest: "{{ litecoin_access_readonly_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: "{{ litecoin_access_ssh_dropin }}" + owner: root + group: root + mode: "0600" + 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 + register: litecoin_access_password_states + loop: + - "{{ litecoin_access_agent_user }}" + - "{{ litecoin_access_admin_user }}" + - "{{ litecoin_access_deploy_user }}" + loop_control: + label: "{{ item }}" + +- name: Verify the locked password states + ansible.builtin.assert: + that: + - item.stdout.split()[1] in ["L", "P"] + fail_msg: >- + Account {{ item.item }} has unsafe password state + {{ item.stdout.split()[1] }}. + loop: "{{ litecoin_access_password_states.results }}" + loop_control: + label: "{{ item.item }}" diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/templates/ltc-readonly.sh.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/templates/ltc-readonly.sh.j2 new file mode 100644 index 0000000..45ea94a --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/templates/ltc-readonly.sh.j2 @@ -0,0 +1,32 @@ +#!/bin/bash +# Managed by Ansible role litecoin_access. +# Read-only litecoin-cli wrapper for the ghost-agent account (NOPASSWD sudo). +# Whitelists read-only RPC calls and executes them as the litecoin service +# user so the node-local cookie auth is used. No sending, no wallet unlock. +set -Eeuo pipefail + +readonly ALLOWED=( +{% for command in litecoin_access_readonly_commands %} "{{ command }}" +{% endfor %}) + +if [[ $# -lt 1 ]]; then + printf 'usage: ltc-readonly [args...]\nallowed:' >&2 + printf ' %s' "${ALLOWED[@]}" >&2 + printf '\n' >&2 + exit 2 +fi + +allowed=0 +for candidate in "${ALLOWED[@]}"; do + if [[ "$1" == "$candidate" ]]; then + allowed=1 + break + fi +done +if [[ "$allowed" -ne 1 ]]; then + printf 'ltc-readonly: command not allowed: %s\n' "$1" >&2 + exit 2 +fi + +exec /usr/sbin/runuser -u litecoin -- \ + /opt/litecoin/bin/litecoin-cli -conf=/etc/litecoin/litecoin.conf "$@" diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/templates/sshd.conf.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/templates/sshd.conf.j2 new file mode 100644 index 0000000..285438b --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_access/templates/sshd.conf.j2 @@ -0,0 +1,18 @@ +# Managed by Ansible role litecoin_access. +# GNAI-011 SSH baseline. TCP forwarding stays disabled on purpose: the +# Litecoin RPC is reached via `ssh ... ltc-readonly` / `sudo -u litecoin +# litecoin-cli`, never via an SSH tunnel (GNAI-024 Abschnitt 2, Befund d). +PermitRootLogin no +PasswordAuthentication no +KbdInteractiveAuthentication no +PubkeyAuthentication yes +AllowUsers {{ litecoin_access_agent_user }} {{ litecoin_access_admin_user }} {{ litecoin_access_deploy_user }} +X11Forwarding no +AllowAgentForwarding no +AllowTcpForwarding no +AllowStreamLocalForwarding no +DisableForwarding yes +PermitTunnel no +MaxAuthTries 3 +LoginGraceTime 30 +LogLevel VERBOSE diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/README.md b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/README.md new file mode 100644 index 0000000..4f6a4f3 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/README.md @@ -0,0 +1,16 @@ +# litecoin_backup + +Daily encrypted wallet backup of CT 114 (GNAI-024 Abschnitt 9): + +- `/usr/local/sbin/litecoin-wallet-backup.sh` runs `backupwallet` as the + `litecoin` user into `/var/lib/litecoin/backups/`, then a restic backup of + `backups/` only (never the chain — a restore re-syncs and then restores + `wallet.dat`), then `forget --keep-daily 30 --prune`. +- restic repository: `sftp:gn-backup@10.0.0.90:...` (host-independent backup + target ghostnet-ki) unless the operator overrides + `litecoin_backup_repository` with a separate PBS. Encryption is + client-side (restic default); the target only sees ciphertext. +- Secrets are never managed here: the restic password file and the dedicated + SSH key are placed by the operator into `/etc/litecoin-backup/` (root-only); + the role only pins the target host key and asserts file modes. The timers + run daily 03:00 (backup) and monthly (restic check). diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/defaults/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/defaults/main.yml new file mode 100644 index 0000000..00ba762 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/defaults/main.yml @@ -0,0 +1,24 @@ +--- +# restic target on the host-independent backup host ghostnet-ki (10.0.0.90), +# account gn-backup; overridden per inventory (a separate PBS in the LAN is +# equally possible — GNAI-024 Abschnitt 2 Befund g). +litecoin_backup_repository: "sftp:gn-backup@10.0.0.90:/var/lib/ghostnet-ai-backup/ct114/restic" +litecoin_backup_keep_daily: 30 + +litecoin_backup_env_dir: /etc/litecoin-backup +litecoin_backup_password_file: "{{ litecoin_backup_env_dir }}/restic-password" +# Default ssh identity name so restic's sftp backend picks it up via HOME. +litecoin_backup_ssh_key: "{{ litecoin_backup_env_dir }}/.ssh/id_ed25519" +litecoin_backup_known_hosts: "{{ litecoin_backup_env_dir }}/.ssh/known_hosts" +# ghostnet-ki host key (ed25519), same pin as pve_lxc_backup_sync. +litecoin_backup_target_host: 10.0.0.90 +litecoin_backup_target_host_key_ed25519: >- + ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID1UMrhG0WoKlRfadNadWdZogijlhjCz8uXfWbjvxuf8 +litecoin_backup_script: /usr/local/sbin/litecoin-wallet-backup.sh +litecoin_backup_service: litecoin-wallet-backup.service +litecoin_backup_timer: litecoin-wallet-backup.timer +litecoin_backup_timer_oncalendar: '*-*-* 03:00:00' +litecoin_restic_check_timer: litecoin-restic-check.timer +litecoin_restic_check_oncalendar: '*-*-01 04:00:00' +litecoin_backup_wallet_dir: /var/lib/litecoin/backups +litecoin_backup_logrotate: /etc/logrotate.d/litecoin-backup diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/handlers/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/handlers/main.yml new file mode 100644 index 0000000..0d67cbf --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/handlers/main.yml @@ -0,0 +1,4 @@ +--- +- name: Reload systemd for litecoin backup + ansible.builtin.systemd_service: + daemon_reload: true diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/tasks/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/tasks/main.yml new file mode 100644 index 0000000..c373a69 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/tasks/main.yml @@ -0,0 +1,116 @@ +--- +- name: Create the protected restic environment directory + ansible.builtin.file: + path: "{{ litecoin_backup_env_dir }}" + state: directory + owner: root + group: root + mode: "0700" + +- name: Create the root-only ssh directory for the restic key + ansible.builtin.file: + path: "{{ litecoin_backup_env_dir }}/.ssh" + state: directory + owner: root + group: root + mode: "0700" + +- name: Pin the backup target host key for restic's sftp backend + ansible.builtin.lineinfile: + path: "{{ litecoin_backup_known_hosts }}" + regexp: '^10\.0\.0\.90 ssh-ed25519 ' + line: "10.0.0.90 {{ litecoin_backup_target_host_key_ed25519 }}" + owner: root + group: root + mode: "0600" + create: true + +- name: Require the operator-provided restic SSH key + ansible.builtin.stat: + path: "{{ litecoin_backup_ssh_key }}" + register: litecoin_backup_ssh_key_stat + +- name: Fail with a clear message when the restic SSH key is missing + ansible.builtin.fail: + msg: >- + {{ litecoin_backup_ssh_key }} is missing. The operator creates the + dedicated CT 114 backup key, authorizes it for gn-backup on + ghostnet-ki (source-restricted to 10.0.0.61) and installs the private + key here with mode 0600; the public key never enters the repository + (GNAI-024 Abschnitt 6 Schritt 0). + when: not litecoin_backup_ssh_key_stat.stat.exists + +- name: Verify the restic SSH key permissions + ansible.builtin.stat: + path: "{{ litecoin_backup_ssh_key }}" + register: litecoin_backup_ssh_key_mode + +- name: Assert the restic SSH key is root-only + ansible.builtin.assert: + that: + - litecoin_backup_ssh_key_mode.stat.mode == "0600" + - litecoin_backup_ssh_key_mode.stat.pw_name == "root" + fail_msg: "{{ litecoin_backup_ssh_key }} must be root:root 0600." + +- name: Install the daily wallet backup script + ansible.builtin.template: + src: litecoin-wallet-backup.sh.j2 + dest: "{{ litecoin_backup_script }}" + owner: root + group: root + mode: "0750" + validate: /bin/bash -n %s + +- name: Install the wallet backup systemd service + ansible.builtin.template: + src: litecoin-wallet-backup.service.j2 + dest: "/etc/systemd/system/{{ litecoin_backup_service }}" + owner: root + group: root + mode: "0644" + notify: Reload systemd for litecoin backup + +- name: Install the daily wallet backup timer + ansible.builtin.template: + src: litecoin-wallet-backup.timer.j2 + dest: "/etc/systemd/system/{{ litecoin_backup_timer }}" + owner: root + group: root + mode: "0644" + notify: Reload systemd for litecoin backup + +- name: Install the monthly restic check service + ansible.builtin.template: + src: litecoin-restic-check.service.j2 + dest: /etc/systemd/system/litecoin-restic-check.service + owner: root + group: root + mode: "0644" + notify: Reload systemd for litecoin backup + +- name: Install the monthly restic check timer + ansible.builtin.template: + src: litecoin-restic-check.timer.j2 + dest: "/etc/systemd/system/{{ litecoin_restic_check_timer }}" + owner: root + group: root + mode: "0644" + notify: Reload systemd for litecoin backup + +- name: Install the backup log logrotate policy + ansible.builtin.template: + src: litecoin-backup.logrotate.j2 + dest: "{{ litecoin_backup_logrotate }}" + owner: root + group: root + mode: "0644" + +- name: Enable the backup timers + ansible.builtin.systemd_service: + name: "{{ item }}" + enabled: true + state: started + daemon_reload: true + loop: + - "{{ litecoin_backup_timer }}" + - "{{ litecoin_restic_check_timer }}" diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-backup.logrotate.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-backup.logrotate.j2 new file mode 100644 index 0000000..717321a --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-backup.logrotate.j2 @@ -0,0 +1,8 @@ +/var/log/litecoin-backup.log { + weekly + rotate 8 + compress + missingok + notifempty + copytruncate +} diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-restic-check.service.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-restic-check.service.j2 new file mode 100644 index 0000000..52a2880 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-restic-check.service.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=Monthly restic check of the Litecoin wallet backup repository + +[Service] +Type=oneshot +Environment=RESTIC_REPOSITORY={{ litecoin_backup_repository }} +Environment=RESTIC_PASSWORD_FILE={{ litecoin_backup_password_file }} +Environment=HOME={{ litecoin_backup_env_dir }} +Environment=SSH_AUTH_SOCK= +ExecStart=/usr/bin/restic check --read-data-subset=5% +Nice=10 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-restic-check.timer.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-restic-check.timer.j2 new file mode 100644 index 0000000..1cbfc09 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-restic-check.timer.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=Monthly restic repository check for the Litecoin wallet backups + +[Timer] +OnCalendar={{ litecoin_restic_check_oncalendar }} +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.service.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.service.j2 new file mode 100644 index 0000000..55fbb5a --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.service.j2 @@ -0,0 +1,11 @@ +[Unit] +Description=Encrypted Litecoin wallet backup to the off-host restic repository +After=litecoind.service + +[Service] +Type=oneshot +ExecStart={{ litecoin_backup_script }} +# SSH key for the restic sftp target, root-only. +Environment=HOME={{ litecoin_backup_env_dir }} +Environment=SSH_AUTH_SOCK= +Nice=10 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.sh.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.sh.j2 new file mode 100644 index 0000000..4c0a9db --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.sh.j2 @@ -0,0 +1,26 @@ +#!/bin/bash +# Managed by Ansible role litecoin_backup. +# Daily wallet backup: backupwallet as the litecoin user, then a +# client-side encrypted restic backup of backups/ only (never the chain — +# a restore re-syncs the chain and then restores wallet.dat). Secrets stay +# in {{ litecoin_backup_password_file }} (root-only) and the dedicated SSH key; +# nothing is written to logs or the repository. +set -Eeuo pipefail + +export RESTIC_REPOSITORY="{{ litecoin_backup_repository }}" +export RESTIC_PASSWORD_FILE="{{ litecoin_backup_password_file }}" + +backup_dir="{{ litecoin_backup_wallet_dir }}" +today="$(date +%F)" + +/usr/sbin/runuser -u litecoin -- \ + /opt/litecoin/bin/litecoin-cli -conf=/etc/litecoin/litecoin.conf \ + backupwallet "${backup_dir}/wallet-${today}" + +/usr/bin/restic -r "$RESTIC_REPOSITORY" \ + --password-file "$RESTIC_PASSWORD_FILE" \ + backup "$backup_dir" + +/usr/bin/restic -r "$RESTIC_REPOSITORY" \ + --password-file "$RESTIC_PASSWORD_FILE" \ + forget --keep-daily {{ litecoin_backup_keep_daily }} --prune diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.timer.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.timer.j2 new file mode 100644 index 0000000..b5d4f45 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_backup/templates/litecoin-wallet-backup.timer.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=Daily encrypted Litecoin wallet backup (03:00) + +[Timer] +OnCalendar={{ litecoin_backup_timer_oncalendar }} +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/README.md b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/README.md new file mode 100644 index 0000000..423e66c --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/README.md @@ -0,0 +1,16 @@ +# litecoin_core + +Installs the pinned Litecoin Core release into `/opt/litecoin-` with +a stable `/opt/litecoin` symlink. The tarball is fetched over HTTPS from +`download.litecoin.org` and verified fail-closed against the pinned SHA-256 +from the signed `SHA256SUMS.asc` (v0.21.5.8, see GNAI-024 Abschnitt 2 Befund +a); the role then asserts `litecoind --version`. + +`litecoin.conf` is Tor-only (`proxy=127.0.0.1:9050`, `onlynet=onion`, +`listen=0`, no seeds/UPNP/NAT-PMP), RPC on `127.0.0.1:9332` with cookie auth +(no `rpcpassword`, no `rpcauth` material in any file — the node is only ever +administered as the `litecoin` user over SSH exec, GNAI-024 Befund d/e). +`litecoind.service` runs as `litecoin` with systemd hardening; the service is +enabled and started only when the inventory sets +`litecoin_service_start_allowed: true` (production). debug.log is rotated +weekly (copytruncate). diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/defaults/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/defaults/main.yml new file mode 100644 index 0000000..7c1f48c --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/defaults/main.yml @@ -0,0 +1,27 @@ +--- +litecoin_core_version: 0.21.5.8 +litecoin_core_tarball_name: "litecoin-{{ litecoin_core_version }}-x86_64-linux-gnu.tar.gz" +litecoin_core_base_url: "https://download.litecoin.org/litecoin-{{ litecoin_core_version }}/linux" +# SHA-256 from the signed SHA256SUMS.asc (GNAI-024 Abschnitt 2 Befund a). +litecoin_core_tarball_sha256: >- + 43200c9f9d65ebc126ea5833ca9429e144c4b3273da6bb9f4e89fd7450ab1be9 + +litecoin_core_install_root: /opt +litecoin_core_versioned_dir: "{{ litecoin_core_install_root }}/litecoin-{{ litecoin_core_version }}" +litecoin_core_symlink: "{{ litecoin_core_install_root }}/litecoin" +litecoin_core_download_dir: /usr/local/src/litecoin + +litecoin_core_user: litecoin +litecoin_core_group: litecoin +litecoin_core_datadir: /var/lib/litecoin +litecoin_core_config_dir: /etc/litecoin +litecoin_core_config: "{{ litecoin_core_config_dir }}/litecoin.conf" + +# Litecoin mainnet: P2P 9333, RPC 9332 (GNAI-024 Befund c: 8332 ist Bitcoin). +litecoin_core_rpc_port: 9332 +litecoin_core_tor_socks: 127.0.0.1:9050 +litecoin_core_dbcache_mb: 2048 +litecoin_core_fallbackfee: 0.0001 + +litecoin_core_service_name: litecoind.service +litecoin_core_logrotate: /etc/logrotate.d/litecoin diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/handlers/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/handlers/main.yml new file mode 100644 index 0000000..e089550 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/handlers/main.yml @@ -0,0 +1,9 @@ +--- +- name: Reload systemd for litecoind + ansible.builtin.systemd_service: + daemon_reload: true + +- name: Restart litecoind + ansible.builtin.systemd_service: + name: litecoind.service + state: restarted diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/tasks/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/tasks/main.yml new file mode 100644 index 0000000..680e102 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/tasks/main.yml @@ -0,0 +1,91 @@ +--- +- name: Require the pinned Litecoin Core tarball checksum + ansible.builtin.assert: + that: + - litecoin_core_tarball_sha256 is match('^[0-9a-f]{64}$') + - litecoin_core_version is match('^0\\.21\\.5\\.[0-9]+$') + fail_msg: >- + litecoin_core_tarball_sha256 must be a pinned 64-hex SHA-256 from the + signed SHA256SUMS.asc and the version must be in the audited 0.21.5.x + series (GNAI-024 Abschnitt 2 Befund a). + +- name: Download the pinned Litecoin Core release tarball + ansible.builtin.get_url: + url: "{{ litecoin_core_base_url }}/{{ litecoin_core_tarball_name }}" + dest: "{{ litecoin_core_download_dir }}/{{ litecoin_core_tarball_name }}" + checksum: "sha256:{{ litecoin_core_tarball_sha256 }}" + mode: "0644" + owner: root + group: root + timeout: 300 + +- name: Extract the verified Litecoin Core release + ansible.builtin.unarchive: + src: "{{ litecoin_core_download_dir }}/{{ litecoin_core_tarball_name }}" + dest: "{{ litecoin_core_install_root }}" + remote_src: true + creates: "{{ litecoin_core_versioned_dir }}/bin/litecoind" + +- name: Point the stable symlink at the verified version + ansible.builtin.file: + src: "{{ litecoin_core_versioned_dir }}" + dest: "{{ litecoin_core_symlink }}" + state: link + owner: root + group: root + +- name: Verify the installed litecoind binary + ansible.builtin.command: + argv: + - "{{ litecoin_core_symlink }}/bin/litecoind" + - --version + check_mode: false + changed_when: false + register: litecoin_core_version_output + +- name: Assert the expected Litecoin Core version + ansible.builtin.assert: + that: + - "('Litecoin Core version v' ~ litecoin_core_version) in litecoin_core_version_output.stdout" + fail_msg: "Unexpected litecoind version: {{ litecoin_core_version_output.stdout }}" + +- name: Install the managed litecoin.conf + ansible.builtin.template: + src: litecoin.conf.j2 + dest: "{{ litecoin_core_config }}" + owner: root + group: "{{ litecoin_core_group }}" + mode: "0640" + notify: Restart litecoind + +- name: Install the hardened litecoind systemd unit + ansible.builtin.template: + src: litecoind.service.j2 + dest: "/etc/systemd/system/{{ litecoin_core_service_name }}" + owner: root + group: root + mode: "0644" + notify: + - Reload systemd for litecoind + - Restart litecoind + +- name: Install the litecoin debug.log logrotate policy + ansible.builtin.template: + src: litecoin.logrotate.j2 + dest: "{{ litecoin_core_logrotate }}" + owner: root + group: root + mode: "0644" + +- name: Enable litecoind without starting it yet + ansible.builtin.systemd_service: + name: "{{ litecoin_core_service_name }}" + enabled: true + state: "{{ 'started' if litecoin_service_start_allowed | bool else 'stopped' }}" + daemon_reload: true + +- name: Start litecoind when the inventory allows it + ansible.builtin.systemd_service: + name: "{{ litecoin_core_service_name }}" + state: started + when: litecoin_service_start_allowed | bool diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/templates/litecoin.conf.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/templates/litecoin.conf.j2 new file mode 100644 index 0000000..18ec377 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/templates/litecoin.conf.j2 @@ -0,0 +1,30 @@ +# Managed by Ansible role litecoin_core. No credentials in this file: +# RPC is cookie-authenticated and bound to loopback only (GNAI-024 Befund d/e). + +# --- Network: Tor only, no clearnet, no inbound --- +proxy={{ litecoin_core_tor_socks }} +onlynet=onion +listen=0 +discover=0 +dnsseed=0 +fixedseeds=0 +upnp=0 +natpmp=0 + +# --- RPC: loopback only, cookie auth, no stored credentials --- +server=1 +rpcbind=127.0.0.1 +rpcallowip=127.0.0.1 +rpcport={{ litecoin_core_rpc_port }} +rpcthreads=4 + +# --- Chain / wallet --- +datadir={{ litecoin_core_datadir }} +dbcache={{ litecoin_core_dbcache_mb }} +txindex=0 +wallet=cold +fallbackfee={{ litecoin_core_fallbackfee }} +# MWEB stays usable locally, but addresses handed to exchanges or services +# (Bitpanda, Rapidgator) must always be legacy/bech32, never ltcmweb1... +# (GNAI-024 Abschnitt 2 Befund f). +prune=0 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/templates/litecoin.logrotate.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/templates/litecoin.logrotate.j2 new file mode 100644 index 0000000..5a7f8f2 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/templates/litecoin.logrotate.j2 @@ -0,0 +1,8 @@ +{{ litecoin_core_datadir }}/debug.log { + weekly + rotate 4 + compress + missingok + notifempty + copytruncate +} diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/templates/litecoind.service.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/templates/litecoind.service.j2 new file mode 100644 index 0000000..de5209d --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_core/templates/litecoind.service.j2 @@ -0,0 +1,34 @@ +[Unit] +Description=Litecoin Core full node (Tor-only cold wallet) +After=network-online.target tor.service +Wants=network-online.target + +[Service] +Type=simple +User={{ litecoin_core_user }} +Group={{ litecoin_core_group }} +ExecStart={{ litecoin_core_symlink }}/bin/litecoind -conf={{ litecoin_core_config }} -datadir={{ litecoin_core_datadir }} +Restart=on-failure +RestartSec=30 +TimeoutStopSec=120 +KillSignal=SIGINT + +# Hardening +NoNewPrivileges=true +ProtectSystem=strict +ProtectHome=true +PrivateTmp=true +PrivateDevices=true +ProtectKernelTunables=true +ProtectKernelModules=true +ProtectControlGroups=true +RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX +RestrictNamespaces=true +LockPersonality=true +MemoryDenyWriteExecute=true +CapabilityBoundingSet= +AmbientCapabilities= +ReadWritePaths={{ litecoin_core_datadir }} + +[Install] +WantedBy=multi-user.target diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/README.md b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/README.md new file mode 100644 index 0000000..39e234f --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/README.md @@ -0,0 +1,7 @@ +# litecoin_fail2ban + +Native fail2ban (apt, no Podman on CT 114) with the sshd jail on the systemd +backend (Debian 13 LXC has no rsyslog), banning via `nftables-multiport`. +Management networks (LAN, WireGuard) are on `ignoreip`; the jail is verified +with `fail2ban-client status sshd`. Mirrors the CT 103 fail2ban abnahme +without the NPM-specific jails. diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/defaults/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/defaults/main.yml new file mode 100644 index 0000000..a054f12 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/defaults/main.yml @@ -0,0 +1,7 @@ +--- +litecoin_fail2ban_jail_dropin: /etc/fail2ban/jail.d/00-ghostnet-litecoin.conf +litecoin_fail2ban_bantime: 1h +litecoin_fail2ban_findtime: 10m +litecoin_fail2ban_maxretry: 3 +# Management networks are trusted; only brute force from elsewhere is banned. +litecoin_fail2ban_ignoreip: 127.0.0.1/8 10.0.0.0/24 10.8.0.0/24 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/handlers/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/handlers/main.yml new file mode 100644 index 0000000..ba2cbac --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: Restart fail2ban + ansible.builtin.systemd_service: + name: fail2ban.service + state: restarted diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/tasks/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/tasks/main.yml new file mode 100644 index 0000000..ccef182 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/tasks/main.yml @@ -0,0 +1,33 @@ +--- +- name: Install the Ghostnet fail2ban jail drop-in + ansible.builtin.template: + src: jail.local.j2 + dest: "{{ litecoin_fail2ban_jail_dropin }}" + owner: root + group: root + mode: "0644" + notify: Restart fail2ban + +- name: Enable and start fail2ban + ansible.builtin.systemd_service: + name: fail2ban.service + enabled: true + state: started + +- name: Read the fail2ban sshd jail status + ansible.builtin.command: + argv: + - /usr/bin/fail2ban-client + - status + - sshd + check_mode: false + changed_when: false + register: litecoin_fail2ban_sshd_status + when: not ansible_check_mode + +- name: Verify the sshd jail is active + ansible.builtin.assert: + that: + - litecoin_fail2ban_sshd_status.stdout is search('Status') + - litecoin_fail2ban_sshd_status.stdout is search('Jail list:.*sshd') + when: not ansible_check_mode diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/templates/jail.local.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/templates/jail.local.j2 new file mode 100644 index 0000000..a11736a --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_fail2ban/templates/jail.local.j2 @@ -0,0 +1,15 @@ +# Managed by Ansible role litecoin_fail2ban. +# Debian 13 has no rsyslog in the LXC; the sshd jail reads the journal. +[DEFAULT] +backend = systemd +bantime = {{ litecoin_fail2ban_bantime }} +findtime = {{ litecoin_fail2ban_findtime }} +maxretry = {{ litecoin_fail2ban_maxretry }} +ignoreip = {{ litecoin_fail2ban_ignoreip }} +action = nftables-multiport[port="ssh", protocol=tcp] + +[sshd] +enabled = true +port = ssh +logpath = %(sshd_log)s +backend = systemd diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/README.md b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/README.md new file mode 100644 index 0000000..e55bad7 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/README.md @@ -0,0 +1,9 @@ +# litecoin_firewall + +Native nftables policy for CT 114 (repo convention: nftables, not ufw — +GNAI-024 Abschnitt 2 Befund b): `inet ghostnet_filter` with default-deny +input, loopback and established traffic accepted, ICMP diagnostics, SSH (TCP +22) only from the management networks (`10.0.0.0/24`, `10.8.0.0/24`), output +accepted (the Tor client needs outbound), forward dropped. No port of +litecoind (P2P 9333, RPC 9332) is ever opened; the service override destroys +only the Ghostnet-owned table on service stop. diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/defaults/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/defaults/main.yml new file mode 100644 index 0000000..9e37276 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/defaults/main.yml @@ -0,0 +1,5 @@ +--- +litecoin_firewall_management_ipv4: + - 10.0.0.0/24 + - 10.8.0.0/24 +litecoin_firewall_ssh_port: 22 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/handlers/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/handlers/main.yml new file mode 100644 index 0000000..f6826de --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/handlers/main.yml @@ -0,0 +1,9 @@ +--- +- name: Reload systemd for the Litecoin firewall + ansible.builtin.systemd_service: + daemon_reload: true + +- name: Restart the Litecoin firewall + ansible.builtin.systemd_service: + name: nftables.service + state: restarted diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/tasks/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/tasks/main.yml new file mode 100644 index 0000000..dec9adf --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/tasks/main.yml @@ -0,0 +1,93 @@ +--- +- name: Require a non-empty management allowlist + ansible.builtin.assert: + that: + - litecoin_firewall_management_ipv4 | length > 0 + fail_msg: The firewall management allowlist must be explicit and non-empty. + +- name: Read the active Ansible SSH transport endpoints + become: false + ansible.builtin.command: + argv: + - /usr/bin/printenv + - SSH_CONNECTION + check_mode: false + changed_when: false + register: litecoin_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)', + litecoin_firewall_ssh_connection.stdout.split()[0] + ] + litecoin_firewall_management_ipv4 + }} + check_mode: false + changed_when: false + vars: + ansible_command_timeout: 5 + +- name: Create the nftables service override directory + ansible.builtin.file: + path: /etc/systemd/system/nftables.service.d + state: directory + owner: root + group: root + mode: "0755" + +- name: Install the scoped nftables stop override + ansible.builtin.template: + src: nftables.service-override.conf.j2 + dest: /etc/systemd/system/nftables.service.d/10-ghostnet-preserve.conf + owner: root + group: root + mode: "0644" + notify: + - Reload systemd for the Litecoin firewall + - Restart the Litecoin firewall + +- name: Install and validate the Litecoin nftables policy + ansible.builtin.template: + src: nftables.conf.j2 + dest: /etc/nftables.conf + owner: root + group: root + mode: "0750" + validate: /usr/sbin/nft --check --file %s + notify: Restart the Litecoin firewall + +- name: Flush firewall handlers before verification + ansible.builtin.meta: flush_handlers + +- name: Enable and start the nftables service + ansible.builtin.systemd_service: + name: nftables.service + enabled: true + state: started + daemon_reload: true + +- name: Read the active Ghostnet nftables table + ansible.builtin.command: + argv: + - /usr/sbin/nft + - list + - table + - inet + - ghostnet_filter + check_mode: false + changed_when: false + register: litecoin_firewall_active_table + when: not ansible_check_mode + +- name: Verify the active firewall policy + ansible.builtin.assert: + that: + - litecoin_firewall_active_table.stdout is search('policy drop') + - litecoin_firewall_active_table.stdout is search('SSH management') + - litecoin_firewall_active_table.stdout is search('default input deny') + - litecoin_firewall_active_table.stdout is search('CT 114 forwards nothing') + when: not ansible_check_mode diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/templates/nftables.conf.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/templates/nftables.conf.j2 new file mode 100644 index 0000000..05bfe75 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/templates/nftables.conf.j2 @@ -0,0 +1,43 @@ +#!/usr/sbin/nft -f + +# Managed by Ansible role litecoin_firewall. +# CT 114 runs no public service: default-deny input, SSH from the management +# networks only, no P2P (9333) and no RPC (9332) listener exposed. The node +# reaches the Litecoin network exclusively as a Tor client (outbound only). +destroy table inet ghostnet_filter + +table inet ghostnet_filter { + set management_ipv4 { + type ipv4_addr + flags interval + elements = { {{ litecoin_firewall_management_ipv4 | join(', ') }} } + } + + chain input { + type filter hook input priority 10; policy drop; + + iifname "lo" counter accept comment "local loopback" + ct state established,related counter accept + ct state invalid counter drop + + meta l4proto icmp counter accept comment "IPv4 diagnostics" + meta l4proto ipv6-icmp counter accept comment "IPv6 neighbor discovery" + + ip saddr @management_ipv4 tcp dport {{ litecoin_firewall_ssh_port }} ct state new counter accept comment "SSH management" + + counter drop comment "default input deny" + } + + chain forward { + type filter hook forward priority 10; policy drop; + + ct state invalid counter drop + counter drop comment "CT 114 forwards nothing" + } + + chain output { + type filter hook output priority 10; policy accept; + } +} + +{{ '' }} diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/templates/nftables.service-override.conf.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/templates/nftables.service-override.conf.j2 new file mode 100644 index 0000000..129c56e --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_firewall/templates/nftables.service-override.conf.j2 @@ -0,0 +1,6 @@ +[Service] +# Keep the Ghostnet table across service stops; only the owned table is +# destroyed so a restart does not leave the host unfiltered. +ExecStop= +ExecStop=/usr/sbin/nft destroy table inet ghostnet_filter +{{ '\n' }} diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/README.md b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/README.md new file mode 100644 index 0000000..a7e4c91 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/README.md @@ -0,0 +1,11 @@ +# litecoin_lxc_baseline + +Baseline role for CT 114 (`ltc-node`, 10.0.0.61): identity assertion against +the inventory safeguards, base packages (incl. `tor`, `fail2ban`, `restic`, +`unattended-upgrades`), the locked `litecoin` service account (UID/GID 1100, +`nologin`, no supplementary groups), timezone `Europe/Berlin`, protected +directories and security-only unattended-upgrades. Mirrors +`keycloak_lxc_baseline` / `dns_lxc_baseline`. + +The role never installs keys, secrets or application state; that belongs to +`litecoin_access`, `litecoin_core` and `litecoin_backup`. diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/defaults/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/defaults/main.yml new file mode 100644 index 0000000..48fac5c --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/defaults/main.yml @@ -0,0 +1,45 @@ +--- +litecoin_lxc_baseline_timezone: Europe/Berlin + +litecoin_lxc_baseline_packages: + - ca-certificates + - curl + - fail2ban + - gnupg + - logrotate + - nftables + - openssh-server + - python3 + - restic + - sudo + - tor + - unattended-upgrades + +litecoin_lxc_baseline_directories: + - path: /etc/litecoin + owner: root + group: litecoin + mode: "0750" + - path: /etc/litecoin-backup + owner: root + group: root + mode: "0700" + - path: /opt/litecoin + owner: root + group: root + mode: "0755" + - path: /usr/local/src/litecoin + owner: root + group: root + mode: "0700" + - path: /var/lib/litecoin + owner: litecoin + group: litecoin + mode: "0700" + - path: /var/lib/litecoin/backups + owner: litecoin + group: litecoin + mode: "0700" + +litecoin_lxc_baseline_unattended_upgrades_allowed_origins: >- + Debian:${distro_codename} ${distro_codename}-security diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/handlers/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/handlers/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/handlers/main.yml @@ -0,0 +1 @@ +--- diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/tasks/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/tasks/main.yml new file mode 100644 index 0000000..6177f25 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_lxc_baseline/tasks/main.yml @@ -0,0 +1,96 @@ +--- +- name: Verify the Litecoin LXC identity before changing baseline state + ansible.builtin.assert: + that: + - ansible_facts["hostname"] == litecoin_lxc_baseline_expected_hostname + - >- + ansible_facts["distribution"] == + litecoin_lxc_baseline_expected_distribution + - >- + ansible_facts["distribution_major_version"] == + litecoin_lxc_baseline_expected_distribution_major_version + - >- + ansible_facts["default_ipv4"]["address"] == + litecoin_lxc_baseline_expected_ipv4 + - >- + ansible_facts["virtualization_type"] == + litecoin_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 114 Litecoin LXC. No + baseline changes may be applied. + +- name: Install baseline administration packages + ansible.builtin.apt: + name: "{{ litecoin_lxc_baseline_packages }}" + state: present + update_cache: true + cache_valid_time: 3600 + install_recommends: false + +- name: Create the fixed primary group for the Litecoin service account + ansible.builtin.group: + name: litecoin + gid: 1100 + state: present + system: true + +- name: Create the locked Litecoin service account without login shell + ansible.builtin.user: + name: litecoin + uid: 1100 + group: litecoin + home: /var/lib/litecoin + shell: /usr/sbin/nologin + create_home: false + state: present + system: true + password_lock: true + +- name: Set the local timezone database link + ansible.builtin.file: + src: "/usr/share/zoneinfo/{{ litecoin_lxc_baseline_timezone }}" + dest: /etc/localtime + state: link + owner: root + group: root + force: true + +- name: Record the configured timezone + ansible.builtin.copy: + content: "{{ litecoin_lxc_baseline_timezone }}\n" + dest: /etc/timezone + owner: root + group: root + mode: "0644" + +- name: Create protected Litecoin configuration and data paths + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + owner: "{{ item.owner }}" + group: "{{ item.group }}" + mode: "{{ item.mode }}" + loop: "{{ litecoin_lxc_baseline_directories }}" + loop_control: + label: "{{ item.path }}" + +- name: Enable and start the unattended-upgrades service (CT 100/102 convention) + ansible.builtin.systemd_service: + name: unattended-upgrades.service + enabled: true + state: started + +- name: Restrict unattended-upgrades to Debian security origins + ansible.builtin.copy: + content: |- + Unattended-Upgrade::Origins-Pattern { + "origin=Debian,codename=${distro_codename},label=Debian-Security"; + }; + Unattended-Upgrade::AutoFixInterruptedDpkg "true"; + Unattended-Upgrade::Remove-Unused-Dependencies "true"; + dest: /etc/apt/apt.conf.d/52ghostnet-unattended-upgrades + owner: root + group: root + mode: "0644" diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/README.md b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/README.md new file mode 100644 index 0000000..4778ec0 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/README.md @@ -0,0 +1,8 @@ +# litecoin_tor + +Local-only Tor client in CT 114. `tor` runs as `debian-tor`, client-only +(`ClientOnly 1`, no OR/Dir/Exit), SOCKS on `127.0.0.1:9050` and ControlPort +on `127.0.0.1:9051`, both loopback-only. `litecoind` is configured with +`proxy=127.0.0.1:9050` and `onlynet=onion`, so all P2P traffic leaves via +Tor and the node accepts no inbound connections (`listen=0`). The role +waits for the SOCKS port and reports the bootstrap phase. diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/defaults/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/defaults/main.yml new file mode 100644 index 0000000..f965e5d --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/defaults/main.yml @@ -0,0 +1,6 @@ +--- +litecoin_tor_socks_port: 127.0.0.1:9050 +litecoin_tor_control_port: 127.0.0.1:9051 +litecoin_tor_data_directory: /var/lib/tor +litecoin_tor_config: /etc/tor/torrc +litecoin_tor_log: /var/log/tor/notices.log diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/handlers/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/handlers/main.yml new file mode 100644 index 0000000..f628a62 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/handlers/main.yml @@ -0,0 +1,5 @@ +--- +- name: Restart tor + ansible.builtin.systemd_service: + name: tor.service + state: restarted diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/tasks/main.yml b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/tasks/main.yml new file mode 100644 index 0000000..8efcb3a --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/tasks/main.yml @@ -0,0 +1,56 @@ +--- +- name: Create the tor runtime directory + ansible.builtin.file: + path: /run/tor + state: directory + owner: debian-tor + group: debian-tor + mode: "0750" + +- name: Install the managed Tor client configuration + ansible.builtin.template: + src: torrc.j2 + dest: "{{ litecoin_tor_config }}" + owner: debian-tor + group: debian-tor + mode: "0640" + validate: /usr/bin/tor --verify-config -f %s + notify: Restart tor + +- name: Create the tor log directory + ansible.builtin.file: + path: /var/log/tor + state: directory + owner: debian-tor + group: debian-tor + mode: "0750" + +- name: Enable and start the Tor client service + ansible.builtin.systemd_service: + name: tor.service + enabled: true + state: started + +- name: Wait for the Tor SOCKS port on loopback + ansible.builtin.wait_for: + host: 127.0.0.1 + port: 9050 + timeout: 120 + when: not ansible_check_mode + +- name: Read the Tor bootstrap status + ansible.builtin.command: + argv: + - /usr/bin/torctl + - --socket /run/tor/control + - getinfo + - status/bootstrap-phase + check_mode: false + changed_when: false + register: litecoin_tor_bootstrap + when: not ansible_check_mode + +- name: Report the Tor bootstrap phase + ansible.builtin.debug: + msg: "{{ litecoin_tor_bootstrap.stdout | default('check mode: skipped') }}" + when: not ansible_check_mode diff --git a/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/templates/torrc.j2 b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/templates/torrc.j2 new file mode 100644 index 0000000..fd44a94 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/ansible/roles/litecoin_tor/templates/torrc.j2 @@ -0,0 +1,19 @@ +# Managed by Ansible role litecoin_tor. +# Local-only Tor client for litecoind: SOCKS on loopback, no public relay, +# no directory service exposure beyond what a client needs. +SocksPort {{ litecoin_tor_socks_port }} +ControlPort {{ litecoin_tor_control_port }} +DataDirectory {{ litecoin_tor_data_directory }} +CacheDirectory {{ litecoin_tor_data_directory }} +PidFile /run/tor/tor.pid +Log notice file {{ litecoin_tor_log }} +RunAsDaemon 0 +User debian-tor +# Client only: never act as relay, bridge or onion service host. +ClientOnly 1 +ORPort 0 +DirPort 0 +ExitPolicy reject *:* +# Keep bootstrap deterministic; litecoind uses onlynet=onion. +AssumeReachable 0 +NumEntryGuards 4 diff --git a/proxmox/lxc/ct-114-litecoin-wallet/scripts/README.md b/proxmox/lxc/ct-114-litecoin-wallet/scripts/README.md new file mode 100644 index 0000000..102545d --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/scripts/README.md @@ -0,0 +1,116 @@ +# Proxmox automation — CT 114 Litecoin wallet + +Reviewed host-side helpers for the reproducible creation of CT 114 +(`ltc-node`, `10.0.0.61`). They contain no password and no private key. + +## CT 114 provisioning profile + +| Setting | CT 114 value | +| --- | --- | +| CT ID / hostname | `114` / `ltc-node` | +| OS | Debian 13, amd64 | +| Container type | unprivileged LXC, **no nesting** (litecoind is a plain systemd service, no Podman) | +| CPU | 2 cores | +| Memory | 4096 MiB | +| Swap | 1024 MiB (set via `pct set` after creation, as with CT 102) | +| Root disk | 150 GiB on `local-lvm` (thin-provisioned, snapshot-capable; chain ~100 GiB + growth) | +| Network | `vmbr0`, `10.0.0.61/24`, gateway `10.0.0.1`, DNS `10.0.0.14` (Pi-hole), IPv6 disabled | +| Boot / protection | start on boot, protection enabled | +| Time zone | `Europe/Berlin` | +| Initial root SSH | not required; the hook installs and hardens OpenSSH | +| Post-install hook | `/usr/local/sbin/ghostnet-litecoin-ansible-bootstrap-hook.sh` | + +`10.0.0.61` is inside the static server range (up to `.99`, GNAI-007 +Adressplan) and was free in the documented inventory; the DHCP client range +starts at `.100`. + +## Step 0 (workstation, before any PVE step) + +The operator generates the three CT 114 key pairs and installs the public +keys: + +```bash +ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519_ghostnet_ct114_ghost -C "ghost@ghostnet-ct114" # interactively, with passphrase +# ghost-agent and ansible-deploy are passphrase-less per AGENTS.md and were +# already generated on 2026-11-25: +# ~/.ssh/id_ed25519_ghostnet_ct114_agent +# ~/.ssh/id_ed25519_ghostnet_ct114_ansible_deploy +cp ~/.ssh/id_ed25519_ghostnet_ct114_*.pub into this repo: + proxmox/lxc/ct-114-litecoin-wallet/ansible/files/ssh/litecoin-ghost.pub + proxmox/lxc/ct-114-litecoin-wallet/ansible/files/ssh/litecoin-ghost-agent.pub + proxmox/lxc/ct-114-litecoin-wallet/ansible/files/ssh/litecoin-ansible-deploy.pub +# then replace the ADMIN_PUBLIC_KEY placeholder in +# ghostnet-litecoin-ansible-bootstrap-hook.sh with the exact line from +# litecoin-ghost.pub, recompute its SHA-256 and update POST_INSTALL_HOOK_SHA256 +# in provision-ct114-litecoin.sh. +``` + +The `ghost` key passphrase is an interactive operator step and is never +written down anywhere (AGENTS.md: operator-run secret steps). + +## Step 1 — install the reviewed hooks on the PVE host (operator, root@pve) + +```bash +install -o root -g root -m 0750 \ + proxmox/shared/scripts/ghostnet-lxc-baseline.sh \ + /usr/local/sbin/ghostnet-lxc-baseline.sh +install -o root -g root -m 0700 \ + proxmox/lxc/ct-114-litecoin-wallet/scripts/ghostnet-litecoin-ansible-bootstrap-hook.sh \ + /usr/local/sbin/ghostnet-litecoin-ansible-bootstrap-hook.sh +sha256sum /usr/local/sbin/ghostnet-lxc-baseline.sh /usr/local/sbin/ghostnet-litecoin-ansible-bootstrap-hook.sh +# compare with BASELINE_HOOK_SHA256 / POST_INSTALL_HOOK_SHA256 in +# provision-ct114-litecoin.sh (baseline pin: 111f1b70…381b10, audited for CT 102) +``` + +## Step 2 — create the container (operator, root@pve) + +```bash +install -o root -g root -m 0700 \ + proxmox/lxc/ct-114-litecoin-wallet/scripts/provision-ct114-litecoin.sh \ + /usr/local/sbin/provision-ct114-litecoin.sh +/usr/local/sbin/provision-ct114-litecoin.sh +``` + +The launcher pins the Community Scripts `ProxmoxVE` and `core` repositories +to the revisions audited on 2026-11-25 (`c0c9d93d…`, `d1cec878…`), verifies +the downloaded `ct/debian.sh` by SHA-256 +(`8396340f…86187d`), requires free capacity on `local-lvm`, names every +material CT setting explicitly, rejects an occupied CT ID, and never deletes +or replaces an existing container. After Community Scripts returns it sets +1024 MiB swap and verifies the complete PVE configuration, the hook log and +the guest account state. + +## `ghostnet-litecoin-ansible-bootstrap-hook.sh` + +CT-114-specific Community Scripts post-install hook. It calls the generic +baseline hook (`ghostnet-lxc-baseline.sh`) and then establishes only the +transport and privilege boundary needed by Ansible: + +- it refuses any CT ID other than 114, any helper application other than + Debian, a hostname other than `ltc-node`, or a guest without `10.0.0.61`; +- it creates or validates `ghost-agent` 1000:1000, `ghost` 1001:1001 and + `ansible-deploy` 1002:1002; +- it installs the three role-specific public keys, limited to + `10.0.0.0/24,10.8.0.0/24`; the embedded keys must remain identical to + `../ansible/files/ssh/litecoin-{ghost-agent,ghost,ansible-deploy}.pub`; +- it keeps `ghost-agent` and `ansible-deploy` passwords locked, grants only + `ansible-deploy` reviewed `NOPASSWD: ALL`, and leaves `ghost` on Debian's + password-gated `sudo` policy; +- it disables SSH root/password authentication and TCP forwarding, empties + the temporary root `authorized_keys`, and validates SSH and sudo before + returning success. + +The hook does not install Tor, Litecoin Core, nftables, fail2ban or any +wallet state. Those belong to the Ansible roles +([`../ansible/`](../ansible/README.md)). + +## After creation + +1. Record the SSH host-key fingerprint (`pct exec 114 -- ssh-keygen -lf + /etc/ssh/ssh_host_ed25519_key.pub`) and pin it in all three + `host_vars/litecoin-ct114.yml` files. +2. `pct exec 114 -- passwd ghost` (interactive, operator). +3. If VPN management access is wanted, add `10.0.0.61` to the WireGuard + server-admin target set on CT 105 (GNAI-007) — separate change with its + own tests. +4. Run the Ansible commissioning sequence in [`../ansible/README.md`](../ansible/README.md). diff --git a/proxmox/lxc/ct-114-litecoin-wallet/scripts/ghostnet-litecoin-ansible-bootstrap-hook.sh b/proxmox/lxc/ct-114-litecoin-wallet/scripts/ghostnet-litecoin-ansible-bootstrap-hook.sh new file mode 100755 index 0000000..69ffa0a --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/scripts/ghostnet-litecoin-ansible-bootstrap-hook.sh @@ -0,0 +1,277 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail +umask 077 + +readonly EXPECTED_CTID="${GHOSTNET_LITECOIN_CTID:-114}" +readonly EXPECTED_HOSTNAME="${GHOSTNET_LITECOIN_HOSTNAME:-ltc-node}" +readonly EXPECTED_IPV4="${GHOSTNET_LITECOIN_IPV4:-10.0.0.61}" +readonly BASELINE_HOOK="${GHOSTNET_BASELINE_HOOK:-/usr/local/sbin/ghostnet-lxc-baseline.sh}" +readonly SSH_SOURCE_NETWORKS="${GHOSTNET_SSH_SOURCE_NETWORKS:-10.0.0.0/24,10.8.0.0/24}" + +readonly AGENT_USER="ghost-agent" +readonly AGENT_UID="1000" +readonly ADMIN_USER="ghost" +readonly ADMIN_UID="1001" +readonly DEPLOY_USER="ansible-deploy" +readonly DEPLOY_UID="1002" + +# Must stay identical to ../ansible/files/ssh/litecoin-*.pub. +# The ADMIN_PUBLIC_KEY placeholder is replaced with the operator-generated +# ghost public key before the hook is installed on the PVE host +# (GNAI-024 Abschnitt 6 Schritt 0); the hook refuses to run while the +# placeholder is present. +readonly AGENT_PUBLIC_KEY='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMvQR56yADYULrpThnXROAa8GxKWfb+xcnIVLVDVX6Yy ghost-agent@ghostnet-ct114' +readonly ADMIN_PUBLIC_KEY='@GHOSTNET-CT114-GHOST-PUBLIC-KEY@' +readonly DEPLOY_PUBLIC_KEY='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILfqlYvqesJK9bhMmfv6tRp5pXPFDu13xmYbV+58fopV ansible-deploy@ghostnet-ct114' + +log() { + printf '[ghostnet-litecoin-bootstrap] %s\n' "$*" +} + +die() { + printf '[ghostnet-litecoin-bootstrap] ERROR: %s\n' "$*" >&2 + exit 1 +} + +[[ "${EUID}" -eq 0 ]] || die "must run as root on the Proxmox host" +command -v pct >/dev/null 2>&1 || die "pct not found; run this hook on Proxmox" +[[ -x "$BASELINE_HOOK" ]] || die "baseline hook is missing or not executable: ${BASELINE_HOOK}" +[[ "$ADMIN_PUBLIC_KEY" != '@GHOSTNET-CT114-GHOST-PUBLIC-KEY@' ]] || + die "ADMIN_PUBLIC_KEY placeholder not replaced; see scripts/README.md step 0" + +ctid="${CTID:-${1:-}}" +[[ "$ctid" =~ ^[0-9]+$ ]] || die "CTID must be supplied by Community Scripts or as the first argument" +[[ "$ctid" == "$EXPECTED_CTID" ]] || die "refusing CT ${ctid}; expected CT ${EXPECTED_CTID}" + +if [[ -n "${APP:-}" ]]; then + [[ "${APP,,}" == "debian" ]] || die "refusing helper application ${APP}; expected Debian" +fi +if [[ -n "${HN:-}" ]]; then + [[ "$HN" == "$EXPECTED_HOSTNAME" ]] || die "refusing helper hostname ${HN}; expected ${EXPECTED_HOSTNAME}" +fi +if [[ -n "${IP:-}" ]]; then + [[ "$IP" == "$EXPECTED_IPV4" || "$IP" == "$EXPECTED_IPV4/"* ]] || + die "refusing helper IPv4 ${IP}; expected ${EXPECTED_IPV4}" +fi + +pct config "$ctid" >/dev/null 2>&1 || die "CT ${ctid} does not exist" +[[ "$(pct status "$ctid")" == 'status: running' ]] || die "CT ${ctid} is not running" + +log "running reviewed generic LXC baseline for CT ${ctid}" +CTID="$ctid" "$BASELINE_HOOK" "$ctid" + +guest_hostname="$(pct exec "$ctid" -- hostname --short)" +[[ "$guest_hostname" == "$EXPECTED_HOSTNAME" ]] || + die "guest hostname is ${guest_hostname}; expected ${EXPECTED_HOSTNAME}" + +pct exec "$ctid" -- ip -o -4 address show scope global | + grep -Eq "[[:space:]]inet[[:space:]]+${EXPECTED_IPV4//./\\.}/" || + die "guest does not own expected IPv4 ${EXPECTED_IPV4}" + +log "installing deterministic CT 114 access bootstrap" +pct exec "$ctid" -- /bin/bash -s -- \ + "$AGENT_USER" "$AGENT_UID" "$ADMIN_USER" "$ADMIN_UID" \ + "$DEPLOY_USER" "$DEPLOY_UID" "$SSH_SOURCE_NETWORKS" \ + "$AGENT_PUBLIC_KEY" "$ADMIN_PUBLIC_KEY" "$DEPLOY_PUBLIC_KEY" <<'GUEST_SCRIPT' +set -Eeuo pipefail +umask 077 + +agent_user="$1" +agent_uid="$2" +admin_user="$3" +admin_uid="$4" +deploy_user="$5" +deploy_uid="$6" +ssh_source_networks="$7" +agent_public_key="$8" +admin_public_key="$9" +deploy_public_key="${10}" + +log() { + printf '[ghostnet-litecoin-bootstrap/guest] %s\n' "$*" +} + +die() { + printf '[ghostnet-litecoin-bootstrap/guest] ERROR: %s\n' "$*" >&2 + exit 1 +} + +[[ "${EUID}" -eq 0 ]] || die "guest stage is not running as root" + +validate_existing_user() { + local user="$1" + local expected_uid="$2" + local actual_uid="" + local actual_gid="" + + getent passwd "$user" >/dev/null || die "baseline account ${user} is missing" + actual_uid="$(id -u "$user")" + actual_gid="$(id -g "$user")" + [[ "$actual_uid" == "$expected_uid" ]] || + die "${user} has UID ${actual_uid}; expected ${expected_uid}" + [[ "$actual_gid" == "$expected_uid" ]] || + die "${user} has GID ${actual_gid}; expected ${expected_uid}" +} + +validate_free_identity_slot() { + local user="$1" + local expected_uid="$2" + local owner_match="" + + if getent passwd "$user" >/dev/null; then + validate_existing_user "$user" "$expected_uid" + return + fi + + getent passwd "$expected_uid" >/dev/null && + die "UID ${expected_uid} is assigned to $(getent passwd "$expected_uid" | cut -d: -f1)" + getent group "$user" >/dev/null && die "group ${user} exists without its user" + getent group "$expected_uid" >/dev/null && + die "GID ${expected_uid} is assigned to $(getent group "$expected_uid" | cut -d: -f1)" + + owner_match="$(find / -xdev \( -uid "$expected_uid" -o -gid "$expected_uid" \) -print -quit 2>/dev/null || true)" + [[ -z "$owner_match" ]] || + die "UID/GID ${expected_uid} already owns guest path ${owner_match}" +} + +validate_existing_user "$agent_user" "$agent_uid" +validate_existing_user "$admin_user" "$admin_uid" +validate_free_identity_slot "$deploy_user" "$deploy_uid" + +if ! getent passwd "$deploy_user" >/dev/null; then + useradd \ + --uid "$deploy_uid" \ + --create-home \ + --shell /bin/bash \ + --user-group \ + "$deploy_user" + passwd --lock "$deploy_user" >/dev/null + log "created locked ${deploy_user} account with UID/GID ${deploy_uid}" +fi + +for user in "$agent_user" "$admin_user" "$deploy_user"; do + [[ "$(getent passwd "$user" | cut -d: -f6)" == "/home/${user}" ]] || + die "unexpected home directory for ${user}" + [[ "$(getent passwd "$user" | cut -d: -f7)" == "/bin/bash" ]] || + die "unexpected shell for ${user}" + [[ ! -L "/home/${user}" ]] || die "home for ${user} is a symlink" + [[ ! -L "/home/${user}/.ssh" ]] || die ".ssh for ${user} is a symlink" + [[ ! -L "/home/${user}/.ssh/authorized_keys" ]] || + die "authorized_keys for ${user} is a symlink" + install -d -o "$user" -g "$user" -m 700 "/home/${user}/.ssh" +done + +install_authorized_key() { + local user="$1" + local options="$2" + local public_key="$3" + local target="/home/${user}/.ssh/authorized_keys" + + install -o "$user" -g "$user" -m 600 /dev/null "$target" + printf '%s %s\n' "$options" "$public_key" >"$target" + chown "$user:$user" "$target" + chmod 600 "$target" + ssh-keygen -l -f "$target" >/dev/null +} + +install_authorized_key \ + "$agent_user" \ + "restrict,from=\"${ssh_source_networks}\"" \ + "$agent_public_key" +install_authorized_key \ + "$admin_user" \ + "from=\"${ssh_source_networks}\",no-agent-forwarding,no-port-forwarding,no-X11-forwarding,no-user-rc" \ + "$admin_public_key" +install_authorized_key \ + "$deploy_user" \ + "restrict,from=\"${ssh_source_networks}\"" \ + "$deploy_public_key" + +passwd --lock "$agent_user" >/dev/null +passwd --lock "$deploy_user" >/dev/null +usermod -aG sudo "$admin_user" + +agent_groups="$(id -Gn "$agent_user")" +deploy_groups="$(id -Gn "$deploy_user")" +[[ "$agent_groups" == "$agent_user" ]] || + die "${agent_user} has unexpected supplementary groups: ${agent_groups}" +[[ "$deploy_groups" == "$deploy_user" ]] || + die "${deploy_user} has unexpected supplementary groups: ${deploy_groups}" + +sudoers_target="/etc/sudoers.d/90-ghostnet-ansible-deploy" +install -o root -g root -m 440 /dev/null "$sudoers_target" +printf '%s ALL=(root) NOPASSWD: ALL\n' "$deploy_user" >"$sudoers_target" +chmod 440 "$sudoers_target" +visudo -cf "$sudoers_target" >/dev/null + +ssh_dropin="/etc/ssh/sshd_config.d/00-ghostnet-bootstrap.conf" +install -o root -g root -m 600 /dev/null "$ssh_dropin" +cat >"$ssh_dropin" </dev/null 2>&1; then + die "${agent_user} unexpectedly has non-interactive sudo" +fi + +agent_password_state="$(passwd -S "$agent_user" | awk '{print $2}')" +admin_password_state="$(passwd -S "$admin_user" | awk '{print $2}')" +deploy_password_state="$(passwd -S "$deploy_user" | awk '{print $2}')" +[[ "$agent_password_state" == "L" ]] || die "${agent_user} password is not locked" +[[ "$deploy_password_state" == "L" ]] || die "${deploy_user} password is not locked" +[[ "$admin_password_state" == "L" || "$admin_password_state" == "P" ]] || + die "${admin_user} has unsafe password state ${admin_password_state}" + +log "SSH host key: $(ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub)" +log "${agent_user}: $(id "$agent_user") / password ${agent_password_state}" +log "${admin_user}: $(id "$admin_user") / password ${admin_password_state}" +log "${deploy_user}: $(id "$deploy_user") / password ${deploy_password_state}" +log "access bootstrap verified; Ansible may connect after independent host-key validation" +GUEST_SCRIPT + +log "CT ${ctid} access bootstrap completed" +log "operator action: set the ${ADMIN_USER} sudo password interactively with 'pct exec ${ctid} -- passwd ${ADMIN_USER}'" +log "do not store that password in this hook, shell history, Ansible inventory, or Git" diff --git a/proxmox/lxc/ct-114-litecoin-wallet/scripts/provision-ct114-litecoin.sh b/proxmox/lxc/ct-114-litecoin-wallet/scripts/provision-ct114-litecoin.sh new file mode 100755 index 0000000..b08f510 --- /dev/null +++ b/proxmox/lxc/ct-114-litecoin-wallet/scripts/provision-ct114-litecoin.sh @@ -0,0 +1,203 @@ +#!/usr/bin/env bash + +set -Eeuo pipefail +umask 077 + +readonly CTID='114' +readonly HOSTNAME='ltc-node' +readonly IPV4_CIDR='10.0.0.61/24' +readonly GATEWAY='10.0.0.1' +readonly NAMESERVER='10.0.0.14' +readonly BRIDGE='vmbr0' +readonly TEMPLATE_STORAGE='local' +readonly CONTAINER_STORAGE='local-lvm' +readonly ROOT_DISK_GIB='150' +readonly POST_INSTALL_HOOK='/usr/local/sbin/ghostnet-litecoin-ansible-bootstrap-hook.sh' +readonly BASELINE_HOOK='/usr/local/sbin/ghostnet-lxc-baseline.sh' + +# Audited together on 2026-11-25. Pin both repositories because debian.sh +# loads its execution engine (core/build.func) from community-scripts/core. +readonly PROXMOXVE_COMMIT='c0c9d93d5db1692167efeee2e019f1519af4e0d2' +readonly CORE_COMMIT='d1cec87881d7de053d86434aaf98eb203170c1b9' +readonly DEBIAN_SCRIPT_SHA256='8396340fb3c91142ddf8356eb80904fad181acd6c6ad2c33b22ed4698c86187d' +readonly BASELINE_HOOK_SHA256='111f1b70e47e3a2f6a1bcce22cb0ec50aacd8fbcff37d87fbcf853a318381b10' +# SHA-256 of the hook BEFORE the ADMIN_PUBLIC_KEY placeholder is replaced. +# The operator replaces the placeholder with the generated ghost public key +# (scripts/README.md step 0), recomputes the SHA-256 and updates this pin. +readonly POST_INSTALL_HOOK_SHA256='a742377acdf41020559fe77b1e4313d112338a7221a89259255bbf03bfa359e3' + +readonly COMMUNITY_SCRIPTS_URL="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/${PROXMOXVE_COMMIT}" +readonly COMMUNITY_SCRIPTS_CORE_URL="https://raw.githubusercontent.com/community-scripts/core/${CORE_COMMIT}" +readonly DEBIAN_SCRIPT_URL="${COMMUNITY_SCRIPTS_URL}/ct/debian.sh" + +log() { + printf '[ghostnet-ct114-provision] %s\n' "$*" +} + +die() { + printf '[ghostnet-ct114-provision] ERROR: %s\n' "$*" >&2 + exit 1 +} + +require_command() { + command -v "$1" >/dev/null 2>&1 || die "required command not found: $1" +} + +require_file_sha256() { + local expected="$1" + local path="$2" + + [[ -f "$path" ]] || die "required file is missing: ${path}" + printf '%s %s\n' "$expected" "$path" | sha256sum --check --status - || + die "SHA-256 mismatch: ${path}" +} + +storage_is_active() { + local storage="$1" + pvesm status | awk -v storage="$storage" ' + $1 == storage && $3 == "active" { found = 1 } + END { exit(found ? 0 : 1) } + ' +} + +storage_has_free() { + local storage="$1" + local required_gib="$2" + pvesm status | awk -v storage="$storage" -v required="$required_gib" ' + $1 == storage && $3 == "active" { + avail_kib = $6 + if (avail_kib ~ /^[0-9]+$/) { + exit(avail_kib / 1048576 >= required ? 0 : 1) + } + exit 1 + } + END { exit 1 } + ' +} + +[[ "${EUID}" -eq 0 ]] || die 'must run as root on the Proxmox VE host' +for command_name in awk curl grep pct pvesm pveversion sha256sum; do + require_command "$command_name" +done + +pveversion >/dev/null 2>&1 || die 'this does not appear to be a Proxmox VE host' +[[ ! -e "/etc/pve/lxc/${CTID}.conf" ]] || + die "CT ${CTID} still exists; this script never replaces or destroys a container" +if pct status "$CTID" >/dev/null 2>&1; then + die "CT ${CTID} is still registered" +fi + +storage_is_active "$TEMPLATE_STORAGE" || + die "template storage ${TEMPLATE_STORAGE} is not active" +storage_is_active "$CONTAINER_STORAGE" || + die "container storage ${CONTAINER_STORAGE} is not active" +# The Litecoin chain needs roughly 100 GB plus growth; require headroom for +# the 150 GiB rootfs plus snapshots before creating anything. +storage_has_free "$CONTAINER_STORAGE" $((ROOT_DISK_GIB + 64)) || + die "container storage ${CONTAINER_STORAGE} has less than $((ROOT_DISK_GIB + 64)) GiB free" + +[[ -x "$BASELINE_HOOK" ]] || die "baseline hook is not executable: ${BASELINE_HOOK}" +[[ -x "$POST_INSTALL_HOOK" ]] || die "post-install hook is not executable: ${POST_INSTALL_HOOK}" +require_file_sha256 "$BASELINE_HOOK_SHA256" "$BASELINE_HOOK" +require_file_sha256 "$POST_INSTALL_HOOK_SHA256" "$POST_INSTALL_HOOK" + +helper_path="$(mktemp /tmp/ghostnet-debian-helper.XXXXXX.sh)" +cleanup() { + rm -f -- "$helper_path" +} +trap cleanup EXIT + +log "downloading pinned Debian helper ${PROXMOXVE_COMMIT}" +curl \ + --fail \ + --silent \ + --show-error \ + --location \ + --proto '=https' \ + --tlsv1.2 \ + --retry 3 \ + --retry-delay 1 \ + --output "$helper_path" \ + "$DEBIAN_SCRIPT_URL" +chmod 0700 "$helper_path" +require_file_sha256 "$DEBIAN_SCRIPT_SHA256" "$helper_path" + +# These are deliberately explicit even where they currently match upstream +# defaults. This keeps the recorded CT profile stable across future rebuilds. +# No nesting and no keyctl: litecoind runs as a plain systemd service under +# the litecoin user, no Podman is involved. +export COMMUNITY_SCRIPTS_URL COMMUNITY_SCRIPTS_CORE_URL +export mode='generated' +export var_cpu='2' +export var_ram='4096' +export var_disk="$ROOT_DISK_GIB" +export var_ctid="$CTID" +export var_hostname="$HOSTNAME" +export var_os='debian' +export var_version='13' +export var_unprivileged='1' +export var_brg="$BRIDGE" +export var_net="$IPV4_CIDR" +export var_gateway="$GATEWAY" +export var_ipv6_method='none' +export var_ns="$NAMESERVER" +export var_timezone='Europe/Berlin' +export var_container_storage="$CONTAINER_STORAGE" +export var_template_storage="$TEMPLATE_STORAGE" +export var_protection='yes' +export var_ssh='no' +export var_tags='container;litecoin;wallet;ansible' +export var_post_install="$POST_INSTALL_HOOK" + +log "creating CT ${CTID} with the pinned Community Scripts Debian helper" +bash "$helper_path" + +pct config "$CTID" >/dev/null 2>&1 || + die "helper returned without creating CT ${CTID}" + +# Community Scripts does not currently expose an LXC swap variable. +pct set "$CTID" --swap 1024 + +config="$(pct config "$CTID")" +grep -qx 'cores: 2' <<<"$config" || die 'unexpected CPU allocation' +grep -qx 'memory: 4096' <<<"$config" || die 'unexpected memory allocation' +grep -qx 'swap: 1024' <<<"$config" || die 'unexpected swap allocation' +grep -qx 'hostname: ltc-node' <<<"$config" || die 'unexpected hostname' +grep -qx 'nameserver: 10.0.0.14' <<<"$config" || die 'unexpected nameserver' +grep -qx 'onboot: 1' <<<"$config" || die 'onboot is not enabled' +grep -qx 'protection: 1' <<<"$config" || die 'container protection is not enabled' +grep -qx 'unprivileged: 1' <<<"$config" || die 'container is not unprivileged' +grep -qx 'timezone: Europe/Berlin' <<<"$config" || die 'unexpected timezone' +grep -Eq '^rootfs: local-lvm:.*,size=150G(,|$)' <<<"$config" || + die 'unexpected root filesystem allocation' +net0="$(grep '^net0: ' <<<"$config")" +for expected_net_field in \ + 'name=eth0' \ + 'bridge=vmbr0' \ + 'gw=10.0.0.1' \ + 'ip=10.0.0.61/24' \ + 'type=veth'; do + [[ "$net0" == *"$expected_net_field"* ]] || + die "net0 is missing ${expected_net_field}" +done + +[[ "$(pct status "$CTID")" == 'status: running' ]] || die "CT ${CTID} is not running" +hook_log="/var/log/community-scripts/post-install-${CTID}.log" +[[ -f "$hook_log" ]] || die "post-install hook log is missing: ${hook_log}" +grep -Fq "CT ${CTID} access bootstrap completed" "$hook_log" || + die "post-install hook did not report successful completion; inspect ${hook_log}" + +pct exec "$CTID" -- sh -eu -c ' + test "$(hostname --short)" = ltc-node + test "$(. /etc/os-release; printf %s "$ID")" = debian + test "$(. /etc/os-release; printf %s "$VERSION_ID")" = 13 + test "$(id -u ghost-agent)" = 1000 + test "$(id -u ghost)" = 1001 + test "$(id -u ansible-deploy)" = 1002 + test "$(runuser -u ansible-deploy -- sudo -n id -u)" = 0 + systemctl is-active --quiet ssh.service +' + +log "CT ${CTID} provisioning and access bootstrap verified" +log "review ${hook_log}, record the SSH host-key fingerprint, then set the ghost password interactively" +log "command: pct exec ${CTID} -- passwd ghost" diff --git a/proxmox/pve-host/README.md b/proxmox/pve-host/README.md index 89e012f..aa21df9 100644 --- a/proxmox/pve-host/README.md +++ b/proxmox/pve-host/README.md @@ -38,6 +38,15 @@ Aktuell verwaltete Host-State: `/root/.ssh/known_hosts` gepinnt. Log: `/var/log/ghostnet-lxc-backup-sync.log`. Eingerichtet am 10.11.2026 (GNAI-000 Abschnitt 4 Punkt 4; erster Lauf und Restore-Test bestanden). +- **Tägliche Snapshots für CT 114 (Litecoin Wallet)**: Rolle + `pve_lxc_snapshot` — Skript + `/usr/local/sbin/ghostnet-lxc-snapshot-ct114.sh` plus Timer + `ghostnet-lxc-snapshot-ct114.timer` (täglich 04:00) erzeugen + `pct snapshot 114 ghostnet-daily-` und prunen auf die 7 + neuesten Snapshots. CT 114 ist bewusst nicht Teil des vzdump-Backup-Jobs + (150 GiB Chain ist re-syncbar; `wallet.dat` wird clientseitig + verschlüsselt via restic aus dem CT heraus gesichert). Log: + `/var/log/ghostnet-lxc-snapshot-ct114.log` (GNAI-024 Abschnitt 9). Die CT-Lebenszyklus-Skripte (`proxmox/lxc//scripts/`: `pct create`, Dist-Upgrade) bleiben Bootstrap-Skripte und laufen einmalig manuell als diff --git a/proxmox/pve-host/ansible/playbooks/site.yml b/proxmox/pve-host/ansible/playbooks/site.yml index 535b723..ce30edb 100644 --- a/proxmox/pve-host/ansible/playbooks/site.yml +++ b/proxmox/pve-host/ansible/playbooks/site.yml @@ -9,3 +9,4 @@ - role: pve_media_cron - role: pve_nfs_export - role: pve_lxc_backup_sync + - role: pve_lxc_snapshot diff --git a/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/README.md b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/README.md new file mode 100644 index 0000000..7f0d7ce --- /dev/null +++ b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/README.md @@ -0,0 +1,12 @@ +# pve_lxc_snapshot + +Daily snapshot of CT 114 (Litecoin wallet LXC) on the PVE host, GNAI-024 +Abschnitt 9: `pct snapshot 114 ghostnet-daily-` every night at +04:00, retention of the newest 7 snapshots (`pct listsnapshot` / +`pct delsnapshot`), log at `/var/log/ghostnet-lxc-snapshot-ct114.log`. + +CT 114 is deliberately not part of the vzdump backup job: the 150 GiB chain +is re-syncable on restore, and `wallet.dat` is covered by the client-side +encrypted restic backups from inside the CT plus these snapshots. The +snapshots require snapshot-capable storage (`local-lvm` / ZFS), which the +provisioning script preflights. diff --git a/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/defaults/main.yml b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/defaults/main.yml new file mode 100644 index 0000000..93aa61c --- /dev/null +++ b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/defaults/main.yml @@ -0,0 +1,11 @@ +--- +# Daily LXC snapshots for CT 114 (Litecoin wallet node, GNAI-024 Abschnitt 9). +# CT 114 is deliberately excluded from the vzdump backup job (150 GiB chain is +# re-syncable; wallet.dat is covered by encrypted restic backups and these +# snapshots), so local-lvm snapshots are its container-level recovery layer. +pve_lxc_snapshot_ctid: 114 +pve_lxc_snapshot_name_prefix: ghostnet-daily +pve_lxc_snapshot_keep: 7 +pve_lxc_snapshot_script: /usr/local/sbin/ghostnet-lxc-snapshot-ct114.sh +pve_lxc_snapshot_log: /var/log/ghostnet-lxc-snapshot-ct114.log +pve_lxc_snapshot_timer_oncalendar: '*-*-* 04:00:00' diff --git a/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/handlers/main.yml b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/handlers/main.yml new file mode 100644 index 0000000..8f99013 --- /dev/null +++ b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/handlers/main.yml @@ -0,0 +1,4 @@ +--- +- name: Reload systemd daemon + ansible.builtin.systemd_service: + daemon_reload: true diff --git a/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/tasks/main.yml b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/tasks/main.yml new file mode 100644 index 0000000..8fa7c1a --- /dev/null +++ b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/tasks/main.yml @@ -0,0 +1,44 @@ +--- +- name: Install the CT 114 snapshot script + ansible.builtin.template: + src: ghostnet-lxc-snapshot-ct114.sh.j2 + dest: "{{ pve_lxc_snapshot_script }}" + owner: root + group: root + mode: "0750" + validate: /bin/bash -n %s + +- name: Install the CT 114 snapshot systemd service + ansible.builtin.template: + src: ghostnet-lxc-snapshot-ct114.service.j2 + dest: /etc/systemd/system/ghostnet-lxc-snapshot-ct114.service + owner: root + group: root + mode: "0644" + notify: Reload systemd daemon + +- name: Install the CT 114 snapshot systemd timer + ansible.builtin.template: + src: ghostnet-lxc-snapshot-ct114.timer.j2 + dest: /etc/systemd/system/ghostnet-lxc-snapshot-ct114.timer + owner: root + group: root + mode: "0644" + notify: Reload systemd daemon + +- name: Create the snapshot log file + ansible.builtin.file: + path: "{{ pve_lxc_snapshot_log }}" + state: touch + owner: root + group: root + mode: "0640" + modification_time: preserve + access_time: preserve + +- name: Enable and start the CT 114 snapshot timer + ansible.builtin.systemd_service: + name: ghostnet-lxc-snapshot-ct114.timer + enabled: true + state: started + daemon_reload: true diff --git a/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/templates/ghostnet-lxc-snapshot-ct114.service.j2 b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/templates/ghostnet-lxc-snapshot-ct114.service.j2 new file mode 100644 index 0000000..7649c4d --- /dev/null +++ b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/templates/ghostnet-lxc-snapshot-ct114.service.j2 @@ -0,0 +1,7 @@ +[Unit] +Description=Ghostnet daily snapshot of CT 114 (Litecoin wallet LXC) + +[Service] +Type=oneshot +ExecStart={{ pve_lxc_snapshot_script }} +# Runs as root: pct snapshot requires host root. diff --git a/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/templates/ghostnet-lxc-snapshot-ct114.sh.j2 b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/templates/ghostnet-lxc-snapshot-ct114.sh.j2 new file mode 100644 index 0000000..980740a --- /dev/null +++ b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/templates/ghostnet-lxc-snapshot-ct114.sh.j2 @@ -0,0 +1,31 @@ +#!/bin/bash +# {{ ansible_managed }} +# Daily snapshot of CT 114 with retention, installed by role pve_lxc_snapshot +# (GNAI-024 Abschnitt 9). Snapshots protect against container-level +# corruption; they do not replace the encrypted wallet backup. +set -euo pipefail + +CTID="{{ pve_lxc_snapshot_ctid }}" +PREFIX="{{ pve_lxc_snapshot_name_prefix }}" +KEEP="{{ pve_lxc_snapshot_keep }}" +LOG="{{ pve_lxc_snapshot_log }}" + +log() { echo "$(date -u +%FT%TZ) $*" >> "$LOG"; } + +pct config "$CTID" >/dev/null 2>&1 || { log "FAIL CT $CTID does not exist"; exit 1; } + +name="${PREFIX}-$(date +%Y%m%d-%H%M%S)" +pct snapshot "$CTID" "$name" --description "ghostnet daily snapshot (keep ${KEEP})" \ + || { log "FAIL pct snapshot $CTID $name"; exit 1; } +log "OK created snapshot $name for CT $CTID" + +# Retention: keep the newest KEEP snapshots of this prefix, delete older ones. +pct listsnapshot "$CTID" \ + | awk -v prefix="$PREFIX" '$1 == prefix || $1 ~ "^"prefix"-" { print $1 }' \ + | sort -r \ + | tail -n +"$((KEEP + 1))" \ + | while read -r old; do + pct delsnapshot "$CTID" "$old" && log "OK pruned snapshot $old" || log "FAIL prune $old" + done + +log "DONE CT $CTID snapshot run" diff --git a/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/templates/ghostnet-lxc-snapshot-ct114.timer.j2 b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/templates/ghostnet-lxc-snapshot-ct114.timer.j2 new file mode 100644 index 0000000..b3a5388 --- /dev/null +++ b/proxmox/pve-host/ansible/roles/pve_lxc_snapshot/templates/ghostnet-lxc-snapshot-ct114.timer.j2 @@ -0,0 +1,9 @@ +[Unit] +Description=Daily snapshot of CT 114 (Litecoin wallet LXC) + +[Timer] +OnCalendar={{ pve_lxc_snapshot_timer_oncalendar }} +Persistent=true + +[Install] +WantedBy=timers.target