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)
- 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-forgeand returns the result. The project never sees the GitHub credential. - 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. - 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.
- Admin portal manages tokens. Team members manage Forge tokens at
admin.ziteox.com(portal appziteox-admin). No separate Core login. Core trusts what the admin portal vouches for via a short-lived signed assertion. - Identity separation. Ziteox Account (Supabase auth at
auth.ziteox.com, portal appziteox-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-goal | Why |
|---|---|
| Client / customer access | Core is internal AI-agent tooling only |
| Env var management | Stays in the admin portal; Core does not become an env store |
| Cache | Future Core piece; not designed here beyond a placeholder box |
| Package registry replacement | GitHub Packages / npm stay; Core may later proxy installs (see §8) |
| UI beyond admin portal pages | No Core UI app; staff use existing admin |
Direct main pushes from projects | Publish is PR-scoped |
| Reading Supabase sessions in Core | Management plane trusts portal assertions only |
| Shipping code in this PR | Docs only |
2. Components and trust boundaries
Components
| Component | Role |
|---|---|
| Connector API | HTTPS data plane + management plane. Validates tokens / assertions, enforces scopes, rate limits, returns file/tree/publish results. |
| Registry | Projects, project tokens (hash/last4/prefix only), scopes/grants, rotation/revoke/expiry metadata, ownership. |
| Secrets vault | Envelope-encrypted upstream secrets (GitHub App private key first). Own KEK; never returns plaintext to callers. |
| Audit / minimal log | Append-only events for token issue/revoke/rotate, read/publish, assertion verify, vault resolve, denials. No secret values. |
| GitHub adapter | Mints short-lived installation tokens from the App private key; contents read/write + PR create; path-scoped. |
| Future: cache | Optional 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"| GHADTrust 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
| Column | Type | Notes |
|---|---|---|
id | uuid PK | |
key | text UNIQUE | Stable slug, e.g. clerk-bot, portal-ci |
label | text | Human name |
owner_user_id | uuid | Staff user id (Ziteox Account) |
status | text | active | disabled |
allowed_scopes | text / JSON | Project scope ceiling |
allowed_environments | text / JSON | Subset of development | staging | production (default all three) |
portal_project_id | text NULL | Optional portal project uuid (canonical lowercase); unique when set — portal resolves portal project → Core project via this link |
created_by | uuid | Staff who created |
created_at | timestamptz | |
updated_at | timestamptz | |
disabled_at | timestamptz 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).
| Column | Type | Notes |
|---|---|---|
id | uuid PK | |
project_id | uuid FK → projects | |
token_prefix | text | Always zxcore_ |
token_hash | text UNIQUE | SHA-256 hex of raw token |
token_last4 | text | Display only |
label | text NULL | |
owner_user_id | uuid | Staff responsible |
created_by | uuid | Issuer |
expires_at | timestamptz | Default +90 days (match agent tokens) |
revoked_at | timestamptz NULL | |
replaced_by | uuid NULL | Rotation chain |
overlap_until | timestamptz NULL | Old token valid until this during rotate |
environment | text NOT NULL | development | staging | production (legacy backfill → production) |
environment_id | text NULL | Opaque portal environment uuid (linking only) |
issued_for_member_id | text NULL | Portal member the token was issued for |
last_used_at | timestamptz NULL | |
created_at | timestamptz |
Raw token form (shown once): zxcore_ + 64 lowercase hex (32 random bytes). Never stored plaintext.
forge_core.token_grants
| Column | Type | Notes |
|---|---|---|
id | uuid PK | |
token_id | uuid FK → project_tokens | |
action | text | read | publish |
path_glob | text | Repo-relative, e.g. packages/ui/**, docs/playbook/** |
created_at | timestamptz |
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.
| Column | Type | Notes |
|---|---|---|
id | uuid PK | |
label | text | e.g. github_app_private_key |
last4 | text | ≤ 8 chars |
key_version | int | ≥ 1 |
ciphertext | text | AES-256-GCM, base64 |
nonce | text | base64 |
algorithm | text | default AES-256-GCM |
vault_secret_id | uuid NULL | Reserved for later Vault DEK wrap |
rotated_by | uuid NULL | |
created_at | timestamptz | |
rotated_at | timestamptz | |
destroyed_at | timestamptz NULL | |
environment | text NOT NULL | Same 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).
| Column | Type | Notes |
|---|---|---|
id | bigserial PK | |
action | text | See below |
actor_kind | text | staff | project_token | system |
actor_user_id | uuid NULL | Staff when known |
project_id | uuid NULL | |
token_id | uuid NULL | |
outcome | text | ok | error | denied |
meta | jsonb | No secret-shaped keys (CHECK) |
environment | text NULL | Token/secret environment when known |
created_at | timestamptz |
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_key | role key | rank (proposed) |
|---|---|---|
forge | forge_admin | 200 |
forge | forge_operator | 100 |
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)
endIn steps:
- Project / agent → Connector API:
GET /v1/files?path=&ref=withAuthorization: Bearer zxcore_… - Connector API → Registry: Lookup token_hash, project, grants
- If invalid / expired / revoked / disabled: Connector API → Project / agent: 401 or 403
- Else if path not in read grant: Connector API → Project / agent: 403 scope_denied
- Else ok:
- Connector API → Secrets vault: Resolve github_app_private_key (in-process)
- Secrets vault → Connector API: plaintext key (memory only)
- Connector API → GitHub adapter: Mint installation token (~1h)
- GitHub adapter → github.com/ziteox-core/ziteox-forge: Contents API get path@ref
- github.com/ziteox-core/ziteox-forge → GitHub adapter: blob / contents
- GitHub adapter → Connector API: bytes + metadata
- Connector API → Registry: Update last_used_at + audit files.read
- 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 }
endIn steps:
- Project / agent → Connector API:
POST /v1/publishwith{ base_ref, branch, files[], title, body } - Connector API → Registry: Validate token + publish grants for each path
- If any path outside grant / traversal / oversize / bad type: Connector API → Project / agent: 403 or 400
- Else ok:
- Connector API → Secrets vault: Resolve App private key
- Connector API → GitHub adapter: Create branch from base_ref
- GitHub adapter → Forge repo: Create/update blobs on branch
- GitHub adapter → Forge repo: Open pull request → main
- Forge repo → GitHub adapter: PR url + number
- Connector API → Registry: Audit publish.create
- 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:
- Staff browser → ziteox-admin: Request new Forge project token
- ziteox-admin → ziteox-auth / Account: Existing session (require AAL2)
- ziteox-auth / Account → ziteox-admin: Staff identity + aal=aal2
- ziteox-admin → ziteox-admin: Check forge app role + role ceiling
- ziteox-admin → ziteox-admin: Mint Ed25519 JWS (
aud=core, ttl~60s, jti, sub, aal,action=token.issue, params_hash) - ziteox-admin → Connector API:
POST /v1/admin/tokenswith Assertion + issue body - Connector API → Connector API: Verify JWS with portal public key
- Connector API → jti replay cache: Reject if jti seen
- Connector API → jti replay cache: Store jti until exp
- Connector API → Registry: Insert project_tokens + grants (store hash/last4 only)
- Connector API → ziteox-admin:
{ id, token once, last4, expires_at, grants } - 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:
- (Note over ziteox-admin, Connector API) Same assertion pattern as issue (
action=token.revokeortoken.rotate) - ziteox-admin → Connector API:
POST /v1/admin/tokens/:id/revokewith Assertion + revoke body - Connector API → Connector API: Verify Ed25519 JWS (sig, aud, exp±skew, aal, action, params_hash)
- Connector API → jti replay cache: Reject if jti seen; else store until exp
- Connector API → Registry: Set revoked_at = now()
- Connector API → Audit log: Append token.revoke (no secret values)
- Connector API → ziteox-admin:
{ id, revoked_at } - (Note over ziteox-admin, Registry) Rotate = issue new + set old.replaced_by + old.overlap_until (e.g. 24h) then old stops working after overlap
- ziteox-admin → Connector API:
POST /v1/admin/tokens/:id/rotate - Connector API → Connector API: Verify JWS + jti (same as revoke)
- Connector API → Registry: Insert new token; link replaced_by; set overlap_until
- Connector API → Audit log: Append token.rotate
- 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
| Plane | Credential | Who |
|---|---|---|
| Data plane | Authorization: Bearer zxcore_… | Projects / agents |
| Management plane | Authorization: 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=
| Query | Required | Notes |
|---|---|---|
path | yes | Repo-relative file path; must match a read: grant |
ref | no | Branch/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)
| Method | Path | Purpose |
|---|---|---|
POST | /v1/admin/projects | Create project (optional portal_project_id) |
GET | /v1/admin/projects | List projects; ?portal_project_id= lookup |
PATCH | /v1/admin/projects/:key | Update/clear portal_project_id |
POST | /v1/admin/tokens | Issue token (returns raw once) |
POST | /v1/admin/tokens/:id/revoke | Immediate revoke |
POST | /v1/admin/tokens/:id/rotate | New token + overlap window |
GET | /v1/admin/audit | Per-key audit feed (filters, cursor before/next_before, role-scoped; see admin-portal-integration v1.6) |
Assertion shape (recommended)
EdDSA / Ed25519 JWS compact serialization.
| Claim / header | Value |
|---|---|
kid (header) | Key id selecting which pinned Core public key verifies this JWS |
iss | admin.ziteox.com (or portal key id) |
aud | core |
sub | Staff user id |
aal | aal2 (reject lower) |
jti | Unique nonce |
iat / exp | ~60s TTL; Core allows clock skew ±30s around iat/exp |
action | e.g. token.issue |
params_hash | SHA-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
kidin 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 oldkidfrom Core. - Compromise: remove the compromised
kidfrom Core immediately (all management assertions signed with that key fail verify); revoke any project tokens issued in the suspect window via audit (token.issuerows).
Vouching alternatives (comparison)
| Approach | Pros | Cons | Verdict |
|---|---|---|---|
| Ed25519 JWS assertion (recommended) | No shared secret at rest in two places; short TTL + jti; action-bound; fits AAL2 claim | Need key distribution + rotation | Pick |
| Shared HMAC secret | Simple | Shared secret doubles blast radius; harder to rotate cleanly | Reject for management plane |
| mTLS (portal ↔ Core) | Strong transport identity | Ops heavy on Workers; still need action binding | Optional later under Zero Trust |
| Cloudflare Access service token | Good for network gate | Not fine-grained action+params binding alone | Use as network layer later (§8), not sole auth |
Error codes
| Code | When |
|---|---|
401 | Missing/invalid token or assertion; expired; bad signature |
403 | Valid cred but scope denied, project disabled, AAL too low, role ceiling |
404 | Unknown path/ref/token id (avoid leaking existence where unsafe) |
409 | Conflict (e.g. rotate already in flight, duplicate project key) |
429 | Rate 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):
| Tool | Maps to |
|---|---|
core_whoami | GET /v1/whoami |
core_read_file | GET /v1/files |
core_list_tree | GET /v1/tree |
core_publish | POST /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
| Option | Notes |
|---|---|
| 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 PAT | Acceptable 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
| Layer | Suggestion |
|---|---|
| Per token | e.g. N req/min for read; stricter for publish |
| Per project | Aggregate cap across tokens |
| GitHub | Respect 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 likeinfra.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 | |
|---|---|---|---|
| Shape | Worker ziteox-core at e.g. core.ziteox.com; Workers secrets for Core KEK; registry in Supabase (forge_core) or D1 | Next.js API routes in ziteox-admin | Edge Functions beside secrets-seal / secrets-resolve |
| Prior art | ziteox-auth already on Workers via OpenNext (ziteox-auth/wrangler.jsonc, ziteox-auth/CLOUDFLARE.md); Forge docs via apps/docs/wrangler.jsonc | Admin already has /api/infra/secrets, /api/mcp | KMS seal/resolve already on Edge (02f112e) |
| Blast radius | Isolated from admin UI and client apps | Couples Core to admin deploy; widens blast radius | Shares Edge project with KMS; careful KEK separation |
| Latency / edge | Good global edge | Tied to admin host | Good, but function model for long GitHub fan-out is awkward |
| Secrets | Workers secrets for CORE_SECRETS_KEK (name only) | Can reuse portal KMS wiring — temptation to share KEK (bad) | Natural envelope crypto; risk of conflating KEKs |
| Ops | New Worker + DNS | No new host | New 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/corein 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)
| ID | Deliverable |
|---|---|
| M0 | This architecture doc accepted (or revised) by Laki |
| M1 | forge_core schema migration (local): projects, tokens, grants, vault_secrets, audit — RLS + revoke anon/authenticated |
| M2 | Worker skeleton: health, assertion verify + jti cache, whoami with hashed tokens |
| M3 | GitHub App (or PAT stopgap) in vault; read files + tree |
| M4 | Publish → branch + PR; scope + size limits |
| M5 | Admin portal pages: issue / rotate / revoke via assertions; register forge in core.apps |
| M6 | MCP 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 |
|---|---|
| CG1 | Automated + manual scan: no GitHub credential or raw zxcore_ appears in browser responses, MCP tool results, or log/audit fixtures |
| CG2 | Management mutations reject missing/invalid Ed25519 assertion, aal ≠ aal2, mismatched action/params_hash, reused jti, and unknown/removed kid |
| CG3 | DB stores only SHA-256 hash (+ prefix/last4); issue API returns raw token once; subsequent reads never return plaintext |
| CG4 | Insert-only audit path; DB CHECK rejects meta keys named like plaintext / secret / value / token / api_key |
| CG5 | If log redaction fails, the request fails closed and nothing secret-shaped is written |
| CG6 | Core KEK exists only as a Workers/platform secret name (e.g. CORE_SECRETS_KEK); absent from git/chat; distinct from portal SECRETS_KEK |
| CG7 | forge_core tables: RLS on; anon and authenticated have no privileges; service/narrow role only |
| CG8 | Publish never writes main directly (PR only); paths with .. / absolute / escape fail; grants matched only after normalization |
| CG9 | GitHub App installed on ziteox-core/ziteox-forge only with least privilege; PAT stopgap path removed from config after App cutover |
| CG10 | Over-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/core | Choice | Open Q |
|---|---|---|
| Hosting shape | Standalone Cloudflare Worker skeleton (ziteox-core), local only — no deploy configured | Q1 — default pending Laki's answer to Q1 |
| Schema / DB | Local 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 auth | Mock adapter + App stub (GITHUB_MODE=mock); real App path stubbed, not live | Q3 — default pending Laki's answer to Q3 |
| Publish policy | Branch + PR only; direct push to default/main/master → 403 direct_push_denied | Q4 — default pending Laki's answer to Q4 |
| Token TTL | 90 days default (TOKEN_TTL_DAYS_DEFAULT) | Q5 — default pending Laki's answer to Q5 |
| Who may issue / role matrix | forge_admin: all management actions; forge_operator: list/issue/rotate/audit/member.tokens.list only — not project.create, token.revoke, vault.seal | Q6 — default pending Laki's answer to Q6 |
| Token ownership | Per-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 claim | Optional; 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 list | GET /v1/admin/members/:memberId/tokens (member.tokens.list); forge_admin + forge_operator; params_hash over path/query params | — (pass 3) |
| Project binding header | Optional data-plane X-Ziteox-Project: <project_key>; mismatch → 403 project_mismatch. Rotate/revoke may send body project_key with the same check. | — (pass 3) |
| Environments | Enum 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 tokens | Not implemented; staff seed users only (dev-admin / dev-operator) | Q8 — default pending Laki's answer to Q8 |
| Package-install proxy | Out of local v1 (unchanged) | Q9 — default pending Laki's answer to Q9 |
| Zero Trust / Access | Not in front of local Worker | Q10 — default pending Laki's answer to Q10 |
| KEK custody | Local .dev.vars CORE_SECRETS_KEK only (gitignored); not platform secrets | Q11 — default pending Laki's answer to Q11 |
| Audit retention | Keep all local rows; no purge job | Q12 — default pending Laki's answer to Q12 |
| Assertion crypto | Ed25519 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 overlap | 24h (overlap_until) | Q14 — default pending Laki's answer to Q14 |
| Revoke bound | 0s (no project-token auth cache; next request sees revoked_at) | — (design §4d; not a numbered Q) |
| Envelope crypto | AES-256-GCM per-secret DEK + local KEK wrap (Workers WebCrypto) | — (pattern from portal KMS; KEK separation per design) |
| Secrets read scope | read:secrets/<label> or read:secrets/** | — |
| Project ceiling | projects.allowed_scopes; issue/rotate must stay within ceiling (scope_exceeds_project) | — |
| Audit | Insert-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
- Hosting: Confirm standalone Cloudflare Worker
ziteox-coreatcore.ziteox.com(option A), or prefer B/C? - Schema / DB:
forge_coreschema in the existing Supabase project, a different name, or a separate database? (Must not collide with portalcore.*.) - GitHub auth: Approve GitHub App (recommended) vs fine-grained PAT stopgap first?
- Publish policy: Lock PR-only (no direct push to
main) for all grants? - Token TTL: Default 90 days to match
AGENT_TOKEN_TTL_DAYS, or different? - Who may issue tokens? Which
forge/ admin roles (and ceiling) are allowed? - Token ownership model: Per-project tokens only, or also per-staff personal tokens?
- Bots holding tokens: May agent accounts own
zxcore_tokens under role ceiling (bot_not_allowedrules), or staff-owned only? - Package-install proxy: Explicitly out of v1 — confirm, and is it on the near backlog?
- Zero Trust timing: Access in front of management plane before first prod deploy, or after?
- KEK custody: Who may
wrangler secret putthe Core KEK (Laki-only, same as portal root ops)? - Audit retention: How long to keep
forge_core.audit_events(e.g. 1 year / indefinite)? - Assertion crypto: Ed25519 JWS as specified, or do you want Cloudflare Access service tokens as a second factor from day one?
- Overlap window on rotate: Default 24h acceptable?
- Admin assertion signing key custody: Confirm private key in admin platform secrets (e.g.
CORE_ASSERTION_SIGNING_KEY) and public keys pinned bykidin 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 newpackages/ui/package.json—@ziteox/ui0.1.2,publishConfig.registry→https://npm.pkg.github.comapps/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:
5f27455M0 docs,5c5b00cM1 schema,02f112eM2 Edge seal/resolve,173e602M3 admin seal UI +/api/infra/secrets,83ce297M4 Railway/Bunny prefersecret_id,b21d4eehardening (CORS allowlist, AAL2, rate limit, G8 docs) docs/infra-kms-project-sketch-2026-10-28.md— envelope model, G1–G10, M0–M6docs/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_metaziteox-client/supabase/functions/_shared/secrets-crypto.ts— AES-256-GCM,SECRETS_KEKziteox-client/supabase/functions/_shared/secrets-admin-auth.ts— JWT, admin role, aal2, rate limitziteox-client/supabase/functions/secrets-seal/index.ts,secrets-resolve/index.tsziteox-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.tsziteox-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— routesmcp_service_tokens,app_connections,apps,app_*→ schemacore(adaf980)ziteox-admin/supabase/migrations/20261101000000_app_connections.sql—core.app_connectionsziteox-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)