Aller au contenu

Déployer le constructeur de flux IA Flowise sur Ubuntu 22.04 (prêt pour la production)

Monter un Flowise durci sur Ubuntu 22.04 via Docker — backend PostgreSQL sur le réseau compose, SSO OIDC, gating par clé API sur les endpoints d'agent, nginx + Let's Encrypt.

On vous demande de monter Flowise pour que l’équipe produit puisse câbler des flux LangChain sans écrire de Python. Le conteneur démarre, le constructeur visuel charge, quelqu’un glisse un nœud OpenAI dans une chaîne, la démo passe bien. Six mois plus tard, l’interface Flowise est sur http://flowise.example.com avec un mot de passe administrateur par défaut que l’équipe n’a jamais roulé, l’endpoint /api/v1/prediction/<id> qui sert chaque chatflow est complètement ouvert, n’importe qui qui devine un identifiant de chatflow peut brûler la clé OpenAI, la base SQLite s’est corrompue deux fois parce que le conteneur a redémarré en pleine écriture, et la seule politique de rotation des secrets, c’est « personne ne sait où sont entreposés les identifiants ».

Ce qui se passe

Un déploiement Flowise qui sert réellement un flux LLM demande beaucoup plus que docker run flowiseai/flowise. La couche de persistance doit être PostgreSQL, pas le SQLite par défaut — chaque identifiant, chaque chatflow, chaque clé API que Flowise émet vit dans la base, et SQLite sous écritures concurrentes depuis des invocations d’agent se corrompt de manières qui ressemblent à des 500 fantômes. Postgres doit rester sur le réseau compose interne, jamais publié sur l’interface publique de l’hôte. L’interface doit s’asseoir derrière nginx avec Let’s Encrypt ; l’hôte ne doit publier que :443. L’endpoint de prédiction de chaque chatflow doit imposer une clé API Flowise — les chatflows sont non authentifiés par défaut, et un identifiant de chatflow fuité plus un endpoint non authentifié, c’est comme ça que des agents RAG finissent par faire tourner les prompts d’un attaquant sur votre facture LLM. Le SSO OIDC remplace le couple admin/mot de passe interne pour que l’identité chevauche le reste de votre IdP. La clé de chiffrement que Flowise utilise pour sceller les identifiants au repos doit être définie explicitement et persistée — la perdre signifie que chaque clé API stockée dans la base est illisible.

Comment vérifier

Après installation, les écouteurs sur l’hôte doivent être ceux-ci :

ss -lntp | grep -E ':(80|443|3000|5432)\b'
# 0.0.0.0:443  nginx
# 127.0.0.1:3000  flowise (via compose)

PostgreSQL sur 5432 ne doit pas apparaître côté hôte — il vit à l’intérieur du réseau compose. L’interface doit basculer vers OIDC et ne pas servir l’écran de connexion local :

curl -sS -o /dev/null -w '%{http_code}\n' https://flowise.example.com/api/v1/ping
# 200
curl -sS -o /dev/null -w '%{http_code}\n' \
  https://flowise.example.com/api/v1/prediction/$CHATFLOW_ID -X POST \
  -H 'Content-Type: application/json' -d '{"question":"hi"}'
# 401

Si l’appel de prédiction retourne 200 sans entête Authorization: Bearer, le gating est absent — supposez que l’endpoint est déjà scrapé.

Le correctif

Enregistrez le script ci-dessous sous /root/setup-flowise-ubuntu22.sh, puis exécutez-le. Il déroule sur une VM Ubuntu 22.04 fraîche : mise à jour de base, UFW (SSH + HTTP + HTTPS uniquement), durcissement SSH avec conservation de l’accès clé root, unattended-upgrades, Docker CE + plugin compose, une pile compose avec PostgreSQL sur le réseau interne et Flowise lié à 127.0.0.1:3000, mot de passe PG et FLOWISE_SECRETKEY_OVERWRITE générés aléatoirement et écrits dans /opt/flowise/.env en chmod 600, variables OIDC câblées pour l’IdP configuré, un utilisateur admin provisionné via les variables d’environnement de bootstrap, nginx qui termine TLS pour l’interface et l’API, Let’s Encrypt via le plugin nginx de certbot, et une boucle d’attente qui valide :3000 puis :443 avant de déclarer succès.

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 22.04 Flowise clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs and configures Docker + Flowise + PostgreSQL + nginx + Let's Encrypt
### OIDC SSO + Flowise API-key gating on chatflow endpoints
### No local backups; assumes VM-level backup
### Reboot remains manual

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${FLOWISE_DOMAIN:?Set FLOWISE_DOMAIN=flowise.example.com}"
: "${FLOWISE_EMAIL:?Set FLOWISE_EMAIL=ops@example.com for Let's Encrypt}"
: "${FLOWISE_ADMIN_EMAIL:?Set FLOWISE_ADMIN_EMAIL=admin@example.com}"
: "${OIDC_ISSUER:?Set OIDC_ISSUER=https://sso.example.com/application/o/flowise/}"
: "${OIDC_CLIENT_ID:?Set OIDC_CLIENT_ID}"
: "${OIDC_CLIENT_SECRET:?Set OIDC_CLIENT_SECRET}"
FLOWISE_VERSION="${FLOWISE_VERSION:-2.2.3}"
FLOWISE_ADMIN_PASSWORD="${FLOWISE_ADMIN_PASSWORD:-$(openssl rand -hex 24)}"
FLOWISE_PG_PASSWORD="${FLOWISE_PG_PASSWORD:-$(openssl rand -hex 24)}"
FLOWISE_SECRETKEY="${FLOWISE_SECRETKEY:-$(openssl rand -hex 32)}"
FLOWISE_JWT_SECRET="${FLOWISE_JWT_SECRET:-$(openssl rand -hex 32)}"

echo
echo "========================================"
echo "Flowise Ubuntu 22.04 Setup"
echo "========================================"
echo

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 \
  chrony fail2ban unattended-upgrades \
  ufw lsof tcpdump dnsutils tar gzip \
  iproute2 net-tools openssl jq \
  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-flowise.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
SYSCTL

modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system

echo "==> Setting file limits"
cat > /etc/security/limits.d/99-flowise.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root 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"
  local 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 ChallengeResponseAuthentication 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 Docker CE"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
  | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" \
  > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

systemctl enable --now docker

echo "==> Preparing /opt/flowise"
mkdir -p /opt/flowise/data /opt/flowise/secrets
chmod 700 /opt/flowise /opt/flowise/data /opt/flowise/secrets

cat > /opt/flowise/.env <<ENV
FLOWISE_VERSION=${FLOWISE_VERSION}
FLOWISE_DOMAIN=${FLOWISE_DOMAIN}
FLOWISE_ADMIN_EMAIL=${FLOWISE_ADMIN_EMAIL}
FLOWISE_ADMIN_PASSWORD=${FLOWISE_ADMIN_PASSWORD}
FLOWISE_PG_PASSWORD=${FLOWISE_PG_PASSWORD}
FLOWISE_SECRETKEY=${FLOWISE_SECRETKEY}
FLOWISE_JWT_SECRET=${FLOWISE_JWT_SECRET}
OIDC_ISSUER=${OIDC_ISSUER}
OIDC_CLIENT_ID=${OIDC_CLIENT_ID}
OIDC_CLIENT_SECRET=${OIDC_CLIENT_SECRET}
ENV

chmod 600 /opt/flowise/.env

cat > /opt/flowise/docker-compose.yml <<'COMPOSE'
services:
  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: flowise
      POSTGRES_PASSWORD: ${FLOWISE_PG_PASSWORD}
      POSTGRES_DB: flowise
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U flowise -d flowise"]
      start_period: 20s
      interval: 30s
      retries: 5
      timeout: 5s

  flowise:
    image: flowiseai/flowise:${FLOWISE_VERSION}
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      PORT: 3000
      DATABASE_TYPE: postgres
      DATABASE_HOST: postgres
      DATABASE_PORT: 5432
      DATABASE_NAME: flowise
      DATABASE_USER: flowise
      DATABASE_PASSWORD: ${FLOWISE_PG_PASSWORD}
      DATABASE_SSL: "false"
      FLOWISE_USERNAME: ${FLOWISE_ADMIN_EMAIL}
      FLOWISE_PASSWORD: ${FLOWISE_ADMIN_PASSWORD}
      FLOWISE_SECRETKEY_OVERWRITE: ${FLOWISE_SECRETKEY}
      JWT_AUTH_TOKEN_SECRET: ${FLOWISE_JWT_SECRET}
      JWT_REFRESH_TOKEN_SECRET: ${FLOWISE_JWT_SECRET}
      JWT_ISSUER: ${FLOWISE_DOMAIN}
      JWT_AUDIENCE: ${FLOWISE_DOMAIN}
      EXPRESS_SESSION_SECRET: ${FLOWISE_JWT_SECRET}
      ENABLE_OIDC_SSO: "true"
      OIDC_ISSUER_BASE_URL: ${OIDC_ISSUER}
      OIDC_CLIENT_ID: ${OIDC_CLIENT_ID}
      OIDC_CLIENT_SECRET: ${OIDC_CLIENT_SECRET}
      OIDC_BASE_URL: https://${FLOWISE_DOMAIN}
      DISABLE_FLOWISE_TELEMETRY: "true"
      CORS_ORIGINS: https://${FLOWISE_DOMAIN}
      IFRAME_ORIGINS: https://${FLOWISE_DOMAIN}
      APIKEY_PATH: /root/.flowise
    ports:
      - "127.0.0.1:3000:3000"
    volumes:
      - /opt/flowise/data:/root/.flowise
    ulimits:
      nofile:
        soft: 64000
        hard: 64000

volumes:
  pgdata:
    driver: local
COMPOSE

echo "==> Starting Flowise stack"
docker compose --env-file /opt/flowise/.env -f /opt/flowise/docker-compose.yml up -d

echo "==> Waiting for Flowise on 127.0.0.1:3000"
for i in {1..90}; 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 "Flowise failed to listen on 127.0.0.1:3000"
  docker compose -f /opt/flowise/docker-compose.yml logs --tail=200 flowise || true
  exit 1
fi

echo "==> Installing nginx and certbot"
apt-get -y install nginx certbot python3-certbot-nginx

cat > /etc/nginx/sites-available/flowise <<NGINX
upstream flowise_backend {
    server 127.0.0.1:3000;
    keepalive 32;
}

server {
    listen 80;
    listen [::]:80;
    server_name ${FLOWISE_DOMAIN};
    return 301 https://\$host\$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name ${FLOWISE_DOMAIN};

    client_max_body_size 100M;
    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 X-Frame-Options SAMEORIGIN always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;

    location /socket.io/ {
        proxy_set_header Upgrade \$http_upgrade;
        proxy_set_header Connection "upgrade";
        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://flowise_backend;
    }

    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://flowise_backend;
    }
}
NGINX

ln -sf /etc/nginx/sites-available/flowise /etc/nginx/sites-enabled/flowise
rm -f /etc/nginx/sites-enabled/default

nginx -t
systemctl enable --now nginx
systemctl reload nginx

echo "==> Requesting Let's Encrypt certificate"
certbot --nginx --non-interactive --agree-tos \
  -m "${FLOWISE_EMAIL}" -d "${FLOWISE_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 "Kernel:"
uname -r

echo
echo "SSH effective settings:"
sshd -T | grep -E '^(permitrootlogin|passwordauthentication|pubkeyauthentication) ' || true

echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|3000|5432)\b' || true

echo
echo "Containers:"
docker compose -f /opt/flowise/docker-compose.yml ps

echo
echo "Services:"
systemctl is-active docker nginx fail2ban chrony || true

echo
echo "Ping endpoint over HTTPS:"
curl -sS "https://${FLOWISE_DOMAIN}/api/v1/ping" || true

echo
echo "Secrets written to /opt/flowise/.env (mode 600). Move them to your secrets manager and remove the file from this host before going live."
echo "FLOWISE_SECRETKEY is the key that seals stored credentials at rest — losing it makes every stored API key in the database unreadable."

echo
echo "Bootstrap admin (replaced by OIDC after first login):"
echo "  ${FLOWISE_ADMIN_EMAIL} / ${FLOWISE_ADMIN_PASSWORD}"

echo
echo "Web UI:"
echo "https://${FLOWISE_DOMAIN}/"

echo
echo "First steps:"
echo "1. Sign in via OIDC, create the first chatflow."
echo "2. Open the chatflow API config and generate a Flowise API key."
echo "3. Wire every /api/v1/prediction/<id> caller to send 'Authorization: Bearer <key>'."
echo "4. Confirm anonymous prediction calls return 401."

Rendez-le exécutable et exécutez-le :

chmod 700 /root/setup-flowise-ubuntu22.sh
FLOWISE_DOMAIN=flowise.example.com \
FLOWISE_EMAIL=ops@example.com \
FLOWISE_ADMIN_EMAIL=admin@example.com \
OIDC_ISSUER=https://sso.example.com/application/o/flowise/ \
OIDC_CLIENT_ID=flowise \
OIDC_CLIENT_SECRET=... \
/root/setup-flowise-ubuntu22.sh

Le mot de passe administrateur de bootstrap est imprimé une seule fois à la fin — connectez-vous, configurez la correspondance de groupes OIDC, puis désactivez le compte local. Chaque chatflow que vous publiez doit recevoir une clé API Flowise assignée dans son panneau de configuration API avant qu’un client puisse l’appeler ; le script ne peut pas imposer cette étape parce que les chatflows n’existent pas encore au moment de l’installation. Déplacez le contenu de /opt/flowise/.env vers votre gestionnaire de secrets et gardez une copie documentée de FLOWISE_SECRETKEY_OVERWRITE dans un endroit durable — sans elle, la colonne d’identifiants chiffrés dans la base Flowise est perdue.

Exploitez le Flowise de production sur une plateforme applicative infogérée par Stack Harbor avec cadence de correctifs, supervision et escalade Sev-1 incluses : Plateforme applicative infogérée (Cloud PaaS).