Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(database): apply reservation meter schema as owner (#7151)
r33drichards603d95db92ea
diff --git a/libs/fleet/backend/database/migrations/000005_hourly_reservation_meter.sql b/libs/fleet/backend/database/migrations/000005_hourly_reservation_meter.sqlindex eaf452032f..1fa0971b57 100644--- a/libs/fleet/backend/database/migrations/000005_hourly_reservation_meter.sql+++ b/libs/fleet/backend/database/migrations/000005_hourly_reservation_meter.sql@@ -3,9 +3,9 @@ CREATE ROLE cyclops_meter_writer LOGIN NOINHERIT NOCREATEROLE NOSUPERUSER NOCREAGRANT billing_meter_owner TO CURRENT_USER WITH INHERIT FALSE, SET TRUE;CREATE SCHEMA billing_meter AUTHORIZATION billing_meter_owner;+SET LOCAL ROLE billing_meter_owner;REVOKE CREATE ON SCHEMA billing_meter FROM PUBLIC;-SET LOCAL ROLE billing_meter_owner;CREATE TABLE billing_meter.reservation_hour_collection (collection_run_id uuid PRIMARY KEY,logical_key text NOT NULL,diff --git a/libs/fleet/backend/database/migrator.go b/libs/fleet/backend/database/migrator.goindex 2dc369264d..284973eaba 100644--- a/libs/fleet/backend/database/migrator.go+++ b/libs/fleet/backend/database/migrator.go@@ -417,17 +417,17 @@ func Run(ctx context.Context, config Config) (runErr error) {roleEvents, membershipEvents, err := reconcileStaticRoleContracts(ctx, transaction)if err != nil {- return err+ return fmt.Errorf("reconcile static role contracts: %w", err)}if err := reconcileReportingBoundary(ctx, transaction); err != nil {- return err+ return fmt.Errorf("reconcile reporting boundary: %w", err)}if err := validateNoPublicSecurityDefiner(ctx, transaction); err != nil {- return err+ return fmt.Errorf("validate security definer boundary: %w", err)}credentialEvents, err := reconcilePasswords(ctx, transaction, credentials)if err != nil {- return err+ return fmt.Errorf("reconcile database credentials: %w", err)}if err := transaction.Commit(ctx); err != nil {return fmt.Errorf("commit database migrations: %w", err)diff --git a/libs/fleet/backend/database/migrator_pg_test.go b/libs/fleet/backend/database/migrator_pg_test.goindex a43fd59ccf..c64e686eb4 100644--- a/libs/fleet/backend/database/migrator_pg_test.go+++ b/libs/fleet/backend/database/migrator_pg_test.go@@ -101,6 +101,7 @@ func TestInitialMigrationBuildsCompleteDatabase(t *testing.T) {bootstrapGrantor := currentRole(t, ctx, maintenanceURL)assertImplicitCreatorAdminMembership(t, ctx, migrationURL, "k8s_state_owner", bootstrapGrantor)assertImplicitCreatorAdminMembership(t, ctx, migrationURL, "k8s_reporting_owner", bootstrapGrantor)+ assertImplicitCreatorAdminMembership(t, ctx, migrationURL, "billing_meter_owner", bootstrapGrantor)assertNoQueryBroker(t, ctx, migrationURL)assertOwnershipAndPublicACLs(t, ctx, inspectionURL, currentRole(t, ctx, migrationURL))assertRLSContract(t, ctx, inspectionURL)@@ -133,14 +134,14 @@ func TestRunUpgradesVersionOneAndThenNoOps(t *testing.T) {upgrade := captureRunSummary(t, func() error {return Run(ctx, Config{MigrationURL: migrationURL, Credentials: credentials})})- if upgrade.Current != 1 || upgrade.Target != 4 || upgrade.Pending != 3 || upgrade.Applied != 3 || upgrade.Skipped != 1 || upgrade.Result != "success" {+ if upgrade.Current != 1 || upgrade.Target != 5 || upgrade.Pending != 4 || upgrade.Applied != 4 || upgrade.Skipped != 1 || upgrade.Result != "success" {t.Fatalf("version-one upgrade summary = %+v", upgrade)}noOp := captureRunSummary(t, func() error {return Run(ctx, Config{MigrationURL: migrationURL, Credentials: credentials})})- if noOp.Current != 4 || noOp.Target != 4 || noOp.Pending != 0 || noOp.Applied != 0 || noOp.Skipped != 4 || noOp.Result != "success" {+ if noOp.Current != 5 || noOp.Target != 5 || noOp.Pending != 0 || noOp.Applied != 0 || noOp.Skipped != 5 || noOp.Result != "success" {t.Fatalf("post-upgrade no-op summary = %+v", noOp)}}@@ -1536,8 +1537,8 @@ func migrationLedgerRows(t *testing.T, ctx context.Context, adminURL string) []lif err := rows.Err(); err != nil {t.Fatal("iterate migration ledger")}- if len(ledger) != 4 {- t.Fatalf("migration ledger row count = %d, want 4", len(ledger))+ if len(ledger) != 5 {+ t.Fatalf("migration ledger row count = %d, want 5", len(ledger))}for index, want := range []struct {version int64@@ -1547,6 +1548,7 @@ func migrationLedgerRows(t *testing.T, ctx context.Context, adminURL string) []l{2, "000002_usage_sandbox_events.sql"},{3, "000003_usage_claimed_sandbox_pool.sql"},{4, "000004_filter_invalid_usage_sandbox_events.sql"},+ {5, "000005_hourly_reservation_meter.sql"},} {if ledger[index].Version != want.version || ledger[index].ApplicationOrder != int64(index+1) || ledger[index].Filename != want.filename {t.Fatalf("migration ledger row %d = version:%d order:%d filename:%q", index, ledger[index].Version, ledger[index].ApplicationOrder, ledger[index].Filename)@@ -1608,7 +1610,7 @@ func assertStaticCreatorAdminMemberships(t *testing.T, ctx context.Context, migrt.Fatalf("iterate static creator memberships for %s: %v", role, err)}rows.Close()- allowOwnerGrant := role == "k8s_state_owner" || role == "k8s_reporting_owner"+ allowOwnerGrant := role == "k8s_state_owner" || role == "k8s_reporting_owner" || role == "billing_meter_owner"if !staticCreatorAdminMembershipsAreExact(migrationOwner, grants, allowOwnerGrant, nil) {t.Fatalf("static creator memberships for %s = %+v", role, grants)}@@ -1878,7 +1880,7 @@ func assertRuntimeLedgerAccess(t *testing.T, ctx context.Context, credentials Crvar count interr := connection.QueryRow(ctx, `select count(*) from cyclops_migrations.applied_migrations`).Scan(&count)connection.Close(ctx)- if err != nil || count != 4 {+ if err != nil || count != 5 {t.Errorf("%s ledger select = count:%d err:%v", role, count, err)}assertStatementFails(t, ctx, databaseURL, `insert into cyclops_migrations.applied_migrations (version, filename, sha256) values (99, 'invalid.sql', 'invalid')`)