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)
# 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
# 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
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)
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)