Security baseline and engine scheduling

The keys, cookies, email, and sign-in allowlist that must be configured before going live, plus the hard constraints on engine scheduling and how to verify them.

This page has two parts:

  1. Security baseline: if it is not configured, the deployment should not go to production
  2. Engine scheduling: which machine and which engine a task lands on

1. Clear this table before going live

Production mode is determined solely by whether env in configs/security.json is the literal production. If it is written as prod, test, or left empty, the deployment is treated as development mode.

# Check Where it is configured Consequence if missing
1 Strong JWT_SECRET Environment variable JWT_SECRET, or the key pool in security.json Production startup is rejected
2 JWT key rotation pool jwt.secret_keys + kid_current in security.json Production startup is rejected
3 Credential encryption key credential_keys in security.json Production startup is rejected; credentials may become undecryptable
4 Database encryption key GRAPE_DB_ENCRYPTION_KEY or configs/crypto.json Sandbox/LLM credentials cannot be stored securely
5 Email channel configs/email.json or SMTP_HOST / RESEND_API_KEY Verification codes cannot be sent; production startup is rejected
6 COOKIE_SECURE=true Environment variable Production startup is rejected
7 A callback URL for each sign-in channel configs/oauth-providers.json / Admin → Sign-in channels Third-party sign-in fails
8 Sign-in allowlist Admin → Sign-in allowlist If the switch is enabled but the list is empty, all OAuth sign-ins are rejected

Multiple control-plane instances must use the same GRAPE_DB_ENCRYPTION_KEY and the same credential_keys. Configuring a different set on each machine produces "this machine can decrypt, that one cannot".

2. A complete security configuration

Step 1: Back up

sudo cp /etc/grape/grape.env /etc/grape/grape.env.bak-$(date +%F)
sudo cp configs/security.json configs/security.json.bak-$(date +%F) 2>/dev/null || true

Do not change keys without a backup. A wrong key change makes all existing sessions and credentials unusable.

Step 2: Generate keys

JWT secret:

python3 -c "import secrets; print(secrets.token_urlsafe(48))"

Credential encryption key (32 bytes):

python3 -c "import base64,secrets; print('prod:'+base64.b64encode(secrets.token_bytes(32)).decode())"

Database encryption key:

python3 -c "import base64,os; print(base64.urlsafe_b64encode(os.urandom(32)).decode())"

After generation, write the values only to configuration files or environment variables on the server. Do not commit them to a repository or paste them into an Issue.

Step 3: Write security.json

{
  "env": "production",
  "jwt": {
    "secret_keys": "prod-1:<jwt-secret>",
    "kid_current": "prod-1"
  },
  "credential_keys": "prod-1:<base64-32byte-key>"
}

Set file permissions so that only the service account can read it:

chmod 600 configs/security.json

Step 4: Configure environment variables

In /etc/grape/grape.env or the Docker .env:

COOKIE_SECURE=true
GRAPE_DB_ENCRYPTION_KEY=<base64-32byte-key>
JWT_SECRET=<strong-random-secret>

Step 5: Restart and verify

sudo systemctl restart grape-server grape-event-server grape-worker-server grape-insight-server

Verify:

  1. The services start and the log has no security gate errors
  2. Sign in once in a browser; the session works
  3. Over HTTPS, the cookie carries the Secure flag
  4. Create an engine credential; it can be used normally after saving
  5. Trigger a verification email; it arrives

3. Key rotation

JWT rotation

  1. Generate a new key
  2. Keep the old key in jwt.secret_keys and append the new key
  3. Point kid_current at the new key
  4. Restart the service
  5. Confirm that new sign-ins work and that old sessions still validate until they expire
  6. Keep the old key for at least one full session cycle before removing it

Format:

prod-1:<old-secret>,prod-2:<new-secret>

Do not point kid_current at a key that is not in the pool, or new tokens cannot be validated.

Credential encryption key rotation

  1. Generate a new key
  2. Put the new key first in the list and keep the old key
  3. Restart the service
prod-2:<new-key>,prod-1:<old-key>

The current implementation encrypts new data with the first key in the list, and the old key still decrypts historical data. Remove the old key only after confirming that all old data can be read and new data can be written.

Replacing the key without keeping the old one makes historical credentials undecryptable, which shows up as sign-in channels or model credentials suddenly failing.

4. Sign-in allowlist

Configuration location: Admin → Sign-in allowlist. Saving takes effect immediately; the database is the runtime authority.

configs/login-whitelist.json is imported into the database only on first startup, or used as a fallback when the database is unavailable; editing the file itself does not change the live decision.

Notes:

  • The allowlist matches by platform username
  • If the switch is enabled but the list is empty, all OAuth sign-ins are rejected (fail-closed)
  • Add people first, then enable the switch; never the other way around

Verify:

  1. Accounts on the list can sign in
  2. Accounts not on the list are rejected
  3. Turning the switch off restores access

5. Engine scheduling

The security baseline decides whether the deployment can go to production; engine scheduling decides where tasks land.

Configuration file

configs/engine-selection.json; copy engine-selection.example.json. Restart for changes to take effect.

{
  "enabled": true,
  "scopes": ["repo", "global", "local"],
  "rule": "order",
  "filters": {
    "only_online": true,
    "only_healthy": true,
    "only_installed": true
  },
  "local_priority": 90,
  "strict_scene_engines": true
}
Field Purpose
enabled Master switch
scopes Sources that participate in scheduling: repository-level / global / local
rule Selection rule; order means fall back in order
only_online / only_healthy / only_installed Filter out engines that are offline, unhealthy, or not installed
local_priority Local engine priority; higher is preferred
strict_scene_engines When a scene node already has an engine bound, an empty candidate list reports no available engine instead of falling back to the global pool

strict_scene_engines=true is the recommended production value. It exposes a wrongly bound engine immediately instead of silently running on another machine.

Verify scheduling

  1. In Observability → Devices and engines, confirm that the target engine is online and passes the health check
  2. Bind the engine to a node in the project scene, save, and apply
  3. Create a low-risk Issue
  4. Confirm in the node log which engine was actually used
  5. Stop the target engine, trigger the task again, and confirm that it reports "no available engine" instead of switching machines

This step verifies the hard constraint; it does not create a fault. Do it during a maintenance window.

6. Common failures

Symptom Likely cause Handling
Production startup is rejected Missing JWT/credential/email/Cookie configuration Fill in each item from the table in section 1
Users are signed out immediately after sign-in Wrong JWT key change, or kid_current is not in the pool Restore the backup and reconfigure with the old key kept
Engine credentials suddenly cannot be decrypted credential_keys was replaced and the old key was deleted Restore the old key and rotate again
All OAuth sign-ins are rejected The allowlist switch is on but the list is empty Add people first, then enable
Tasks always land on an unwanted machine The node has no engine bound, or the filters are too broad Bind engine_runtime_ids and enable strict mode
Reports no available engine The engine bound to the node is offline, or the filters excluded the available engine Check the health check and filters

7. Completion criteria

  • [ ] env in security.json is production
  • [ ] The JWT key pool and kid_current are configured, and the rotation plan is defined
  • [ ] credential_keys and GRAPE_DB_ENCRYPTION_KEY are configured and identical across instances
  • [ ] COOKIE_SECURE=true
  • [ ] The email channel actually delivers verification codes
  • [ ] People were added to the sign-in allowlist before it was enabled
  • [ ] Scene nodes have engines bound and strict mode is enabled
  • [ ] The engine-stop test was run and confirmed no silent machine switch

Architecture and deployment topologies | Object storage and email | Runtime and Worker | Engine overview