carlos / platform Public

console: system pdf and antivirus status admit system operators

carlos system pdf status is read-only, but it shared the scanning-change
gate (apiSystemOperator, CARLOS_STORE_OPERATORS only), so a deployment
system operator got 403 "changing deployment-wide scanning needs a
deployment operator". The PDF spec reused that gate for convenience, not
to keep the read store-operator only.

The two read-only status doors (GET /api/cli/system/pdf and GET
/api/cli/system/antivirus) now use apiSystemStatusReader, which admits an
address on CARLOS_SYSTEM_OPERATORS or CARLOS_STORE_OPERATORS and refuses a
member with a door-specific sentence. A non-person still gets a stranger's
404. Antivirus enable/disable and rotate-webhook-key keep apiSystemOperator
and its sentence unchanged. PDF status no longer needs a deployment bucket,
which it never read.

Tests: TestSystemStatusDoorsAdmitEitherOperator,
TestSystemScanningWritesStayStoreOperatorOnly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev b7c8c3607fa88368e3228bd3691b10a440cb99bf parent 6ef0091
4 files changed, +142 −7
  • docs/site/cli.md +4 −1
  • internal/console/apisystem.go +39 −5
  • internal/console/apisystem_test.go +96 −0
  • internal/console/routedecls.go +3 −1

CI failed — run details

diff --git a/docs/site/cli.md b/docs/site/cli.md
index 6e71592cb..675bcb977 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -3176,6 +3176,8 @@ The migration census reads the backfill plan `backfill-collect` wrote. It report
carlos system pdf status
```
+For system operators (`CARLOS_SYSTEM_OPERATORS`) and store operators (`CARLOS_STORE_OPERATORS`).
+
#### Deployment-wide object scanning
```sh
@@ -3197,7 +3199,8 @@ not just the hourly pass. `enable` is refused when no engine is wired: a record
claiming enabled with nothing behind it would report health for a deployment
where no scan can run.
-Deployment operators only (`CARLOS_STORE_OPERATORS`). Enabling scans nothing by
+`enable` and `disable` are for store operators only (`CARLOS_STORE_OPERATORS`).
+`status` is also open to system operators (`CARLOS_SYSTEM_OPERATORS`). Enabling scans nothing by
itself — a member still requests scanning for their app and an operator still
grants it per store.
diff --git a/internal/console/apisystem.go b/internal/console/apisystem.go
index c8d45b24b..6ebdaf574 100644
--- a/internal/console/apisystem.go
+++ b/internal/console/apisystem.go
@@ -12,7 +12,11 @@
//
// AUTHORITY IS AN ADDRESS, not a role. Operators are the addresses on
// CARLOS_STORE_OPERATORS (server.go), the same list that governs `store grant`
-// and every scan operator verb. A service actor renders as "service:"/"app:"
+// and every scan operator verb. The read-only status doors (`system pdf
+// status`, `system antivirus status`) also answer an address on
+// CARLOS_SYSTEM_OPERATORS (apiSystemStatusReader): the people who run the
+// deployment need to see whether its services work, and reading that changes
+// nothing. A service actor renders as "service:"/"app:"
// (apicli.go) and can never match one, so the empty role set and the operator
// check are belt and braces pointing the same way: enabling this starts
// reading tenant bytes across the whole deployment, and that is the
@@ -35,8 +39,9 @@ import (
"github.com/carlosframework/platform/internal/release"
)
-// apiSystemPerson resolves the caller as a person and checks the operator
-// list. It is the whole gate for these doors.
+// apiSystemOperator resolves the caller as a person and checks the store
+// operator list. It is the whole gate for the doors that change scanning;
+// the read-only status doors use apiSystemStatusReader.
//
// A non-person gets the same 404 a stranger gets, not a 403: these doors do
// not confirm the shape of the caller any more than the store doors confirm
@@ -59,6 +64,28 @@ func (s *Server) apiSystemOperator(w http.ResponseWriter, r *http.Request) (stri
return p.Address, true
}
+// apiSystemStatusReader is the gate for the read-only status doors. It
+// admits a store operator, as apiSystemOperator does, and also a deployment
+// system operator (CARLOS_SYSTEM_OPERATORS), who runs the platform but may
+// not hold the store list. refusal names the door, so a member is not told
+// they tried to change something.
+//
+// A non-person gets the same 404 a stranger gets, exactly as at
+// apiSystemOperator. No deployment bucket is required here: a door that
+// reads one checks for it itself.
+func (s *Server) apiSystemStatusReader(w http.ResponseWriter, r *http.Request, refusal string) bool {
+ p, ok := principalFrom(r.Context())
+ if !ok || p.Kind != PrincipalUser {
+ http.NotFound(w, r)
+ return false
+ }
+ if !s.storeOperator(p.Address) && !s.systemOperator(p.Address) {
+ jsonError(w, http.StatusForbidden, refusal)
+ return false
+ }
+ return true
+}
+
// handleAPISystemWebhookRotate spends one sweep-sized request budget sealing
// the current master for scanning-enabled apps. Progress needs no cursor: the
// non-secret key id is the cursor, so a retry skips everything already done.
@@ -214,7 +241,12 @@ func (s *Server) systemAntivirusReply(ctx context.Context) map[string]any {
// handleAPISystemAntivirusGet answers `carlos system antivirus status`.
func (s *Server) handleAPISystemAntivirusGet(w http.ResponseWriter, r *http.Request) {
- if _, ok := s.apiSystemOperator(w, r); !ok {
+ if !s.apiSystemStatusReader(w, r,
+ "antivirus status needs a deployment operator (CARLOS_SYSTEM_OPERATORS or CARLOS_STORE_OPERATORS)") {
+ return
+ }
+ if s.cfg.Releases == nil {
+ storeNoBucket(w)
return
}
ctx, cancel := context.WithTimeout(r.Context(), storeTimeout)
@@ -222,8 +254,10 @@ func (s *Server) handleAPISystemAntivirusGet(w http.ResponseWriter, r *http.Requ
writeJSON(w, http.StatusOK, s.systemAntivirusReply(ctx))
}
+// handleAPISystemPDFGet answers `carlos system pdf status`.
func (s *Server) handleAPISystemPDFGet(w http.ResponseWriter, r *http.Request) {
- if _, ok := s.apiSystemOperator(w, r); !ok {
+ if !s.apiSystemStatusReader(w, r,
+ "pdf status needs a deployment operator (CARLOS_SYSTEM_OPERATORS or CARLOS_STORE_OPERATORS)") {
return
}
rendered, refused, failed, err := s.store.PDFRenderSummary(r.Context(), time.Now().Add(-24*time.Hour))
diff --git a/internal/console/apisystem_test.go b/internal/console/apisystem_test.go
index 0afad16a1..731b6f15e 100644
--- a/internal/console/apisystem_test.go
+++ b/internal/console/apisystem_test.go
@@ -318,3 +318,99 @@ func TestSystemPDFStatus(t *testing.T) {
}
})
}
+
+// The read-only status doors answer either operator list: a deployment
+// system operator (CARLOS_SYSTEM_OPERATORS) runs the platform and needs to
+// see whether its services work, without holding the store operator's
+// authority to change scanning. The doors that change scanning stay the
+// store operator's alone.
+func TestSystemStatusDoorsAdmitEitherOperator(t *testing.T) {
+ doors := []struct {
+ name, path, word string
+ handler func(*Server, http.ResponseWriter, *http.Request)
+ }{
+ {"pdf", "/api/cli/system/pdf", "pdf status", (*Server).handleAPISystemPDFGet},
+ {"antivirus", systemAntivirusURL, "antivirus status", (*Server).handleAPISystemAntivirusGet},
+ }
+ for _, door := range doors {
+ t.Run(door.name, func(t *testing.T) {
+ t.Run("system operator", func(t *testing.T) {
+ fx, token := systemArmed(t, "code-sys-read-system")
+ fx.srv.cfg.StoreOperators = []string{"someone-else@keymail.dev"}
+ fx.srv.cfg.SystemOperators = []string{"Alice@Keymail.dev"}
+ if status, out := getJSON(t, fx.ts.URL+door.path, token); status != http.StatusOK {
+ t.Fatalf("system operator = %d %v, want 200", status, out)
+ }
+ })
+ t.Run("store operator", func(t *testing.T) {
+ fx, token := systemArmed(t, "code-sys-read-store")
+ if status, out := getJSON(t, fx.ts.URL+door.path, token); status != http.StatusOK {
+ t.Fatalf("store operator = %d %v, want 200", status, out)
+ }
+ })
+ t.Run("member", func(t *testing.T) {
+ fx, token := systemArmed(t, "code-sys-read-member")
+ fx.srv.cfg.StoreOperators = []string{"someone-else@keymail.dev"}
+ fx.srv.cfg.SystemOperators = []string{"someone-else@keymail.dev"}
+ status, out := getJSON(t, fx.ts.URL+door.path, token)
+ if status != http.StatusForbidden {
+ t.Fatalf("member = %d %v, want 403", status, out)
+ }
+ msg := str(t, out, "error")
+ if !strings.Contains(msg, door.word) || strings.Contains(msg, "changing") ||
+ !strings.Contains(msg, "CARLOS_SYSTEM_OPERATORS") || !strings.Contains(msg, "CARLOS_STORE_OPERATORS") {
+ t.Fatalf("member refusal = %q, want it about %s naming both lists", msg, door.word)
+ }
+ })
+ t.Run("non-person", func(t *testing.T) {
+ fx, _ := systemArmed(t, "code-sys-read-nonperson")
+ stranger := httptest.NewRecorder()
+ http.NotFound(stranger, httptest.NewRequest(http.MethodGet, door.path, nil))
+ for _, p := range []*Principal{
+ nil,
+ {Kind: PrincipalService, Address: "alice@keymail.dev"},
+ {Kind: PrincipalLink, Address: "alice@keymail.dev"},
+ } {
+ fx.srv.cfg.StoreOperators = []string{"alice@keymail.dev"}
+ fx.srv.cfg.SystemOperators = []string{"alice@keymail.dev"}
+ req := httptest.NewRequest(http.MethodGet, door.path, nil)
+ if p != nil {
+ req = req.WithContext(context.WithValue(req.Context(), cliRouteKey{}, *p))
+ }
+ rec := httptest.NewRecorder()
+ door.handler(fx.srv, rec, req)
+ if rec.Code != http.StatusNotFound || rec.Body.String() != stranger.Body.String() {
+ t.Fatalf("non-person %+v = %d %q, want a stranger's 404", p, rec.Code, rec.Body.String())
+ }
+ }
+ })
+ })
+ }
+}
+
+// Widening the status doors must not widen the doors that change scanning:
+// a system operator who is not a store operator is refused there with the
+// original sentence.
+func TestSystemScanningWritesStayStoreOperatorOnly(t *testing.T) {
+ const want = "changing deployment-wide scanning needs a deployment operator (CARLOS_STORE_OPERATORS)"
+ fx, token := systemArmed(t, "code-sys-write-system")
+ fx.srv.cfg.StoreOperators = []string{"someone-else@keymail.dev"}
+ fx.srv.cfg.SystemOperators = []string{"alice@keymail.dev"}
+ for _, door := range []struct {
+ path string
+ body map[string]any
+ }{
+ {systemAntivirusURL, map[string]any{"enabled": true}},
+ {systemAntivirusURL, map[string]any{"enabled": false}},
+ {systemAntivirusURL + "/rotate-webhook-key", map[string]any{}},
+ } {
+ status, out := postJSON(t, fx.ts.URL+door.path, door.body, token)
+ if status != http.StatusForbidden || str(t, out, "error") != want {
+ t.Fatalf("POST %s %v as a system operator = %d %v, want 403 %q", door.path, door.body, status, out, want)
+ }
+ }
+ av, _, err := release.GetAntivirus(context.Background(), fx.srv.cfg.Releases)
+ if err != nil || av != nil {
+ t.Fatalf("antivirus record after refusals = %+v, %v; want none", av, err)
+ }
+}
diff --git a/internal/console/routedecls.go b/internal/console/routedecls.go
index ee2026f39..9ed13a6b9 100644
--- a/internal/console/routedecls.go
+++ b/internal/console/routedecls.go
@@ -1067,7 +1067,9 @@ var routeDecls = []routeDecl{
// The update doors want an OWNER of the ops account or an address on
// CARLOS_SYSTEM_OPERATORS, with upload the owner's alone
// (apiSystemRoller); the antivirus doors want an address on
- // CARLOS_STORE_OPERATORS (apiSystemOperator). Managed fleet settings require
+ // CARLOS_STORE_OPERATORS (apiSystemOperator), except that the read-only
+ // antivirus and pdf status doors also answer CARLOS_SYSTEM_OPERATORS
+ // (apiSystemStatusReader). Managed fleet settings require
// a configured system operator, without the ops-owner exception.
{Pattern: "GET /api/cli/system/managed-fleets", Kind: kindCLI, Allow: svcrole.Set{}, Handler: (*Server).handleAPISystemManagedGet},
{Pattern: "PUT /api/cli/system/managed-fleets", Kind: kindCLI, Allow: svcrole.Set{}, Handler: (*Server).handleAPISystemManagedSet},