OpenWork Labs Access Policy + Usage Logging Setup
Use this guide when deploying hosted OpenWork Labs (for example labs.brainforge.ai) and you need an internal-only access gate with auditable usage logs.
What this setup does
- Enforces a shared access gate before non-health OpenWork routes can be used.
- Keeps health checks open (
/health,/w/:id/health) for deployment liveness probes. - Emits request logs with access and actor metadata for internal rollout tracking.
This is intentionally a lightweight, reversible policy for pre-public rollout.
Required environment variables
Set on the OpenWork host service:
OPENWORK_LABS_ACCESS_TOKEN(required to enable the gate)OPENWORK_TOKEN(existing OpenWork API bearer token)OPENWORK_HOST_TOKEN(existing owner/admin token)
Recommended:
OPENWORK_LOG_FORMAT=jsonOPENWORK_LOG_REQUESTS=true
Optional tuning:
OPENWORK_LABS_ACCESS_COOKIE_NAME(defaultopenwork_labs_access)OPENWORK_LABS_ACCESS_LOGIN_PATH(default/labs-access)OPENWORK_LABS_ACCESS_QUERY_PARAM(defaultlabs_access_token)OPENWORK_LABS_ACCESS_COOKIE_MAX_AGE_SECONDS(default43200, max2592000)
Access flow
When OPENWORK_LABS_ACCESS_TOKEN is set:
- Browser users are redirected to
/labs-accessand submit the token once. - Server sets an HttpOnly cookie and redirects back.
- API/script users can send
X-OpenWork-Access-Token: <token>instead of using the form. - Bootstrap links can use
?labs_access_token=<token>once; server converts it into a cookie and removes the query param.
Unauthenticated API requests return:
{ "code": "labs_access_required", "message": "Labs access token required" }Rotation + recovery runbook
Rotate the Labs access token
- Generate a new token (1Password item or secure random generator).
- Update
OPENWORK_LABS_ACCESS_TOKENin deployment env. - Redeploy/restart the OpenWork host service.
- Share the new token with internal users through approved internal channel.
Result: existing Labs access cookies are immediately invalid after restart because they contain the old token.
Recover access
If a user is locked out:
- Send them the current Labs token.
- Ask them to open
https://labs.brainforge.ai/labs-access. - Submit token, then retry
https://labs.brainforge.ai/ui.
If needed, force reset by rotating OPENWORK_LABS_ACCESS_TOKEN again.
Inspect usage logs after test sessions
With OPENWORK_LOG_FORMAT=json, filter host logs by:
labs.access.policy_enabledlabs.access.sourcelabs.access.cookie_issuedactor.type,actor.scope,actor.client_id,actor.token_hashclient.ip,client.user_agent
Example (local/container):
docker compose logs openwork-host | rg "labs\\.access|actor\\.|client\\."Example (Railway):
railway logs --service <service-name> | rg "labs\\.access|actor\\.|client\\."Security notes
- Do not commit real token values.
- Keep the Labs token distinct from
OPENWORK_TOKENto avoid exposing API auth semantics as the rollout gate. - Prefer passing token by login form or header; avoid persistent sharing of tokenized URLs.