Running FlowAssembly on Kubernetes

FlowAssembly runs as a few small services that share one PostgreSQL database:

  • the web server, which people use in their browser and which other systems call;

  • the connector worker, which sends email and calls the organisation’s other systems;

  • the script worker, which runs the Python scripts projects use for calculations, each in a short-lived, locked-down pod of its own;

  • the scheduler, which fires reminders and deadlines when they fall due, and emails people when work is passed or reassigned to them, where you name a mail server in notifications.email;

  • ClamAV, the virus scanner that checks each file people add to a case before FlowAssembly keeps it.

Each can run as several copies for capacity and resilience. If one stops, Kubernetes restarts it, and work that was in progress is picked up again: nothing a person has submitted is lost.

This guide is for the people who install and run FlowAssembly.

Trying it on a development cluster

The development overlay brings everything needed: its own database, stand-ins for the policy registry and mail server, development users and the reference application, with a small example project whose step runs a script (examples/affordability). It is for trying FlowAssembly out, never for real data.

docker build -t flowassembly:dev .
docker build --target script-runtime -t flowassembly-script-runtime:dev .
kind create cluster --name flowassembly              # or any local cluster
kind load docker-image flowassembly:dev flowassembly-script-runtime:dev --name flowassembly
kubectl apply -k deploy/kubernetes/overlays/dev
kubectl wait --for=condition=complete job/flowassembly-seed --timeout=300s
kubectl port-forward svc/flowassembly-web 8000:80

Open http://127.0.0.1:8000 and sign in as bola (recruiter), chidi (location manager), efe (agency administration) or halima (supervisor), password flowassembly-dev. Chidi is also the loan officer in the affordability example.

To run FlowAssembly on one Windows or Linux machine as a stand-in for production, with a project pipeline deploying to it, see workstation.md.

Setting up a real environment

Make an overlay of your own next to overlays/dev, based on ../../base. It supplies six things:

  1. The images: your registry and tag, in the overlay’s images section, and the script runtime image in scripts.kubernetes.image. See Using the published images.

  2. The database: a managed or highly available PostgreSQL 16, outside the cluster. FlowAssembly applies its own schema changes when it starts.

  3. Settings: a ConfigMap named flowassembly-config with

    • flowassembly.yaml: the instance settings. They cover the database address, web addresses, sessions, logging, metrics and health checks, the mail server for notices, and where the files below are. Every service finds it through FA_CONFIG, which the base manifests set; nothing else comes from the environment;

    • identity.yaml: how people sign in to begin with (your LDAP directory, and local accounts for administrators if wanted). It seeds the instance’s sign-in sources; after that, administrators change them under Admin > Users > Authentication sources;

    • access.yaml: which directory groups hold which roles to begin with. It seeds the instance’s first access policy; after that, administrators change access under Admin > Users;

    • connectors.yaml: your mail server and other systems.

    See examples/instance for an annotated example of each.

  4. Secrets: a Secret named flowassembly-secrets with one key, secrets.yaml: every password, key and token, by name (examples/instance/secrets.example.yaml). The settings only name them: database.passwordSecret, web.sessionKeySecret (a long random value, stable across restarts), metrics.tokenSecret, files.keySecret (64 hexadecimal characters, openssl rand -hex 32; never change it, or files already kept cannot be read), and in the other files bindPasswordSecret and each connection’s secretRef.

    Use your usual secret management (for example External Secrets or Sealed Secrets); never commit real values. Before deploying, run fa config check --config flowassembly.yaml against the real files. It reports anything missing or unsafe without showing any secret.

    Or keep them in Vault or OpenBao. Put every secret, under its name, in one key/value (version 2) entry, and let the pods read it:

    secretStore:
      vault:
        address: https://vault.bank.example:8200
        caFile: vault-ca.pem                 # in the settings ConfigMap
        path: flowassembly/production        # in the secret/ engine (mount: to change it)
        auth:
          kubernetes: {role: flowassembly}
    

    In Vault, enable Kubernetes sign-in for your cluster, and make a role flowassembly bound to the namespace’s service accounts, with a policy that allows only read on secret/data/flowassembly/production. The base manifests do not give pods a service account token, so add one to each FlowAssembly deployment in your overlay, for Vault’s audience:

    # a patch for flowassembly-web; the same for flowassembly-scheduler (container
    # scheduler), flowassembly-worker and flowassembly-script-worker (container worker)
    spec:
      template:
        spec:
          initContainers:
            - name: migrate
              volumeMounts:
                - {name: vault-token, mountPath: /var/run/secrets/flowassembly/vault, readOnly: true}
          containers:
            - name: web
              volumeMounts:
                - {name: vault-token, mountPath: /var/run/secrets/flowassembly/vault, readOnly: true}
          volumes:
            - name: vault-token
              projected:
                sources:
                  - serviceAccountToken: {path: token, audience: vault, expirationSeconds: 3600}
    

    Secrets are read when a service starts: restart the deployments after changing one. A name may be in the secrets file or the store, never both; the database password can stay in the file, for example, while everything else moves. For a cloud secret manager (AWS Secrets Manager, Azure Key Vault, Google Secret Manager), let the External Secrets Operator fill the flowassembly-secrets Secret from it.

  5. Your web address: list the host name people use in web.allowedHosts (keep localhost for the probes), leave web.secureCookies on (the default), and put the web service behind your ingress with TLS. If your ingress adds X-Forwarded-For, list its addresses in web.trustedProxies so sign-in rate limits see real client addresses.

  6. Where scripts run: apply deploy/kubernetes/scripts beside your overlay, and set scripts in the instance settings:

    scripts:
      sandbox: kubernetes
      kubernetes:
        namespace: flowassembly-scripts
        image: registry.bank.example/flowassembly-script-runtime:0.1.0
        runtimeClass: gvisor        # optional, where your cluster offers it
    

    Build the script runtime image with docker build --target script-runtime . and push it with the main image. It holds Python, the script runner and the reviewed packages scripts may use (fa scripts packages list), nothing of the platform. If FlowAssembly runs in a namespace other than default, change the role binding’s subject in deploy/kubernetes/scripts/rbac.yaml to match.

  7. Files people add to cases: apply deploy/kubernetes/clamav beside your overlay, and set files in the instance settings:

    files:
      directory: /var/lib/flowassembly/files   # the flowassembly-files volume
      keySecret: files-key
      scanner: {host: flowassembly-clamav, port: 3310}
    

    The base manifests claim a 5 GB volume, flowassembly-files, mounted by every web server, the connector worker and the scheduler. Files are encrypted before they are written, but the volume holds personal documents: back it up with the database, as one. On a cluster of several machines, give it a storage class that offers ReadWriteMany, so web servers on different machines share it. ClamAV needs about 1 GB of memory and to reach database.clamav.net for new virus definitions. Without a scanner, only a development instance keeps files.

    Or keep them in object storage (S3, MinIO, or another S3-compatible store), for a cluster without ReadWriteMany volumes. Files are encrypted before they are sent, so the store’s operator sees nothing of them:

    files:
      objectStorage:
        endpoint: https://s3.eu-west-1.amazonaws.com
        bucket: bank-flowassembly-files
        region: eu-west-1
        accessKeyId: <the access key id>       # not secret
        secretAccessKeySecret: files-s3        # the secret access key, in the secrets file
        # caFile: /etc/flowassembly/ca/minio.pem   # a store with its own CA
        # prefix: case-files                       # the default
      keySecret: files-key
      scanner: {host: flowassembly-clamav, port: 3310}
    

    Give the access key only reading, writing and deleting objects in that bucket. Then remove the flowassembly-files volume from your overlay. Back the bucket up with the database, as one; versioning on the bucket helps. Files already kept in a volume are not moved by changing the setting.

How scripts are kept apart

Each script run gets a pod of its own in the flowassembly-scripts namespace, deleted as soon as the run ends:

  • The namespace enforces Kubernetes’ restricted pod security standard. A script pod runs as a non-root user with every capability dropped, a read-only file system and a small private /tmp.

  • It has no credentials: no service account token, and the namespace has no secrets to mount.

  • Its network reaches the script worker’s broker port and nothing else: no other pod or service, no DNS, no internet. Your cluster’s network plugin must enforce network policies (most do; check yours). Some plugins, kind’s among them, do not apply them to the Kubernetes API server’s own address; a script pod holds no token, so the API treats it as anonymous and refuses it.

  • It has the memory limit the script declares, a CPU limit, and a deadline after which Kubernetes stops it. A quota caps the namespace at 20 pods.

  • It fetches its script and the case fields it may read from the broker, with a token valid for that run only, and returns its result there. Case data never passes through the Kubernetes API.

  • The broker gives out only the secrets the script declares, and calls only the destinations it declares.

The script worker may create, read and delete pods in that namespace, and nothing else. A run costs one to three seconds for its pod to start; the dashboard shows how long starts take. Where the cluster offers gVisor (for example GKE Sandbox), runtimeClass puts each script behind gVisor’s own kernel as well.

Using the published images

Every change merged into FlowAssembly publishes both images to GitHub’s container registry, and every release tag publishes them under its version:

Image

What runs it

ghcr.io/dave-aganran/flowassembly

every service: web, workers, scheduler, migrations

ghcr.io/dave-aganran/flowassembly-script-runtime

script pods

Tags are the version (such as 0.2.0), main for the latest merged change, and sha-<commit>. Deploy by digest (@sha256:...) so what runs cannot change under you. The registry is private for now; give your cluster a pull secret for it.

Each image is signed with FlowAssembly’s image key and carries a record of how it was built (the repository, the commit and the build steps) and an SBOM of what it holds. Check an image before you use it, with the public key in deploy/signing/flowassembly-images.pub:

cosign verify --key deploy/signing/flowassembly-images.pub \
  --insecure-ignore-tlog=true ghcr.io/dave-aganran/flowassembly@sha256:...
docker buildx imagetools inspect ghcr.io/dave-aganran/flowassembly@sha256:... \
  --format '{{ json .Provenance }}'

The signature is kept in the registry beside the image and is not written to Sigstore’s public log (hence --insecure-ignore-tlog), because the repository is private. A cluster policy controller such as Kyverno or the Sigstore policy controller can require the signature before a pod starts, with the same key.

Sizing

Service

Copies

Each copy

Web server

2 or more

1 process x 8 threads; about 250m CPU and 400 MB

Connector worker

1 or more

about 100m CPU and 256 MB

Script worker

1 or more

about 100m CPU and 256 MB, and a pod per script run (its declared memory, up to 500m CPU)

Scheduler

1 (more is safe)

about 100m CPU and 256 MB

ClamAV

1

little CPU when idle (it asks for 50m), more while it scans; 1 GB, up to 2 GB while new definitions load

Each web copy runs one process: a process keeps its own counts of requests and sign-ins, so with one process per copy every scrape of /metrics sees all of them. Scale by adding copies rather than processes.

Database connections: each web copy uses up to its thread count plus two (10 by default); each worker and scheduler uses up to 4. Two web copies, one worker and one scheduler need about 30 connections.

Watching it

  • Every service writes one JSON object per log line, ready for your log collector. Each line is a named event (case.started, job.dead_lettered, signin.refused and so on) with the service, version and whichever of the request, user, case, task and job it concerns. Lines never carry case data values or secrets.

  • /metrics on the web service (the metrics token as a bearer token) shows cases started and finished, task waiting times, form refusals, decisions, calls to other systems, waiting work, failed steps, sign-ins and response times. Workers and the scheduler serve their own /metrics on port 8081.

  • docs/operations/telemetry.md lists every event, metric and trace span, what it means, and what to watch for.

  • Alerts and a dashboard: deploy/monitoring holds alert rules, a PodMonitor and a Grafana dashboard for clusters running the Prometheus Operator (for example kube-prometheus-stack). Apply it with kubectl apply -k deploy/monitoring after creating the flowassembly-metrics-token Secret it describes. Every alert links to its section of docs/operations/runbook.md.

  • Traces: set tracing.endpoint in the instance settings to your OpenTelemetry collector (OTLP over HTTP) to follow a case from a person’s request through the background steps to the calls FlowAssembly makes to other systems. Those calls carry the traceparent header, so the other systems’ own traces can join. Log lines carry trace_id either way. tracing.detail: [database, engine] adds finer spans while you look into a slow case (docs/operations/runbook.md, FlowAssemblyWebSlow); leave it out otherwise.

  • /healthz and /readyz on every service are used by the probes.

Not yet

  • Packages for scripts beyond the reviewed set, chosen by your organisation (backlog B-075).

  • Backup and restore procedures are part of the nonfunctional checkpoint (backlog B-015).