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
feat(cyclops-cs): back GitHub trust policies with Postgres using GORM AutoMigrate (CUA-675) (#5302)
r33drichardsb9047166763e
diff --git a/libs/fleet/backend/config/config.go b/libs/fleet/backend/config/config.goindex aee2ac1ed0..44a26a075a 100644--- a/libs/fleet/backend/config/config.go+++ b/libs/fleet/backend/config/config.go@@ -24,7 +24,7 @@ type Configuration struct {Auth AuthConfigurationKeycloak KeycloakConfigurationGateway GatewayConfiguration- Templates TemplatesConfiguration+ Database DatabaseConfigurationStripe StripeConfigurationMetrics MetricsConfigurationTelemetry TelemetryConfiguration@@ -78,12 +78,6 @@ type GatewayConfiguration struct {ClusterDomain string}-// TemplatesConfiguration carries the Redis URL used by the original-// GitHub trust-policy store. PR #5302 replaces this with DatabaseConfiguration.-type TemplatesConfiguration struct {- RedisURL string-}-type StripeConfiguration struct {SecretKey stringWebhookSecret string@@ -92,6 +86,13 @@ type StripeConfiguration struct {PortalReturnURL string}+// DatabaseConfiguration drives the Postgres-backed stores (currently the+// GitHub OIDC trust policies). An empty URL disables those routes (503),+// keeping the backend bootable without a database — see CUA-675.+type DatabaseConfiguration struct {+ URL string // DATABASE_URL — postgres://user:pass@host:5432/dbname?sslmode=require+}+type MetricsConfiguration struct {Addr string // METRICS_ADDR — Prometheus listen addr}@@ -132,8 +133,7 @@ var specs = []flagSpec{{"gateway.scheme", "orch-scheme", "ORCH_SCHEME", "http", "orchestrator scheme"},{"gateway.port", "orch-port", "ORCH_PORT", "80", "orchestrator port"},{"gateway.cluster-domain", "cluster-domain", "CLUSTER_DOMAIN", "svc.cluster.local", "in-cluster DNS domain"},- {"batch.redis-url", "batch-redis-url", "BATCH_REDIS_URL", "", "legacy GitHub trust-policy Redis URL fallback"},- {"templates.redis-url", "pool-templates-redis-url", "POOL_TEMPLATES_REDIS_URL", "", "GitHub trust-policy Redis URL (falls back to batch Redis)"},+ {"database.url", "database-url", "DATABASE_URL", "", "Postgres URL for trust-policy storage (enables /api/github-trust-policies)"},{"stripe.secret-key", "stripe-secret-key", "STRIPE_SECRET_KEY", "", "Stripe secret key (server-only)"},{"stripe.webhook-secret", "stripe-webhook-secret", "STRIPE_WEBHOOK_SECRET", "", "Stripe webhook signing secret"},{"stripe.checkout-success-url", "stripe-checkout-success-url", "STRIPE_CHECKOUT_SUCCESS_URL", "", "Stripe Checkout success redirect URL"},@@ -170,11 +170,6 @@ func LoadConfig() (*Configuration, error) {issuer = realmPath}- templatesRedis := viper.GetString("templates.redis-url")- if templatesRedis == "" {- templatesRedis = viper.GetString("batch.redis-url")- }-cfg := &Configuration{WebServer: WebServerConfiguration{Addr: viper.GetString("webserver.addr")},Auth: AuthConfiguration{@@ -209,7 +204,7 @@ func LoadConfig() (*Configuration, error) {Port: viper.GetString("gateway.port"),ClusterDomain: viper.GetString("gateway.cluster-domain"),},- Templates: TemplatesConfiguration{RedisURL: templatesRedis},+ Database: DatabaseConfiguration{URL: viper.GetString("database.url")},Stripe: StripeConfiguration{SecretKey: viper.GetString("stripe.secret-key"),WebhookSecret: viper.GetString("stripe.webhook-secret"),diff --git a/libs/fleet/backend/githubtrust/store.go b/libs/fleet/backend/githubtrust/store.goindex 8dabf49830..94461843b0 100644--- a/libs/fleet/backend/githubtrust/store.go+++ b/libs/fleet/backend/githubtrust/store.go@@ -1,21 +1,35 @@package githubtrust+// Postgres-backed persistence for GitHub Actions OIDC trust policies.+//+// Schema is derived from the Policy struct via GORM AutoMigrate — no manual+// DDL. Queries use pgx directly (the GORM postgres driver also uses pgx+// under the hood, so there is no driver conflict).+//+// Listing is indexed by owner_sub (List); ResolveByRepository (the per-request+// auth hot path) is indexed by repository. Every read takes the owner so the+// storage layer enforces the same tenant isolation the HTTP layer does —+// CUA-675 moved this off Redis so policies survive a Pod eviction (the+// cyclops-cs Redis persists to an emptyDir, which does not).+import ("context"- "encoding/json"+ "errors""fmt"- "log/slog""time""github.com/google/uuid"- "github.com/redis/go-redis/v9"+ "github.com/jackc/pgx/v5"+ "github.com/jackc/pgx/v5/pgxpool"+ "gorm.io/driver/postgres"+ "gorm.io/gorm")-const (- keyPrefix = "ghtrust:policy:"- ownerIndexPrefix = "ghtrust:owner:"- repoIndexPrefix = "ghtrust:repo:"-)+// ErrNotFound is returned by Update when the policy no longer exists for the+// given owner. Handlers Get-then-Update, so this is a race backstop.+var ErrNotFound = errors.New("github trust policy not found")++const policyColumns = "id, owner_sub, name, repository, allowed_namespaces, enabled, created_at, updated_at"type Store interface {List(ctx context.Context, ownerSub string) ([]*Policy, error)@@ -26,58 +40,68 @@ type Store interface {ResolveByRepository(ctx context.Context, repository string) ([]*Policy, error)}-type redisStore struct{ c *redis.Client }--func policyKey(id string) string { return keyPrefix + id }-func ownerKey(owner string) string { return ownerIndexPrefix + owner }-func repoKey(repo string) string { return repoIndexPrefix + repo }+type pgStore struct{ pool *pgxpool.Pool }+// New opens a connection pool against url (a Postgres DSN or URL) and ensures+// the schema exists by running GORM AutoMigrate against the Policy struct. An+// empty url disables the feature (returns nil, nil) so the handlers reply+// 503, mirroring the previous Redis behaviour. A startup connectivity blip is+// non-fatal to the process: initialization returns an error so the caller can+// leave the routes disabled rather than exposing a store without its table.func New(ctx context.Context, url string) (Store, error) {if url == "" {return nil, nil}- opts, err := redis.ParseURL(url)++ pool, err := pgxpool.New(ctx, url)if err != nil {- return nil, fmt.Errorf("parse redis url: %w", err)+ return nil, fmt.Errorf("connect postgres: %w", err)}- c := redis.NewClient(opts)- pingCtx, cancel := context.WithTimeout(ctx, 5*time.Second)+ s := &pgStore{pool: pool}++ initCtx, cancel := context.WithTimeout(ctx, 10*time.Second)defer cancel()- if err := c.Ping(pingCtx).Err(); err != nil {- slog.Warn("githubtrust: redis ping failed at startup; will retry on demand", "err", err)++ if err := pool.Ping(initCtx); err != nil {+ pool.Close()+ return nil, fmt.Errorf("ping postgres: %w", err)}- return &redisStore{c: c}, nil-}-func (s *redisStore) List(ctx context.Context, ownerSub string) ([]*Policy, error) {- ids, err := s.c.SMembers(ctx, ownerKey(ownerSub)).Result()+ // AutoMigrate derives the table schema from the Policy struct — no manual+ // DDL. GORM creates the table, columns, and indexes based on struct tags.+ // We open a throwaway gorm.DB from the same URL for migration only; pgx+ // is used for all queries.+ gormDB, err := gorm.Open(postgres.Open(url), &gorm.Config{})if err != nil {- return nil, fmt.Errorf("smembers owner index: %w", err)+ pool.Close()+ return nil, fmt.Errorf("open postgres migrator: %w", err)}- out := make([]*Policy, 0, len(ids))- for _, id := range ids {- fields, err := s.c.HGetAll(ctx, policyKey(id)).Result()- if err != nil {- return nil, fmt.Errorf("hgetall %s: %w", id, err)- }- if len(fields) == 0 {- s.c.SRem(ctx, ownerKey(ownerSub), id)- continue- }- policy, err := hydrate(fields)- if err != nil {- return nil, err- }- if policy.OwnerSub != ownerSub {- continue- }- out = append(out, policy)+ gormSQLDB, err := gormDB.DB()+ if err != nil {+ pool.Close()+ return nil, fmt.Errorf("get postgres migrator connection: %w", err)}- sortByUpdatedDesc(out)- return out, nil+ defer gormSQLDB.Close()+ if err := gormDB.WithContext(initCtx).AutoMigrate(&Policy{}); err != nil {+ pool.Close()+ return nil, fmt.Errorf("auto-migrate github trust policies: %w", err)+ }++ return s, nil+}++func (s *pgStore) List(ctx context.Context, ownerSub string) ([]*Policy, error) {+ rows, err := s.pool.Query(ctx,+ `SELECT `+policyColumns+` FROM github_trust_policies+ WHERE owner_sub = $1+ ORDER BY updated_at DESC, id ASC`, ownerSub)+ if err != nil {+ return nil, fmt.Errorf("list policies: %w", err)+ }+ return collect(rows)}-func (s *redisStore) Create(ctx context.Context, policy *Policy) error {+func (s *pgStore) Create(ctx context.Context, policy *Policy) error {now := time.Now().UTC()if policy.ID == "" {policy.ID = uuid.NewString()@@ -86,137 +110,98 @@ func (s *redisStore) Create(ctx context.Context, policy *Policy) error {policy.CreatedAt = now}policy.UpdatedAt = now- return s.save(ctx, nil, policy)-}--func (s *redisStore) Get(ctx context.Context, ownerSub, id string) (*Policy, error) {- fields, err := s.c.HGetAll(ctx, policyKey(id)).Result()+ _, err := s.pool.Exec(ctx,+ `INSERT INTO github_trust_policies (`+policyColumns+`)+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8)`,+ policy.ID, policy.OwnerSub, policy.Name, policy.Repository,+ policy.AllowedNamespaces, policy.Enabled, policy.CreatedAt, policy.UpdatedAt)if err != nil {- return nil, fmt.Errorf("hgetall: %w", err)+ return fmt.Errorf("create policy: %w", err)}- if len(fields) == 0 {+ return nil+}++func (s *pgStore) Get(ctx context.Context, ownerSub, id string) (*Policy, error) {+ row := s.pool.QueryRow(ctx,+ `SELECT `+policyColumns+` FROM github_trust_policies+ WHERE id = $1 AND owner_sub = $2`, id, ownerSub)+ policy, err := scanPolicy(row)+ if errors.Is(err, pgx.ErrNoRows) {return nil, nil}- policy, err := hydrate(fields)if err != nil {- return nil, err- }- if policy.OwnerSub != ownerSub {- return nil, nil+ return nil, fmt.Errorf("get policy: %w", err)}return policy, nil}-func (s *redisStore) Update(ctx context.Context, policy *Policy) error {- current, err := s.Get(ctx, policy.OwnerSub, policy.ID)+func (s *pgStore) Update(ctx context.Context, policy *Policy) error {+ policy.UpdatedAt = time.Now().UTC()+ tag, err := s.pool.Exec(ctx,+ `UPDATE github_trust_policies+ SET name = $3, repository = $4, allowed_namespaces = $5, enabled = $6, updated_at = $7+ WHERE id = $1 AND owner_sub = $2`,+ policy.ID, policy.OwnerSub, policy.Name, policy.Repository,+ policy.AllowedNamespaces, policy.Enabled, policy.UpdatedAt)if err != nil {- return err+ return fmt.Errorf("update policy: %w", err)}- if current == nil {- return redis.Nil+ if tag.RowsAffected() == 0 {+ return ErrNotFound}- policy.CreatedAt = current.CreatedAt- policy.UpdatedAt = time.Now().UTC()- return s.save(ctx, current, policy)+ return nil}-func (s *redisStore) Delete(ctx context.Context, ownerSub, id string) (bool, error) {- current, err := s.Get(ctx, ownerSub, id)+func (s *pgStore) Delete(ctx context.Context, ownerSub, id string) (bool, error) {+ tag, err := s.pool.Exec(ctx,+ `DELETE FROM github_trust_policies WHERE id = $1 AND owner_sub = $2`, id, ownerSub)if err != nil {- return false, err- }- if current == nil {- return false, nil- }- pipe := s.c.TxPipeline()- pipe.Del(ctx, policyKey(id))- pipe.SRem(ctx, ownerKey(ownerSub), id)- pipe.SRem(ctx, repoKey(current.Repository), id)- if _, err := pipe.Exec(ctx); err != nil {return false, fmt.Errorf("delete policy: %w", err)}- return true, nil+ return tag.RowsAffected() > 0, nil}-func (s *redisStore) ResolveByRepository(ctx context.Context, repository string) ([]*Policy, error) {- ids, err := s.c.SMembers(ctx, repoKey(repository)).Result()+func (s *pgStore) ResolveByRepository(ctx context.Context, repository string) ([]*Policy, error) {+ rows, err := s.pool.Query(ctx,+ `SELECT `+policyColumns+` FROM github_trust_policies+ WHERE repository = $1+ ORDER BY updated_at DESC, id ASC`, repository)if err != nil {- return nil, fmt.Errorf("smembers repo index: %w", err)+ return nil, fmt.Errorf("resolve policies by repository: %w", err)}- out := make([]*Policy, 0, len(ids))- for _, id := range ids {- fields, err := s.c.HGetAll(ctx, policyKey(id)).Result()- if err != nil {- return nil, fmt.Errorf("hgetall %s: %w", id, err)- }- if len(fields) == 0 {- s.c.SRem(ctx, repoKey(repository), id)- continue- }- policy, err := hydrate(fields)+ return collect(rows)+}++// collect scans all rows from a pgx.Rows into a slice of policies.+func collect(rows pgx.Rows) ([]*Policy, error) {+ out := make([]*Policy, 0)+ for rows.Next() {+ policy, err := scanPolicy(rows)if err != nil {+ rows.Close()return nil, err}- if policy.Repository != repository {- continue- }out = append(out, policy)}- sortByUpdatedDesc(out)+ if err := rows.Err(); err != nil {+ return nil, fmt.Errorf("scan policies: %w", err)+ }return out, nil}-func (s *redisStore) save(ctx context.Context, previous, policy *Policy) error {- allowed, err := json.Marshal(policy.AllowedNamespaces)- if err != nil {- return fmt.Errorf("marshal allowed_namespaces: %w", err)- }- pipe := s.c.TxPipeline()- pipe.HSet(ctx, policyKey(policy.ID), map[string]any{- "id": policy.ID,- "owner_sub": policy.OwnerSub,- "name": policy.Name,- "repository": policy.Repository,- "allowed_namespaces": string(allowed),- "enabled": policy.Enabled,- "created_at": policy.CreatedAt.UTC().Format(time.RFC3339Nano),- "updated_at": policy.UpdatedAt.UTC().Format(time.RFC3339Nano),- })- pipe.SAdd(ctx, ownerKey(policy.OwnerSub), policy.ID)- pipe.SAdd(ctx, repoKey(policy.Repository), policy.ID)- if previous != nil && previous.Repository != "" && previous.Repository != policy.Repository {- pipe.SRem(ctx, repoKey(previous.Repository), policy.ID)- }- if _, err := pipe.Exec(ctx); err != nil {- return fmt.Errorf("save policy: %w", err)- }- return nil+// scanner is implemented by both pgx.Row and pgx.Rows.+type scanner interface {+ Scan(dest ...any) error}-func hydrate(fields map[string]string) (*Policy, error) {- policy := &Policy{- ID: fields["id"],- OwnerSub: fields["owner_sub"],- Name: fields["name"],- Repository: fields["repository"],- }- if v := fields["allowed_namespaces"]; v != "" {- if err := json.Unmarshal([]byte(v), &policy.AllowedNamespaces); err != nil {- return nil, fmt.Errorf("decode allowed_namespaces: %w", err)- }- }- if v := fields["enabled"]; v == "1" || v == "true" {- policy.Enabled = true- }- if v := fields["created_at"]; v != "" {- if parsed, err := time.Parse(time.RFC3339Nano, v); err == nil {- policy.CreatedAt = parsed- }- }- if v := fields["updated_at"]; v != "" {- if parsed, err := time.Parse(time.RFC3339Nano, v); err == nil {- policy.UpdatedAt = parsed- }+func scanPolicy(r scanner) (*Policy, error) {+ p := &Policy{}+ err := r.Scan(+ &p.ID, &p.OwnerSub, &p.Name, &p.Repository,+ &p.AllowedNamespaces, &p.Enabled, &p.CreatedAt, &p.UpdatedAt,+ )+ if err != nil {+ return nil, err}- return policy, nil+ return p, nil}diff --git a/libs/fleet/backend/githubtrust/store_pg_test.go b/libs/fleet/backend/githubtrust/store_pg_test.gonew file mode 100644index 0000000000..c6984fa9b5--- /dev/null+++ b/libs/fleet/backend/githubtrust/store_pg_test.go@@ -0,0 +1,73 @@+package githubtrust++import (+ "context"+ "os"+ "testing"+)++// TestPostgresStoreRoundTrip exercises the real Postgres-backed store against+// a live database. It is skipped unless CYCLOPS_TEST_DATABASE_URL points at a+// throwaway Postgres (e.g. `docker run --rm -e POSTGRES_PASSWORD=pg -p+// 5432:5432 postgres:16`). The test creates the schema on its own via New.+func TestPostgresStoreRoundTrip(t *testing.T) {+ url := os.Getenv("CYCLOPS_TEST_DATABASE_URL")+ if url == "" {+ t.Skip("set CYCLOPS_TEST_DATABASE_URL to run the Postgres store test")+ }+ ctx := context.Background()+ store, err := New(ctx, url)+ if err != nil {+ t.Fatalf("New: %v", err)+ }+ if store == nil {+ t.Fatal("New returned a nil store for a non-empty url")+ }++ const owner = "user-roundtrip"+ policy, err := NormalizePolicyInput(PolicyInput{+ Name: "ci",+ Repository: "trycua/cloud",+ AllowedNamespaces: []string{"ns-a", "ns-b"},+ Enabled: true,+ })+ if err != nil {+ t.Fatalf("NormalizePolicyInput: %v", err)+ }+ policy.OwnerSub = owner+ if err := store.Create(ctx, policy); err != nil {+ t.Fatalf("Create: %v", err)+ }+ t.Cleanup(func() { _, _ = store.Delete(ctx, owner, policy.ID) })++ got, err := store.Get(ctx, owner, policy.ID)+ if err != nil || got == nil {+ t.Fatalf("Get: %v (got %v)", err, got)+ }+ if got.Repository != "trycua/cloud" || len(got.AllowedNamespaces) != 2 {+ t.Fatalf("unexpected policy: %#v", got)+ }++ // Tenant isolation: another owner cannot see it.+ if other, err := store.Get(ctx, "someone-else", policy.ID); err != nil || other != nil {+ t.Fatalf("expected nil for other owner, got %v (err %v)", other, err)+ }++ resolved, err := store.ResolveByRepository(ctx, "trycua/cloud")+ if err != nil || len(resolved) == 0 {+ t.Fatalf("ResolveByRepository: %v (n=%d)", err, len(resolved))+ }++ policy.Enabled = false+ if err := store.Update(ctx, policy); err != nil {+ t.Fatalf("Update: %v", err)+ }++ found, err := store.Delete(ctx, owner, policy.ID)+ if err != nil || !found {+ t.Fatalf("Delete: %v (found %v)", err, found)+ }+ if missing, err := store.Get(ctx, owner, policy.ID); err != nil || missing != nil {+ t.Fatalf("expected deleted policy to be gone, got %v (err %v)", missing, err)+ }+}diff --git a/libs/fleet/backend/githubtrust/types.go b/libs/fleet/backend/githubtrust/types.goindex 4d0d2d6fe1..6674c2c428 100644--- a/libs/fleet/backend/githubtrust/types.go+++ b/libs/fleet/backend/githubtrust/types.go@@ -17,17 +17,24 @@ var (ErrInvalidNamespace = errors.New("allowed_namespaces must be DNS-1123 labels"))+// Policy is the runtime representation of a GitHub Actions OIDC trust policy.+// GORM tags drive AutoMigrate so the schema is derived from this struct —+// no manual DDL. pgx is still used for queries; GORM is migration-only.type Policy struct {- ID string `json:"id"`- OwnerSub string `json:"owner_sub"`+ ID string `json:"id" gorm:"primaryKey"`+ OwnerSub string `json:"owner_sub" gorm:"column:owner_sub;index"`Name string `json:"name"`- Repository string `json:"repository"`- AllowedNamespaces []string `json:"allowed_namespaces"`+ Repository string `json:"repository" gorm:"column:repository;index"`+ AllowedNamespaces []string `json:"allowed_namespaces" gorm:"type:text[]"`Enabled bool `json:"enabled"`CreatedAt time.Time `json:"created_at"`UpdatedAt time.Time `json:"updated_at"`}+// TableName overrides GORM's default pluralisation so the table name matches+// what the pgx queries expect.+func (Policy) TableName() string { return "github_trust_policies" }+type PolicyInput struct {Name string `json:"name"`Repository string `json:"repository"`diff --git a/libs/fleet/backend/go.mod b/libs/fleet/backend/go.modindex b785203403..22716eb8c4 100644--- a/libs/fleet/backend/go.mod+++ b/libs/fleet/backend/go.mod@@ -9,6 +9,7 @@ require (github.com/Nerzal/gocloak/v13 v13.9.0github.com/golang-jwt/jwt/v5 v5.2.1github.com/google/uuid v1.6.0+ github.com/jackc/pgx/v5 v5.5.5github.com/open-feature/go-sdk v1.17.0github.com/open-policy-agent/opa v0.69.0github.com/prometheus/client_golang v1.20.4@@ -22,6 +23,8 @@ require (go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.28.0golang.org/x/sync v0.17.0+ gorm.io/driver/postgres v1.5.11+ gorm.io/gorm v1.25.12)require (@@ -33,6 +36,11 @@ require (github.com/go-viper/mapstructure/v2 v2.4.0 // indirectgithub.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirectgithub.com/inconshreveable/mousetrap v1.1.0 // indirect+ github.com/jinzhu/inflection v1.0.0 // indirect+ github.com/jinzhu/now v1.1.5 // indirect+ github.com/jackc/pgpassfile v1.0.0 // indirect+ github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect+ github.com/jackc/puddle/v2 v2.2.1 // indirectgithub.com/open-feature/go-sdk-contrib/providers/aws-ssm v1.0.0 // indirectgithub.com/open-feature/go-sdk-contrib/providers/from-env v0.1.6 // indirectgithub.com/pelletier/go-toml/v2 v2.2.4 // indirect@@ -45,6 +53,7 @@ require (go.opentelemetry.io/proto/otlp v1.3.1 // indirectgo.uber.org/mock v0.6.0 // indirectgo.yaml.in/yaml/v3 v3.0.4 // indirect+ golang.org/x/crypto v0.42.0 // indirectgolang.org/x/text v0.30.0 // indirectgoogle.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirectgoogle.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirectdiff --git a/libs/fleet/backend/go.sum b/libs/fleet/backend/go.sumindex 8aa61d7fa4..2b6322526b 100644--- a/libs/fleet/backend/go.sum+++ b/libs/fleet/backend/go.sum@@ -125,6 +125,14 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=+github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=+github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=+github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA=+github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=+github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=+github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=+github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=+github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=@@ -203,6 +211,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=+github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=github.com/stripe/stripe-go/v85 v85.2.0 h1:LomL8ulv13+y+nIKtFP48Cn/pCIZmi4IBz5qjdDn+FY=@@ -251,6 +260,7 @@ go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=+golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI=golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8=golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=@@ -258,6 +268,7 @@ golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=golang.org/x/net v0.0.0-20211029224645-99673261e6eb/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=+golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=@@ -267,6 +278,7 @@ golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=+golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=@@ -294,3 +306,11 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=+github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=+github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=+github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=+github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=+gorm.io/driver/postgres v1.5.11 h1:ubBVAfbKEUld/twyKZ0IYn9rSQh448EdelLYk9Mv314=+gorm.io/driver/postgres v1.5.11/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=+gorm.io/gorm v1.25.12 h1:I0u8i2hWQItBq1WfE0o2+WuL9+8L21K9e2HHSTE/0f8=+gorm.io/gorm v1.25.12/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=diff --git a/libs/fleet/backend/main.go b/libs/fleet/backend/main.goindex 3fd2ac23bf..1b06d52053 100644--- a/libs/fleet/backend/main.go+++ b/libs/fleet/backend/main.go@@ -316,14 +316,18 @@ func run() error {h.WorkloadAdmin = workloadAdminh.WorkloadAudience = cfg.Keycloak.WorkloadAudienceh.WorkloadTokenURL = cfg.Keycloak.WorkloadTokenURL- if store, err := githubtrust.New(ctx, cfg.Templates.RedisURL); err != nil {+ // Postgres-backed GitHub OIDC trust policies (CUA-675). A connection+ // failure is non-fatal — the routes stay registered and reply 503 until+ // the database is reachable, mirroring how the other optional surfaces+ // degrade gracefully.+ if store, err := githubtrust.New(ctx, cfg.Database.URL); err != nil {slog.Error("github trust policies: init failed; /api/github-trust-policies will return 503", "err", err)} else if store != nil {h.GitHubTrustPolicies = storeauth.SetGitHubTrustResolver(handlers.NewGitHubTrustResolver(store))slog.Info("github trust policies: enabled")} else {- slog.Info("github trust policies: disabled (no Redis URL configured)")+ slog.Info("github trust policies: disabled (no DATABASE_URL configured)")}router := setupRouter(h)