Skip to content

Manage template tags, description, visibility and owner through the API #747

Closed

Description

@webchang

Problem

With templates in a store (#736) and self-serve creates (#737), what changes after create can only be
changed by editing the store: an owner cannot move default (or stable, v2) to a new build, nor
change a template's description or visibility; an admin cannot hand a template to another user. A
template the deployment declared (imported once from SH_SANDBOX_TEMPLATES) has no owner, so its id
blocks every self-serve create under it (409 template_exists) and nobody can ever build a new version
of it without a store edit.

Proposal

Each change is an API call and a provenance record (#730) naming the new value and the one before.

  • POST /v1/templates/{id}/tags {tags, build} (the owner): moves tags onto a registered build;
    DELETE /v1/templates/{id}/tags/{tag} removes one (never default; the build stays). A tag record
    {tag, buildId (null when removed), before}. Sandboxes and sessions created earlier keep the build
    they were given.
  • PATCH /v1/templates/{id} {description?, visibility?} (the owner): a visibility record {field, value, before}. A self-attested template cannot become deployment-visible (Trust a subject's own gate record for its own templates; allow repositories per registry #738).
  • PUT /v1/templates/{id}/owner {owner} (admins): an owner record {owner, before}. A declared
    template (owner: null) can be handed to an enrolled subject, recorded with before: null; the
    subject then builds, tags and retires it like any of theirs, and a restart does not undo it (the env
    list is not re-imported). owner takes the subject grammar of Enroll subjects and grant the admin role through the API, recorded and effective per request #739: github:<id> or oidc:<sub>
    (feat: generic OIDC identity provider (w3id) behind the login seam #701), never test:<n>.
  • Every owner action is also open to admins, on any template.
  • mocactl (the client part, filed here): sbx templates tag ID TAG… --build B, untag ID TAG,
    edit ID [--visibility private|deployment] [--description TEXT], transfer ID SUBJECT (admins).

What the PR will contain

One PR, about 1,150 added lines with tests (client included).

  • control-plane: src/sandbox-handlers.ts (ownTemplate, moveTemplateTags, removeTemplateTag,
    updateTemplate, transferTemplateOwner), src/routes.ts; test/activation.test.ts (tags, edit,
    owner transfer including a declared template; an oidc: owner passes the subject grammar), test/routes.test.ts,
    test/openapi-contract.test.ts.
  • mocactl: src/sbx/api.ts, src/sbx/commands.ts, src/sbx/cli.ts; test/sbx-cli.test.ts,
    test/contract.test.ts, test/helpers/sbx.ts.
  • docs: docs/api/openapi.yaml (a minor API version bump), CHANGELOG; the template lifecycle design §5.1-§5.2.

Depends on

#736, #730, #737. The subject grammar (MEMBER_SUBJECT_RE in src/identity.ts, after #701) is shared with
#739 and #748: whichever lands first carries it.

How to verify

  • pnpm -C packages/control-plane test -- activation routes openapi-contract
  • pnpm -C packages/mocactl test -- sbx-cli contract
  • On a deployment with a store: an admin transfers a declared template to a user; the user's
    templates create under that id is a new build of it (not 409); tag ID stable --build B moves
    stable, and a sandbox created with ID:stable is served by B; the template's stream holds the
    owner (before: null) and tag records.

Limits / out of scope

  • A transfer needs an admin; a deployment with none cannot transfer.
  • Whether a declared id should be claimable without an admin, and whether a retired id should become
    free for others, are left open (today: neither).
  • No per-template roles (a maintainer who may tag but not transfer).

Assisted-By: Claude Code

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions