carlos / platform Public

Plan storage: deny a keyless fleet app's healthy store without a key (branch review R1)

The storage stage skipped every app whose key is absent by design, so a
store granted before its app was placed on a keyless fleet escaped the
storage deny for good. As the scan doors do, a key is now needed only
when the regrant would mint: a healthy store (objstore.GrantHealthy) is
regranted with the zero Sealer, which seals nothing, and gets its deny.
A store whose regrant would mint is still skipped and retried.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 3b93618a519a0ffe725e33d19099abf270352cb4 parent 8868a12
2 files changed, +80 −16
  • internal/console/fleetsecrets_relay_test.go +55 −5
  • internal/console/planstorage.go +25 −11
diff --git a/internal/console/fleetsecrets_relay_test.go b/internal/console/fleetsecrets_relay_test.go
index e46149a2d..7f3bc9ead 100644
--- a/internal/console/fleetsecrets_relay_test.go
+++ b/internal/console/fleetsecrets_relay_test.go
@@ -7,8 +7,9 @@ package console
// owned environment, never to the deployment key; a relay enable on a
// keyless fleet writes nothing; the reconcile re-seals an envelope sealed to
// a key the app's boxes do not hold, and leaves a platform app's legacy
-// envelope alone; plan storage skips an app whose key cannot be chosen and
-// converges it once it can; and an operator can always turn scanning or its
+// envelope alone; plan storage denies a keyless fleet app's healthy store
+// without minting, skips one whose regrant would mint and converges it once
+// its key can be chosen; and an operator can always turn scanning or its
// enforcement off, keyless fleet or not, unless doing so would mint.
import (
@@ -317,11 +318,13 @@ func fsrPlaceByColumn(t *testing.T, w *fcmWorld, fleet string) {
}
// TestPlanStorageSkipsKeylessFleet: the storage stage over shop (on a
-// keyless fleet) and cart (on the platform). cart is denied; shop is left
-// exactly as it was, nothing sealed or written; once home has a key, the
-// next pass converges shop too.
+// keyless fleet, its store's delivery broken, so its regrant would mint) and
+// cart (on the platform). cart is denied; shop is left exactly as it was,
+// nothing sealed or written; once home has a key, the next pass converges
+// shop too.
func TestPlanStorageSkipsKeylessFleet(t *testing.T) {
w, fake := fsrLegacyShop(t, "code-fsr-plan", false)
+ fsrBreakDelivery(t, w)
fsrCart(t, w)
if status, out := postJSON(t, storeURL(w.fx, "cart"), map[string]any{}, w.token); status != http.StatusOK {
t.Fatalf("declare cart's store = %d %v", status, out)
@@ -358,6 +361,53 @@ func TestPlanStorageSkipsKeylessFleet(t *testing.T) {
}
}
+// TestPlanStorageDeniesKeylessFleetStoreWithoutMinting: shop's store was
+// granted before shop was placed on keyless home, and its delivery is
+// whole, so the regrant that writes the deny mints and seals nothing and
+// needs no key: the storage stage denies it, and lifts the deny once usage
+// is back under, with the delivered credential untouched both times. A
+// store that existed before its fleet escapes enforcement no longer.
+func TestPlanStorageDeniesKeylessFleetStoreWithoutMinting(t *testing.T) {
+ w, fake := fsrLegacyShop(t, "code-fsr-plan-healthy", false)
+ fsrPlaceByColumn(t, w, "home")
+ w.fx.srv.cfg.PlanCatalog = examplePlanCatalog(t)
+ acct := w.fx.account(t)
+ _, _, _, accessName, secretName := objstore.EnvNames(objstore.DefaultEnvPrefix)
+ before := appVars(t, w.fx, "shop")
+ keyID := storedRecord(t, w.fx, "shop").Provisioned.KeyID
+ untouched := func(when string) {
+ t.Helper()
+ after := appVars(t, w.fx, "shop")
+ if after[secretName].Envelope != before[secretName].Envelope || after[accessName] != before[accessName] {
+ t.Fatalf("%s: shop's delivered credential changed, so the regrant minted", when)
+ }
+ if id := storedRecord(t, w.fx, "shop").Provisioned.KeyID; id != keyID {
+ t.Fatalf("%s: shop's access key is %q, was %q", when, id, keyID)
+ }
+ }
+ ctx := context.Background()
+ st := storageRow(acct, 2_000_000_000, 1_500_000_000, planNow.Add(-10*24*time.Hour))
+ st.NoticeAt = planNow.Add(-9 * 24 * time.Hour)
+ if err := w.fx.srv.convergeStorageDeny(ctx, acct, st, true, planNow); err != nil {
+ t.Fatalf("storage stage: %v", err)
+ }
+ shop := storedRecord(t, w.fx, "shop")
+ if shop.WritesDenied == nil || shop.WritesDenyApplied == nil || !*shop.WritesDenyApplied || !hasWriteDeny(t, fake.PolicyFor(shop.Provisioned.IAMUser)) {
+ t.Fatalf("shop, on a keyless fleet with a healthy store, was not denied: %+v", shop)
+ }
+ untouched("the deny")
+
+ under := storageRow(acct, 500_000_000, 1_500_000_000, planNow)
+ if err := w.fx.srv.convergeStorageDeny(ctx, acct, under, true, planNow.Add(time.Hour)); err != nil {
+ t.Fatalf("storage stage, back under: %v", err)
+ }
+ shop = storedRecord(t, w.fx, "shop")
+ if shop.WritesDenied != nil || hasWriteDeny(t, fake.PolicyFor(shop.Provisioned.IAMUser)) {
+ t.Fatalf("shop's deny was not lifted: %+v", shop)
+ }
+ untouched("the lift")
+}
+
// fsrScanEnforcing is fsrLegacyShop with scanning granted and enforcing on
// shop's store, and shop then placed on keyless home.
func fsrScanEnforcing(t *testing.T, code string) (*fcmWorld, *objstore.MemProvisioner) {
diff --git a/internal/console/planstorage.go b/internal/console/planstorage.go
index e7086e80b..2226f226f 100644
--- a/internal/console/planstorage.go
+++ b/internal/console/planstorage.go
@@ -7,6 +7,7 @@ import (
"log"
"time"
+ "github.com/carlosframework/platform/internal/appconfig"
"github.com/carlosframework/platform/internal/objstore"
)
@@ -91,19 +92,32 @@ func (s *Server) convergeStoreDeny(ctx context.Context, acct *Account, app, env
return nil
}
// The app's own key (sealKeyFor), chosen before the first write, under
- // the account lock convergeStores holds. Nothing is written for an app
- // whose key cannot be chosen, so WritesDenyApplied still disagrees and
- // the next pass tries again. A key absent by design (sealKeyAbsent: a
- // keyless fleet, say) is the app's state and is skipped with a log line;
- // anything else (a read that failed, a placement naming a fleet not the
- // account's) also fails the job.
+ // the account lock convergeStores holds. A key absent by design
+ // (sealKeyAbsent: a keyless fleet, say) is needed only when the regrant
+ // would mint: on a healthy store (objstore.GrantHealthy) the grant only
+ // rewrites the policy, so it goes on with the zero Sealer, which refuses
+ // every binding and seals nothing, and the deny is enforced whatever the
+ // app's key (the scan doors' rule, scanRegrantSealer). A store whose
+ // regrant would mint is skipped with a log line and nothing written, so
+ // WritesDenyApplied still disagrees and the next pass tries again. Any
+ // other failure to choose the key (a read that failed, a placement naming
+ // a fleet not the account's) also fails the job.
sealer, err := s.sealKeyFor(ctx, acct.Sqid, app)
if err != nil && sealKeyAbsent(err) {
- // Logged as err.Error(), not err: this is the quiet skip, not a
- // failure, and TestPassFailureLogsAlsoFailTheJob reads a logged
- // error-named identifier as a failure that must also fail the job.
- log.Printf("console: plan storage %s/%s: skipped, no key to seal a store credential to; the next pass tries again: %v", acct.Sqid, app, err.Error())
- return nil
+ healthy, herr := objstore.GrantHealthy(ctx, s.cfg.Releases, s.cfg.StoreDeployment, rec, acct.Sqid, app, env)
+ if herr != nil || !healthy {
+ // Logged as err.Error(), not err: this is the quiet skip, not a
+ // failure, and TestPassFailureLogsAlsoFailTheJob reads a logged
+ // error-named identifier as a failure that must also fail the
+ // job. A failed read of the store is retried the same way.
+ why := err.Error()
+ if herr != nil {
+ why += "; reading the store to see whether a regrant mints: " + herr.Error()
+ }
+ log.Printf("console: plan storage %s/%s: skipped, no key to seal a store credential to; the next pass tries again: %v", acct.Sqid, app, why)
+ return nil
+ }
+ sealer, err = appconfig.Sealer{}, nil
}
if err != nil {
log.Printf("console: plan storage %s/%s: no key could be chosen, store policy left as it is: %v", acct.Sqid, app, err)