--- id: "0165" title: "Cifrar media_store/ Synapse con LUKS at-rest" status: pendiente type: infra domain: - matrix scope: app:element_matrix_chat priority: media depends: [] blocks: [] related: ["0162"] created: 2026-05-24 updated: 2026-05-24 tags: [matrix, synapse, encryption, security, luks] --- # 0165 — Cifrar media_store/ Synapse con LUKS at-rest **Status:** pendiente **Created:** 2026-05-24 **Type:** infra **Priority:** media **Domain:** matrix **Scope:** app:element_matrix_chat **Depends:** — **Blocks:** — ## Problema `synapse_data/media_store/` contiene archivos subidos (fotos, voice messages, attachments) + thumbnails. Rooms NO-E2EE: media cleartext en disco. Tabla `media_repository` Postgres: filename/mime/uploader/room_id siempre cleartext. Riesgo: VPS provider snapshot disk, backups desencriptados, disco fisico. ## Objetivo `media_store/` cifrado at-rest. Synapse arranca y sirve media normal. Decrypt automatico via keyfile en TPM o passphrase al boot. ## Plan 1. Decidir estrategia: LUKS container file-based (loop device) vs LUKS sobre volumen Docker dedicado. 2. Crear LUKS container 50GB (ajustar segun crecimiento previsto). 3. Montar como `/home/ubuntu/CodeProyects/element_matrix_chat/synapse_data/media_store_encrypted/`. 4. Stop Synapse → rsync `media_store/` → `media_store_encrypted/` → swap mountpoint. 5. Verificar Synapse sirve thumbnails + uploads OK. 6. Configurar auto-unlock via keyfile en `/root/.luks-media.key` con permisos 0400. 7. Documentar recovery passphrase en `pass` (entry `matrix/luks-media-passphrase`). ## Acceptance - [ ] `media_store/` montado sobre LUKS, `lsblk -f` muestra crypto_LUKS. - [ ] Synapse arranca tras reboot completo del VPS sin intervencion manual. - [ ] Test: subir imagen via Element, verificar thumb generado. - [ ] Test: leer media_store via `dd if=/dev/sdX` directo retorna basura cifrada. - [ ] Passphrase backed up en `pass`. ## Definition of Done - [ ] Repetibilidad: reboot VPS, media accesible sin intervencion. - [ ] Observabilidad: log entry en `journalctl -u systemd-cryptsetup@*`. - [ ] User-facing: clientes Element no notan diferencia. - [ ] Recovery probado: detach LUKS y reattach con passphrase. ## Notas LUKS solo protege at-rest. VPS provider con acceso a RAM viva ve plaintext via memory dump. Sin TPM atestado, utilidad real = anti-snapshot/anti-backup-leak/anti-physical-theft. Caveat: si keyfile vive en mismo disco que LUKS device, no protege contra disk theft. Mover keyfile a USB removible o TPM2 (`systemd-cryptenroll`).