03_ARCHITECTURE_DIAGRAMMES.md 11 KB

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)