| 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) { |