Repository navigation
Open
Description
Companion change for rossoctl/moca#358, specified in moca's per-subject claim names design §2.2 (PR rossoctl/moca#543). Moca lifts its claimName stop-gap and forwards a caller-supplied slug; Context Service derives, scopes and enforces the claim. Verified against this repo at main 7951826: a Context today is its managed PVC, so this is most of the work on the Moca side of the feature.
What is needed
- Metadata record for attached-claim Contexts. A namespaced ConfigMap per attached-claim Context (the existing
queryIndexNamepattern) carries name, type, revision history, frozen revision, owner, grants, consumers, audit and the attachment. Writing annotations on the caller's PVC is rejected: anyone with edit rights on the claim could rewrite its grants. Managed-PVC Contexts keep today's PVC-carried metadata untouched (additive). The record is deterministically named for the Context name and created with create-if-absent semantics, and the managed path creates the same reservation before its PVC — today its uniqueness comes for free fromPersistentVolumeClaims.Createoncontext-<name>(manager.go:72) — so a managed and an attached create of one Context name cannot both succeed. contextId= the record's UID for attached-claim Contexts, never the claim's UID (shared across Contexts, stable across delete-recreate). Upload, freeze and export verify their expected UID against the record where they verifypvc.UIDtoday (context_upload.go).- One claim backs at most one live Context:
409 claim_in_use. The check is a per-claim marker object, deterministically named from the claim and created if-absent — a list-then-create check cannot refuse both of two concurrent creates that name the same claim. Delete removes the record and the marker before the claim counts as released; the re-created Context's fresh record has a fresh UID. storage.claimNameaccepted on create (internal and public). When set, no PVC is created: the claim namedmoca-<scope>-<slug>must already exist for the request's subject (409 claim_not_found, never provisioned).<scope>=HMAC-SHA256(secret, subjectKey)[:32]wheresubjectKey=kind + ":" + name(access.go:315's encoding — souser:xandserviceaccount:xnever share a scope) and the secret is a newCONTEXT_CLAIM_SECRETsetting, stable per deployment (random per process if unset — fine single-replica, wrong for more).size/storageClassare ignored on that path.- The claim is a revision store, exactly as a managed PVC is today. An upload materializes into
.context-service/materialized/<digest>/on it — content-addressed (materializeUploadWithLimit,cmd/context-service/main.go:210;UploadContextrefuses any otherWorkspacePath) — the revision id is the digest of exactly what export streams (exportMaterializedRevision), and export streams only that directory, so the freeze pin's property is unchanged. Pre-existing content at the claim's root is invisible: never read, never part of a revision, never exported, never overwritten — Context Service touches only.context-service/on the claim. Bring-your-own-PVC buys the caller the volume's capacity, storage class and placement, not its data. Two footnotes on an adopted claim:ensureMaterializationDirectorychmods.context-service/andmaterialized/to 0755, and the expanded-size limit (contextUploadExpandedLimit) comes from the claim's requested size, not its free space.DELETEremoves the Context (record included) but never the claim. - The trusted create response gains
attachment.claimName— the only attachment field on the trusted contract — amending the "omits the PVC attachment because Moca receives content as bundles, not mounts" rationale atuploads.go:106: for an attached-claim Context, Moca stores the derived name and returns it to the owner.
Deliberately not built: importing the claim's existing tree as a revision (digesting and materializing the root content as its own revision, with its own size and type checks) — a further change with no consumer yet; see the moca spec §3's limits.
Tests (with the change)
- The same slug from two subjects derives to two different claim names; a subject cannot attach a claim outside its scope.
claim_not_foundandclaim_in_use; two concurrent creates naming the same claim let exactly one win, and a managed and an attached create of one Context name let exactly one win (the shared reservation).- A freeze with a stale
contextIdfails against the record's UID; deleting the Context removes the record and leaves the claim. - Context Service writes only under
.context-service/on an adopted claim, and pre-existing content there never reaches a revision or an export.
🤖 Generated with Claude Code
Metadata
Metadata
Assignees
Labels
No labels
Activity
docs(spec): the claim is a revision store, not an adopted filesystem
moonlight16 commentedon Oct 20, 2026
Thanks for writing this up, Paolo. Some history and where phases 1 and 2 have landed, before we build it.
History. Context Service could already attach an existing PVC:
a182685("Support externally managed workspace claims",contextctl create --claim <pvc> --read-only|--read-write). It mounted the claim into a sandbox pool and never deleted it. #51 (Context Service stores context only) removed it along with the sandbox pools. So #59 brings the idea back, but attached to a Context instead of a sandbox pool, and that adds two things the old version never had to handle: per-user scoping, and frozen revisions on a volume the user also controls.Where this meets Moca's phase 2. The phase 2 design (rossoctl/moca#553 and its follow-up rossoctl/moca#561) gives each workload its own sandboxes and a PVC. Its §11 lists simplifications to explore, including "MOCA owns the workload's PVC; Context Service only fills it with the revision." If we go that way, bring-your-own-claim belongs in Moca's workload API, close to the old
--claimbehavior, and Context Service needs no attach-claim path at all. I'd like to settle that before we build #59.If we do build it here, four things to fix first:
moca-<scope>-<slug>, but nothing tells them that name before a create succeeds, and409 claim_not_founddoesn't include it. Return the expected name in the 409, or add a call that derives it.requestSubjecttrustsX-Context-Subjectwithout authentication (internal/api/handler.go:387), soclaimNamemust be accepted only on/internal/v1/contexts.fsGroup(internal/kube/context_upload.go:359-372), so kubelet would change group ownership on everything already on the claim. Attached claims should get nofsGroup.exportMaterializedRevision(cmd/context-service/main.go:114) streams the revision folder without re-checking it, so anyone with write access to the claim can change a frozen revision. Verify the content against its digest on export.Smaller items:
CONTEXT_CLAIM_SECRETa startup error.Proposal: hold #59 until we decide who owns workload storage in phase 2. If it stays in Context Service, we fix the four above, and the old
--claimcode is a good starting point for the claim lookup, access-mode checks and the never-delete rule.