carlos / platform Public

console: an ownerless fleet is nobody's; usage-day keys refuse dot segments

The edge-day reader compared a fleet's owner after defaulting an empty
one to the ops account, so the ops account read a fleet the registry
names no owner for, and its rows counted for ops. The owner is now kept
as the registry holds it: an ownerless fleet is listed by no account's
read and vouches for no account. Only a row's or tally's own account
defaults to ops.

usageDayDate accepted "." and ".." as a fleet or box segment; a key
segment must now be plain.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev aa0d943181a8d59f81e0a761771d240fb5af559f parent e412d5c
4 files changed, +94 −22
  • internal/console/edgedays.go +21 −19
  • internal/console/edgedays_test.go +48 −0
  • internal/console/usagedays.go +11 −1
  • internal/console/usagedays_test.go +14 −2
diff --git a/internal/console/edgedays.go b/internal/console/edgedays.go
index 46e769256..5087fad3f 100644
--- a/internal/console/edgedays.go
+++ b/internal/console/edgedays.go
@@ -29,8 +29,9 @@ import (
// tallyCounts are the rule every consumer applies, never a check of its own.
// edgeDaySource is one box's day as read, with where it came from: Fleet is
-// "" for a root box, and FleetAccount the owner of the fleet whose prefix
-// held it. Day.Box and Day.Date are the key's, never the body's.
+// "" for a root box, and FleetAccount the registry's owner of the fleet whose
+// prefix held it, as the registry holds it ("" when it names none). Day.Box
+// and Day.Date are the key's, never the body's.
type edgeDaySource struct {
Day usage.EdgeDay
Fleet string
@@ -87,7 +88,9 @@ func (s *Server) readEdgeDays(ctx context.Context, st release.Store, dates []str
type edgeDayFleet struct{ name, account string }
// edgeDayFleets is the registry's fleets in name order, only acct's when
-// acct is set. A console with no registry has no fleets. A registry that
+// acct is set. The owner is compared as the registry holds it: a fleet with
+// no owner is nobody's, so no account's read lists it, the ops account's
+// included. A console with no registry has no fleets. A registry that
// cannot be read fails the read: the fleets it holds are unknown, and
// leaving them out would be a short total.
func (s *Server) edgeDayFleets(acct string) ([]edgeDayFleet, error) {
@@ -104,11 +107,10 @@ func (s *Server) edgeDayFleets(acct string) ([]edgeDayFleet, error) {
}
var out []edgeDayFleet
for _, f := range fleets {
- owner := edgeAccount(f.Account)
- if acct != "" && owner != acct {
+ if acct != "" && f.Account != acct {
continue
}
- out = append(out, edgeDayFleet{name: f.Name, account: owner})
+ out = append(out, edgeDayFleet{name: f.Name, account: f.Account})
}
sort.Slice(out, func(i, j int) bool { return out[i].name < out[j].name })
return out, nil
@@ -151,7 +153,8 @@ func readEdgeDayBoxes(ctx context.Context, st release.Store, base string, dates
// rowCounts reports whether row is acct's app's traffic as src may vouch
// for it: the row names acct (an empty account is the ops account, as on a
-// route) and app, and, read from a fleet's prefix, acct owns that fleet.
+// route) and app, and, read from a fleet's prefix, the registry names acct
+// as that fleet's owner.
func rowCounts(src edgeDaySource, row usage.EdgeRow, acct, app string) bool {
return row.App == app && edgeOwnerCounts(src, row.Account, acct)
}
@@ -161,18 +164,17 @@ func tallyCounts(src edgeDaySource, t usage.GuardTally, acct, app string) bool {
return t.App == app && edgeOwnerCounts(src, t.Account, acct)
}
-// edgeOwnerCounts is the account half of rowCounts: claimed is acct, and a
-// fleet source vouches for no account but its owner.
+// edgeOwnerCounts is the account half of rowCounts: claimed (an empty one
+// being the ops account, release.RouteAccount's rule for a route with none)
+// is acct, and a fleet source vouches for no account but its registry
+// owner. The owner is never defaulted: a fleet the registry names no owner
+// for vouches for nobody.
func edgeOwnerCounts(src edgeDaySource, claimed, acct string) bool {
- claimed = edgeAccount(claimed)
- return claimed == acct && (src.Fleet == "" || claimed == edgeAccount(src.FleetAccount))
-}
-
-// edgeAccount is an edge row's or a fleet's account, an empty one being the
-// ops account (release.RouteAccount's rule for a route with none).
-func edgeAccount(a string) string {
- if a == "" {
- return release.OpsAccount
+ if claimed == "" {
+ claimed = release.OpsAccount
+ }
+ if claimed != acct {
+ return false
}
- return a
+ return src.Fleet == "" || (src.FleetAccount != "" && claimed == src.FleetAccount)
}
diff --git a/internal/console/edgedays_test.go b/internal/console/edgedays_test.go
index 1a07ccf8d..bd027b3ba 100644
--- a/internal/console/edgedays_test.go
+++ b/internal/console/edgedays_test.go
@@ -315,3 +315,51 @@ func TestRateLimitCountsIncludesFleetBoxes(t *testing.T) {
t.Errorf("counts = %+v, want shed 4 ceiling 0: bab's fleet row counts, bdk's fleet's claim does not", v.Counts)
}
}
+
+// A fleet the registry names no owner for is owned by nobody: no account's
+// read lists or reads it, the ops account's included, and its rows and
+// tallies vouch for no account. The operator's read still reads it.
+func TestReadEdgeDaysOwnerlessFleet(t *testing.T) {
+ fx := newConsoleFixture(t)
+ edCreateFleet(t, fx, "f0", "")
+ edUpsert(t, fx.rel, "box-a", edAt, "shop.example.com", usage.EdgeRow{Account: "bab", App: "shop"})
+ edUpsert(t, edFleetStore(fx, "f0"), "pi-0", edAt, "shop.example.com", usage.EdgeRow{Account: release.OpsAccount, App: "shop", RateShed: 9})
+ edUpsert(t, edFleetStore(fx, "f0"), "pi-9", edAt, "shop.example.com", usage.EdgeRow{App: "shop", RateShed: 9})
+
+ for _, acct := range []string{release.OpsAccount, "bdk"} {
+ st := &edKeyLog{Store: fx.rel}
+ srcs, unread, err := fx.srv.readEdgeDays(context.Background(), st, []string{edDate}, acct)
+ if err != nil {
+ t.Fatalf("%s's read: %v", acct, err)
+ }
+ if got, want := sourceNames(srcs), []string{"/box-a"}; !reflect.DeepEqual(got, want) || len(unread) != 0 {
+ t.Errorf("%s's read = %v, unreadable %v; want %v and none", acct, got, unread, want)
+ }
+ for _, s := range st.seen {
+ if _, key, _ := strings.Cut(s, " "); strings.HasPrefix(key, "fleets/") {
+ t.Errorf("%s's read touched %q", acct, s)
+ }
+ }
+ }
+
+ srcs, _, err := fx.srv.readEdgeDays(context.Background(), fx.rel, []string{edDate}, "")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if got, want := sourceNames(srcs), []string{"/box-a", "f0/pi-0", "f0/pi-9"}; !reflect.DeepEqual(got, want) {
+ t.Fatalf("operator read = %v, want %v", got, want)
+ }
+ for _, src := range srcs[1:] {
+ if src.FleetAccount != "" {
+ t.Errorf("%s: FleetAccount = %q, want the registry's empty owner kept", src.Day.Box, src.FleetAccount)
+ }
+ row := src.Day.Hours["09"]["shop.example.com"]
+ tally := src.Day.Guard[usage.GuardKey("shop.example.com", row.Account, row.App)]
+ if rowCounts(src, row, release.OpsAccount, "shop") || tallyCounts(src, tally, release.OpsAccount, "shop") {
+ t.Errorf("%s: an ownerless fleet's row or tally counts for the ops account", src.Day.Box)
+ }
+ }
+ if rowCounts(edgeDaySource{Fleet: "f0"}, usage.EdgeRow{App: "shop"}, release.OpsAccount, "shop") {
+ t.Error("an ownerless fleet's row with no account counts for the ops account")
+ }
+}
diff --git a/internal/console/usagedays.go b/internal/console/usagedays.go
index e8a30269f..0f8693741 100644
--- a/internal/console/usagedays.go
+++ b/internal/console/usagedays.go
@@ -125,6 +125,9 @@ func usageDayDate(key string) (date string, ok bool) {
return "", false
}
fleet, inner := fleetRest[:j], fleetRest[j+1:]
+ if !keySegment(fleet) {
+ return "", false
+ }
if box, ok := daysDirBox(inner, "metrics/boxes/"); ok {
return date, key == "fleets/"+fleet+"/"+metrics.DayKey(box, date)
}
@@ -156,7 +159,14 @@ func daysDirBox(dir, prefix string) (string, bool) {
return "", false
}
box, ok := strings.CutSuffix(rest, "/days")
- return box, ok && box != "" && !strings.Contains(box, "/")
+ return box, ok && keySegment(box)
+}
+
+// keySegment reports whether s is one plain key segment: not empty, no
+// slash, and not "." or "..", which a path-cleaning store would resolve to
+// another directory than the key names.
+func keySegment(s string) bool {
+ return s != "" && s != "." && s != ".." && !strings.Contains(s, "/")
}
// usageDaySettled reports whether date's objects have stopped changing by
diff --git a/internal/console/usagedays_test.go b/internal/console/usagedays_test.go
index 1b169ef03..88ebe2722 100644
--- a/internal/console/usagedays_test.go
+++ b/internal/console/usagedays_test.go
@@ -9,7 +9,19 @@ func TestUsageDayDateFleetEdgeDay(t *testing.T) {
if got, ok := usageDayDate("fleets/f1/usage/edge/box-a/days/2026-11-02.json"); !ok || got != "2026-11-02" {
t.Errorf("fleet edge day = %q, %v; want 2026-11-02, true", got, ok)
}
- if got, ok := usageDayDate("fleets/f1/usage/edge/box-a/x/days/2026-11-02.json"); ok {
- t.Errorf("nested fleet edge path = %q, true; want not a day object", got)
+ for _, key := range []string{
+ "fleets/f1/usage/edge/box-a/x/days/2026-11-02.json",
+ "fleets/f1/usage/edge/../days/2026-11-02.json",
+ "fleets/f1/usage/edge/./days/2026-11-02.json",
+ "fleets/f1/usage/edge//days/2026-11-02.json",
+ "fleets/../usage/edge/box-a/days/2026-11-02.json",
+ "fleets/./usage/edge/box-a/days/2026-11-02.json",
+ "fleets//usage/edge/box-a/days/2026-11-02.json",
+ "fleets/../metrics/boxes/box-a/days/2026-11-02.json",
+ "usage/edge/../days/2026-11-02.json",
+ } {
+ if got, ok := usageDayDate(key); ok {
+ t.Errorf("usageDayDate(%q) = %q, true; want not a day object", key, got)
+ }
}
}