Vous déployez CryptPad parce que l’équipe juridique veut des notes partagées chiffrées et que l’équipe produit veut des pads collaboratifs qui ne sortent pas du périmètre. Le quickstart Docker fonctionne, trois personnes s’inscrivent, le premier pad est créé. Six mois plus tard, l’instance tourne sur un seul domaine (l’iframe sandbox a été « réparée » en la branchant sur le même nom d’hôte), l’inscription est ouverte de sorte que le standup du mardi inclut deux comptes inconnus venus de l’internet public, le volume de données persistant est dans /tmp parce que personne n’a changé la valeur par défaut, et le certificat TLS n’a pas été renouvelé parce que nginx a été édité à la main après certbot. Rien n’est chiffré au repos comme la brochure le promettait, parce que le déploiement n’a en fait jamais eu deux domaines.
Ce qui se passe
Le modèle de menace de CryptPad repose sur deux noms d’hôte. Le nom principal sert l’application ; le nom sandbox sert les iframes de documents depuis une origine différente, de sorte que le contenu rendu ne puisse pas atteindre les clés de chiffrement détenues par la frame parente. Fusionnez les deux dans une seule origine et la politique same-origin disparaît — chaque pad « chiffré » se trouve à un XSS de fuiter sa clé symétrique. Le volume de données vit à /cryptpad/data et contient tous les pads, tous les blobs de compte, tous les journaux de canal ; il doit persister entre les déploiements et être couvert par la sauvegarde au niveau VM. L’inscription doit être contrôlée par liste blanche via restrictRegistration: true et une invitation manuelle d’admin, sinon quiconque connaît l’URL devient locataire. Nginx termine TLS et proxifie les websockets — les en-têtes d’upgrade comptent, sinon l’édition temps réel se dégrade en « sauvegarder et rafraîchir ». Le bloc CSP dans application_config.js est fragile ; ne l’éditez pas à la main sans lire d’abord customize.dist/application_config.js.
Comment vérifier
Les deux noms d’hôte doivent servir :443, et seulement :443 et :22 sur la machine :
ss -lntp | grep -E ':(80|443|3000|3001|3003)\b'
# 0.0.0.0:443 nginx
# 127.0.0.1:3000 cryptpad http
# 127.0.0.1:3001 cryptpad ws
# 127.0.0.1:3003 cryptpad admin
Isolation sandbox — la réponse sandbox doit inclure une CSP stricte et un host différent :
curl -sS -D - -o /dev/null https://sandbox.cryptpad.example.com/ | grep -iE '^(content-security-policy|host)'
Fermeture des inscriptions — l’endpoint admin doit refuser les inscriptions anonymes :
curl -sS -o /dev/null -w '%{http_code}\n' \
-X POST https://cryptpad.example.com/api/profile
# 401 ou 403
Si la CSP sandbox est absente ou que le POST d’inscription retourne 200 pour un corps quelconque, l’installation n’est pas prête pour la production — corrigez-la avant la première invitation.
Le correctif
Enregistrez le script ci-dessous sous /root/setup-cryptpad-ubuntu22.sh, puis exécutez-le. Il installe CryptPad sur une VM Ubuntu 22.04 propre, sous un compte de service non-root, avec les domaines principal et sandbox sur des certificats distincts, le volume de données persistant en /cryptpad/data, l’inscription verrouillée sur invitation admin, nginx terminant TLS avec les en-têtes d’upgrade requis pour les websockets, et certbot lié à un hook de renouvellement qui recharge nginx.
#!/usr/bin/env bash
set -euo pipefail
### Ubuntu 22.04 CryptPad clean VM installer
### Two domains: main + sandbox (REQUIRED for E2EE isolation)
### Persistent data volume at /cryptpad/data
### Registration locked; admin must invite manually
### No local backups; assumes VM-level backup
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
: "${CRYPTPAD_MAIN_DOMAIN:?Set CRYPTPAD_MAIN_DOMAIN=cryptpad.example.com}"
: "${CRYPTPAD_SANDBOX_DOMAIN:?Set CRYPTPAD_SANDBOX_DOMAIN=sandbox.cryptpad.example.com}"
: "${CRYPTPAD_EMAIL:?Set CRYPTPAD_EMAIL=ops@example.com for Let's Encrypt}"
CRYPTPAD_VERSION="${CRYPTPAD_VERSION:-2024.12.0}"
CRYPTPAD_USER="${CRYPTPAD_USER:-cryptpad}"
CRYPTPAD_HOME="${CRYPTPAD_HOME:-/cryptpad}"
echo
echo "========================================"
echo "CryptPad Ubuntu 22.04 Setup"
echo "========================================"
echo "Main: ${CRYPTPAD_MAIN_DOMAIN}"
echo "Sandbox: ${CRYPTPAD_SANDBOX_DOMAIN}"
echo
if [[ "${CRYPTPAD_MAIN_DOMAIN}" == "${CRYPTPAD_SANDBOX_DOMAIN}" ]]; then
echo "Main and sandbox domains must differ. Aborting."
exit 1
fi
echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
echo "==> Installing base packages"
apt-get -y install \
vim curl wget ca-certificates gnupg2 git \
chrony fail2ban unattended-upgrades \
ufw lsof tcpdump dnsutils tar gzip \
iproute2 net-tools openssl jq build-essential \
software-properties-common
echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true
echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-cryptpad.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
vm.max_map_count = 262144
SYSCTL
modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system
cat > /etc/security/limits.d/99-cryptpad.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
${CRYPTPAD_USER} soft nofile 64000
${CRYPTPAD_USER} hard nofile 64000
LIMITS
echo "==> Configuring UFW"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable
echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
set_sshd_option() {
local key="$1" value="$2"
if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
else
echo "${key} ${value}" >> /etc/ssh/sshd_config
fi
}
set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4
sshd -t
systemctl restart ssh
echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
echo "==> Configuring unattended-upgrades for security"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG
echo "==> Installing Node.js 20 via NodeSource"
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get -y install nodejs
echo "==> Creating cryptpad service user"
if ! id "${CRYPTPAD_USER}" >/dev/null 2>&1; then
useradd --system --home-dir "${CRYPTPAD_HOME}" --shell /usr/sbin/nologin "${CRYPTPAD_USER}"
fi
mkdir -p "${CRYPTPAD_HOME}/data" "${CRYPTPAD_HOME}/blob" "${CRYPTPAD_HOME}/blobstage" \
"${CRYPTPAD_HOME}/datastore" "${CRYPTPAD_HOME}/block" "${CRYPTPAD_HOME}/customize"
chown -R "${CRYPTPAD_USER}:${CRYPTPAD_USER}" "${CRYPTPAD_HOME}"
echo "==> Cloning CryptPad ${CRYPTPAD_VERSION}"
sudo -u "${CRYPTPAD_USER}" git clone https://github.com/cryptpad/cryptpad.git "${CRYPTPAD_HOME}/src"
cd "${CRYPTPAD_HOME}/src"
sudo -u "${CRYPTPAD_USER}" git checkout "${CRYPTPAD_VERSION}"
echo "==> Installing CryptPad dependencies"
sudo -u "${CRYPTPAD_USER}" npm ci --omit=dev
sudo -u "${CRYPTPAD_USER}" npm run install:components
echo "==> Writing config.js (main + sandbox + locked registration)"
cat > "${CRYPTPAD_HOME}/src/config/config.js" <<EOF
/* CryptPad production config */
module.exports = {
httpUnsafeOrigin: 'https://${CRYPTPAD_MAIN_DOMAIN}',
httpSafeOrigin: 'https://${CRYPTPAD_SANDBOX_DOMAIN}',
httpAddress: '127.0.0.1',
httpPort: 3000,
websocketPath: '/cryptpad_websocket',
adminEmail: '${CRYPTPAD_EMAIL}',
adminKeys: [],
inactiveTime: 90,
archiveRetentionTime: 30,
accountRetentionTime: -1,
maxUploadSize: 50 * 1024 * 1024,
premiumUploadSize: 150 * 1024 * 1024,
enableEmbedding: false,
logToStdout: false,
logLevel: 'info',
logFeedback: false,
verbose: false,
installMethod: 'unspecified',
filePath: './datastore/',
archivePath: './data/archive',
pinPath: './data/pins',
taskPath: './data/tasks',
blockPath: './block',
blobPath: './blob',
blobStagingPath: './blobstage',
decreePath: './data/decrees',
logPath: './data/logs',
restrictRegistration: true,
restrictSsoRegistration: true,
disableIntegratedTasks: false,
disableIntegratedEviction: true,
enforceMFA: true
};
EOF
chown "${CRYPTPAD_USER}:${CRYPTPAD_USER}" "${CRYPTPAD_HOME}/src/config/config.js"
chmod 600 "${CRYPTPAD_HOME}/src/config/config.js"
echo "==> Customize directory (preserves overrides across upgrades)"
sudo -u "${CRYPTPAD_USER}" cp -a "${CRYPTPAD_HOME}/src/customize.dist/." "${CRYPTPAD_HOME}/customize/"
ln -sfn "${CRYPTPAD_HOME}/customize" "${CRYPTPAD_HOME}/src/customize"
echo "==> systemd unit"
cat > /etc/systemd/system/cryptpad.service <<UNIT
[Unit]
Description=CryptPad — encrypted collaboration suite
After=network.target
[Service]
Type=simple
User=${CRYPTPAD_USER}
Group=${CRYPTPAD_USER}
WorkingDirectory=${CRYPTPAD_HOME}/src
ExecStart=/usr/bin/node ${CRYPTPAD_HOME}/src/server.js
Restart=on-failure
RestartSec=5
LimitNOFILE=64000
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
ReadWritePaths=${CRYPTPAD_HOME}
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
UNIT
systemctl daemon-reload
systemctl enable --now cryptpad
echo "==> Waiting for CryptPad on 127.0.0.1:3000"
for i in {1..120}; do
if ss -lntp | grep -q '127.0.0.1:3000'; then break; fi
sleep 2
done
if ! ss -lntp | grep -q '127.0.0.1:3000'; then
echo "CryptPad failed to listen on 127.0.0.1:3000"
journalctl -u cryptpad --no-pager -n 200 || true
exit 1
fi
echo "==> Installing nginx and certbot"
apt-get -y install nginx certbot python3-certbot-nginx
cat > /etc/nginx/sites-available/cryptpad <<NGINX
map \$http_upgrade \$connection_upgrade {
default upgrade;
'' close;
}
upstream cryptpad_main {
server 127.0.0.1:3000;
keepalive 32;
}
server {
listen 80;
listen [::]:80;
server_name ${CRYPTPAD_MAIN_DOMAIN} ${CRYPTPAD_SANDBOX_DOMAIN};
return 301 https://\$host\$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ${CRYPTPAD_MAIN_DOMAIN};
client_max_body_size 150M;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_connect_timeout 60s;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
location /cryptpad_websocket {
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection \$connection_upgrade;
proxy_pass http://cryptpad_main;
proxy_read_timeout 3600s;
}
location / {
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_http_version 1.1;
proxy_pass http://cryptpad_main;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name ${CRYPTPAD_SANDBOX_DOMAIN};
client_max_body_size 150M;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
proxy_connect_timeout 60s;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy strict-origin-when-cross-origin always;
location / {
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_http_version 1.1;
proxy_pass http://cryptpad_main;
}
}
NGINX
ln -sf /etc/nginx/sites-available/cryptpad /etc/nginx/sites-enabled/cryptpad
rm -f /etc/nginx/sites-enabled/default
nginx -t
systemctl enable --now nginx
systemctl reload nginx
echo "==> Requesting Let's Encrypt certificates (main + sandbox)"
certbot --nginx --non-interactive --agree-tos \
-m "${CRYPTPAD_EMAIL}" \
-d "${CRYPTPAD_MAIN_DOMAIN}" \
-d "${CRYPTPAD_SANDBOX_DOMAIN}" \
--redirect
systemctl enable --now certbot.timer
echo "==> Waiting for HTTPS listener"
for i in {1..30}; do
if ss -lntp | grep -q ':443'; then break; fi
sleep 1
done
echo "==> Final package update"
apt-get -y upgrade
echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|3000|3001|3003)\b' || true
echo
echo "Service:"
systemctl is-active cryptpad nginx fail2ban chrony || true
echo
echo "Sandbox isolation check (expect CSP header on sandbox response):"
curl -sS -D - -o /dev/null "https://${CRYPTPAD_SANDBOX_DOMAIN}/" | grep -iE 'content-security-policy' || true
echo
echo "Registration check (expect non-200 on profile POST without keys):"
curl -sS -o /dev/null -w '%{http_code}\n' -X POST "https://${CRYPTPAD_MAIN_DOMAIN}/api/profile" || true
echo
echo "Web UI: https://${CRYPTPAD_MAIN_DOMAIN}/"
echo
echo "First steps:"
echo "1. Register the first account from a browser on the main domain."
echo "2. Note its public signing key (Settings -> Account -> public key)."
echo "3. Add the key to adminKeys in ${CRYPTPAD_HOME}/src/config/config.js then 'systemctl reload cryptpad'."
echo "4. Visit /admin/ to invite the rest of the team via signed invite links."
echo "5. Confirm the persistent data volume at ${CRYPTPAD_HOME}/data is covered by your VM-level backup."
Rendez-le exécutable et lancez-le :
chmod 700 /root/setup-cryptpad-ubuntu22.sh
CRYPTPAD_MAIN_DOMAIN=cryptpad.example.com \
CRYPTPAD_SANDBOX_DOMAIN=sandbox.cryptpad.example.com \
CRYPTPAD_EMAIL=ops@example.com \
/root/setup-cryptpad-ubuntu22.sh
Le premier compte qui s’inscrit sur le domaine principal devient l’identité de départ — copiez sa clé publique de signature dans le tableau adminKeys de /cryptpad/src/config/config.js, rechargez le service, et utilisez /admin/ pour inviter le reste de l’équipe. Ne rouvrez pas restrictRegistration. Vérifiez que le domaine sandbox a son propre certificat TLS et que l’en-tête CSP est présent dans la réponse de l’origine sandbox uniquement ; sans cet en-tête, l’isolation du chiffrement disparaît. Confirmez que la sauvegarde au niveau VM couvre /cryptpad/data, /cryptpad/blob, /cryptpad/datastore et /cryptpad/block — ces quatre répertoires forment l’état complet de l’instance.
Faites tourner ce CryptPad de production sur la compute infogérée Stack Harbor avec patching, supervision et escalade Sev-1 incluses : Cloud Compute — ou parlons-en si vous souhaitez planifier la migration.