Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# 🔐 Fonctionnement d’un VPN & Utilité en Infrastructure Réseau

## 🧠 Qu’est-ce qu’un VPN (Virtual Private Network) ?

Un VPN est une **connexion chiffrée** entre deux points (par exemple, un poste client et un réseau privé d’entreprise), qui permet de **transporter des données en toute sécurité via un réseau public comme Internet**.

> 🎯 Objectif principal : créer un tunnel sécurisé entre deux entités réseau.

---

## 🧩 Composants principaux

- **Client VPN** : logiciel installé sur un poste.
- **Serveur VPN** : équipement ou service qui reçoit et déchiffre le trafic.
- **Tunnel VPN** : canal chiffré entre le client et le serveur.
- **Protocole VPN** : OpenVPN, IPSec, WireGuard...

---

## 🛡️ Utilité dans une infrastructure

### 🏢 Pour une entreprise :
- Accès sécurisé aux ressources internes depuis l'extérieur
- Connexion entre plusieurs sites (VPN site-à-site)
- Sécurisation des données en transit

### ☁️ Cloud / Hybride :
- Relier un réseau on-premise à un VPC cloud
- Accès sécurisé aux ressources cloud privées

---

## 📈 Exemple 1 : VPN client → entreprise

🔍 Flux :

1. Le client VPN s’authentifie.
1. Un tunnel chiffré est établi.
1. Le trafic est redirigé via le tunnel.
1. L’utilisateur accède au réseau interne.

```mermaid
flowchart TD
A[Ordinateur distant] --> B[Client VPN]
B -- Tunnel chiffré --> C[Internet]
C --> D[Pare-feu / Routeur VPN]
D --> E[Serveur interne]
```

## 📈 Exemple 2 : VPN site-à-site (entre 2 sites)

🔍 Flux :

1. Tunnel IPSec entre les routeurs.
1. Accès direct entre les réseaux internes.

```mermaid
flowchart TD
subgraph SiteA [Site A - Siège]
A1[LAN 192.168.1.0/24]
A2[Routeur VPN A]
A1 --> A2
end

subgraph Internet
I1
end

subgraph SiteB [Site B - Filiale]
B1[LAN 192.168.2.0/24]
B2[Routeur VPN B]
B1 --> B2
end

A2 -- Tunnel IPSec --> I1
B2 -- Tunnel IPSec --> I1
```

## 🔒 Protocoles VPN courants

| Protocole | Type | Avantages |
|---------------|----------------|--------------------------------------|
| IPSec | Site-to-site | Standard, sécurisé, matériel supporté |
| OpenVPN | Remote access | Sécurisé, open-source, flexible |
| WireGuard | Remote access | Léger, rapide, moderne |
| SSL VPN | Remote access | Utilisable dans navigateur |

---

## 🔧 Exemple : Télétravail

```mermaid
flowchart TD
A[Utilisateur à domicile] --> B[Client OpenVPN]
B -- Tunnel SSL --> C[Internet]
C --> D[Pare-feu VPN]
D --> E[Intranet / NAS / Apps internes]
```

### 🔍 Fonctionnement :
- Authentification du client
- Tunnel SSL sécurisé
- Accès aux ressources internes

---

## ⚠️ Points de vigilance

- **Performance** : latence induite par le chiffrement.
- **Sécurité** : bien définir les règles d’accès.
- **Maintenance** : surveillance des certificats et connexions.

---

## 🛠️ Outils VPN

### Logiciels :
- pfSense / OPNsense
- OpenVPN Access Server
- StrongSwan (IPSec)
- WireGuard

### Cloud :
- AWS VPN Gateway
- Azure VPN Gateway
- GCP Cloud VPN

2 changes: 1 addition & 1 deletion MyWebSite/docs/blog/posts/00_vision_and_objectives.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
draft: false
date: 2024-07-11
date: 2025-07-11
categories:
- Divers
comments: true
Expand Down
238 changes: 238 additions & 0 deletions MyWebSite/docs/blog/posts/01_deploy_wireguard_vpn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@

---
draft: true
date: 2025-08-01
categories:
- INFRASTRUCTURE
- CYBER
comments: true
---

# 🚀 Déploiement complet d’un VPN WireGuard (avec automatisation & Docker)

Ce tutoriel vous guide étape par étape pour déployer un **VPN WireGuard sécurisé** avec :

- Scripts d’installation en **Bash et Python**
- Génération automatique des clés
- Configuration serveur et client
- Génération de QR code pour mobile
- 🚀 Bonus : déploiement avec Docker

---

## 📦 Prérequis

- Serveur Linux (Ubuntu/Debian/CentOS)
- Accès root (`sudo`)
- Port UDP 51820 ouvert
- Python 3, Bash
- Docker (pour partie Docker)

---

## 1. 🔧 Installation de WireGuard (Bash)

```bash
#!/bin/bash
set -e
sudo apt update && sudo apt upgrade -y
sudo apt install -y wireguard qrencode
sudo mkdir -p /etc/wireguard
sudo chmod 700 /etc/wireguard
```

---

## 2. 🔑 Génération des clés serveur et client

```bash
#!/bin/bash
set -e
cd /etc/wireguard
umask 077

wg genkey | tee privatekey | wg pubkey > publickey
mkdir -p clients
CLIENT="client1"
wg genkey | tee clients/$CLIENT-privatekey | wg pubkey > clients/$CLIENT-publickey
```

---

## 3. ⚙️ Configuration serveur `wg0.conf`

```bash
#!/bin/bash
cd /etc/wireguard
cat <<EOF | sudo tee wg0.conf
[Interface]
PrivateKey = $(cat privatekey)
Address = 10.10.10.1/24
ListenPort = 51820
SaveConfig = true

[Peer]
PublicKey = $(cat clients/client1-publickey)
AllowedIPs = 10.10.10.2/32
EOF

chmod 600 wg0.conf
```

---

## 4. 📜 Génération configuration client (Python)

```python
import os

client = "client1"
client_dir = "/etc/wireguard/clients"
priv = open(f"{client_dir}/{client}-privatekey").read().strip()
server_pub = open("/etc/wireguard/publickey").read().strip()
server_ip = "YOUR.SERVER.IP"

conf = f"""[Interface]
PrivateKey = {priv}
Address = 10.10.10.2/24
DNS = 1.1.1.1

[Peer]
PublicKey = {server_pub}
Endpoint = {server_ip}:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
"""

with open(f"{client_dir}/{client}.conf", "w") as f:
f.write(conf)
```

---

## 5. ✅ Activer et démarrer WireGuard

```bash
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
```

---

## 6. 📲 Génération QR Code client

```bash
qrencode -t ansiutf8 < /etc/wireguard/clients/client1.conf
```

---

## 7. 🔁 Script tout-en-un `deploy_wireguard.sh`

```bash
#!/bin/bash
set -e
WG_DIR="/etc/wireguard"
CLIENT="client1"
apt update && apt install -y wireguard qrencode

mkdir -p $WG_DIR/clients && cd $WG_DIR && umask 077
wg genkey | tee privatekey | wg pubkey > publickey
wg genkey | tee clients/$CLIENT-privatekey | wg pubkey > clients/$CLIENT-publickey

cat <<EOF > $WG_DIR/wg0.conf
[Interface]
PrivateKey = $(cat privatekey)
Address = 10.10.10.1/24
ListenPort = 51820
SaveConfig = true

[Peer]
PublicKey = $(cat clients/$CLIENT-publickey)
AllowedIPs = 10.10.10.2/32
EOF

cat <<EOF > $WG_DIR/clients/$CLIENT.conf
[Interface]
PrivateKey = $(cat clients/$CLIENT-privatekey)
Address = 10.10.10.2/24
DNS = 1.1.1.1

[Peer]
PublicKey = $(cat publickey)
Endpoint = YOUR.SERVER.IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
EOF

qrencode -t ansiutf8 < $WG_DIR/clients/$CLIENT.conf
systemctl enable wg-quick@wg0
systemctl start wg-quick@wg0
```

---

## 🐳 Déploiement avec Docker (optionnel)

### 📁 Structure du projet

```
wireguard-docker/
├── docker-compose.yml
├── config/
│ └── wg0.conf
├── entrypoint.sh
```

### 📜 `docker-compose.yml`

```yaml
version: "3.8"
services:
wireguard:
image: linuxserver/wireguard
container_name: wireguard
cap_add:
- NET_ADMIN
- SYS_MODULE
environment:
- PUID=1000
- PGID=1000
- SERVERURL=YOUR.SERVER.IP
- SERVERPORT=51820
- PEERS=client1
- PEERDNS=1.1.1.1
- INTERNAL_SUBNET=10.10.10.0
volumes:
- ./config:/config
- /lib/modules:/lib/modules
ports:
- 51820:51820/udp
restart: unless-stopped
```

### 📝 `entrypoint.sh` (optionnel si génération custom)

```bash
#!/bin/bash
docker-compose up -d
```

---

## ✅ Vérification

```bash
sudo wg show
```

---

## 🎯 Résultat

- Serveur WireGuard actif sur port UDP 51820
- Client prêt à se connecter avec fichier `.conf` ou QR code
- Déploiement automatisé en Bash et Python

---

Loading