feat(lab-02): complete Phase 3 - Network & VPC lab
Implement Lab 02 with Docker bridge networks simulating VPC/Subnets. Test Infrastructure (RED phase): - 6 bash test scripts for network creation, isolation, INF-02 compliance - Fail-fast orchestration with run-all-tests.sh - Quick validation script for development Documentation (Diátaxis framework): - 3 tutorials: VPC creation, container deployment, isolation verification - 4 how-to guides: create network, inspect config, test isolation, cleanup - 3 reference docs: Docker network commands, Compose syntax, VPC mapping - 1 explanation: Docker ↔ VPC parallels (PARA-01/02/03/04) Infrastructure (GREEN phase): - docker-compose.yml with VPC networks (10.0.1.0/24, 10.0.2.0/24) - 5 services: web, app, db, test-public, test-private - INF-02 compliant: 127.0.0.1 bindings only, no 0.0.0.0 - Private network with --internal flag - Multi-homed app container (public + private networks) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
292
labs/lab-02-network/tutorial/03-verify-network-isolation.md
Normal file
292
labs/lab-02-network/tutorial/03-verify-network-isolation.md
Normal file
@@ -0,0 +1,292 @@
|
||||
# Tutorial: Verificare l'Isolamento delle Reti VPC
|
||||
|
||||
In questo tutorial imparerai a verificare e testare l'isolamento tra le reti Docker bridge, confermando che la tua architettura VPC multi-tier funziona correttamente.
|
||||
|
||||
## Obiettivo
|
||||
|
||||
Verificare che:
|
||||
- I container nella stessa rete possono comunicare
|
||||
- I container in reti diverse NON possono comunicare (isolamento)
|
||||
- Il DNS funziona entro la stessa rete
|
||||
- I container multi-homed possono raggiungere entrambe le reti
|
||||
|
||||
## Prerequisiti
|
||||
|
||||
- Completati [Tutorial 1](./01-create-vpc-networks.md) e [Tutorial 2](./02-deploy-containers-networks.md)
|
||||
- Container in esecuzione: `docker compose ps` mostra 3 container attivi
|
||||
|
||||
---
|
||||
|
||||
## Passo 1: Verificare i Container in Esecuzione
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
cd ~/laboratori-cloud/labs/lab-02-network
|
||||
docker compose ps
|
||||
```
|
||||
|
||||
Assicurati che lab02-web, lab02-app, e lab02-db siano "Up".
|
||||
|
||||
Se non lo sono:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Passo 2: Test Comunicazione Stessa Rete
|
||||
|
||||
I container nella stessa rete devono potersi comunicare.
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
# Verifica: app puo raggiungere web (stessa rete pubblica)
|
||||
docker exec lab02-app ping -c 2 lab02-web
|
||||
```
|
||||
|
||||
Atteso:
|
||||
```
|
||||
PING lab02-web (10.0.1.10): 56 data bytes
|
||||
64 bytes from 10.0.1.10: seq=0 ttl=64 time=0.123 ms
|
||||
64 bytes from 10.0.1.10: seq=1 ttl=64 time=0.045 ms
|
||||
--- lab02-web ping statistics ---
|
||||
2 packets transmitted, 2 packets received, 0% packet loss
|
||||
```
|
||||
|
||||
**SUCCESS** = Comunicazione funziona nella stessa rete.
|
||||
|
||||
---
|
||||
|
||||
## Passo 3: Test Comunicazione Cross-Rete (DEVE FALLIRE)
|
||||
|
||||
Verifica che l'isolamento funzioni.
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
# Verifica: web NON puo raggiungere db (reti diverse)
|
||||
docker exec lab02-web ping -c 2 lab02-db
|
||||
```
|
||||
|
||||
Atteso:
|
||||
```
|
||||
ping: bad address 'lab02-db'
|
||||
```
|
||||
|
||||
Oppure:
|
||||
```
|
||||
PING lab02-db (10.0.2.10): 56 data bytes
|
||||
--- lab02-db ping statistics ---
|
||||
2 packets transmitted, 0 packets received, 100% packet loss
|
||||
```
|
||||
|
||||
**FALLIMENTO ATTESO** = Isolamento funzionante!
|
||||
|
||||
Questo e corretto: `lab02-web` (10.0.1.10) non puo raggiungere `lab02-db` (10.0.2.10) perche sono in reti diverse.
|
||||
|
||||
---
|
||||
|
||||
## Passo 4: Test Container Multi-Homed
|
||||
|
||||
Il container `lab02-app` e connesso a entrambe le reti.
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
# Verifica: app puo raggiungere web (stessa rete pubblica)
|
||||
docker exec lab02-app ping -c 2 lab02-web
|
||||
```
|
||||
|
||||
Atteso: SUCCESSO
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
# Verifica: app puo raggiungere db (stessa rete privata)
|
||||
docker exec lab02-app ping -c 2 lab02-db
|
||||
```
|
||||
|
||||
Atteso: SUCCESSO
|
||||
|
||||
Questo dimostra che `lab02-app` puo fungere da ponte tra le reti.
|
||||
|
||||
---
|
||||
|
||||
## Passo 5: Test DNS Resolution
|
||||
|
||||
Verifica che il DNS funzioni entro la stessa rete.
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
# Test DNS nella stessa rete
|
||||
docker exec lab02-app nslookup lab02-web
|
||||
```
|
||||
|
||||
Atteso:
|
||||
```
|
||||
Name: lab02-web
|
||||
Address 1: 10.0.1.10
|
||||
```
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
# Test DNS cross-rete (dovrebbe fallire)
|
||||
docker exec lab02-web nslookup lab02-db
|
||||
```
|
||||
|
||||
Atteso: Fallisce o restituisce errore
|
||||
|
||||
---
|
||||
|
||||
## Passo 6: Test Accesso da Host
|
||||
|
||||
Verifica INF-02 compliance: servizi privati non accessibili dall'host.
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
# Test accesso web (pubblico, ma solo localhost)
|
||||
curl http://127.0.0.1:8080
|
||||
```
|
||||
|
||||
Atteso: SUCCESSO (HTML response)
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
# Test accesso app
|
||||
curl http://127.0.0.1:8081
|
||||
```
|
||||
|
||||
Atteso: SUCCESSO
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
# Test accesso database (privato - NON deve funzionare)
|
||||
curl http://127.0.0.1:5432
|
||||
```
|
||||
|
||||
Atteso:
|
||||
```
|
||||
curl: (7) Failed to connect to 127.0.0.1 port 5432 after X ms: Connection refused
|
||||
```
|
||||
|
||||
Questo e corretto! Il database e nella rete privata senza porte esposte.
|
||||
|
||||
---
|
||||
|
||||
## Passo 7: Test Isolamento Internet (Rete Privata)
|
||||
|
||||
La rete privata con flag `--internal` non puo raggiungere internet.
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
# Test database non puo raggiungere internet
|
||||
docker exec lab02-db ping -c 1 -W 1 8.8.8.8
|
||||
```
|
||||
|
||||
Atteso: FALLISCE (nessuna route verso internet)
|
||||
|
||||
Questo e corretto per una subnet privata cloud.
|
||||
|
||||
---
|
||||
|
||||
## Passo 8: Test Container di Isolamento
|
||||
|
||||
Usa lo script di test del lab.
|
||||
|
||||
Esegui:
|
||||
|
||||
```bash
|
||||
bash tests/02-isolation-verification-test.sh
|
||||
```
|
||||
|
||||
Questo script verifica automaticamente tutti i casi di isolamento.
|
||||
|
||||
---
|
||||
|
||||
## Matrice di Connettività
|
||||
|
||||
| Source | Target | Stesso Network | Risultato |
|
||||
|--------|--------|----------------|----------|
|
||||
| web (10.0.1.10) | app (10.0.1.20) | Si (vpc-public) | SUCCESSO |
|
||||
| app (10.0.1.20) | db (10.0.2.10) | Si (vpc-private) | SUCCESSO |
|
||||
| web (10.0.1.10) | db (10.0.2.10) | No | FALLISCE |
|
||||
| db (10.0.2.10) | web (10.0.1.10) | No | FALLISCE |
|
||||
| Host (127.0.0.1) | web (8080) | Port mapping | SUCCESSO |
|
||||
| Host (127.0.0.1) | db (5432) | Nessun mapping | FALLISCE |
|
||||
| db | Internet (8.8.8.8) | --internal flag | FALLISCE |
|
||||
|
||||
---
|
||||
|
||||
## Verifica
|
||||
|
||||
Hai completato questo tutorial quando:
|
||||
- [ ] Container nella stessa rete comunicano
|
||||
- [ ] Container in reti diverse sono isolati (ping fallisce)
|
||||
- [ ] Container multi-homed raggiungono entrambe le reti
|
||||
- [ ] DNS risolve i nomi nella stessa rete
|
||||
- [ ] Servizi privati non accessibili dall'host
|
||||
- [ ] Rete privata non raggiunge internet
|
||||
|
||||
## Prossimi Passi
|
||||
|
||||
- Esegui la verifica finale: `bash tests/99-final-verification.sh`
|
||||
- Leggi [Explanation: Parallelismi VPC](../explanation/docker-network-vpc-parallels.md)
|
||||
- Procedi al Lab 03: Compute & EC2
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Problema: Tutti i ping funzionano (nessun isolamento)**
|
||||
|
||||
Causa: Container potrebbero essere nella rete di default `bridge`
|
||||
|
||||
Soluzione:
|
||||
```bash
|
||||
# Verifica reti dei container
|
||||
docker inspect lab02-web --format '{{json .NetworkSettings.Networks}}'
|
||||
|
||||
# Devono mostrare solo lab02-vpc-public, non "bridge"
|
||||
```
|
||||
|
||||
**Problema: `lab02-app` non puo raggiungere nessuno**
|
||||
|
||||
Causa: IP statici potrebbero entrare in conflitto
|
||||
|
||||
Soluzione:
|
||||
```bash
|
||||
# Ricrea senza IP statici
|
||||
docker compose down
|
||||
# Rimuovi ipv4_address dal compose
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
**Problema: DNS non funziona**
|
||||
|
||||
Soluzione:
|
||||
```bash
|
||||
# Verifica configurazione DNS container
|
||||
docker exec lab02-app cat /etc/resolv.conf
|
||||
|
||||
# Dovrebbe mostrare 127.0.0.11 (Docker embedded DNS)
|
||||
```
|
||||
|
||||
**Problema: Container web non si avvia**
|
||||
|
||||
Soluzione:
|
||||
```bash
|
||||
# Verifica logs
|
||||
docker compose logs web
|
||||
|
||||
# Verifica che la porta non sia in uso
|
||||
ss -tlnp | grep 8080
|
||||
```
|
||||
Reference in New Issue
Block a user