# Quick Reference β€” Architecture du proxy SSH transparent ## πŸ“ Architecture Visuelle ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ WINDOWS CLIENT (ssh -p 2222 -i lab_rsa testuser@localhost) β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ Port 2222 (remappΓ© vers 172.30.0.10:22) β”‚ ClΓ©: lab_rsa ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ GATEWAY (172.30.0.10:22) β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ SSH Daemon (sshd) β”‚ β”‚ β”‚ β”‚ - Accepte clΓ© lab_rsa.pub β”‚ β”‚ β”‚ β”‚ - ExΓ©cute: ForceCommand /usr/sbin/sshproxy-wrapper β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ sshproxy-wrapper.sh β”‚ β”‚ β”‚ β”‚ - DΓ©tecte commande vs shell β”‚ β”‚ β”‚ β”‚ - Lance: /usr/sbin/sshproxy β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ β”‚ sshproxy (daemon compilΓ© en Go) β”‚ β”‚ β”‚ β”‚ - Lit config: sshproxy.yaml β”‚ β”‚ β”‚ β”‚ - Choisit destination: random(dest1, dest2) β”‚ β”‚ β”‚ β”‚ - ExΓ©cute rebond SSH avec clΓ© gateway_rsa β”‚ β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ random() β”‚ ↓ 50% ↓ 50% β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ DEST1 β”‚ β”‚ DEST2 β”‚ β”‚ 172.30.0.11:22 β”‚ β”‚ 172.30.0.12:22 β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ SSH Daemon β”‚ β”‚ SSH Daemon β”‚ β”‚ - Accepte β”‚ β”‚ - Accepte β”‚ β”‚ gateway_rsa.pub β”‚ β”‚ gateway_rsa.pub β”‚ β”‚ - Shell normal β”‚ β”‚ - Shell normal β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` --- ## πŸ”‘ Authentification Γ  2 niveaux ``` AUTHENTIFICATION NIVEAU 1: Windows β†’ Gateway β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Client Windows β”‚ β”‚ ClΓ© privΓ©e: lab_rsa β”‚ β”‚ ClΓ© publique: lab_rsa.pub β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ ↓ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Gateway /home/testuser/.ssh/ β”‚ β”‚ authorized_keys (contient) β”‚ β”‚ β†’ lab_rsa.pub β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ βœ“ Connexion Windowsβ†’Gateway autorisΓ©e AUTHENTIFICATION NIVEAU 2: Gateway β†’ Destinations β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Gateway /etc/sshproxy/ β”‚ β”‚ ClΓ© privΓ©e: gateway_rsa β”‚ β”‚ ClΓ© publique: gateway_rsa.pub β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ ↓ (utilisΓ©e par sshproxy) β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Dest1/Dest2 /home/testuser/.ssh/β”‚ β”‚ authorized_keys (contient) β”‚ β”‚ β†’ gateway_rsa.pub β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ βœ“ Connexion Gatewayβ†’Destinations autorisΓ©e ``` --- ## πŸ“ Fichiers clΓ©s et leurs rΓ΄les ### INFRASTRUCTURE - **docker-compose.yaml**: DΓ©finit 3 conteneurs + rΓ©seau privΓ© ### GATEWAY - **gateway/Dockerfile**: - Build sshproxy v2.1.0 en Go - Installe sshd - Configure comptes + permissions - **gateway/sshd_config**: - **ForceCommand /usr/sbin/sshproxy-wrapper** ← ClΓ©! - Auth par clΓ© uniquement - **gateway/sshproxy.yaml**: - Destinations: 172.30.0.11, 172.30.0.12 - Selection: random - SSH args: **-tt** (PTY) crucial - **gateway/sshproxy-wrapper.sh**: - DΓ©tecte shell interactif vs commande - ExΓ©cute sshproxy dans les deux cas ### DESTINATIONS - **dest/Dockerfile**: - Installe sshd uniquement - Pas de sshproxy (pas besoin) - **dest/sshd_config**: - SSH normal (pas de ForceCommand) - Auth par clΓ© (gateway_rsa.pub) ### AUTHENTIFICATION - **keys/lab_rsa**: PrivΓ©e Windows (utilisateur garde secret) - **keys/lab_rsa.pub**: Publique β†’ authorized_keys gateway - **keys/gateway_rsa**: PrivΓ©e gateway (compilΓ©e dans image) - **keys/gateway_rsa.pub**: Publique β†’ authorized_keys dest1/dest2 --- ## πŸ”„ Processus d'une connexion ``` CLIENT WINDOWS β”‚ β”œβ”€ ssh -p 2222 -i lab_rsa testuser@localhost 'hostname' β”‚ (ou sans 'hostname' pour shell interactif) β”‚ └─→ GATEWAY sshd (port 2222) β”‚ β”œβ”€ VΓ©rifie: lab_rsa.pub en authorized_keys? βœ“ β”œβ”€ Lance: /usr/sbin/sshproxy-wrapper β”‚ └─→ SSHPROXY-WRAPPER β”‚ β”œβ”€ DΓ©tecte: $SSH_ORIGINAL_COMMAND fournie? β”‚ (oui/non, peu importe β†’ fait pareil) β”‚ └─→ /usr/sbin/sshproxy (daemon Go) β”‚ β”œβ”€ Lit: /etc/sshproxy/sshproxy.yaml β”œβ”€ Choisit: random β†’ 172.30.0.11 ou 172.30.0.12 β”‚ └─→ ExΓ©cute: ssh -tt -i /etc/sshproxy/gateway_rsa testuser@DESTINATION 'hostname' β”‚ β”œβ”€ VΓ©rifie: gateway_rsa en authorized_keys? βœ“ β”‚ └─→ DESTINATION sshd (normal) β”‚ └─ ExΓ©cute: 'hostname' Retourne rΓ©sultat Γ  client ``` --- ## βš™οΈ Configuration minimale requise ### ClΓ©s SSH (prΓ©-gΓ©nΓ©rΓ©es) ```bash # GΓ©nΓ©rer si manquantes: ssh-keygen -t ed25519 -f keys/lab_rsa -N "" # Windowsβ†’Gateway ssh-keygen -t ed25519 -f keys/gateway_rsa -N "" # Gatewayβ†’Dest ``` ### Structure minimale ``` . β”œβ”€β”€ docker-compose.yaml β”œβ”€β”€ keys/ β”‚ β”œβ”€β”€ lab_rsa # ← Windows garde privΓ© β”‚ β”œβ”€β”€ lab_rsa.pub # ← CopiΓ© dans gateway β”‚ β”œβ”€β”€ gateway_rsa # ← Compilation dans image β”‚ └── gateway_rsa.pub # ← CopiΓ© dans destinations β”œβ”€β”€ gateway/ β”‚ β”œβ”€β”€ Dockerfile β”‚ β”œβ”€β”€ sshd_config # ← ForceCommand crucial β”‚ β”œβ”€β”€ sshproxy.yaml # ← -tt crucial β”‚ └── sshproxy-wrapper.sh └── dest/ β”œβ”€β”€ Dockerfile └── sshd_config ``` --- ## πŸš€ Commandes de test ```bash # Lancer l'infrastructure docker compose up -d # Test 1: Commande simple ssh -p 2222 -i keys/lab_rsa testuser@localhost 'hostname' # RΓ©sultat: dest1 ou dest2 (random) # Test 2: Commande avec sortie ssh -p 2222 -i keys/lab_rsa testuser@localhost 'whoami; pwd; id' # RΓ©sultat: testuser, /home/testuser, uid=1000... # Test 3: Shell interactif (piped) echo "hostname" | ssh -p 2222 -i keys/lab_rsa testuser@localhost # RΓ©sultat: testuser@dest1:~$ hostname ↡ dest1 # Test 4: VΓ©rifier round-robin for i in {1..5}; do ssh -p 2222 -i keys/lab_rsa testuser@localhost hostname; done # RΓ©sultat: dest2, dest1, dest2, dest1, dest2 (alternance alΓ©atoire) # Test 5: Voir les logs sshproxy docker exec sshproxy-gateway tail -f /tmp/sshproxy-testuser.log # VΓ©rifier structure rΓ©seau docker network inspect sshproxy_net # ArrΓͺter docker compose down -v ``` --- ## 🎯 Ce qui rend le proxy transparent | Γ‰lΓ©ment | Raison | |---------|--------| | **ForceCommand** | Intercepte SSH β†’ proxifie | | **sshproxy wrapper** | GΓ¨re shell et commandes uniformΓ©ment | | **-tt flag** | PTY allocation pour interactivitΓ© | | **gateway_rsa** | IdentitΓ© gateway pour rebond auto | | **Random route_select** | RΓ©partition charge automatique | | **IPs Docker fixes** | Destinations prΓ©visibles pour sshproxy | --- ## πŸ” Cas d'usage ### βœ… Fonctionne ```bash ssh gateway 'ls -la' # Commandes ssh gateway 'for i in 1..3; do date; done' # Scripts ssh gateway # Shell interactif ssh gateway 'bash' # Lancer shell explicite ``` ### ❌ Ne fonctionne pas (intentionnel) ```bash ssh gateway -L 3306:dest:3306 # Port forwarding (AllowTcpForwarding no) ssh gateway -X # X11 forwarding (X11Forwarding no) ``` --- ## πŸ“Š Statistiques architecture - **Gateway**: 1 conteneur (proxy + orchestration) - **Destinations**: 2 conteneurs (SSH normal) - **RΓ©seau**: Bridge Docker privΓ© (172.30.0.0/24) - **Port exposΓ©**: 2222 (remappΓ© vers port 22 gateway) - **Auth**: 2 niveaux (clientβ†’gateway + gatewayβ†’dest) - **SΓ©lection**: Random (50/50 dest1 vs dest2)