# đŸŒČ Alliance BorĂ©ale - Phase 2 : IdentitĂ© & Forge Extension de l'infrastructure avec SSO (Keycloak) et Forge Git (Forgejo). --- ## 📋 SERVICES DÉPLOYÉS | Service | VMID | FQDN | IP | Couche | Port(s) | |---------|------|------|----|----|---------| | **Keycloak** | 03010 | `sso.infra.chezlepro.ca` | 10.0.3.20 | C3 | 443 (HTTPS) | | **Forgejo** | 04021 | `git.infra.chezlepro.ca` | 10.0.1.20 | C4 | 443 (HTTPS), 2222 (SSH) | --- ## 🚀 DÉPLOIEMENT PHASE 2 ### 1. CrĂ©er les VMs ```bash # VM Keycloak VMID: 03010 RAM: 4GB (Keycloak = gourmand en Java) CPU: 2 cores Disk: 30GB OS: Ubuntu 22.04 LTS IP: 10.0.3.20 # VM Forgejo VMID: 04021 RAM: 2GB CPU: 2 cores Disk: 50GB (repos Git) OS: Ubuntu 22.04 LTS IP: 10.0.1.20 ``` ### 2. Mettre Ă  jour l'inventaire ```bash # Copier le nouvel inventaire cp inventories/production/hosts-phase2.yml inventories/production/hosts.yml # Éditer les IPs si nĂ©cessaire vi inventories/production/hosts.yml ``` ### 3. GĂ©nĂ©rer les secrets Phase 2 ```bash # Mots de passe openssl rand -base64 24 # Keycloak admin openssl rand -base64 24 # Keycloak DB openssl rand -base64 24 # Forgejo admin openssl rand -base64 24 # Forgejo DB # Secrets Forgejo (64 chars hex) openssl rand -hex 64 # secret_key openssl rand -hex 64 # internal_token openssl rand -hex 64 # jwt_secret ``` ### 4. Mettre Ă  jour le vault ```bash # Éditer vault ansible-vault edit vault/production.yml # Ajouter les secrets Phase 2 (voir vault/production-phase2.yml.example) ``` ### 5. DĂ©ployer Keycloak d'abord ```bash # DĂ©ployer seulement Keycloak ansible-playbook playbooks/phase2-deploy.yml --limit idp_servers --ask-vault-pass ``` ### 6. Configurer Keycloak ```bash # AccĂ©der Ă  Keycloak https://sso.infra.chezlepro.ca # Login admin (vault_keycloak_admin_password) # Le realm "alliance-boreale" devrait ĂȘtre créé automatiquement # Aller dans: Realm "alliance-boreale" → Clients → "forgejo" ``` ### 7. RĂ©cupĂ©rer le Client Secret Forgejo ``` Keycloak UI: 1. Realm: alliance-boreale 2. Clients → forgejo 3. Credentials tab 4. Copier "Client Secret" ``` ### 8. Ajouter le secret au vault ```bash ansible-vault edit vault/production.yml # Ajouter: vault_keycloak_forgejo_client_secret: "" ``` ### 9. DĂ©ployer Forgejo ```bash # DĂ©ployer Forgejo avec SSO configurĂ© ansible-playbook playbooks/phase2-deploy.yml --limit forge_servers --ask-vault-pass ``` --- ## ✅ VALIDATION POST-DÉPLOIEMENT ### Test Keycloak ```bash # AccĂšs web curl -k https://sso.infra.chezlepro.ca/realms/alliance-boreale # Devrait retourner du JSON avec config du realm ``` ### Test Forgejo ```bash # AccĂšs web curl -k https://git.infra.chezlepro.ca # Devrait retourner HTML de la page d'accueil # Test SSH ssh -T -p 2222 git@git.infra.chezlepro.ca # Devrait afficher: "Hi there, You've successfully authenticated..." ``` ### Test SSO (Forgejo → Keycloak) ``` 1. Aller sur https://git.infra.chezlepro.ca 2. Cliquer "Sign in with L'Alliance BorĂ©ale SSO" 3. Devrait rediriger vers Keycloak 4. CrĂ©er un compte ou se connecter 5. Devrait rediriger vers Forgejo connectĂ© ``` --- ## đŸ‘„ GESTION UTILISATEURS ### CrĂ©er des utilisateurs dans Keycloak ``` Keycloak UI: 1. Realm: alliance-boreale 2. Users → Add user 3. Remplir: username, email, first name, last name 4. Save 5. Credentials tab → Set Password 6. Temporary: OFF 7. Save ``` ### Donner accĂšs admin Forgejo ``` SSH sur serveur Forgejo: ssh ansible@10.0.1.20 # Promouvoir utilisateur admin sudo -u git /opt/forgejo/forgejo admin user change-password \ --username \ --password \ --config /etc/forgejo/app.ini # Ou donner rĂŽle admin sudo -u git /opt/forgejo/forgejo admin user create \ --admin \ --username \ --email \ --password \ --config /etc/forgejo/app.ini ``` --- ## 📩 PREMIERS DÉPÔTS ### CrĂ©er organisation "alliance-boreale" ``` Forgejo UI: 1. Sign in via SSO 2. + → New Organization 3. Name: alliance-boreale 4. Visibility: Public 5. Create ``` ### CrĂ©er dĂ©pĂŽts essentiels ``` Dans l'organisation "alliance-boreale": 1. ansible-infrastructure Description: Infrastructure as Code Private: No Initialize: Yes (README.md) 2. documentation Description: Documentation technique Private: No 3. registraire Description: Registraire membres (Document 14) Private: No ``` ### Pousser ce dĂ©pĂŽt Ansible ```bash cd /chemin/vers/ansible # Ajouter remote Forgejo git remote add forgejo git@git.infra.chezlepro.ca:2222/alliance-boreale/ansible-infrastructure.git # Pousser git push -u forgejo main ``` --- ## 🔄 INTÉGRATION CONTINUE (CI/CD) Forgejo Actions (GitHub Actions compatible) est activĂ©. ### Exemple workflow `.forgejo/workflows/lint.yml` ```yaml name: Ansible Lint on: push: branches: [main] pull_request: jobs: lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Install Ansible run: | pip3 install ansible ansible-lint - name: Run ansible-lint run: | ansible-lint playbooks/*.yml ``` --- ## 🔐 SÉCURITÉ ### Certificats SSL Phase 2 utilise des **certificats auto-signĂ©s** par dĂ©faut. **Pour production** : Utiliser Let's Encrypt ```yaml # Dans group_vars/idp_servers.yml et forge_servers.yml nginx: ssl: cert_source: letsencrypt letsencrypt_email: admin@chezlepro.ca ``` Puis redĂ©ployer : ```bash ansible-playbook playbooks/phase2-deploy.yml --tags nginx ``` ### Firewall Les rĂšgles nftables sont automatiquement configurĂ©es : ```bash # VĂ©rifier sur les serveurs sudo nft list ruleset | grep -A 10 "Keycloak\|Forgejo" ``` ### Backups PostgreSQL ConfigurĂ©s automatiquement : - **Keycloak DB** : Backup quotidien Ă  3h, rĂ©tention 14 jours - **Forgejo DB** : Backup quotidien Ă  4h, rĂ©tention 14 jours VĂ©rifier : ```bash ls -lh /var/backups/postgresql/ ``` --- ## 🐛 DÉPANNAGE ### Keycloak ne dĂ©marre pas ```bash # Logs sudo journalctl -u keycloak -n 100 --no-pager # VĂ©rifier Java java -version # Devrait ĂȘtre OpenJDK 17 # VĂ©rifier PostgreSQL sudo -u postgres psql keycloak -c "SELECT version();" # Rebuild Keycloak sudo -u keycloak /opt/keycloak/bin/kc.sh build sudo systemctl restart keycloak ``` ### Forgejo ne se connecte pas Ă  Keycloak ```bash # VĂ©rifier logs Forgejo sudo journalctl -u forgejo -n 100 --no-pager # Tester dĂ©couverte OpenID curl -k https://sso.infra.chezlepro.ca/realms/alliance-boreale/.well-known/openid-configuration # VĂ©rifier client secret dans app.ini sudo grep -A 5 "oauth2.alliance-boreale" /etc/forgejo/app.ini ``` ### SSH Forgejo ne fonctionne pas ```bash # VĂ©rifier port SSH Forgejo sudo ss -tulnp | grep 2222 # Tester localement ssh -T -p 2222 git@localhost # VĂ©rifier firewall sudo nft list ruleset | grep 2222 # Logs SSH Forgejo sudo journalctl -u forgejo -f | grep SSH ``` --- ## 📚 RÉFÉRENCES - [Keycloak Documentation](https://www.keycloak.org/documentation) - [Forgejo Documentation](https://forgejo.org/docs/) - [Forgejo Actions](https://forgejo.org/docs/latest/user/actions/) - [OpenID Connect](https://openid.net/connect/) --- ## 🎯 PROCHAINE ÉTAPE : PHASE 3 **Phase 3 : FastAPI Pivot (C5)** Services Ă  dĂ©ployer : - FastAPI Admin Portal - API Gateway - Tenant provisioning - Monitoring dashboard --- **Version:** 1.0 **Date:** 2025-10-31 **Membre:** Chezlepro Inc. **Phases:** 1 (DNS) + 2 (IdP + Forge)