Skip to content

Deploying Flowise AI workflow builder on Ubuntu 22.04 (production-ready)

Stand up a hardened Flowise on Ubuntu 22.04 via Docker — PostgreSQL backend on the compose network, OIDC SSO, API-key gating on agent endpoints, nginx + Let's Encrypt.

You’ve been asked to stand up Flowise so the product team can wire LangChain flows without writing Python. The container starts, the visual builder loads, somebody drags an OpenAI node into a chain, the demo lands well. Six months later, the Flowise UI is on http://flowise.example.com with a default admin password the team never rotated, the /api/v1/prediction/<id> endpoint that fronts every chatflow is wide open so anyone who guesses a chatflow id can burn through the OpenAI key, the SQLite database has corrupted twice because the container restarted mid-write, and the only secret rotation policy is “nobody knows where the credentials are stored.”

What’s happening

A Flowise deployment that actually fronts an LLM workflow needs more than docker run flowiseai/flowise. The persistence layer should be PostgreSQL, not the default SQLite — every credential, every chatflow, every API key Flowise issues lives in the database, and SQLite under concurrent writes from agent invocations corrupts in ways that look like phantom 500s. Postgres has to stay on the internal compose network, never published to the host’s public interface. The UI must sit behind nginx with Let’s Encrypt; the host should publish :443 only. Every chatflow’s prediction endpoint has to enforce a Flowise API key — chatflows are unauthenticated by default, and a leaked chatflow id plus an unauthenticated endpoint is how RAG agents end up running attacker prompts against your model bill. OIDC SSO replaces the built-in admin/password so identity rides with the rest of your IdP. The encryption key Flowise uses to seal credentials at rest has to be set explicitly and persisted — losing it means every stored API key in the database is unreadable.

How to verify

After install, the listeners on the host should be these:

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

PostgreSQL on 5432 must not appear on the host at all — it lives inside the compose network. The UI must redirect to OIDC and not serve the legacy login:

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

If the prediction call returns 200 without an Authorization: Bearer header, the gating is missing — assume the endpoint is being scraped.

The fix

Save the script below as /root/setup-flowise-ubuntu22.sh, then run it. It runs on a fresh Ubuntu 22.04 VM: base update, UFW (SSH + HTTP + HTTPS only), SSH hardening with root key preserved, unattended-upgrades, Docker CE + compose plugin, a compose stack with PostgreSQL on the internal network and Flowise bound to 127.0.0.1:3000, randomly generated PG password and FLOWISE_SECRETKEY_OVERWRITE written to /opt/flowise/.env with chmod 600, OIDC variables wired for the configured IdP, an admin user provisioned via the bootstrap env, nginx terminating TLS for the UI and API, Let’s Encrypt via the certbot nginx plugin, and a poll loop that waits for :3000 and :443 before declaring success.

#!/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."

Make it executable and run it:

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

The bootstrap admin password is printed once at the end — sign in, configure the OIDC group mapping, then disable the local account. Every chatflow you publish must have a Flowise API key assigned in its API configuration panel before any client is allowed to call it; the script intentionally cannot enforce that step because chatflows do not exist yet. Move the contents of /opt/flowise/.env into your secrets manager and keep a documented copy of FLOWISE_SECRETKEY_OVERWRITE somewhere durable — without it, the encrypted credentials column in the Flowise database is gone.

Run the production Flowise on a Stack Harbor-managed app platform with patch cadence, monitoring, and Sev-1 escalation built in: Managed app platform (Cloud PaaS).