Core

Core — Connector & Registry

Architecture for Ziteox Core connector API, project registry, secrets vault, and admin-portal vouching. First Core slice.

Core — Connector & Registry

Status: Draft for Laki — architecture only, no code. Merged into Forge phase one, design only, no code.

Loom home (context only): 30_Areas/Work/Ziteox/Forge/Ziteox Forge — Architecture. This file in the Forge repo is the source of truth for the design.

Scope reminder: Forge is Ziteox Core. There is no separate core repo or bot. Core is the internal AI-agent tooling slice inside Forge: connector, registry, secrets vault, minimal logging, and (later) cache. Env vars stay in the admin portal. No client access.


1. Goals and non-goals

Goals (v1)

  1. Read path. A project (app or AI agent/bot) presents a small project token. Core checks it against the registry (project, token, scopes). If valid, Core uses its single stored GitHub credential to fetch from github.com/ziteox-core/ziteox-forge and returns the result. The project never sees the GitHub credential.
  2. Publish path. A project sends content through Core. Core writes to the Forge repo with the GitHub credential — recommend branch + PR, never direct to main, path-scoped by grants.
  3. Secrets stay in Core. The GitHub credential and any other upstream secrets live in Core’s secrets vault, encrypted at rest, reachable only through Core.
  4. Admin portal manages tokens. Team members manage Forge tokens at admin.ziteox.com (portal app ziteox-admin). No separate Core login. Core trusts what the admin portal vouches for via a short-lived signed assertion.
  5. Identity separation. Ziteox Account (Supabase auth at auth.ziteox.com, portal app ziteox-auth) is who the staff member is (including AAL2). It is separate from Core’s project-token permission logic. Core never reads Supabase sessions directly.

Non-goals (this slice)

Non-goalWhy
Client / customer accessCore is internal AI-agent tooling only
Env var managementStays in the admin portal; Core does not become an env store
CacheFuture Core piece; not designed here beyond a placeholder box
Package registry replacementGitHub Packages / npm stay; Core may later proxy installs (see §8)
UI beyond admin portal pagesNo Core UI app; staff use existing admin
Direct main pushes from projectsPublish is PR-scoped
Reading Supabase sessions in CoreManagement plane trusts portal assertions only
Shipping code in this PRDocs only

2. Components and trust boundaries

Components

ComponentRole
Connector APIHTTPS data plane + management plane. Validates tokens / assertions, enforces scopes, rate limits, returns file/tree/publish results.
RegistryProjects, project tokens (hash/last4/prefix only), scopes/grants, rotation/revoke/expiry metadata, ownership.
Secrets vaultEnvelope-encrypted upstream secrets (GitHub App private key first). Own KEK; never returns plaintext to callers.
Audit / minimal logAppend-only events for token issue/revoke/rotate, read/publish, assertion verify, vault resolve, denials. No secret values.
GitHub adapterMints short-lived installation tokens from the App private key; contents read/write + PR create; path-scoped.
Future: cacheOptional read cache for hot paths; out of v1.

Where code would later live (proposal only — no code in this slice)

ziteox-forge/
├── apps/core/              # Cloudflare Worker (ziteox-core) — Connector API
├── packages/core-client/   # Thin SDK / MCP tool wrappers for agents
└── docs/core/              # This architecture tree (source of truth)

Admin portal pages for token issue/revoke stay in the portal repo (ziteox-admin), calling Core’s management plane with assertions.

Component diagram (trust boundaries)

Diagrams are shown as Mermaid source; the plain list below each one says the same thing.

flowchart TB
  subgraph external["Outside Ziteox"]
    GH["GitHub<br/>ziteox-core/ziteox-forge"]
  end

  subgraph projects["Projects / agents (data plane)"]
    P1["App or bot<br/>Bearer zxcore_…"]
  end

  subgraph identity["Identity (separate)"]
    AUTH["ziteox-auth<br/>auth.ziteox.com<br/>Supabase sessions + AAL2"]
  end

  subgraph portalTB["Admin portal trust zone"]
    ADMIN["ziteox-admin<br/>admin.ziteox.com<br/>token UX + assertion mint"]
  end

  subgraph coreTB["Core trust zone — core.ziteox.com"]
    API["Connector API"]
    REG["Registry<br/>forge_core.*"]
    VAULT["Secrets vault<br/>own KEK"]
    AUDIT["Audit log"]
    GHAD["GitHub adapter"]
    CACHE["Cache (future)"]
  end

  P1 -->|"project token"| API
  AUTH -->|"staff session"| ADMIN
  ADMIN -->|"Ed25519 JWS assertion<br/>~60s TTL"| API
  API --> REG
  API --> VAULT
  API --> AUDIT
  API --> GHAD
  API -.-> CACHE
  GHAD -->|"installation token<br/>1h"| GH
  VAULT -.->|"never leaves Core"| GHAD

Trust notes

  • Projects trust Core for Forge content; they do not hold GitHub credentials.
  • Core trusts the admin portal’s public key for management assertions — not Supabase JWTs.
  • Admin portal trusts Ziteox Account for “who is this staff member + AAL2”.
  • GitHub trusts only Core’s App installation (or temporary PAT stopgap).

3. Data model

Schema naming (open — see §10)

Portal already uses a Postgres schema named core for apps/roles/memberships/invites/connections (core.apps, core.app_roles, core.app_memberships, core.app_invites, plus site registration and core.mcp_service_tokens). Do not collide.

Citation: portal packages/supabase-routing/src/index.ts routes mcp_service_tokens, app_connections, apps, and app_* to schema core (commit adaf980); migration ziteox-admin/supabase/migrations/20261101000000_app_connections.sql creates core.app_connections.

Recommendation: use a distinct schema name such as forge_core in the existing Supabase project, or a separate database. Schema-in-same-project is enough for v1 if privileges stay service-role-only and RLS denies anon/authenticated (same pattern as infra.*). Final call is an open question for Laki.

Below uses forge_core as the working name.

forge_core.projects

ColumnTypeNotes
iduuid PK
keytext UNIQUEStable slug, e.g. clerk-bot, portal-ci
labeltextHuman name
owner_user_iduuidStaff user id (Ziteox Account)
statustextactive | disabled
allowed_scopestext / JSONProject scope ceiling
allowed_environmentstext / JSONSubset of development | staging | production (default all three)
portal_project_idtext NULLOptional portal project uuid (canonical lowercase); unique when set — portal resolves portal project → Core project via this link
created_byuuidStaff who created
created_attimestamptz
updated_attimestamptz
disabled_attimestamptz NULL

forge_core.project_tokens

Mirrors portal agent token hygiene: show once, store hash + last4 + prefix only.

Prior art: packages/auth/src/identity/tokens.ts (zxmcp_ + 64 hex, SHA-256 hex hash); AGENT_TOKEN_TTL_DAYS = 90 in packages/auth/src/identity/constants.ts; issue/resolve in ziteox-admin/src/lib/mcp-service-tokens.ts; migrations ziteox-client/supabase/migrations/20260720120308_mcp_service_tokens.sql, ziteox-admin/supabase/migrations/20261012160000_mcp_service_token_expires_at.sql (commits 45c5363, 5592fc8).

ColumnTypeNotes
iduuid PK
project_iduuid FK → projects
token_prefixtextAlways zxcore_
token_hashtext UNIQUESHA-256 hex of raw token
token_last4textDisplay only
labeltext NULL
owner_user_iduuidStaff responsible
created_byuuidIssuer
expires_attimestamptzDefault +90 days (match agent tokens)
revoked_attimestamptz NULL
replaced_byuuid NULLRotation chain
overlap_untiltimestamptz NULLOld token valid until this during rotate
environmenttext NOT NULLdevelopment | staging | production (legacy backfill → production)
environment_idtext NULLOpaque portal environment uuid (linking only)
issued_for_member_idtext NULLPortal member the token was issued for
last_used_attimestamptz NULL
created_attimestamptz

Raw token form (shown once): zxcore_ + 64 lowercase hex (32 random bytes). Never stored plaintext.

forge_core.token_grants

ColumnTypeNotes
iduuid PK
token_iduuid FK → project_tokens
actiontextread | publish
path_globtextRepo-relative, e.g. packages/ui/**, docs/playbook/**
created_attimestamptz

Scope string convention (API / MCP): read:packages/ui/**, publish:docs/playbook/**. Glob matching must reject .., absolute paths, and escapes outside the repo root (see §6).

forge_core.vault_secrets

Reuse the portal KMS envelope pattern, with Core’s own KEK (do not share SECRETS_KEK).

Prior art: design docs/infra-kms-project-sketch-2026-10-28.md (envelope, G1–G10, M0–M6); superseded env-ref decision docs/infra-secrets-decision-2026-10-28.md; schema ziteox-admin/supabase/migrations/20261028220000_infra_secrets_kms.sql (infra.secrets, infra.secret_audit); crypto ziteox-client/supabase/functions/_shared/secrets-crypto.ts (AES-256-GCM, Edge secret SECRETS_KEK); commits 5f27455 M0, 5c5b00c M1, 02f112e M2, 173e602 M3, 83ce297 M4, b21d4ee hardening. Supabase Vault 0.3.1 confirmed installed (M0); Edge envelope for unwrap; Vault reserved for later DEK wrap.

ColumnTypeNotes
iduuid PK
labeltexte.g. github_app_private_key
last4text≤ 8 chars
key_versionint≥ 1
ciphertexttextAES-256-GCM, base64
noncetextbase64
algorithmtextdefault AES-256-GCM
vault_secret_iduuid NULLReserved for later Vault DEK wrap
rotated_byuuid NULL
created_attimestamptz
rotated_attimestamptz
destroyed_attimestamptz NULL
environmenttext NOT NULLSame enum as tokens; uniqueness is (project_id, environment, label)

RLS on; revoke anon/authenticated; metadata-only view allowed (no ciphertext), same spirit as infra.secrets_meta.

forge_core.audit_events

Append-only, like infra.secret_audit (actions seal/resolve/rotate/destroy/denied; CHECK that meta has no plaintext / secret / value / token / api_key keys).

ColumnTypeNotes
idbigserial PK
actiontextSee below
actor_kindtextstaff | project_token | system
actor_user_iduuid NULLStaff when known
project_iduuid NULL
token_iduuid NULL
outcometextok | error | denied
metajsonbNo secret-shaped keys (CHECK)
environmenttext NULLToken/secret environment when known
created_attimestamptz

Actions (illustrative): token.issue, token.revoke, token.rotate, assertion.verify, assertion.replay_denied, files.read, tree.read, publish.create, vault.resolve, vault.seal, rate_limited, scope_denied.

Role registry hook (portal core.*, not forge_core)

Register Core as an app key (e.g. forge) in portal core.apps with roles so the admin portal can decide who may issue Forge tokens using the existing role ceiling.

Prior art: migration ziteox-admin/supabase/migrations/20261029220000_app_role_registry.sql (commit 87c355c) — core.apps, core.app_roles, core.app_memberships (admin app has null org), core.app_invites (7-day expiry); site registration 20261031200000_app_site_registration.sql (commit 5a362d4); ceiling packages/auth/src/roles/ceiling.ts (reasons include above_your_role, bot_not_allowed), packages/auth/src/roles/registry.ts (commits 4ea5e93, 8a50d16, 68e9207).

Suggested seed (product-confirm ranks):

app_keyrole keyrank (proposed)
forgeforge_admin200
forgeforge_operator100

Only staff with sufficient forge membership (and AAL2) mint management assertions that can issue/revoke/rotate tokens.


4. Sequence diagrams

(a) Read

sequenceDiagram
  participant Proj as Project / agent
  participant Core as Connector API
  participant Reg as Registry
  participant Vault as Secrets vault
  participant GH as GitHub adapter
  participant Repo as github.com/ziteox-core/ziteox-forge

  Proj->>Core: GET /v1/files?path=&ref=<br/>Authorization: Bearer zxcore_…
  Core->>Reg: Lookup token_hash, project, grants
  alt invalid / expired / revoked / disabled
    Core-->>Proj: 401 or 403
  else path not in read grant
    Core-->>Proj: 403 scope_denied
  else ok
    Core->>Vault: Resolve github_app_private_key (in-process)
    Vault-->>Core: plaintext key (memory only)
    Core->>GH: Mint installation token (~1h)
    GH->>Repo: Contents API get path@ref
    Repo-->>GH: blob / contents
    GH-->>Core: bytes + metadata
    Core->>Reg: Update last_used_at + audit files.read
    Core-->>Proj: file payload (no GitHub credential)
  end

In steps:

  1. Project / agent → Connector API: GET /v1/files?path=&ref= with Authorization: Bearer zxcore_…
  2. Connector API → Registry: Lookup token_hash, project, grants
  3. If invalid / expired / revoked / disabled: Connector API → Project / agent: 401 or 403
  4. Else if path not in read grant: Connector API → Project / agent: 403 scope_denied
  5. Else ok:
    1. Connector API → Secrets vault: Resolve github_app_private_key (in-process)
    2. Secrets vault → Connector API: plaintext key (memory only)
    3. Connector API → GitHub adapter: Mint installation token (~1h)
    4. GitHub adapter → github.com/ziteox-core/ziteox-forge: Contents API get path@ref
    5. github.com/ziteox-core/ziteox-forge → GitHub adapter: blob / contents
    6. GitHub adapter → Connector API: bytes + metadata
    7. Connector API → Registry: Update last_used_at + audit files.read
    8. Connector API → Project / agent: file payload (no GitHub credential)

(b) Publish

sequenceDiagram
  participant Proj as Project / agent
  participant Core as Connector API
  participant Reg as Registry
  participant Vault as Secrets vault
  participant GH as GitHub adapter
  participant Repo as Forge repo

  Proj->>Core: POST /v1/publish<br/>{ base_ref, branch, files[], title, body }
  Core->>Reg: Validate token + publish grants for each path
  alt any path outside grant / traversal / oversize / bad type
    Core-->>Proj: 403 or 400
  else ok
    Core->>Vault: Resolve App private key
    Core->>GH: Create branch from base_ref
    GH->>Repo: Create/update blobs on branch
    GH->>Repo: Open pull request → main
    Repo-->>GH: PR url + number
    Core->>Reg: Audit publish.create
    Core-->>Proj: { pr_url, pr_number, branch }
  end

In steps:

  1. Project / agent → Connector API: POST /v1/publish with { base_ref, branch, files[], title, body }
  2. Connector API → Registry: Validate token + publish grants for each path
  3. If any path outside grant / traversal / oversize / bad type: Connector API → Project / agent: 403 or 400
  4. Else ok:
    1. Connector API → Secrets vault: Resolve App private key
    2. Connector API → GitHub adapter: Create branch from base_ref
    3. GitHub adapter → Forge repo: Create/update blobs on branch
    4. GitHub adapter → Forge repo: Open pull request → main
    5. Forge repo → GitHub adapter: PR url + number
    6. Connector API → Registry: Audit publish.create
    7. Connector API → Project / agent: { pr_url, pr_number, branch }

(c) Issue token via admin portal

sequenceDiagram
  participant Staff as Staff browser
  participant Admin as ziteox-admin
  participant Auth as ziteox-auth / Account
  participant Core as Connector API
  participant Reg as Registry
  participant Jti as jti replay cache

  Staff->>Admin: Request new Forge project token
  Admin->>Auth: Existing session (require AAL2)
  Auth-->>Admin: Staff identity + aal=aal2
  Admin->>Admin: Check forge app role + role ceiling
  Admin->>Admin: Mint Ed25519 JWS<br/>aud=core, ttl~60s, jti, sub, aal,<br/>action=token.issue, params_hash
  Admin->>Core: POST /v1/admin/tokens<br/>Assertion + issue body
  Core->>Core: Verify JWS with portal public key
  Core->>Jti: Reject if jti seen
  Core->>Jti: Store jti until exp
  Core->>Reg: Insert project_tokens + grants<br/>(store hash/last4 only)
  Core-->>Admin: { id, token once, last4, expires_at, grants }
  Admin-->>Staff: Show token once (copy UI)

In steps:

  1. Staff browser → ziteox-admin: Request new Forge project token
  2. ziteox-admin → ziteox-auth / Account: Existing session (require AAL2)
  3. ziteox-auth / Account → ziteox-admin: Staff identity + aal=aal2
  4. ziteox-admin → ziteox-admin: Check forge app role + role ceiling
  5. ziteox-admin → ziteox-admin: Mint Ed25519 JWS (aud=core, ttl~60s, jti, sub, aal, action=token.issue, params_hash)
  6. ziteox-admin → Connector API: POST /v1/admin/tokens with Assertion + issue body
  7. Connector API → Connector API: Verify JWS with portal public key
  8. Connector API → jti replay cache: Reject if jti seen
  9. Connector API → jti replay cache: Store jti until exp
  10. Connector API → Registry: Insert project_tokens + grants (store hash/last4 only)
  11. Connector API → ziteox-admin: { id, token once, last4, expires_at, grants }
  12. ziteox-admin → Staff browser: Show token once (copy UI)

(d) Revoke (and rotation briefly)

sequenceDiagram
  participant Admin as ziteox-admin
  participant Core as Connector API
  participant Jti as jti replay cache
  participant Reg as Registry
  participant Audit as Audit log

  Note over Admin,Core: Same assertion pattern as issue (action=token.revoke or token.rotate)

  Admin->>Core: POST /v1/admin/tokens/:id/revoke<br/>Assertion + revoke body
  Core->>Core: Verify Ed25519 JWS (sig, aud, exp±skew, aal, action, params_hash)
  Core->>Jti: Reject if jti seen; else store until exp
  Core->>Reg: Set revoked_at = now()
  Core->>Audit: Append token.revoke (no secret values)
  Core-->>Admin: { id, revoked_at }

  Note over Admin,Reg: Rotate = issue new + set old.replaced_by + old.overlap_until<br/>(e.g. 24h) then old stops working after overlap
  Admin->>Core: POST /v1/admin/tokens/:id/rotate
  Core->>Core: Verify JWS + jti (same as revoke)
  Core->>Reg: Insert new token; link replaced_by; set overlap_until
  Core->>Audit: Append token.rotate
  Core-->>Admin: { previous_id, new token once, overlap_until }

In steps:

  1. (Note over ziteox-admin, Connector API) Same assertion pattern as issue (action=token.revoke or token.rotate)
  2. ziteox-admin → Connector API: POST /v1/admin/tokens/:id/revoke with Assertion + revoke body
  3. Connector API → Connector API: Verify Ed25519 JWS (sig, aud, exp±skew, aal, action, params_hash)
  4. Connector API → jti replay cache: Reject if jti seen; else store until exp
  5. Connector API → Registry: Set revoked_at = now()
  6. Connector API → Audit log: Append token.revoke (no secret values)
  7. Connector API → ziteox-admin: { id, revoked_at }
  8. (Note over ziteox-admin, Registry) Rotate = issue new + set old.replaced_by + old.overlap_until (e.g. 24h) then old stops working after overlap
  9. ziteox-admin → Connector API: POST /v1/admin/tokens/:id/rotate
  10. Connector API → Connector API: Verify JWS + jti (same as revoke)
  11. Connector API → Registry: Insert new token; link replaced_by; set overlap_until
  12. Connector API → Audit log: Append token.rotate
  13. Connector API → ziteox-admin: { previous_id, new token once, overlap_until }

Revoke effectivity: takes effect on the next data-plane request that looks up the token. v1 has no project-token auth cache (bound = 0s), so the request after revoked_at is set is denied. If a short in-process cache is added later, state its TTL as the upper bound on revoke lag.


5. Interfaces and endpoints

Base URL (proposed): https://core.ziteox.com.

Auth schemes

PlaneCredentialWho
Data planeAuthorization: Bearer zxcore_…Projects / agents
Management planeAuthorization: Bearer <JWS assertion> (or X-Ziteox-Assertion)Admin portal only

Core does not accept Supabase access tokens.

Data plane

GET /v1/whoami

Returns the authenticated project/token metadata (no secret).

200

{
  "project": { "id": "…", "key": "clerk-bot", "label": "Clerk" },
  "token": { "id": "…", "last4": "a1b2", "expires_at": "…", "grants": ["read:packages/ui/**"] }
}

GET /v1/files?path=&ref=

QueryRequiredNotes
pathyesRepo-relative file path; must match a read: grant
refnoBranch/tag/SHA; default configured (e.g. main)

200

{
  "path": "packages/ui/package.json",
  "ref": "main",
  "sha": "…",
  "content_base64": "…",
  "encoding": "base64",
  "size": 1234
}

GET /v1/tree?path=&ref=&recursive=

Lists a directory tree under a granted prefix.

POST /v1/publish

Creates a branch + PR. Never pushes to main.

Request

{
  "base_ref": "main",
  "branch": "core/bot-update-playbook-…",
  "title": "docs: update playbook section",
  "body": "Automated via Core publish",
  "files": [
    { "path": "docs/playbook/foo.md", "content_base64": "…", "mode": "100644" }
  ]
}

201

{
  "branch": "core/bot-update-playbook-…",
  "pr_number": 42,
  "pr_url": "https://github.com/ziteox-core/ziteox-forge/pull/42"
}

Management plane (admin portal + assertion only)

MethodPathPurpose
POST/v1/admin/projectsCreate project (optional portal_project_id)
GET/v1/admin/projectsList projects; ?portal_project_id= lookup
PATCH/v1/admin/projects/:keyUpdate/clear portal_project_id
POST/v1/admin/tokensIssue token (returns raw once)
POST/v1/admin/tokens/:id/revokeImmediate revoke
POST/v1/admin/tokens/:id/rotateNew token + overlap window
GET/v1/admin/auditPer-key audit feed (filters, cursor before/next_before, role-scoped; see admin-portal-integration v1.6)

EdDSA / Ed25519 JWS compact serialization.

Claim / headerValue
kid (header)Key id selecting which pinned Core public key verifies this JWS
issadmin.ziteox.com (or portal key id)
audcore
subStaff user id
aalaal2 (reject lower)
jtiUnique nonce
iat / exp~60s TTL; Core allows clock skew ±30s around iat/exp
actione.g. token.issue
params_hashSHA-256 of canonical JSON body

Core verifies signature with the admin portal’s public key selected by kid, checks aud/exp/aal/action (with ±30s skew), hashes the body and compares to params_hash, then records jti until exp (+ skew) in a replay cache.

Admin portal signing key

  • Custody: ziteox-admin holds the Ed25519 private keypair in its platform secrets (name only, e.g. CORE_ASSERTION_SIGNING_KEY). Core does not hold the private key.
  • Pinning: Core pins the matching public key(s) by kid in its own config/secrets (name only, e.g. ADMIN_ASSERTION_PUBLIC_KEYS). Core does not fetch a remote JWKS at request time.
  • Rotation: add the new kid + public key to Core first; switch admin to sign with the new key; after the ~60s assertion TTL (+ skew) drains, remove the old kid from Core.
  • Compromise: remove the compromised kid from Core immediately (all management assertions signed with that key fail verify); revoke any project tokens issued in the suspect window via audit (token.issue rows).

Vouching alternatives (comparison)

ApproachProsConsVerdict
Ed25519 JWS assertion (recommended)No shared secret at rest in two places; short TTL + jti; action-bound; fits AAL2 claimNeed key distribution + rotationPick
Shared HMAC secretSimpleShared secret doubles blast radius; harder to rotate cleanlyReject for management plane
mTLS (portal ↔ Core)Strong transport identityOps heavy on Workers; still need action bindingOptional later under Zero Trust
Cloudflare Access service tokenGood for network gateNot fine-grained action+params binding aloneUse as network layer later (§8), not sole auth

Error codes

CodeWhen
401Missing/invalid token or assertion; expired; bad signature
403Valid cred but scope denied, project disabled, AAL too low, role ceiling
404Unknown path/ref/token id (avoid leaking existence where unsafe)
409Conflict (e.g. rotate already in flight, duplicate project key)
429Rate limited — include Retry-After

MCP surface (agents)

Thin wrapper over the same endpoints, mirroring portal ziteox-admin/src/app/api/mcp/route.ts (mcp-handler + withMcpAuth), tools registry ziteox-admin/src/lib/mcp-tools-registry.ts, auth ziteox-admin/src/lib/mcp-agent-auth.ts (bearer reasons: expired, revoked, owner_inactive, agent_disabled, not_agent, no_owner, invalid; owner ceiling + scopes) — commits 45c5363, 5592fc8.

Proposed Core MCP tools (names illustrative):

ToolMaps to
core_whoamiGET /v1/whoami
core_read_fileGET /v1/files
core_list_treeGET /v1/tree
core_publishPOST /v1/publish

Auth for MCP = project token (zxcore_), same as data plane. Management tools stay out of MCP unless a dedicated staff-bot path is approved later.


6. Trust boundaries and threats

GitHub credential blast radius

Core holds one upstream GitHub credential for ziteox-core/ziteox-forge. Compromise of Core’s vault KEK or resolve path = full contents read/write + PR create on that repo. Mitigations: GitHub App least privilege, installation scoped to that single repo, short-lived installation tokens, audit every resolve/publish, fail closed.

Fine-grained PAT vs GitHub App

OptionNotes
GitHub App (recommend)Install only on ziteox-core/ziteox-forge. Permissions: contents:read, contents:write, pull_requests:write. Core stores App private key in vault; mints ~1-hour installation tokens per call batch.
Fine-grained PATAcceptable stopgap only. Longer-lived; rotation manual; still vaulted. Kill PAT path once App works (same spirit as KMS G6 dual-run kill).

Token theft (zxcore_)

Treat like portal zxmcp_ tokens: hash at rest, show once, TTL, revoke, rotate with overlap, last_used_at for anomaly spotting. Stolen token is limited to its path grants — keep grants tight.

Assertion replay

Short TTL (~60s) + jti nonce + replay cache + modest clock skew window. Reject reused jti. Bind action + params_hash so a stolen assertion cannot be retargeted to another body.

Rate limits

LayerSuggestion
Per tokene.g. N req/min for read; stricter for publish
Per projectAggregate cap across tokens
GitHubRespect GitHub secondary rate limits; surface 429 + Retry-After

Path traversal / scope escape

Normalize paths; reject .., leading /, NUL, symlink tricks; match only after normalization; grants are allowlists, not denylists.

Publish abuse

  • PR only (no direct main)
  • Max files per request, max bytes per file, max total bytes
  • Content-type / extension allowlist (e.g. markdown, json, ts/tsx — product-defined)
  • Branch name prefix reserved for Core (core/…)

Audit and logging

  • Append-only audit rows; no secret values in meta (CHECK like infra.secret_audit)
  • Logging redaction fail-closed (KMS G4): if redaction fails, fail the request — never log plaintext keys or raw tokens
  • Vault resolve only in-process inside Core; never return plaintext on any API

Insider / admin compromise

Staff with forge roles + AAL2 can issue powerful tokens. Mitigate with role ceiling, short assertion TTL, audit of every issue/revoke, optional dual-control later. Compromised admin session ≠ automatic Core vault dump — vault resolve is not exposed on management issue endpoints.

Core outage

Fail closed. Projects cannot fall back to embedding a GitHub PAT “just for now” in v1 design. Admin token UX fails closed if Core is down (no local mint of Core-trusted tokens).


7. Hosting options

Options

(A) Standalone Cloudflare Worker(B) Inside admin portal(C) Supabase Edge Functions
ShapeWorker ziteox-core at e.g. core.ziteox.com; Workers secrets for Core KEK; registry in Supabase (forge_core) or D1Next.js API routes in ziteox-adminEdge Functions beside secrets-seal / secrets-resolve
Prior artziteox-auth already on Workers via OpenNext (ziteox-auth/wrangler.jsonc, ziteox-auth/CLOUDFLARE.md); Forge docs via apps/docs/wrangler.jsoncAdmin already has /api/infra/secrets, /api/mcpKMS seal/resolve already on Edge (02f112e)
Blast radiusIsolated from admin UI and client appsCouples Core to admin deploy; widens blast radiusShares Edge project with KMS; careful KEK separation
Latency / edgeGood global edgeTied to admin hostGood, but function model for long GitHub fan-out is awkward
SecretsWorkers secrets for CORE_SECRETS_KEK (name only)Can reuse portal KMS wiring — temptation to share KEK (bad)Natural envelope crypto; risk of conflating KEKs
OpsNew Worker + DNSNo new hostNew functions + JWT/assert gates

Recommendation

Pick (A): standalone Cloudflare Worker ziteox-core at core.ziteox.com.

  • Registry tables in the existing Supabase project under schema forge_core (or rename per Laki).
  • Vault reuses the portal envelope pattern with Core’s own KEK in Workers secrets — do not reuse Edge SECRETS_KEK.
  • Keeps Core as an internal tool with a clear trust boundary (matches “Forge is Core”, code later under apps/core in this monorepo).
  • Aligns with existing Cloudflare muscle (ziteox-auth, apps/docs).

Trade-offs: another deployable and DNS name; must build assertion verify + jti cache on Workers (KV/Durable Object or short TTL store); Supabase access from Worker needs a locked-down service role or narrower DB role (prefer narrow).

(B) is faster to prototype but couples outages and credentials to admin — reject for steady state.

(C) is attractive for crypto familiarity but muddies “Core is not the portal KMS” and is a weaker long-term home for a GitHub-facing connector.


8. Relationship to later work

Security bot audit

When implemented, the security bot should review this slice against a hard-gates list (see §9). Minimum checks: no plaintext in logs/API; assertion verify before management mutations; project tokens hashed; publish is PR-only; path grants enforced; KEK only in platform secrets; audit CHECK constraints present.

Cloudflare Zero Trust

Later: put Access in front of the management plane (and optionally require Access service tokens for agents). Assertion auth remains; Zero Trust is defense-in-depth at the network edge — not a replacement for action-bound JWS. Timing is an open question.

@ziteox/ui / package installs via Core

Consumers should install @ziteox/* through Core’s npm registry proxy (GET /npm/*) with a project token scoped packages:read. Core holds the upstream GitHub Packages credential; client builds do not. See Install packages through Core and Connect a project.

Deprecated: putting a long-lived GITHUB_PACKAGES_TOKEN (classic PAT) in consumer .npmrc / host env. Design history: From package token to connector.


9. Rollout milestones and security hard gates

All milestones local only, gated on Laki OK — same discipline as KMS M0–M6 (docs/infra-kms-project-sketch-2026-10-28.md). No push/deploy/prod migration without explicit go-ahead.

Milestones (proposed)

IDDeliverable
M0This architecture doc accepted (or revised) by Laki
M1forge_core schema migration (local): projects, tokens, grants, vault_secrets, audit — RLS + revoke anon/authenticated
M2Worker skeleton: health, assertion verify + jti cache, whoami with hashed tokens
M3GitHub App (or PAT stopgap) in vault; read files + tree
M4Publish → branch + PR; scope + size limits
M5Admin portal pages: issue / rotate / revoke via assertions; register forge in core.apps
M6MCP thin wrapper; rate limits; Security gates sign-off; drill revoke + KEK restore

Security hard gates (G1–G10 style, Core)

Borrow spirit from KMS G1–G10 (docs/infra-kms-project-sketch-2026-10-28.md, also b21d4ee / G8 docs).

#Gate — must be true
CG1Automated + manual scan: no GitHub credential or raw zxcore_ appears in browser responses, MCP tool results, or log/audit fixtures
CG2Management mutations reject missing/invalid Ed25519 assertion, aal ≠ aal2, mismatched action/params_hash, reused jti, and unknown/removed kid
CG3DB stores only SHA-256 hash (+ prefix/last4); issue API returns raw token once; subsequent reads never return plaintext
CG4Insert-only audit path; DB CHECK rejects meta keys named like plaintext / secret / value / token / api_key
CG5If log redaction fails, the request fails closed and nothing secret-shaped is written
CG6Core KEK exists only as a Workers/platform secret name (e.g. CORE_SECRETS_KEK); absent from git/chat; distinct from portal SECRETS_KEK
CG7forge_core tables: RLS on; anon and authenticated have no privileges; service/narrow role only
CG8Publish never writes main directly (PR only); paths with .. / absolute / escape fail; grants matched only after normalization
CG9GitHub App installed on ziteox-core/ziteox-forge only with least privilege; PAT stopgap path removed from config after App cutover
CG10Over-limit requests return 429 + Retry-After; with Core down, projects have no GitHub-credential fallback and admin cannot mint Core-trusted tokens locally

No real GitHub App private key or production tokens until CG1–CG10 pass (KEK restore drill before first prod vault secret).


Local v1 defaults chosen

Local Worker in apps/core (pass 1–2) picked working defaults so the connector can run without prod decisions. Each row that maps to an open question is marked default pending Laki's answer to Qn. These are not production commitments.

Default in apps/coreChoiceOpen Q
Hosting shapeStandalone Cloudflare Worker skeleton (ziteox-core), local only — no deploy configuredQ1 — default pending Laki's answer to Q1
Schema / DBLocal D1 plain tables mirroring forge_core.* (projects, project_tokens, token_grants, vault_secrets, audit_events, assertion_jti, staff_roles, mock_github_*)Q2 — default pending Laki's answer to Q2
GitHub authMock adapter + App stub (GITHUB_MODE=mock); real App path stubbed, not liveQ3 — default pending Laki's answer to Q3
Publish policyBranch + PR only; direct push to default/main/master → 403 direct_push_deniedQ4 — default pending Laki's answer to Q4
Token TTL90 days default (TOKEN_TTL_DAYS_DEFAULT)Q5 — default pending Laki's answer to Q5
Who may issue / role matrixforge_admin: all management actions; forge_operator: list/issue/rotate/audit/member.tokens.list only — not project.create, token.revoke, vault.sealQ6 — default pending Laki's answer to Q6
Token ownershipPer-project tokens only (owner_user_id on project; issued_for_member_id attributes the portal member; no cross-project member token)Q7 — default pending Laki's answer to Q7
Assertion member_id claimOptional; portal member the action is for. sub stays acting staff. On token.issue: issued_for_member_id = claims.member_id ?? claims.sub. Body may also send member_id (must match claim when both set).— (pass 3; admin portal)
Member token listGET /v1/admin/members/:memberId/tokens (member.tokens.list); forge_admin + forge_operator; params_hash over path/query params— (pass 3)
Project binding headerOptional data-plane X-Ziteox-Project: <project_key>; mismatch → 403 project_mismatch. Rotate/revoke may send body project_key with the same check.— (pass 3)
EnvironmentsEnum development | staging | production. Projects: allowed_environments (default all three). Tokens require environment (+ optional opaque environment_id). Secrets unique per (project_id, environment, label). Optional X-Ziteox-Environment; mismatch → 403 environment_mismatch. Legacy rows / omitted vault.seal environment → production. SQL DEFAULT on token/secret environment is backfill-only — app inserts must be explicit.— (pass 7)
Bots holding tokensNot implemented; staff seed users only (dev-admin / dev-operator)Q8 — default pending Laki's answer to Q8
Package-install proxyOut of local v1 (unchanged)Q9 — default pending Laki's answer to Q9
Zero Trust / AccessNot in front of local WorkerQ10 — default pending Laki's answer to Q10
KEK custodyLocal .dev.vars CORE_SECRETS_KEK only (gitignored); not platform secretsQ11 — default pending Laki's answer to Q11
Audit retentionKeep all local rows; no purge jobQ12 — default pending Laki's answer to Q12
Assertion cryptoEd25519 compact JWS; aal2 required; TTL 60s max; clock skew ±30s; kid pinning via ADMIN_ASSERTION_PUBLIC_KEYS (no remote JWKS)Q13 / Q15 — default pending Laki's answer to Q13 / Q15
Rotate overlap24h (overlap_until)Q14 — default pending Laki's answer to Q14
Revoke bound0s (no project-token auth cache; next request sees revoked_at)— (design §4d; not a numbered Q)
Envelope cryptoAES-256-GCM per-secret DEK + local KEK wrap (Workers WebCrypto)— (pattern from portal KMS; KEK separation per design)
Secrets read scoperead:secrets/<label> or read:secrets/**—
Project ceilingprojects.allowed_scopes; issue/rotate must stay within ceiling (scope_exceeds_project)—
AuditInsert-only triggers (UPDATE/DELETE abort with insert-only); meta forbids secret-shaped keys—
Client package@ziteox/core-client + @ziteox/core-client/admin-signer—

How to run: Run Core locally. Open questions list: §10 and Open questions.


10. Open questions for Laki

  1. Hosting: Confirm standalone Cloudflare Worker ziteox-core at core.ziteox.com (option A), or prefer B/C?
  2. Schema / DB: forge_core schema in the existing Supabase project, a different name, or a separate database? (Must not collide with portal core.*.)
  3. GitHub auth: Approve GitHub App (recommended) vs fine-grained PAT stopgap first?
  4. Publish policy: Lock PR-only (no direct push to main) for all grants?
  5. Token TTL: Default 90 days to match AGENT_TOKEN_TTL_DAYS, or different?
  6. Who may issue tokens? Which forge / admin roles (and ceiling) are allowed?
  7. Token ownership model: Per-project tokens only, or also per-staff personal tokens?
  8. Bots holding tokens: May agent accounts own zxcore_ tokens under role ceiling (bot_not_allowed rules), or staff-owned only?
  9. Package-install proxy: Explicitly out of v1 — confirm, and is it on the near backlog?
  10. Zero Trust timing: Access in front of management plane before first prod deploy, or after?
  11. KEK custody: Who may wrangler secret put the Core KEK (Laki-only, same as portal root ops)?
  12. Audit retention: How long to keep forge_core.audit_events (e.g. 1 year / indefinite)?
  13. Assertion crypto: Ed25519 JWS as specified, or do you want Cloudflare Access service tokens as a second factor from day one?
  14. Overlap window on rotate: Default 24h acceptable?
  15. Admin assertion signing key custody: Confirm private key in admin platform secrets (e.g. CORE_ASSERTION_SIGNING_KEY) and public keys pinned by kid in Core (e.g. ADMIN_ASSERTION_PUBLIC_KEYS) — no remote JWKS at request time; who may rotate/remove kids?

References

This repo (Forge / Core)

  • Forge architecture — monorepo layout (packages, apps/docs, reserved agents/prompts/standards)
  • ROADMAP.md — Templates / Agents / Workflows not started; Core slice is new
  • packages/ui/package.json — @ziteox/ui 0.1.2, publishConfig.registry → https://npm.pkg.github.com
  • apps/docs/wrangler.jsonc — docs static deploy on Cloudflare
  • Loom MOC (context): 30_Areas/Work/Ziteox/Forge/Ziteox Forge — Architecture

Portal repo (development, local — cite only)

KMS / secrets

  • Commits: 5f27455 M0 docs, 5c5b00c M1 schema, 02f112e M2 Edge seal/resolve, 173e602 M3 admin seal UI + /api/infra/secrets, 83ce297 M4 Railway/Bunny prefer secret_id, b21d4ee hardening (CORS allowlist, AAL2, rate limit, G8 docs)
  • docs/infra-kms-project-sketch-2026-10-28.md — envelope model, G1–G10, M0–M6
  • docs/infra-secrets-decision-2026-10-28.md — earlier env-ref decision (superseded)
  • ziteox-admin/supabase/migrations/20261028220000_infra_secrets_kms.sql — infra.secrets, infra.secret_audit, infra.secrets_meta
  • ziteox-client/supabase/functions/_shared/secrets-crypto.ts — AES-256-GCM, SECRETS_KEK
  • ziteox-client/supabase/functions/_shared/secrets-admin-auth.ts — JWT, admin role, aal2, rate limit
  • ziteox-client/supabase/functions/secrets-seal/index.ts, secrets-resolve/index.ts
  • ziteox-admin/src/app/api/infra/secrets/route.ts, ziteox-admin/src/lib/secrets/resolve-provider-secret.ts

Bot / MCP tokens

  • packages/auth/src/identity/tokens.ts, packages/auth/src/identity/constants.ts (zxmcp_, 90-day TTL)
  • ziteox-admin/src/lib/mcp-service-tokens.ts, mcp-agent-auth.ts, mcp-tools-registry.ts
  • ziteox-admin/src/app/api/mcp/route.ts
  • Migrations: ziteox-client/supabase/migrations/20260720120308_mcp_service_tokens.sql, ziteox-admin/supabase/migrations/20261012160000_mcp_service_token_expires_at.sql
  • Commits: 45c5363, 5592fc8

Roles / apps / schema routing

  • packages/supabase-routing/src/index.ts — routes mcp_service_tokens, app_connections, apps, app_* → schema core (adaf980)
  • ziteox-admin/supabase/migrations/20261101000000_app_connections.sql — core.app_connections
  • ziteox-admin/supabase/migrations/20261029220000_app_role_registry.sql (87c355c)
  • ziteox-admin/supabase/migrations/20261031200000_app_site_registration.sql (5a362d4)
  • packages/auth/src/roles/ceiling.ts, packages/auth/src/roles/registry.ts (4ea5e93, 8a50d16, 68e9207)
  • Handoff client secret: ziteox-auth/src/app/api/handoff/token/route.ts, ziteox-auth/src/lib/handoff-client-secret.ts

Hosting / packages pain

  • ziteox-auth/wrangler.jsonc, ziteox-auth/CLOUDFLARE.md
  • Portal .npmrc, ziteox-admin/.npmrc, README.md, MONOREPO_MIGRATION.md, .github/workflows/ci.yml (GITHUB_PACKAGES_TOKEN)