commit 5d751b9cda8452f6f77abeefc0d8238bed119b12 Author: Ambrogio Date: Wed Feb 11 10:29:46 2026 +0000 Initial commit: PrivX HA Architecture & Setup Guides diff --git a/README.md b/README.md new file mode 100644 index 0000000..f62ebb8 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# PrivX Home Lab - Enterprise High Availability Setup + +Questo repository contiene la documentazione, le configurazioni e gli script per implementare un ambiente **SSH PrivX v42** in configurazione **High Availability (HA)**, replicando l'architettura Enterprise del **Polo Strategico Nazionale (PSN)**. + +## 🏛️ Architettura Target + +L'obiettivo è simulare un'infrastruttura critica resilient, distribuita su più nodi per garantire continuità operativa e scalabilità. + +### Componenti +* **Load Balancer (LB):** Entry point unico (VIP). Gestisce il traffico HTTPS verso i Core e i Web Proxy. Richiede *Sticky Sessions*. +* **PrivX Core (2 Nodi):** Il cuore della gestione accessi, policy e audit. In configurazione Active/Active. +* **PrivX Carrier + Web Proxy (2 Nodi):** Gestiscono le sessioni web isolate (browser-in-browser). Scalano orizzontalmente. +* **Database (PostgreSQL):** Backend centrale per configurazioni, log e sessioni. +* **Storage (NFS/S3):** Per la registrazione delle sessioni (audit trail). + +### Diagramma Logico + +```mermaid +graph TD + User((User)) -->|HTTPS/443| LB[Load Balancer HAProxy/Nginx] + + subgraph "PrivX Core Cluster" + LB -->|Sticky| Core1[PrivX Core 01] + LB -->|Sticky| Core2[PrivX Core 02] + end + + subgraph "PrivX Web Access Cluster" + LB -->|WSS/443| Web1[Carrier + Web Proxy 01] + LB -->|WSS/443| Web2[Carrier + Web Proxy 02] + end + + Core1 & Core2 -->|Persistenza| DB[(PostgreSQL 15)] + Web1 & Web2 -->|Config| Core1 & Core2 + Core1 & Core2 -->|Audit Logs| NAS[NFS Storage] +``` + +## 🛠️ Risorse Richieste (Proxmox) + +| Ruolo | Hostname | vCPU | RAM | Disk | OS | Note | +|-------|----------|------|-----|------|----|------| +| **Load Balancer** | `privx-lb` | 2 | 4GB | 20GB | Rocky 9 / Debian | Entry point SSL | +| **Core Node 1** | `privx-core-01` | 4 | 8GB | 50GB | Rocky Linux 9 | Master 1 | +| **Core Node 2** | `privx-core-02` | 4 | 8GB | 50GB | Rocky Linux 9 | Master 2 | +| **Web/Carrier 1** | `privx-web-01` | 4 | 16GB | 80GB | Rocky Linux 9 | Docker nested | +| **Web/Carrier 2** | `privx-web-02` | 4 | 16GB | 80GB | Rocky Linux 9 | Docker nested | +| **Database** | `privx-db` | 4 | 8GB | 100GB | Rocky Linux 9 | PostgreSQL 15 | + +**Totale Stimato:** ~22 vCPU, ~56GB RAM (Rientra nel budget del lab: 16 core fisici / 64GB RAM). + +## 🚀 Roadmap Implementazione + +1. **[Database]**: Setup PostgreSQL 15 con SSL e ottimizzazioni per audit log (`pg_trigram`). +2. **[Core]**: Installazione dei due nodi Core e configurazione Cluster via DB condiviso. +3. **[Load Balancer]**: Configurazione HAProxy/Nginx per sticky sessions e SSL termination. +4. **[Web/Carrier]**: Deployment dei container Docker per il browser isolation e link ai Core. +5. **[Hardening]**: Chiusura porte, firewalling interno (simil-PSN). + +--- +*Progetto basato su PrivX v42 Architecture & PSN Low Level Design.* diff --git a/core/setup-ha-nodes.md b/core/setup-ha-nodes.md new file mode 100644 index 0000000..03c00b8 --- /dev/null +++ b/core/setup-ha-nodes.md @@ -0,0 +1,146 @@ +# PrivX Core HA Setup - 2 Nodi (Rocky Linux 9) + +Questa guida descrive l'installazione di due server **PrivX Core** in configurazione Active-Active, connessi al DB centralizzato. + +**Hostname:** `privx-core-01`, `privx-core-02` +**Ruolo:** Gestione autenticazione, API, storage configurazioni. + +## 1. Prerequisiti su entrambi i nodi + +### 1.1 Configurazione OS (Rocky Linux 9) + +Assicurarsi che l'orario sia sincronizzato (Cruciale per i token TOTP/JWT): +```bash +sudo dnf install -y chrony +sudo systemctl enable --now chronyd +``` + +Disabilitare SELinux (Opzionale ma consigliato per evitare problemi iniziali nel lab, riabilitare poi): +```bash +sudo sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config +sudo setenforce 0 +``` + +### 1.2 Firewall (UFW/Firewalld) + +Aprire le porte necessarie per la comunicazione tra nodi Core e verso il DB: +* TCP 80/443 (HTTP/S per Load Balancer) +* TCP 5432 (PostgreSQL - Outbound) +* TCP 8888 (PrivX internal API - Inbound da altri nodi PrivX) + +```bash +sudo firewall-cmd --permanent --add-port=80/tcp +sudo firewall-cmd --permanent --add-port=443/tcp +sudo firewall-cmd --permanent --add-port=8888/tcp +sudo firewall-cmd --reload +``` + +## 2. Installazione PrivX (Nodo 01 - Master Iniziale) + +### 2.1 Aggiunta Repository PrivX +Scarica e installa la repo ufficiale SSH.com (richiede licenza o trial): + +```bash +sudo dnf config-manager --add-repo https://product-repository.ssh.com/rhel8/privx/privx.repo +# Nota: La repo RHEL8 funziona spesso anche su RHEL9, altrimenti cercare specifica RHEL9 se disponibile. +sudo dnf install -y privx +``` + +### 2.2 Configurazione Post-Install (Script interattivo) + +Lancia lo script di setup sul primo nodo. Questo popolerà il DB. + +```bash +sudo /opt/privx/scripts/postinstall.sh +``` + +Durante il setup, ti verranno chiesti i parametri del DB. Inserisci quelli creati nella guida `setup-postgresql.md`: +* **Database Host:** `privx-db` (o IP del DB) +* **Database User:** `privx` +* **Database Password:** `password_super_segreta...` +* **Database Name:** `privx` +* **SSL Mode:** `verify-full` (o `require` se hai certificati self-signed senza CA affidabile nel sistema). + +Lo script genererà anche i certificati interni per Nginx e i microservizi. + +## 3. Configurazione HA (Shared Config) + +Per far funzionare il cluster, entrambi i nodi devono condividere la **stessa chiave di cifratura** e puntare allo stesso DB. + +### 3.1 Backup Chiavi e Config dal Nodo 01 + +Copia i file critici dal Nodo 01 al Nodo 02 (via SCP sicuro): + +```bash +# Sul Nodo 01 +sudo tar czvf privx-ha-pack.tar.gz \ + /opt/privx/keyvault \ + /opt/privx/etc/shared-config.toml \ + /opt/privx/etc/privx-ca.crt \ + /opt/privx/etc/privx-ca.key +``` + +Trasferisci `privx-ha-pack.tar.gz` sul Nodo 02. + +## 4. Installazione PrivX (Nodo 02 - Replica) + +### 4.1 Installazione RPM + +Sul secondo nodo, installa solo i pacchetti senza lanciare `postinstall.sh` subito. + +```bash +sudo dnf config-manager --add-repo https://product-repository.ssh.com/rhel8/privx/privx.repo +sudo dnf install -y privx +``` + +### 4.2 Ripristino Configurazione HA + +Prima di avviare, sovrascrivi le config con quelle del Nodo 01: + +```bash +# Sul Nodo 02 +sudo systemctl stop privx || true +sudo tar xzvf privx-ha-pack.tar.gz -C / +sudo chown -R privx:privx /opt/privx +``` + +### 4.3 Registrazione Nodo + +Ora avvia PrivX sul secondo nodo. Se la configurazione DB in `shared-config.toml` è corretta, il nodo si collegherà al DB esistente e scaricherà le policy. + +```bash +sudo systemctl enable --now privx +sudo /opt/privx/scripts/init_node.sh # Se disponibile, per registrare il nodo nel cluster DB +``` + +## 5. Verifica Cluster + +Dal Nodo 01, controlla lo stato dei componenti: + +```bash +privx-status +# Dovresti vedere entrambi i nodi (hostname) listati nei log o nella dashboard "Settings > Deployment". +``` + +## 6. Configurazione Load Balancer (Nginx/HAProxy) + +Davanti ai due nodi Core devi mettere un LB. Esempio config Nginx (upstream): + +```nginx +upstream privx_core { + ip_hash; # Sticky session obbligatoria! + server privx-core-01:443; + server privx-core-02:443; +} + +server { + listen 443 ssl; + server_name privx-lb.tuodominio.local; + + location / { + proxy_pass https://privx_core; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + } +} +``` diff --git a/database/setup-postgresql.md b/database/setup-postgresql.md new file mode 100644 index 0000000..7fdfbf4 --- /dev/null +++ b/database/setup-postgresql.md @@ -0,0 +1,127 @@ +# Setup PostgreSQL per PrivX HA (Rocky Linux 9) + +Questa guida descrive l'installazione e la configurazione di un server PostgreSQL dedicato per un cluster PrivX in High Availability. + +**Target OS:** Rocky Linux 9 +**PostgreSQL Version:** 15 (Versione stabile raccomandata per PrivX v42) +**Ruolo:** Database Backend (Configurazioni, Sessioni, Audit Log) + +## 1. Installazione PostgreSQL 15 + +Disabilita il modulo standard (spesso versione vecchia) e installa la repo ufficiale PGDG: + +```bash +sudo dnf -qy module disable postgresql +sudo dnf install -y https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm +sudo dnf install -y postgresql15-server postgresql15-contrib +``` + +Inizializza il database: + +```bash +sudo /usr/pgsql-15/bin/postgresql-15-setup initdb +sudo systemctl enable --now postgresql-15 +``` + +## 2. Configurazione SSL (Obbligatorio per PrivX) + +PrivX **rifiuta** connessioni non criptate al DB core. Generiamo certificati self-signed per il lab (in produzione useresti una CA interna). + +```bash +# Diventa utente postgres +sudo su - postgres +cd /var/lib/pgsql/15/data + +# Genera chiave privata (senza passphr) e certificato valido 10 anni +openssl req -new -text -passout pass:abcd -subj /CN=privx-db -out server.req -keyout privkey.pem +openssl rsa -in privkey.pem -passin pass:abcd -out server.key +openssl req -x509 -in server.req -text -key server.key -out server.crt -days 3650 + +# Imposta permessi restrittivi (Postgres si rifiuta di partire se la chiave è leggibile da altri) +chmod 600 server.key +ls -l server.key +``` + +## 3. Configurazione `postgresql.conf` + +Modifica `/var/lib/pgsql/15/data/postgresql.conf`: + +```ini +# Ascolta su tutte le interfacce (o specifica l'IP del server DB) +listen_addresses = '*' + +# Abilita SSL +ssl = on +ssl_cert_file = 'server.crt' +ssl_key_file = 'server.key' + +# Ottimizzazioni per PrivX (Audit Log pesanti) +max_connections = 500 # PrivX apre molte connessioni (microservizi) +shared_buffers = 2GB # ~25% della RAM totale (assumendo 8GB RAM per la VM DB) +work_mem = 16MB # Aumenta per query complesse sugli audit +maintenance_work_mem = 512MB +effective_cache_size = 6GB # ~75% della RAM totale +logging_collector = on +log_directory = 'log' +``` + +## 4. Configurazione `pg_hba.conf` + +Modifica `/var/lib/pgsql/15/data/pg_hba.conf` per consentire l'accesso ai nodi PrivX **solo via SSL** e con password cifrate (SCRAM-SHA-256). + +```bash +# TYPE DATABASE USER ADDRESS METHOD +# Accesso locale +local all all peer + +# Accesso remoto dai Nodi PrivX (Core e Web Proxy) +# Sostituisci la subnet con quella del tuo lab (es. 192.168.1.0/24) +hostssl all all 192.168.1.0/24 scram-sha-256 +``` + +Riavvia il servizio: +```bash +exit # torna utente root +sudo systemctl restart postgresql-15 +``` + +## 5. Creazione Database e Utente PrivX + +PrivX richiede un DB vuoto e un utente con privilegi. Le estensioni verranno create dall'installer di PrivX, ma è buona norma pre-abilitarle o assicurarsi che l'utente abbia i diritti per farlo. + +Accedi alla shell psql: +```bash +sudo -u postgres psql +``` + +Esegui le query: + +```sql +-- Crea utente dedicato +CREATE USER privx WITH PASSWORD 'password_super_segreta_da_cambiare'; + +-- Crea database +CREATE DATABASE privx OWNER privx; + +-- Concedi privilegi (necessario per creare estensioni come pgcrypto) +GRANT ALL PRIVILEGES ON DATABASE privx TO privx; + +-- (Opzionale ma consigliato) Pre-abilita le estensioni richieste +\c privx +CREATE EXTENSION IF NOT EXISTS pgcrypto; +CREATE EXTENSION IF NOT EXISTS citext; +CREATE EXTENSION IF NOT EXISTS pg_trigram; -- Cruciale per la ricerca veloce negli audit log! + +-- Esci +\q +``` + +## 6. Verifica Connessione (Hardening Check) + +Da un altro nodo (o dalla stessa macchina se hai il client), prova a connetterti forzando SSL: + +```bash +psql "host=privx-db user=privx dbname=privx sslmode=require" +``` + +Se ricevi il prompt della password e entri, il DB è pronto per l'installer di PrivX. diff --git a/load-balancer/nginx.conf b/load-balancer/nginx.conf new file mode 100644 index 0000000..2a95159 --- /dev/null +++ b/load-balancer/nginx.conf @@ -0,0 +1,102 @@ +user nginx; +worker_processes auto; +error_log /var/log/nginx/error.log; +pid /run/nginx.pid; + +include /usr/share/nginx/modules/*.conf; + +events { + worker_connections 1024; +} + +http { + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + # Load modular configuration files from the /etc/nginx/conf.d directory. + # See http://nginx.org/en/docs/ngx_core_module.html#include + # for more information. + include /etc/nginx/conf.d/*.conf; + + # ========================================================================= + # PrivX HA Load Balancer Configuration + # ========================================================================= + + # 1. PrivX Core Cluster (API & GUI) + # Sticky Sessions (ip_hash) are MANDATORY for OAuth flow and user sessions. + upstream privx_core_cluster { + ip_hash; + server 192.168.1.51:443; # Core Node 01 + server 192.168.1.52:443; # Core Node 02 + } + + # 2. PrivX Web Access Cluster (Carrier + Web Proxy) + # WebSocket support is critical here. Sticky sessions required for browser consistency. + upstream privx_web_cluster { + ip_hash; + server 192.168.1.61:443; # Web Proxy Node 01 + server 192.168.1.62:443; # Web Proxy Node 02 + } + + server { + listen 443 ssl http2; + server_name privx.tuodominio.local; + + # SSL Termination (Self-Signed or CA) + ssl_certificate "/etc/nginx/ssl/privx-lb.crt"; + ssl_certificate_key "/etc/nginx/ssl/privx-lb.key"; + ssl_session_cache shared:SSL:1m; + ssl_session_timeout 10m; + ssl_ciphers PROFILE=SYSTEM; + ssl_prefer_server_ciphers on; + + # --- Location: Core API & GUI --- + location / { + proxy_pass https://privx_core_cluster; + + # Forward headers required by PrivX + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + # Timeout tuning for long running API calls + proxy_read_timeout 90; + } + + # --- Location: Web Access (Browser-in-Browser) --- + # Routes WSS traffic specifically to the Web Proxy nodes + location /ws { + proxy_pass https://privx_web_cluster; + + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + + # Increase timeouts for long SSH/RDP sessions + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + } + + error_page 404 /404.html; + location = /40x.html { + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + } + } +} diff --git a/web-access/setup-web-proxy-ha.md b/web-access/setup-web-proxy-ha.md new file mode 100644 index 0000000..e2aee88 --- /dev/null +++ b/web-access/setup-web-proxy-ha.md @@ -0,0 +1,137 @@ +# Setup PrivX Web Access HA (Carrier + Web Proxy) - 2 Nodi + +Questa guida copre l'installazione dei componenti per l'accesso Web (RDP/SSH via browser) in alta affidabilità. +Replichiamo l'architettura Enterprise con **2 Carrier** e **2 Web Proxy**. + +**Hostname:** `privx-web-01`, `privx-web-02` +**Ruolo:** Gestione sessioni browser isolate (Docker-in-Docker) e proxy WSS. + +## 1. Architettura Logica + +* **Web Proxy:** Gestisce il traffico WebSocket sicuro (WSS) tra il browser dell'utente e il Carrier. +* **Carrier:** Esegue container Docker effimeri (Firefox) che renderizzano la sessione remota. +* **Relazione:** Ogni Web Proxy deve avere un Carrier associato (spesso sulla stessa macchina per latenza zero). + +Nel nostro lab, installeremo entrambi i ruoli su ciascuno dei 2 nodi dedicati (`privx-web-01`, `privx-web-02`). + +## 2. Prerequisiti (Rocky Linux 9) + +Queste macchine richiedono **più RAM** (min 8GB, meglio 16GB) perché eseguono browser pesanti per ogni utente connesso. + +### 2.1 Installazione Docker (Podman non supportato ufficialmente per Carrier) + +PrivX Carrier usa Docker per spawnare i browser. + +```bash +sudo dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo +sudo dnf install -y docker-ce docker-ce-cli containerd.io +sudo systemctl enable --now docker +sudo usermod -aG docker privx-carrier # (Dopo installazione pacchetto) +``` + +### 2.2 Repository PrivX + +Aggiungi la repo come per i Core: + +```bash +sudo dnf config-manager --add-repo https://product-repository.ssh.com/rhel8/privx/privx.repo +``` + +## 3. Installazione Componenti + +Su entrambi i nodi (`privx-web-01` e `privx-web-02`), installa i pacchetti specifici: + +```bash +sudo dnf install -y privx-carrier privx-web-proxy +``` + +## 4. Configurazione Nodo 01 (Master Web) + +### 4.1 Registrazione al Core + +Il Web Proxy deve autenticarsi con il Core. Genera un token di pairing sul Core (`privx-core-01`): + +```bash +# SUL NODO CORE +sudo /opt/privx/scripts/generate_token.sh --ttl 3600 --type extender +# Copia il token generato. +``` + +Ora configura il Web Proxy sul Nodo 01: + +```bash +# SUL NODO WEB 01 +sudo /opt/privx/scripts/postinstall-web-proxy.sh +# Inserisci: +# - Core URL: https://privx-lb.tuodominio.local (o IP Core 01 per test) +# - Pairing Token: +``` + +### 4.2 Configurazione Carrier + +Il Carrier deve sapere dove trovare il Web Proxy (localhost) e scaricare l'immagine Docker del browser. + +```bash +sudo /opt/privx/scripts/postinstall-carrier.sh +# L'installer scaricherà l'immagine Docker ufficiale di PrivX Browser. +# Verifica che Docker sia attivo! +``` + +## 5. Configurazione Nodo 02 (Replica HA) + +Ripeti ESATTAMENTE gli stessi passaggi sul Nodo 02 (`privx-web-02`). +Usa un **nuovo token** generato dal Core (i token sono monouso). + +### 5.1 Verifica HA + +In PrivX GUI (Settings > Deployment > Status), dovresti vedere: +* 2 Web Proxies Online +* 2 Carriers Online + +Se un nodo cade, il Load Balancer (vedi sotto) sposterà le nuove sessioni sull'altro. Le sessioni attive sul nodo caduto verranno perse (comportamento standard, non c'è live migration delle sessioni browser). + +## 6. Configurazione Load Balancer per Web Access + +Il traffico Web Access usa WebSocket (WSS). Il Load Balancer deve supportarlo. + +Aggiungi al file di config del LB (es. Nginx): + +```nginx +upstream privx_web { + ip_hash; # Sticky session CRUCIALE anche qui + server privx-web-01:443; + server privx-web-02:443; +} + +server { + listen 443 ssl; + server_name privx-web.tuodominio.local; + + location /ws { + proxy_pass https://privx_web; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "Upgrade"; + proxy_set_header Host $host; + } +} +``` + +## 7. Tuning Performance (Carrier) + +Poiché girano browser, questi nodi consumano CPU/RAM. +Modifica `/opt/privx/etc/carrier-config.toml`: + +```toml +[carrier] +# Limita il numero max di sessioni per nodo per non crashare +max_sessions = 50 + +# Pulisci container orfani ogni ora +cleanup_interval = 3600 +``` + +Riavvia i servizi dopo le modifiche: +```bash +sudo systemctl restart privx-carrier privx-web-proxy +```