Pre-flight Checks
Problem Description
Engram Cloud currently treats token and project administration as deploy-time configuration:
ENGRAM_CLOUD_TOKEN is read from the environment at server startup.
ENGRAM_CLOUD_ALLOWED_PROJECTS is read from the environment at server startup.
- Adding or rotating a sync token requires editing environment/configuration and restarting or recreating the container.
- Allowing or denying a project requires editing
ENGRAM_CLOUD_ALLOWED_PROJECTS and restarting or recreating the container.
- The local
engram cloud enroll <project> state and the server-side allowed-project policy are managed through separate workflows, which makes the operational model feel manual and fragile.
This is painful for standalone/self-hosted cloud deployments. Operators should not need to treat Docker environment variables as the admin UI for routine token and project policy changes.
The desired improvement is not a SaaS identity system. Engram should remain local-first and standalone, but cloud policy should be administrable at runtime.
Proposed Solution
Add a standalone DB-backed cloud admin policy layer for tokens and projects.
High-level behavior:
- Store cloud admin/sync tokens in the cloud database.
- Store only secure token hashes, never plaintext tokens.
- Return generated token plaintext only once at creation time.
- Store project sync policy in the cloud database using explicit
allowed / denied project rows.
- Keep
ENGRAM_CLOUD_TOKEN as a bootstrap seed for the first active admin-capable token.
- Keep
ENGRAM_CLOUD_ALLOWED_PROJECTS as a bootstrap seed for the initial project policy.
- After initial seeding, routine administration happens through CLI commands, not by editing env vars.
- Server auth and project policy checks read current DB state per request, or through an explicitly safe refresh strategy, so changes take effect without Docker/server restart.
- Preserve the existing local-first model: local enrollment remains a local decision; cloud policy remains server-side enforcement.
- Preserve loud failure behavior: denied/unknown projects should return an explicit policy error rather than silently dropping data.
Suggested CLI surface:
engram cloud token add --label "laptop"
engram cloud token list
engram cloud token revoke --id 123
engram cloud project allow my-project
engram cloud project deny my-project
engram cloud project list
Suggested server-side data model:
cloud_admin_tokens
id
prefix
label
token_hash
created_at
revoked_at
last_used_at
cloud_allowed_projects
project
status (allowed / denied)
created_at
updated_at
updated_by
Acceptance Criteria
Non-Goals
This issue intentionally does not propose:
- organizations
- managed users
- invitations
- username/password login
- RBAC roles
- SSO / external identity providers
- billing / tenant management
- a SaaS-style control plane
- changing sync payload formats
- changing the core chunk/mutation sync protocol
The goal is a standalone operational improvement: make token and project policy manageable without Docker restarts, while keeping Engram's local-first and single-binary philosophy intact.
Affected Area
Sync (multi-instance)
Alternatives Considered
1. Hot reload for environment variables
The server could reload ENGRAM_CLOUD_TOKEN and ENGRAM_CLOUD_ALLOWED_PROJECTS without restart.
This removes the immediate restart pain, but keeps Docker/env vars as the admin interface. It is still manual, hard to audit, and awkward for normal operations.
2. Wildcard allowlist
Issue #260 proposes wildcard support for ENGRAM_CLOUD_ALLOWED_PROJECTS.
That helps local development, but it weakens project policy rather than making policy easier to administer. It also does not solve token creation/revocation.
3. Project-scoped bearer tokens
Issue #274 proposes project-scoped bearer tokens. That is related and in scope, but still needs a concrete persistence/administration model.
This issue proposes a smaller standalone foundation: DB-backed token and project policy administration first.
4. Managed users / per-user sync tokens
Issue #348 proposes managed users, per-user tokens, dashboard login, and project grants.
That may be useful later, but it is intentionally larger than this issue. For standalone/self-hosted deployments, token/project policy in DB is enough to remove the operational pain without building an identity platform.
Related Issues / PRs
Additional Context
This issue is meant to be reviewable as a focused cloud administration improvement.
A possible implementation can be split into small PRs:
-
Storage foundation
- Add token and project policy tables.
- Add cloudstore CRUD.
- Add live DB tests.
-
Auth/bootstrap
- Add token generation, validation, revocation behavior.
- Seed from
ENGRAM_CLOUD_TOKEN when DB has no active tokens.
- Seed project policy from
ENGRAM_CLOUD_ALLOWED_PROJECTS when policy table is empty.
-
Server enforcement
- Route auth and project policy checks through DB-backed policy.
- Return structured auth/policy errors.
- Preserve existing sync contracts.
-
CLI admin
- Add token and project commands.
- Ensure changes take effect on the next request without restart.
-
Docs and compose examples
- Explain first-start bootstrap seeds.
- Explain runtime CLI administration.
- Clarify that env vars are no longer the ongoing admin surface.
This keeps the work modular and avoids turning Engram Cloud into a SaaS identity platform.
Pre-flight Checks
status:approvedbefore a PR can be openedProblem Description
Engram Cloud currently treats token and project administration as deploy-time configuration:
ENGRAM_CLOUD_TOKENis read from the environment at server startup.ENGRAM_CLOUD_ALLOWED_PROJECTSis read from the environment at server startup.ENGRAM_CLOUD_ALLOWED_PROJECTSand restarting or recreating the container.engram cloud enroll <project>state and the server-side allowed-project policy are managed through separate workflows, which makes the operational model feel manual and fragile.This is painful for standalone/self-hosted cloud deployments. Operators should not need to treat Docker environment variables as the admin UI for routine token and project policy changes.
The desired improvement is not a SaaS identity system. Engram should remain local-first and standalone, but cloud policy should be administrable at runtime.
Proposed Solution
Add a standalone DB-backed cloud admin policy layer for tokens and projects.
High-level behavior:
allowed/deniedproject rows.ENGRAM_CLOUD_TOKENas a bootstrap seed for the first active admin-capable token.ENGRAM_CLOUD_ALLOWED_PROJECTSas a bootstrap seed for the initial project policy.Suggested CLI surface:
engram cloud token add --label "laptop" engram cloud token list engram cloud token revoke --id 123 engram cloud project allow my-project engram cloud project deny my-project engram cloud project listSuggested server-side data model:
cloud_admin_tokensidprefixlabeltoken_hashcreated_atrevoked_atlast_used_atcloud_allowed_projectsprojectstatus(allowed/denied)created_atupdated_atupdated_byAcceptance Criteria
ENGRAM_CLOUD_TOKENremains backward-compatible as a bootstrap seed when the DB has no active token rows.ENGRAM_CLOUD_ALLOWED_PROJECTSremains backward-compatible as a bootstrap seed when the DB has no project policy rows./sync/*route shapes remain unchanged.Non-Goals
This issue intentionally does not propose:
The goal is a standalone operational improvement: make token and project policy manageable without Docker restarts, while keeping Engram's local-first and single-binary philosophy intact.
Affected Area
Sync (multi-instance)
Alternatives Considered
1. Hot reload for environment variables
The server could reload
ENGRAM_CLOUD_TOKENandENGRAM_CLOUD_ALLOWED_PROJECTSwithout restart.This removes the immediate restart pain, but keeps Docker/env vars as the admin interface. It is still manual, hard to audit, and awkward for normal operations.
2. Wildcard allowlist
Issue #260 proposes wildcard support for
ENGRAM_CLOUD_ALLOWED_PROJECTS.That helps local development, but it weakens project policy rather than making policy easier to administer. It also does not solve token creation/revocation.
3. Project-scoped bearer tokens
Issue #274 proposes project-scoped bearer tokens. That is related and in scope, but still needs a concrete persistence/administration model.
This issue proposes a smaller standalone foundation: DB-backed token and project policy administration first.
4. Managed users / per-user sync tokens
Issue #348 proposes managed users, per-user tokens, dashboard login, and project grants.
That may be useful later, but it is intentionally larger than this issue. For standalone/self-hosted deployments, token/project policy in DB is enough to remove the operational pain without building an identity platform.
Related Issues / PRs
Additional Context
This issue is meant to be reviewable as a focused cloud administration improvement.
A possible implementation can be split into small PRs:
Storage foundation
Auth/bootstrap
ENGRAM_CLOUD_TOKENwhen DB has no active tokens.ENGRAM_CLOUD_ALLOWED_PROJECTSwhen policy table is empty.Server enforcement
CLI admin
Docs and compose examples
This keeps the work modular and avoids turning Engram Cloud into a SaaS identity platform.