Skip to content

web, pods: session interface for the practice app - #110

Closed
tire-fire wants to merge 36 commits into
mainfrom
session-interface
Closed

tire-fire wants to merge 36 commits into
mainfrom
session-interface

Conversation

@tire-fire

Copy link
Copy Markdown
Collaborator

Draft: group 2 of openspec/changes/self-service-team-play is built and reviewed. The real-cluster checks are still to do (see "Left to do").

What it adds

  • Session interface (internal/web/practice.go): served on its own listener ([practice] listen) and off unless [practice] is set. Each call presents the session principal's Proxmox ticket plus BATTLESHIP_PRACTICE_KEY. Routes:
    • GET /v1/sets: the approved sets, each with its templates' VMIDs and config digests, one pod's footprint, and whether it can deploy now.
    • GET /v1/pods/{pod}/vms
    • POST /v1/jobs: deploy or teardown to a session pod (51–59).
    • GET /v1/jobs/{id}
    • POST /v1/jobs/{id}/cancel
    • Refused without contacting Proxmox: another user's ticket, a wrong or missing key, a pod outside the range, any other kind, an unapproved set, and a body over 16 KiB.
  • Approval by a Proxmox registered tag (deploy.approved_tag, internal/pods/approved.go). A set is approved when every master carries the tag spelled exactly as configured. Approval is refused where a case variant could forge it:
    • Proxmox must have tag-style case-sensitive, or a user-allow list holding every tag Battleship writes with no case variant of the approval tag.
    • existing never approves.
    • env-edit drops the tag when a host moves to another domain.
  • Template digests:
    • A session deploy sends back the digests GET /v1/sets listed. A missing digest is refused 422 bad_digests. A template changed since the listing is blocked (409), at submission and again at the worker's re-plan.
    • A teardown that sends digests is refused.
  • jobs.origin column (migration 020) records which jobs the interface submitted.
  • Clone and tag rights asked as Proxmox checks them (all planners, not just session deploys):
    • SDN.Use on each clone source NIC's tag path or bare vnet, in zones Battleship knows from config. Trunk VLANs and other bridges are left to Proxmox at run time.
    • The network steps also ask for the value each NIC write replaces.
    • Sys.Modify on / for any step that adds or removes a tag that user-tag-access refuses. deploy.approved_tag counts as registered when the reader is shown no registered tags.
    • Each step's edits are replayed on the config as read, through the executor's own change functions.
  • openspec: self-service-team-play (proposal, design, threat model, tasks) and practice-ai-addon.

Behaviour changes for existing users

  • Every clone now needs SDN.Use on the source's known-zone NIC networks (dev-slot and edit vnets for templates). Proxmox's clone already checks this, so the plan now refuses up front what used to fail at clone.
  • The capacity estimate reports boot disk as 0 under linked clones.
  • Planning asks for more rights, all of which Proxmox already enforces, so the preview now refuses what used to fail at run time:
    • Sys.Modify on / for label, tag-set and retire steps that change a tag user-tag-access refuses.
    • SDN.Use on a NIC's old vnet when a network step moves it.
  • A deploy reads the config of each pod VM it keeps. A VM that can't be read, or is gone since the listing, blocks only its own item.
  • A network step that has neither NICs nor a template now fails its item and writes nothing. Before, the executor would have panicked; no planner builds such an item.
  • deploy.approved_tag and deploy.master_tag are trimmed once at config load.
  • Fingerprints of stored plans are unchanged, with one exception: a resumed env-create whose VM spells a wanted tag in another case now re-spells Tags to the VM's spelling. A job like that queued across the upgrade ends stale and has to be submitted again.
  • The interface's request body cap is 16 KiB.

Accepted risk

The session principal needs SDN.Use on the dev-slot networks that approved templates' NICs sit on. With VM.Config.Network on the session pools, a compromised practice app could attach a session VM to a staff dev network. This is recorded in THREAT_MODEL.md and design.md decision 5. Task 2.11 removes it.

Left to do

  • Group 1: the real-system setup (1.12 Authentik first).
  • 2.7: check on the real cluster that rebuilding a template changes its digest.
  • 2.9: list the interface's active jobs.
  • 2.11: keep templates off dev-slot networks.

Review

The lenses ran from round 6 onward on the rebased branch (the ledgers from rounds 1–5 were lost to a VM reboot). Each round reviewed the previous round's fixes. All 7 lenses ran whenever the structure changed.

Round Range Rows Outcome
6 origin/main..36cb9eb 22 all fixed
7 round-6 fixes 18 17 fixed; 1 deferred to task 2.11 (principal's SDN.Use on dev-slot networks)
8 round-7 fixes 14 13 fixed; 1 rejected (the four template-blocks-its-items cascades differ by design)
9 round-8 fixes 11 all fixed
10 round-9 fixes 15 all fixed
11 round-10 fixes 11 10 fixed; 1 rejected (a wording rollback round 10 had already corrected)
12 round-11 fixes 6 all fixed
13 round-12 fixes 2 wording only, fixed; lenses 1, 2, 4, 5 and 7 clean, so the loop stopped

Main fixes across the rounds:

  • An env-edit could carry approval into another domain; it can't now.
  • Template digests are checked on every path.
  • Clone and network rights are asked as Proxmox's check_bridge_access asks them, without guessing zones and without expanding trunk ranges, which cost 4,099 Proxmox calls for one trunked NIC in a scratch run.
  • Tags are compared exactly as typed.
  • A single pods.StepChanges is shared by the executor and the rights replay.
  • A VM that can't be read now blocks only its own item.

Checks on the pushed head:

  • b24fa63: gofmt is clean and go vet ./... passes.
  • CI=true go test -race -count=1 ./... passes against Postgres.
  • The browser suite passes 26/26 with -race (headless Chrome).
  • openspec validate --all --strict: 2 passed. The INFO notes are pre-existing: practice-ai-addon modifies specs that don't exist yet.

deploy.approved_tag marks a set whose every master carries it as approved
for self-service sessions. A deploy with approved_only is refused unless
its set is approved, at submission and at the worker's re-plan.

[practice] holds the session interface's settings (pods, principal,
listen, key); unset, the interface is off.
With [practice] set, serve opens a second listener for five calls: list
approved sets (with templates, config digests and one pod's size), list a
session pod's VMs, submit a deploy or teardown, and read or cancel a job
the interface submitted. Each call carries practice.key and a Proxmox
ticket of practice.principal, which Proxmox proves by renewing it.

internal/web/testdata/practice records one exchange per call for the
practice app's client tests.
…s origin

Review findings on the session interface, resolved:

- Approval has one authority, internal/pods/approved.go. The tag counts
  only as one of Proxmox's registered tags, a session deploy takes
  exactly its set's masters rather than a name pattern's matches, and it
  clones built templates without building any. MasterSet no longer
  counts approvals, so the status poller is as it was.
- jobs.origin (migration 020) says what submitted a job. The interface
  reads and cancels its own by that, and a volunteer is a job's starter
  only on jobs from the volunteer pages.
- GET /v1/sets sizes a pod from its built templates, with every disk
  counted, reports battleship's own digest of each template's config,
  and marks a template it can't read instead of failing every set.
- An outage while planning answers 502 or 504, not a 409 refusal, and
  each call has a deadline shorter than the listener's write timeout.
- Both listeners shut down together.
- The commented-out manifest blocks are gone; deploy/README.md says how
  to turn the interface on. practice.listen is documented as plain HTTP.
Second review round on the session interface:

- GET /v1/sets plans a deploy of each approved set and lists the
  planner's templates, with what it blocks and why, so the listing can't
  show a template a deploy would refuse. The separate model of a set's
  templates is gone.
- The approval tag is matched in its exact spelling, on the masters and
  in Proxmox's registered tags, and a set with no masters is not
  approved. The fake Proxmox shows the registered tags only to
  Sys.Audit on /, as Proxmox does; the principal needs that right.
- MasterSets and approval group masters by set through one function.
- Planning errors need no classifying: the request is refused only as
  not approved, and anything else is Proxmox's failure or the store's.
- A pod's disk is the boot-disk figure the capacity estimate uses.
- serve keeps its listeners in one slice.
…ts as the job plans them

Proxmox checks a tag as typed and then stores it lower-cased unless tag-style is case-sensitive, so under the default settings anyone may set a variant of the registered approval tag. approvalTag now refuses unless tag-style is case-sensitive, the tag has no letters, or user-allow is not free (a list holding no variant). TagAccess reads tag-style, and Allows looks a tag up as typed, as Proxmox does.

GET /v1/sets plans each set through jobs.BuildPlan, so it applies the principal's privileges and lists as blocked a template it could not clone. The digest comes from the planner's own read (TemplateSpec.Digest); the second config read and its error go, and one timeout bounds each set's plan. A submission reads the reserved keys before planning, so a store failure is told apart without a flag.

THREAT_MODEL records the case-variant rule, the tag copy on clone, Sys.Audit granted at / without propagation, and that a volunteer's retry needs it too.
…k the clone right of each listed template

user-allow=existing also allows the allow-list and the tags on guests the reader sees, so it is no safer than list. TagAccess.AllowsVariantOf decides on allowed-tags in every mode but free, through Allows, and approvalTag calls it.

GET /v1/sets asks VM.Clone of each template itself (pods.Unclonable), since a first session pod that already holds the set clones nothing and its plan checks no clone right. Sets still unplanned 5 s before the call's deadline answer with their own error instead of turning the whole call into a 504.
…ets through the job plan again

Under existing each user may also set the tags on guests it audits, which no one reader sees whole, so AllowsVariantOf allows a variant unless tag-style is case-sensitive, the tag has no letters, user-allow is none, or a list holds no unregistered variant.

GET /v1/sets plans through jobs.BuildPlan again, so the first pod's pool, storage, network and tag rights show in the listing, and still asks VM.Clone of each template itself.
TagAccess's case-sensitive and the agent's exec-status exited each parsed the same RawMessage by hand.
…vedOnly

DeployRequest takes ApprovedOnly and keeps Pattern, which deployMasters parses once with SetOfPattern, in place of ApprovedSet and the rewrite in jobs; the no-master message names the pattern either way. deployMasters no longer guards a nil Access, which NewPlanner never leaves and BlockUnpermitted refuses.
…e the listing

POST /v1/jobs takes the digests GET /v1/sets listed, by template name, and refuses a deploy without them (422 bad_digests). jobs.Inputs keeps them (only with ApprovedOnly) and DeployRequest.Digests blocks a template whose digest differs or is missing, so the submission answers 409 blocked. An approved-set plan's template digests are in the fingerprint, so a template rebuilt in place before the worker claims the job ends it stale.
cloneNeeds is the one definition of what a clone asks (VM.Clone on the source, VM.Allocate in the pool, Datastore.AllocateSpace, SDN.Use on the source's vnet bridges, Mapping.Use for a custom CPU); itemNeeds' clone step and pods.Uncloneable both use it. GET /v1/sets asks it for the first session pod whether or not that pod already holds the set, in place of Unclonable's VM.Clone alone.
pods.PodFootprint sums a pod's clones of the reused templates, counting boot disks through cloneDisk, which EstimateCapacity now shares: a full clone copies the boot disk, a linked clone (deploy.linked, the default) counts as none. GET /v1/sets reports it in place of practiceSize's own sum of MaxDisk.
practiceAnswerMargin's earlier deadline duplicated the slack the listener's write timeout already leaves, and nothing reads the context after the plans. A test pins that sets the call runs out of time for carry their errors in a 200.
A clone asks SDN.Use on every NIC of its source, plain bridges under zone
localnetwork and VLAN tags on their path; a template build asks it as the
clone it is. An env-edit label step that adds or removes a tag
user-tag-access refuses asks Sys.Modify on /.
BlockChanged runs after BlockUnpermitted on unblocked templates only, so a
blocked template keeps its reason. The fingerprint drops Digest: the
re-plan blocks a changed template, and Blocked is fingerprinted. Every plan
records a reused template's digest.
…terface's checks

Name the SDN.Use the principal needs on the networks approved templates'
NICs sit on as an accepted risk (task 2.11), the root@pam ticket exception,
the env-edit's Sys.Modify ask, the listing's deadline, and the digest check
after the privilege checks.
- sdnUse asks SDN.Use only for bridges in a zone Battleship knows
  (environments.sdn_zone, images.edit_zone, proxmox.sdn_zone) and
  leaves any other bridge to Proxmox; vnetPaths follows
  check_vnet_access (tag, each trunk VLAN, bare bridge with neither).
  Clones and both network steps use it, the network steps on the NIC
  values they write (Item.NICsWas).
- tagChanges compares tags as typed, as a multiset diff; sameTags is
  no changes, and hostTags keeps the VM's spelling.
- Every label and tag-set planner records TagsChanged from the tags as
  read; the retire step asks for the deprecated tag; tagNeeds treats
  deploy.approved_tag as registered.
- BlockChanged skips a template whose items are all blocked already.
- Source, TemplateSpec and Item hold one AsRead map (tags and netN, the
  clone source's under StepClone, else the VM's own); stepEdits replays
  NICChanges/NetworkChanges, LabelChanges, SetTagChanges and AddTag on it
  for the tags and NICs each step changes. Bridges, NICsWas, TagsChanged,
  the TemplateSpec side channels, withSetTag and nicsOf go. Fingerprints
  are unchanged; old stored keys are ignored.
- A deploy reads each pod VM it keeps, so its network step starts from
  the VM's own NICs; the network steps ask SDN.Use on each written netN
  value and on the value it replaces, as update_vm checks both.
- vnetPath asks only <bridge>/<tag> or the bare vnet; trunk VLANs are left
  to Proxmox, so trunk ranges are no longer parsed.
- respellTags re-spells wanted tags as the VM has them for env-create and
  env-edit; hostTags drops its own copy.
- tagNeeds counts deploy.approved_tag as registered only when TagAccess
  shows no registered tags.
…ept VM

- Item.AsRead holds only a kept VM's own config; stepEdits starts from the
  clone source's (cloneSource, shared with itemNeeds) under StepClone, and
  the planners no longer copy it. AsRead is json:"-": rights are checked
  on a fresh plan, so stored plans drop it; fingerprints are unchanged.
- StepChanges maps a network, label, tag-set or retire step to its change
  function, used by apply.runStep and stepEdits. The retire step's tag edit
  is [deprecated], so Supersedes no longer carries its tags, and the tag
  diff is taken before and after each replayed step (tagEdit goes).
- Deploy reads its kept pod VMs with readConfigs, which now reports each
  VM's error: an unreadable VM blocks only its item, one gone since the
  listing is blocked as gone, and the VM's own cloud-init drive decides its
  network step's VM.Config.Cloudinit. keepVMs still narrows after planning:
  it runs in jobs on every team kind's plan.
…ribed

- Recommend tag-style case-sensitive, or user-allow list holding every tag
  Battleship writes and no case variant of the approval tag; drop none,
  under which the principal's set-<set> tag step is blocked (THREAT_MODEL,
  design decision 5, task 1.5).
- Uncloneable asks SDN.Use on the tag path or bare vnet in known zones; an
  unregistered approved_tag asks Sys.Modify when user-tag-access refuses it.
…k step

asRead keeps the cloud-init drive and stepEdits records whether the network step regenerates it, replacing Item.CloudInit and TemplateSpec.CloudInit. StepChanges takes the template and returns nil for a network step with neither NICs nor a template, which the executor fails; retire is inline in runStep again. TemplateSpec.CPU is no longer stored in plans. A deploy cancelled while reading its kept VMs returns the cancellation instead of blocking them.
RegeneratesCloudInit decides it for stepEdits' replay and the executor's network step, which now regenerates itself; applyConfig loses its cloudInit parameter. isCloudInitDrive serves HasCloudInit and CDROMChanges. AsRead holds the config as read, without asRead's filter; docs and a test comment are reworded.
@tire-fire tire-fire closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant