|
|
1 주 전 | |
|---|---|---|
| dest | 1 주 전 | |
| doc | 1 주 전 | |
| gateway | 1 주 전 | |
| .gitignore | 1 주 전 | |
| .gitlab-ci.yml | 1 주 전 | |
| FINAL_CHANGES.md | 1 주 전 | |
| README.md | 1 주 전 | |
| STRUCTURE.md | 1 주 전 | |
| docker-compose.yaml | 1 주 전 | |
| init-keys.ps1 | 1 주 전 |
De Debian vierge à proxy SSH transparent en 30 minutes
# 1. Générer les clés SSH (créées localement, jamais commitées)
.\init-keys.ps1
# 2. Vérifier que le répertoire keys/ est créé
ls keys/
# lab_rsa, lab_rsa.pub, gateway_rsa, gateway_rsa.pub
# 3. Lancer le lab
docker compose up -d
# 4. Tester
ssh -p 2222 -i keys/lab_rsa testuser@localhost 'hostname'
# Résultat: dest1 ou dest2 ✓
⚠️ Important:
keys/ entier est ignoré par .gitignore — jamais commitéinit-keys.ps1À chaque docker compose down/up, supprimer l'entrée host:
ssh-keygen -f ~/.ssh/known_hosts -R "[localhost]:2222"
→ Voir: doc/SETUP_INITIAL.md pour plus de détails
Créer une gateway SSH transparente qui:
# 1. Lancer
docker compose up -d
# 2. Tester commande
ssh -p 2222 -i keys/lab_rsa testuser@localhost 'hostname'
# Affiche: dest1 ou dest2 (aléatoire) ✓
# 3. Shell interactif
ssh -p 2222 -i keys/lab_rsa testuser@localhost
# testuser@dest1:~$ (ou dest2)
# 4. Arrêter
docker compose down
# 5. Relancer (après avoir nettoyé known_hosts)
ssh-keygen -f ~/.ssh/known_hosts -R "[localhost]:2222"
docker compose up -d
Vous êtes nouveau? → doc/SETUP_INITIAL.md (5 min) ⭐⭐⭐
Vous avez 5 minutes? → doc/01_DEMARRAGE_RAPIDE.md
Vous avez 20 minutes? → doc/02_ARCHITECTURE_VUE_ENSEMBLE.md
Vous voulez des diagrammes? → doc/03_ARCHITECTURE_DIAGRAMMES.md
Vous trouvez ça compliqué? → doc/04_CONCEPT_EXPLIQUE_SIMPLEMENT.md
Vous maîtrisez déjà? → doc/05_DETAILS_TECHNIQUES_COMPLETS.md
Vous débogguez? → doc/06_DEBUG_ET_SOLUTIONS.md
Redémarrage/down-up? → doc/REDEMARRAGE_QUICK_REFERENCE.md
Voir tout l'index: → doc/INDEX.md
sshproxy-lab/
├── README.md ← Vous êtes ici
├── STRUCTURE.md ← Visualisation du projet
├── .gitignore ← Protège keys/ (jamais commité)
├── init-keys.ps1 ← 🔑 À lancer UNE FOIS avant de démarrer
├── docker-compose.yaml ← Orchestration
├── doc/ ← 📚 Documentation (16 fichiers)
│ ├── INDEX.md ← Navigation principale
│ ├── SETUP_INITIAL.md ← ⭐ Clés SSH et setup
│ ├── REDEMARRAGE_QUICK_REFERENCE.md ← Down/up guide
│ ├── 01_DEMARRAGE_RAPIDE.md
│ ├── 02_ARCHITECTURE_VUE_ENSEMBLE.md
│ └── ...et 10 autres fichiers
├── gateway/ ← Configuration gateway
│ ├── Dockerfile
│ ├── sshd_config (ForceCommand crucial!)
│ ├── sshproxy.yaml (-tt crucial!)
│ └── sshproxy-wrapper.sh
├── dest/ ← Configuration destinations
│ ├── Dockerfile
│ └── sshd_config
└── keys/ ← SSH keys (générées par init-keys.ps1)
└── README.md ← Explication du workflow
(Contenu jamais commité dans GitLab - .gitignore)
.\init-keys.ps1
Crée le répertoire keys/ et génère les 2 paires de clés SSH localement uniquement
keys/ ← Tout le dossier est ignoré - jamais commité
ForceCommand /usr/sbin/sshproxy-wrapper
↑ TOUTE connexion SSH est interceptée et proxifiée
args: ["-tt", ...]
↑ Alloue PTY sur destination → shell interactif possible
Layer 1: lab_rsa (Windows → Gateway - généré localement)
Layer 2: gateway_rsa (Gateway → Destinations - généré localement)
# Commande simple
ssh -p 2222 testuser@localhost 'hostname'
# Shell interactif
echo "hostname" | ssh -p 2222 testuser@localhost
# Vérifier round-robin (5 fois)
for i in {1..5}; do ssh -p 2222 testuser@localhost hostname; done
# Voir les logs sshproxy
docker exec sshproxy-gateway tail -f /tmp/sshproxy-testuser.log
# Arrêter
docker compose down -v
# Relancer (nettoyer known_hosts d'abord!)
ssh-keygen -f ~/.ssh/known_hosts -R "[localhost]:2222"
docker compose up -d
Step 1: ssh -p 2222 -i lab_rsa testuser@localhost
Step 2: Gateway sshd accept (vérifie lab_rsa.pub)
Step 3: Exécute ForceCommand: /usr/sbin/sshproxy-wrapper
Step 4: Wrapper lance: /usr/sbin/sshproxy
Step 5: sshproxy choisit random: dest1 ou dest2
Step 6: sshproxy exécute: ssh -tt -i gateway_rsa testuser@DEST
Step 7: Destination sshd accept (vérifie gateway_rsa.pub)
Step 8: Résultat retourné à Windows
Vous avez l'impression de faire ssh dest1 'cmd' alors que vous faites vraiment ssh gateway 'cmd' qui se redirige tout seul.
.gitignore ignore keys/ entièrementchown testuser /etc/sshproxy/gateway_rsa-tt flag dans sshproxy.yamlssh-keygen -f ~/.ssh/known_hosts -R "[localhost]:2222"┌─ Windows ─────────────────────────────────────────┐
│ ssh -p 2222 -i lab_rsa testuser@localhost │
└────────────────────┬────────────────────────────────┘
│ Port 2222
↓
┌──────────────────────────┐
│ Gateway (172.30.0.10) │
│ ┌────────────────────┐ │
│ │ SSH Daemon (sshd) │ │
│ ├────────────────────┤ │
│ │ ForceCommand │ │
│ │ ↓ │ │
│ │ sshproxy-wrapper │ │
│ │ ↓ │ │
│ │ sshproxy │ │
│ │ (random select) │ │
│ └────────────────────┘ │
└────────┬──────────────────┘
┌───────┴────────┐
↓ 50% ↓ 50%
dest1 (172.30.0.11) dest2 (172.30.0.12)
Shell normal Shell normal
✅ Fonctionne:
ssh gateway 'ls -la'
ssh gateway 'for i in 1..3; do date; done'
ssh gateway # Shell interactif
❌ Ne fonctionne pas (intentionnel):
ssh gateway -L 3306:dest:3306 # Port forwarding disabled
ssh gateway -X # X11 forwarding disabled
Modifier gateway/sshproxy.yaml:
dest:
- "172.30.0.11:22"
- "172.30.0.12:22"
- "172.30.0.13:22" # ← Ajouter ici
route_select: "round_robin" # Au lieu de "random"
Modifier gateway/sshproxy-wrapper.sh:
echo "$(date): $USER executed $SSH_ORIGINAL_COMMAND" >> /var/log/audit.log
exec /usr/sbin/sshproxy
Besoin d'aide?
Commencez par:
docker compose up -d