proxy-oidcv2/PROJECT_SUMMARY.md
2025-12-03 21:34:44 +01:00

7.9 KiB
Raw Permalink Blame History

🎉 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

# 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

# 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)

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

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)

# 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

# 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)

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é

# Changer le port dans .env
PORT=3001

Erreur: Database locked

# Réinitialiser
rm db/services.db
npm run init-db

OIDC ne fonctionne pas

# 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

// 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 :

sqlite3 db/services.db
> SELECT * FROM services;
> SELECT * FROM audit_logs LIMIT 10;

🌐 URLs Importantes

Développement

Production

🚄 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 :

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