feat: Initial Matrix server setup with Postgres, Element, and Keycloak OIDC
This commit is contained in:
12
.env.example
Normal file
12
.env.example
Normal file
@@ -0,0 +1,12 @@
|
||||
# Ports
|
||||
SYNAPSE_PORT=8008
|
||||
ELEMENT_PORT=8088
|
||||
|
||||
# PostgreSQL Configuration
|
||||
POSTGRES_DB=synapse
|
||||
POSTGRES_USER=synapse
|
||||
POSTGRES_PASSWORD=generate_a_secure_password_here
|
||||
|
||||
# Keycloak OIDC Configuration
|
||||
# Erstelle einen confidential Client namens 'matrix' im Keycloak auth.mischlabs.de
|
||||
KEYCLOAK_CLIENT_SECRET=your_keycloak_client_secret_here
|
||||
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
# Environment files
|
||||
.env
|
||||
|
||||
# Runtime data and state
|
||||
data/homeserver.pid
|
||||
data/*.signing.key
|
||||
data/media_store/
|
||||
|
||||
# Database data
|
||||
postgres_data/
|
||||
107
README.md
Normal file
107
README.md
Normal file
@@ -0,0 +1,107 @@
|
||||
# Matrix Homeserver Setup - mischlabs.de
|
||||
|
||||
Dieses Projekt stellt einen eigenen, föderierbaren **Matrix Homeserver** auf Basis von **Synapse** bereit, inklusive einer **PostgreSQL-Datenbank** und dem Web-Client **Element Web**.
|
||||
|
||||
---
|
||||
|
||||
## 🛠 Architektur & Dienste
|
||||
|
||||
Das Setup besteht aus drei Docker-Containern:
|
||||
1. **`matrix_synapse`**: Der eigentliche Matrix Homeserver (Synapse), vorkonfiguriert für das Domain-Routing unter `mischlabs.de` und die technische Bereitstellung auf `matrix.mischlabs.de`.
|
||||
2. **`matrix_synapse_db`**: Eine dedizierte PostgreSQL 16 Datenbank für maximale Performance und Zuverlässigkeit.
|
||||
3. **`matrix_element`**: Der Web-Client **Element**, erreichbar unter `chat.mischlabs.de`.
|
||||
|
||||
Die Container binden sich an das Docker-Netzwerk `npm-net` an, damit sie vom **Nginx Proxy Manager** (oder Cloudflare Tunnel) auf der NAS direkt erreicht und mit SSL-Zertifikaten versorgt werden können.
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Deployment auf der NAS
|
||||
|
||||
Da du Docker auf deiner UGREEN NAS betreibst, sind dies die Schritte zur Bereitstellung:
|
||||
|
||||
### 1. Dateien vorbereiten
|
||||
Kopiere den gesamten Ordner `D:\Vibecoding\Website\Matrix` auf dein NAS in das entsprechende Docker-Verzeichnis (z. B. `/volume2/docker/matrix/`).
|
||||
|
||||
### 2. Keycloak Client einrichten
|
||||
Melde dich in deiner Keycloak Admin-Konsole (`https://auth.mischlabs.de`) an:
|
||||
1. Wähle den Realm **`mischlabs`**.
|
||||
2. Gehe auf **Clients** -> **Create client**.
|
||||
3. Einstellungen:
|
||||
* **Client type:** `OpenID Connect`
|
||||
* **Client ID:** `matrix`
|
||||
* **Name:** `Matrix Synapse`
|
||||
4. Klicke auf **Next** und aktiviere:
|
||||
* **Client authentication:** `ON` (Confidential Client, erfordert ein Secret)
|
||||
* **Authorization:** `OFF`
|
||||
* **Authentication flow:** Standard Flow aktiviert (`Authorization Code Flow`)
|
||||
5. Klicke auf **Save**.
|
||||
6. Unter **Settings** -> **Capability config** folgende URIs einpflegen:
|
||||
* **Valid Redirect URIs:** `https://matrix.mischlabs.de/_synapse/client/oidc/callback`
|
||||
* **Web Origins:** `https://matrix.mischlabs.de`
|
||||
7. Gehe auf den Reiter **Credentials** und kopiere das **Client Secret**.
|
||||
|
||||
### 3. Konfiguration anpassen
|
||||
1. Öffne die `.env`-Datei auf der NAS und trage dein Keycloak-Secret bei `KEYCLOAK_CLIENT_SECRET` ein.
|
||||
2. Öffne `/data/homeserver.yaml` und ersetze `DEIN_KEYCLOAK_CLIENT_SECRET` durch dein Keycloak Client Secret.
|
||||
|
||||
### 4. Reverse Proxy einrichten (Nginx Proxy Manager)
|
||||
Erstelle im Nginx Proxy Manager zwei neue Proxy Hosts:
|
||||
|
||||
#### Host 1: Matrix Server (`matrix.mischlabs.de`)
|
||||
* **Domain Names:** `matrix.mischlabs.de`
|
||||
* **Scheme:** `http`
|
||||
* **Forward Host IP:** `matrix_synapse` (oder die NAS-IP `192.168.178.88`)
|
||||
* **Forward Port:** `8008`
|
||||
* **Block Common Exploits:** Aktiviert
|
||||
* **SSL:** Let's Encrypt Zertifikat aktivieren, *Force SSL* und *HTTP/2 Support* aktivieren.
|
||||
* **Advanced Config (Sehr Wichtig für Föderation):**
|
||||
Füge unter *Custom Nginx Configuration* Folgendes hinzu, damit große Datei-Uploads klappen:
|
||||
```nginx
|
||||
client_max_body_size 100M;
|
||||
```
|
||||
|
||||
#### Host 2: Element Web Client (`chat.mischlabs.de`)
|
||||
* **Domain Names:** `chat.mischlabs.de`
|
||||
* **Scheme:** `http`
|
||||
* **Forward Host IP:** `matrix_element` (oder die NAS-IP `192.168.178.88`)
|
||||
* **Forward Port:** `8088`
|
||||
* **SSL:** Let's Encrypt Zertifikat aktivieren, *Force SSL* und *HTTP/2 Support* aktivieren.
|
||||
|
||||
---
|
||||
|
||||
## 🏁 Container starten
|
||||
|
||||
Verbinde dich per SSH mit deinem NAS, navigiere in das Matrix-Verzeichnis und starte die Container:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### Logs prüfen
|
||||
Stelle sicher, dass Synapse und die Datenbank sauber starten:
|
||||
```bash
|
||||
docker compose logs -f synapse
|
||||
docker compose logs -f synapse_db
|
||||
```
|
||||
|
||||
*Hinweis:* Beim ersten Start generiert Synapse automatisch den Signierungsschlüssel `/data/mischlabs.de.signing.key` im Datenordner.
|
||||
|
||||
---
|
||||
|
||||
## 🌐 .well-known Domain-Delegierung aktivieren
|
||||
|
||||
Damit dein Server über `@username:mischlabs.de` föderieren kann und Clients die richtige Homeserver-URL finden, haben wir die `nginx.conf` deiner `mischlabs` Landingpage angepasst.
|
||||
|
||||
Wenn du das nächste Mal die Landingpage deployst (per Gitea Actions/Watchtower), werden die Pfade `https://mischlabs.de/.well-known/matrix/server` und `https://mischlabs.de/.well-known/matrix/client` automatisch korrekt ausgeliefert.
|
||||
|
||||
---
|
||||
|
||||
## 🔒 Administration & Wartung
|
||||
|
||||
### Synapse-Admin (CLI)
|
||||
Da die Standardregistrierung deaktiviert ist, werden neue Accounts ausschließlich über Keycloak erstellt. Solltest du jemals einen lokalen Admin-Account (ohne Keycloak) erstellen müssen, kannst du das über das Synapse CLI im Container tun:
|
||||
|
||||
```bash
|
||||
docker exec -it matrix_synapse register_new_matrix_user -c /data/homeserver.yaml http://localhost:8008
|
||||
```
|
||||
Folge den Eingabeaufforderungen (Admin-Rechte mit `yes` bestätigen).
|
||||
62
data/homeserver.yaml
Normal file
62
data/homeserver.yaml
Normal file
@@ -0,0 +1,62 @@
|
||||
# Matrix Synapse Configuration for mischlabs.de
|
||||
# Vor-konfiguriert für Docker, PostgreSQL und Keycloak SSO
|
||||
|
||||
server_name: "mischlabs.de"
|
||||
public_baseurl: "https://matrix.mischlabs.de/"
|
||||
|
||||
pid_file: /data/homeserver.pid
|
||||
signing_key_path: "/data/mischlabs.de.signing.key"
|
||||
|
||||
# Liste vertrauenswürdiger Key-Server für Föderation
|
||||
trusted_key_servers:
|
||||
- server_name: "matrix.org"
|
||||
|
||||
# Listener-Konfiguration für Nginx Proxy Manager (hinter Reverse Proxy)
|
||||
listeners:
|
||||
- port: 8008
|
||||
tls: false
|
||||
type: http
|
||||
x_forwarded: true
|
||||
resources:
|
||||
- names: [client, federation]
|
||||
compress: true
|
||||
|
||||
# PostgreSQL Datenbank-Anbindung
|
||||
database:
|
||||
name: psycopg2
|
||||
args:
|
||||
user: synapse
|
||||
password: kX9_qL2_zP8_wY4_vT9_mJ7_hQ1_bN3
|
||||
database: synapse
|
||||
host: synapse_db
|
||||
cp_min: 5
|
||||
cp_max: 10
|
||||
|
||||
# Medienspeicher und Uploads
|
||||
media_store_path: /data/media_store
|
||||
max_upload_size: 100M
|
||||
|
||||
# Sicherheit & Registrierung (Deaktiviert zugunsten von Keycloak SSO)
|
||||
enable_registration: false
|
||||
allow_guest_access: false
|
||||
password_config:
|
||||
enabled: false
|
||||
|
||||
# Keycloak SSO (OIDC) Integration
|
||||
oidc_providers:
|
||||
- idp_id: keycloak
|
||||
idp_name: "MischLabs Keycloak"
|
||||
idp_brand_name: "Keycloak"
|
||||
discover: true
|
||||
issuer: "https://auth.mischlabs.de/realms/mischlabs"
|
||||
client_id: "matrix"
|
||||
client_secret: "DEIN_KEYCLOAK_CLIENT_SECRET"
|
||||
scopes: ["openid", "profile", "email"]
|
||||
user_mapping_provider:
|
||||
config:
|
||||
localpart_template: "{{ user.preferred_username }}"
|
||||
display_name_template: "{{ user.name }}"
|
||||
email_template: "{{ user.email }}"
|
||||
|
||||
# Föderation aktivieren
|
||||
federation_domain_whitelist: []
|
||||
49
docker-compose.yml
Normal file
49
docker-compose.yml
Normal file
@@ -0,0 +1,49 @@
|
||||
services:
|
||||
synapse:
|
||||
image: matrixdotorg/synapse:latest
|
||||
container_name: matrix_synapse
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "${SYNAPSE_PORT:-8008}:8008"
|
||||
volumes:
|
||||
- ./data:/data
|
||||
environment:
|
||||
- SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
|
||||
- UID=1000
|
||||
- GID=1000
|
||||
- TZ=Europe/Berlin
|
||||
depends_on:
|
||||
- synapse_db
|
||||
networks:
|
||||
- default
|
||||
- npm-net
|
||||
|
||||
synapse_db:
|
||||
image: postgres:16-alpine
|
||||
container_name: matrix_synapse_db
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB:-synapse}
|
||||
POSTGRES_USER: ${POSTGRES_USER:-synapse}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
PGDATA: /var/lib/postgresql/data/pgdata
|
||||
volumes:
|
||||
- ./postgres_data:/var/lib/postgresql/data
|
||||
networks:
|
||||
- default
|
||||
|
||||
element:
|
||||
image: vectorim/element-web:latest
|
||||
container_name: matrix_element
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "${ELEMENT_PORT:-8088}:80"
|
||||
volumes:
|
||||
- ./element-config.json:/app/config.json
|
||||
networks:
|
||||
- default
|
||||
- npm-net
|
||||
|
||||
networks:
|
||||
npm-net:
|
||||
external: true
|
||||
10
element-config.json
Normal file
10
element-config.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"default_server_config": {
|
||||
"m.homeserver": {
|
||||
"base_url": "https://matrix.mischlabs.de",
|
||||
"server_name": "mischlabs.de"
|
||||
}
|
||||
},
|
||||
"brand": "MischLabs Chat",
|
||||
"integrated_jitsi_domain": "meet.element.io"
|
||||
}
|
||||
Reference in New Issue
Block a user