Skip to content

Security: LikelyCause/rainforest

Security

docs/security.md

Security

What Rainforest protects, how, and what you need to set up yourself. The deployment steps are in Deployment.

Choose the right sign-in mode

Use RAINFOREST_AUTH_MODE=oidc for anything but a single person or a trusted network. Pick mode lets anyone who reaches the UI act as any user, including an admin.

Network

Service Listens on
ui (UI_PORT, 8080) every interface, so you can reach it over the LAN
api (API_PORT) and db (DB_PORT) localhost only
mlflow no published port
keycloak profile (KEYCLOAK_PORT, 8081) every interface

Every API route needs the session cookie, file downloads included, except /health, sign-in and profile pictures. The MLflow UI at /mlflow/ needs it too, and answers 403 unless MLFLOW_UI_OPEN=true: its pages show every project's runs and can't apply project access.

On plain HTTP, the session cookie crosses the network unencrypted. Anywhere beyond a trusted LAN, put the UI behind a TLS proxy that sets X-Forwarded-Proto.

Set RAINFOREST_ALLOWED_HOSTS to the names and addresses you use, so a DNS-rebound name is refused outright.

Requests that change data

  • Browser requests that change data must be same-origin: Origin or Referer must match the host. http://localhost:5173 and http://127.0.0.1:5173 are also accepted, for npm run dev.
  • A request body must be application/json, or multipart/form-data for uploads. This blocks cross-site form posts.

Sessions

  • The session cookie holds only the user id and their session version. It is signed (HMAC) with the session secret.
  • It is HttpOnly and SameSite=Strict, and lasts 7 days. It is Secure when the request came over HTTPS.
  • Every request checks that the user is still active and the version current. So deactivation and role changes apply at once.
  • Rotating RAINFOREST_SESSION_SECRET signs everyone out. When it is empty, the secret is generated on first start and kept in /data/session_secret.

OIDC sign-in

  • Every sign-in uses PKCE (S256), state and nonce.
  • The state travels in a short-lived signed cookie. It is SameSite=Lax, which the provider's redirect back needs, and scoped to /api/auth/oidc.
  • The PKCE verifier and nonce are derived from the state with the server's secret, so nothing else is stored.
  • ID tokens are checked against the provider's published keys (asymmetric algorithms only), issuer, audience, expiry and nonce.
  • Provider tokens are never stored or sent to the browser.
  • Users are matched by the provider's subject id, never by email.

The reference Keycloak is for development only. Its client secret and passwords are public.

Endpoint keys

  • A key opens only POST /predict/<its slug> and the GETs of that slug's /schema and /openapi.json. It isn't a session and reads nothing else: on /api/ or on another endpoint it is 401.
  • Only its SHA-256 and first 8 characters are stored, and it is compared in constant time. It is shown once and never logged. The SQL console reads only dataset files, so it can't reach the keys table at all.
  • The predict call with a key is exempt from the same-origin check: a browser never sends a key on its own, so it can't be forged cross-site. With a session it is checked like any other write.
  • Revoking a key stops it at once. A retired endpoint refuses its keys. See Keys.
  • The serve process is a separate process with its own checks: it reads the models only from bundles under the data volume, which it mounts read-only but for its request samples (/data/serving). The API process never loads a model.

API tokens

  • A user's API token (rfu_ and 32 random URL-safe characters) stands in for their session on every /api/ route except sign-in. It acts with the user's current roles, so a token of someone who is a viewer in a project is refused writes there like their session. A Lab's token is refused on admin routes, token minting and membership changes.
  • Only its SHA-256 and first 8 characters are stored. It is shown once, when it is created, and never logged. The SQL console can't reach the tokens table.
  • Every request looks the token up afresh: a revoked or expired token, or one of a deactivated user, is refused (401) on its next use. Only the last_used_at write is held to once a minute.
  • A request with a token is exempt from the same-origin check: a browser never sends one on its own, so it can't be forged cross-site.
  • Under /api/auth/ a token opens only /api/auth/me and /api/auth/tokens. Sign-in, sign-out and /api/auth/check (MLflow) ignore it.
  • In oidc mode a user's role is refreshed only when they sign in. Someone removed from the provider's groups keeps working tokens until they sign in again or an admin deactivates them in Rainforest.

Profile pictures

  • Pictures are open at a URL naming the picture's hash, because the sign-in page shows them.
  • Uploads are decoded and re-encoded as WebP, never stored as sent.
  • Pictures are served with nosniff and a sandboxing content policy.

Notebooks

A notebook Lab runs a user's own code, so it is isolated: a pod of its own with no app secrets, only a token for that user, reached through a gateway behind the session, with a worker whose Kubernetes permissions cover one namespace. Give Rainforest a namespace of its own and use OIDC. See How a Lab is isolated.

Projects

  • Every top-level object belongs to one project, and a person reads and changes only what their role in it allows. The structural guard is row-level security: the API's queries run as a role that does not own the tables, and each request carries its scope (the projects the person is in, and what is shared into them) as session settings. A forgotten WHERE can't leak another project's rows. A lint test and the route matrix check the routes on top of it.
  • Outside your projects an object is a 404, never a 403, and a private project's slug can't be probed. See Projects.
  • No instance-wide data access exists. An admin manages people and projects but opens a private project's contents only after an owner adds them (or a second person, who adds them): there is no break-glass path and no admin bypass in the policies. Every access change is a row in the audit log.
  • A membership or share that lapses stops API reads at once, trims the job stream within 30 seconds and restarts a running Lab within three minutes. What a borrower built stays readable to them.
  • The database needs direct connections, not a transaction-pooling proxy. See Deployment.

Connection secrets

The passwords, access keys and connection strings saved with a connection are encrypted with Fernet under RAINFOREST_SECRET_KEY and stored in a table only the system scope can read: the SQL console and every project role are closed out of it by row-level security. They are decrypted in one place, only inside an API request that tests, browses or previews, or inside the pull job, and never appear in a response, a log line, a job, the audit log or an error message. A database dump without the key reveals nothing.

  • The key. Set RAINFOREST_SECRET_KEY to one or more Fernet keys, comma separated: the first encrypts and every one decrypts. When it is empty, Compose generates a key once into DATA_DIR/secret_key (mode 0600) on the data volume, next to the Parquet copies. Back it up apart from the database dump. Losing it means entering every saved secret again. On Kubernetes it is secrets.values.secretKey, required.
  • Rotating. Prepend the new key (RAINFOREST_SECRET_KEY=new,old), restart, run python -m app.connections rotate in the API container or pod, which re-encrypts every secret under new all or nothing, then drop old and restart. The run is audited as connection.rotate.
  • Bound to where it connects. Changing where a saved secret connects needs the secret again, so a stored password can't be sent to an address someone else chose.

Connections

A connection reaches out from the API and worker, so what it may reach is limited.

  • The deny list. RAINFOREST_CONNECT_DENY lists address ranges no connection may reach: loopback, link-local, multicast, unique-local IPv6 and the cloud metadata addresses by default. The chart adds the cluster's pod and service ranges (connections.denyCidrs), so a contributor can't point a pull at another pod, a service or the Kubernetes API. Set them to your cluster's ranges. Aliases count: localhost, 127.1, 2130706433, ::ffff:127.0.0.1 and NAT64 forms are the addresses inside them, and a name that resolves to the database, MLflow or the serve process is refused.
  • The allowance. Only an admin, and only on an instance-wide connection, can allow a private range (allow_cidrs). It never reopens loopback, link-local, the cloud metadata addresses or Rainforest's own services: on Compose the stack's services, and on Kubernetes also the IP of every pod in the release's namespace (read through the notebook spawner's Kubernetes access, refreshed every minute, never shrinking, and connections are refused until the first read). So with the cluster's pod range allowed, a connection reaches other pods in it but not Rainforest's. A range covering any always-closed address is refused when saved, 0.0.0.0/0 included. A project connection can't have a range, and a draft test of a project connection can't carry one either.
  • Only a checked address is used. Every connection goes to an address checked at that moment, never to a name that could resolve differently a moment later. Postgres connects to the checked address (hostaddr). S3 over http is told the checked address as its endpoint; over https, and for AWS, it goes through a small in-process proxy that checks each host when the client asks for it, with TLS still verified end to end. MongoDB's connect function is replaced, so every socket it opens, including replica-set members the server advertises, is checked and opened to the checked address.
  • Nothing from the server's environment. A Postgres connection never uses the API's own PG* variables or password file, and an S3 project connection never falls back to the server's AWS credentials.
  • Read-only, in plain words. Every Postgres pull runs in a read-only transaction and as one statement, so it can't change data. That stops writes, not side effects: a SELECT can still call functions the database user may call, such as pg_terminate_backend, pg_advisory_lock, pg_sleep (bounded by the timeouts), dblink, lo_export or pg_notify. What limits that is the user you give Rainforest. Use one with SELECT only, NOSUPERUSER, outside pg_signal_backend and pg_read_server_files, and without dblink. A MongoDB filter and projection reach the server as written, so the same applies: use an account that can only read.
  • What remains. A MongoDB replica-set member the server advertises can name another host. The guard checks each one, but a private range an admin allowed can reach them. An S3 redirect to another host is refused. Network reachability (egress rules, network policies) is yours to set.
  • Who sees a connection. Project connections follow the project's roles, and an admin has no way into them (Projects); viewers and reviewers see a name and a kind. Instance-wide connections are managed by admins and used only from the projects they choose.

Privacy between users

  • An assessment is private to its assessor while the version is assessing. See Assessing.
  • A personal experiment is private while its version is assessing. See Privacy.
  • The SQL console is DuckDB over the Parquet files of the datasets you can see, and nothing else: no Postgres, no other project's dataset, no file, network or extension access. See SQL.
  • MLflow has no project access control (its UI is closed by default), and runs in private experiments wait. See MLflow.
  • A Lab, and the log of a headless notebook run, belong to their user alone, admins included. See Notebooks.
  • The lineage panel leaves out what you may not see: a private experiment and what hangs off it are not drawn, and asking for one answers 404.
  • Viewers are read-only in their project. The API refuses their writes with 403.

Storage

Settings › Storage and its clean-up are for admins: the report names every item on disk, private experiments' exports included. The clean-up removes only what its dry run listed and only what nothing references; compositions, registry bundles, datasets, notebooks and trained models' files are never removed by it.

There aren't any published security advisories