carlos / platform Public

console: CLI fleet box doors are owner-only, like the browser (H4-M3)

add-box, rotate, detach and tags on /api/cli/fleets/ checked membership
only, so a member could mint or swap a box credential that reads the
account's whole app estate, or detach boxes. The browser twins use
ownerFleet. apiOwnerFleet puts the same owner gate on the four CLI doors:
the family's 404 first, then apiOwnerAccountFor's 403, then the fleet's
own 404. The browser fleet doors have no passkey step, so none is owed.

Carries the hunt test TestHunt_H4_M3_MemberCannotManageFleetBoxes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev bdad33fd327233b2a8834c984eb69255b199b07f parent f6ac853
2 files changed, +93 −4
  • internal/console/fleets.go +21 −4
  • internal/console/hunt_H4-M3_test.go +72 −0
diff --git a/internal/console/fleets.go b/internal/console/fleets.go
index bad2b9c16..74fa0be43 100644
--- a/internal/console/fleets.go
+++ b/internal/console/fleets.go
@@ -98,6 +98,23 @@ func (s *Server) apiFleet(w http.ResponseWriter, r *http.Request) (addr string,
return addr, acct, fleet, reg, true
}
+// apiOwnerFleet is apiFleet behind the owner gate the browser's fleet box
+// doors hold (ownerFleet), for the CLI doors that mint, swap or withdraw a
+// box's credential (security hunt H4-M3). A member gets
+// apiOwnerAccountFor's 403; the family's byte-identical 404 still comes
+// first, and the fleet's own 404 after.
+func (s *Server) apiOwnerFleet(w http.ResponseWriter, r *http.Request, purpose string) (addr string, acct *Account, fleet *registry.Fleet, reg consoleRegistry, ok bool) {
+ p, acct, ok := s.apiOwnerAccountFor(w, r, purpose)
+ if !ok {
+ return "", nil, nil, nil, false
+ }
+ fleet, reg, ok = s.apiFleetOf(w, r, acct)
+ if !ok {
+ return "", nil, nil, nil, false
+ }
+ return auditActor(p, acct), acct, fleet, reg, true
+}
+
// apiFleetOf is apiFleet's fleet half for a door that has already resolved
// the account its own way (the secrets key door's owner gate): the
// {fleet} segment read from the registry, with an unknown fleet and one
@@ -388,7 +405,7 @@ func (s *Server) handleAPIFleetList(w http.ResponseWriter, r *http.Request) {
// only its sha256 hex reaches the registry (AddFleetBox), and it is never
// logged.
func (s *Server) handleAPIFleetAddBox(w http.ResponseWriter, r *http.Request) {
- addr, acct, fleet, reg, ok := s.apiFleet(w, r)
+ addr, acct, fleet, reg, ok := s.apiOwnerFleet(w, r, "add a box to a fleet")
if !ok {
return
}
@@ -472,7 +489,7 @@ func (s *Server) handleAPIFleetAddBox(w http.ResponseWriter, r *http.Request) {
// which the edge honours by closing the live channel outright — rotation
// alone is the wrong tool for "get this box off the network right now".
func (s *Server) handleAPIFleetRotateBox(w http.ResponseWriter, r *http.Request) {
- addr, acct, fleet, reg, ok := s.apiFleet(w, r)
+ addr, acct, fleet, reg, ok := s.apiOwnerFleet(w, r, "rotate a fleet box's token")
if !ok {
return
}
@@ -533,7 +550,7 @@ func (s *Server) handleAPIFleetRotateBox(w http.ResponseWriter, r *http.Request)
// findFleetBox's doc comment for why that one is not the cross-tenant-probe
// 404.
func (s *Server) handleAPIFleetTagBox(w http.ResponseWriter, r *http.Request) {
- addr, acct, fleet, reg, ok := s.apiFleet(w, r)
+ addr, acct, fleet, reg, ok := s.apiOwnerFleet(w, r, "tag a fleet box")
if !ok {
return
}
@@ -579,7 +596,7 @@ func (s *Server) handleAPIFleetTagBox(w http.ResponseWriter, r *http.Request) {
// refused, and — unlike rotation — an already-connected channel is closed).
// This is the hard revocation rotation is not.
func (s *Server) handleAPIFleetDetachBox(w http.ResponseWriter, r *http.Request) {
- addr, acct, fleet, reg, ok := s.apiFleet(w, r)
+ addr, acct, fleet, reg, ok := s.apiOwnerFleet(w, r, "detach a fleet box")
if !ok {
return
}
diff --git a/internal/console/hunt_H4-M3_test.go b/internal/console/hunt_H4-M3_test.go
new file mode 100644
index 000000000..b63e37fe2
--- /dev/null
+++ b/internal/console/hunt_H4-M3_test.go
@@ -0,0 +1,72 @@
+package console
+
+import (
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/edge"
+)
+
+func TestHunt_H4_M3_MemberCannotManageFleetBoxes(t *testing.T) {
+ for _, action := range []string{"add", "rotate", "detach", "tags"} {
+ t.Run(action, func(t *testing.T) {
+ fx, owner := huntFleetFixture(t, "hunt-m3-owner")
+ if err := fx.st.AddMember(OpsAccountID, "alice@keymail.dev", RoleMember, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ member := huntCLIToken(t, fx, "alice@keymail.dev", "hunt-m3-member")
+ base := fleetsURL(fx, fx.sqid)
+ if code, out := postJSON(t, base+"/new", map[string]string{"name": "hunt", "bucket": "hunt-data"}, owner); code != http.StatusOK {
+ t.Fatalf("setup fleet: %d %v", code, out)
+ }
+ base += "/hunt/boxes"
+ if code, out := postJSON(t, base, map[string]string{"label": "existing"}, owner); code != http.StatusOK {
+ t.Fatalf("setup box: %d %v", code, out)
+ }
+ reg := openTestReg(t, fx)
+ defer reg.Close()
+ before, err := reg.ListFleetBoxes("hunt")
+ if err != nil {
+ t.Fatal(err)
+ }
+ path := base + "/existing/" + action
+ body := map[string]string{}
+ if action == "add" {
+ path = base
+ body["label"] = "attacker"
+ }
+ if action == "tags" {
+ body["tags"] = "attacker"
+ }
+ code, out := postJSON(t, path, body, member)
+ after, err := reg.ListFleetBoxes("hunt")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if action == "add" || action == "rotate" {
+ auth, err := reg.FleetChannelAuth()
+ if err != nil {
+ t.Fatal(err)
+ }
+ hub := &edge.TunnelHub{}
+ hub.SetDynamicAuth(auth)
+ label := "existing"
+ if action == "add" {
+ label = "attacker"
+ }
+ token, _ := out["token"].(string)
+ if fleet, ok := hub.VerifyDynamic("hunt/"+label, token); ok {
+ t.Errorf("member-issued %s token authenticates at edge as fleet=%q; want rejection", action, fleet)
+ }
+ }
+ changed := len(before) != len(after)
+ if len(before) == len(after) {
+ changed = before[0].TokenHash != after[0].TokenHash || before[0].Status != after[0].Status || before[0].Tags != after[0].Tags
+ }
+ if code != http.StatusForbidden && code != http.StatusNotFound || changed {
+ t.Errorf("member fleet %s: status=%d state_changed=%v token_returned=%v; want refusal and unchanged registry", action, code, changed, out["token"] != "" && out["token"] != nil)
+ }
+ })
+ }
+}