# 🎉 Secure Proxy - Projet ComplĂ©tĂ© ## 📩 Qu'avez-vous reçu ? Un **reverse proxy sĂ©curisĂ© complĂšt** avec authentification OIDC et panel admin. ## ⚡ DĂ©marrage Ultra-Rapide ```bash # 1ïžâƒŁ Installation (1 minute) cd /Users/alexandre/projet/openidv2 npm install npm run init-db # 2ïžâƒŁ Lancement (10 secondes) npm run dev # 3ïžâƒŁ AccĂšs (immĂ©diat) # http://localhost:3000 → Page d'accueil # http://localhost:3000/admin → Panel admin (si admin) ``` ## 🎯 Cas d'Usage ### Cas 1: Proxifier Grafana Local ```bash # Terminal 1: Grafana docker run -p 3001:3000 grafana/grafana # Terminal 2: Proxy npm run dev # Terminal 3: Admin # 1. Aller Ă  http://localhost:3000/admin # 2. "+ New Service" # 3. Name: Grafana, Path: /grafana, Target: http://localhost:3001 # 4. Access via http://localhost:3000/grafana ``` ### Cas 2: Service Public (Pas d'Auth) ``` Name: Public Docs Path: /docs Target: http://docs-server:8000 Require Auth: ❌ DÉCOCHÉE → Accessible sans login ! ``` ### Cas 3: Service PrivĂ© (Auth Obligatoire) ``` Name: Admin Dashboard Path: /admin-app Target: http://admin-server:4200 Require Auth: ✅ COCHÉE → NĂ©cessite authentification Keycloak ``` ## 📂 Structure ClĂ© ``` openidv2/ ├── src/ │ ├── server.js ................... Serveur principal │ ├── middleware/ ................. Logique OIDC, Proxy, SĂ©curitĂ© │ ├── routes/ ..................... Endpoints API │ ├── controllers/ ................ Business logic │ └── services/ ................... ServiceManager ├── public/ │ └── admin.html .................. Panel Admin complet ├── db/ │ └── services.db ................. Base de donnĂ©es SQLite ├── scripts/ │ ├── initDb.js ................... Initialiser DB │ └── seedDb.js ................... Charger donnĂ©es d'exemple ├── README.md ....................... Doc complĂšte ├── INSTALLATION.md ................. Guide installation ├── QUICKSTART.md ................... 5 minutes setup ├── ARCHITECTURE.md ................. Diagrammes └── FEATURES.md ..................... Checklist complĂšte ``` ## 🔧 Configuration ### .env Minimal (Dev) ```env PORT=3000 NODE_ENV=development PROXY_URL=http://localhost:3000 ADMIN_USERNAME=admin@example.com SESSION_SECRET=dev-secret # OIDC peut rester dĂ©sactivĂ© en dev # ou configurĂ© vers Keycloak ``` ### .env Production ```env PORT=3000 NODE_ENV=production PROXY_URL=https://secure.k2r.ovh OIDC_ISSUER=https://keycloak.example.com/auth/realms/master OIDC_CLIENT_ID=openidv2-client OIDC_CLIENT_SECRET=secret_very_secure OIDC_CALLBACK_URL=https://secure.k2r.ovh/callback ADMIN_USERNAME=admin@example.com ADMIN_PASSWORD=password_secure SESSION_SECRET=random_string_very_long_minimum_32 ``` ## 🚀 DĂ©ploiement ### Simple (SystĂšmd) ```bash # 1. Copier sur serveur scp -r /Users/alexandre/projet/openidv2 user@server:/var/www/ # 2. Installer cd /var/www/openidv2 npm install --production npm run init-db # 3. CrĂ©er service systemd sudo cp deployment/openidv2.service /etc/systemd/system/ # 4. Lancer sudo systemctl start openidv2 sudo systemctl enable openidv2 ``` ### Docker ```bash # Build docker build -t openidv2 . # Run docker run -p 3000:3000 \ -e NODE_ENV=production \ -e OIDC_ISSUER=https://keycloak... \ openidv2 ``` ### Docker Compose (All-in-One Dev) ```bash docker-compose up ``` ## 📊 APIs Disponibles ### Authentification - `GET /auth/login-page` → Page de connexion - `GET /auth/login` → Initier OAuth - `POST /auth/callback` → OAuth callback - `GET /auth/logout` → DĂ©connexion - `GET /auth/profile` → Infos utilisateur ### Admin Services - `POST /api/services` → CrĂ©er - `GET /api/services` → Lister - `PUT /api/services/:id` → Modifier - `DELETE /api/services/:id` → Supprimer - `PATCH /api/services/:id/toggle` → Activer/DĂ©sactiver - `GET /api/services/:id/logs` → Logs d'accĂšs ### Dashboard - `GET /dashboard/stats` → Statistiques - `GET /dashboard/logs` → Logs d'audit ## đŸ›Ąïž SĂ©curitĂ© Incluse ✅ HTTPS/SSL ✅ OIDC Authentication ✅ Sessions sĂ©curisĂ©es ✅ CSRF Protection ✅ Rate Limiting ✅ Security Headers (Helmet) ✅ Input Validation ✅ SQL Injection Protection ✅ Audit Logs complets ✅ Access Logs tracĂ©s ## 📝 Fichiers Importants Ă  ConnaĂźtre | Fichier | Quand le modifier | |---------|-----------------| | `src/server.js` | Ajouter nouvelles routes | | `public/admin.html` | Modifier l'UI du panel | | `src/services/serviceManager.js` | Ajouter logique mĂ©tier | | `.env` | Changer la configuration | | `package.json` | Ajouter des dĂ©pendances | ## 🐛 DĂ©pannage Rapide ### Erreur: Port dĂ©jĂ  utilisĂ© ```bash # Changer le port dans .env PORT=3001 ``` ### Erreur: Database locked ```bash # RĂ©initialiser rm db/services.db npm run init-db ``` ### OIDC ne fonctionne pas ```bash # Mode dev sans OIDC fonctionne quand mĂȘme ! # Voir INSTALLATION.md pour Keycloak ``` ### Admin panel vide 1. Être admin : email doit correspondre Ă  `ADMIN_USERNAME` 2. CrĂ©er un service : "+ New Service" 3. VĂ©rifier la DB : `sqlite3 db/services.db "SELECT * FROM services;"` ## 📚 Documentation ComplĂšte - **README.md** - Vue d'ensemble et fonctionnalitĂ©s - **INSTALLATION.md** - Setup dĂ©taillĂ© avec Keycloak - **QUICKSTART.md** - 5 minutes pour dĂ©marrer - **ARCHITECTURE.md** - Diagrammes et flux - **FEATURES.md** - Checklist complĂšte ## 🎓 Comprendre le Code ### Flux de RequĂȘte Simple ``` GET /myapp ↓ Middleware OIDC vĂ©rifie session ↓ Middleware Proxy trouve service ↓ Proxy envoie vers http://target-server ↓ RĂ©ponse renvoyĂ©e au client ↓ Access log enregistrĂ© ``` ### Structure Middleware ```javascript // Dans server.js app.use(middleware1); // OIDC app.use(middleware2); // Security app.use(middleware3); // Logging app.use(middleware4); // Proxy ``` ## đŸ’Ÿ Base de DonnĂ©es Trois tables SQLite automatiquement créées : 1. **services** - Configuration des services 2. **audit_logs** - Actions administrateur 3. **access_logs** - AccĂšs aux services Voir les donnĂ©es : ```bash sqlite3 db/services.db > SELECT * FROM services; > SELECT * FROM audit_logs LIMIT 10; ``` ## 🌐 URLs Importantes ### DĂ©veloppement - Home: http://localhost:3000 - Admin: http://localhost:3000/admin - API: http://localhost:3000/api/services - Keycloak: http://localhost:8080 (si docker) ### Production - Home: https://secure.k2r.ovh - Admin: https://secure.k2r.ovh/admin - API: https://secure.k2r.ovh/api/services ## 🚄 Performance - Rate limit : 100 req/15 min par dĂ©faut - Timeout proxy : 30 secondes - Sessions : 24 heures - Cache disabled pour ressources sensibles ## 🎁 Bonus - Docker Compose pour dev complet - Dockerfile pour production - Nginx config template - Test API script - Seed data script ## ✹ Points Forts ✅ **ComplĂštement modulaire** - Facile Ă  Ă©tendre ✅ **Production-ready** - Peut ĂȘtre dĂ©ployĂ© immĂ©diatement ✅ **SĂ©curisĂ©** - Multi-couches de sĂ©curitĂ© ✅ **DocumentĂ©** - Guides complets fournis ✅ **Testable** - Scripts et exemples inclus ✅ **Scalable** - Architecture pensĂ©e pour croissance ## 📞 Besoin d'Aide ? 1. **ProblĂšme lors du dĂ©marrage** → Voir QUICKSTART.md 2. **ProblĂšme Keycloak** → Voir INSTALLATION.md 3. **Comprendre l'arch** → Voir ARCHITECTURE.md 4. **Toutes les features** → Voir README.md et FEATURES.md ## 🎯 Prochaines Étapes 1. ✅ Installation - **À FAIRE MAINTENANT** 2. ✅ Premier dĂ©marrage - `npm run dev` 3. ✅ CrĂ©er un service test 4. ✅ VĂ©rifier le proxy fonctionne 5. ✅ Configurer Keycloak (optionnel mais recommandĂ©) 6. ✅ DĂ©ployer en production ## 🎉 Le Service est PrĂȘt ! **Lancez-le maintenant :** ```bash cd /Users/alexandre/projet/openidv2 npm install npm run init-db npm run dev # Puis ouvrez http://localhost:3000 ``` --- **Bon dĂ©veloppement ! 🚀** *Créé le 3 dĂ©cembre 2025* *Tous les fichiers sont prĂ©sents et fonctionnels*