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(growth): exclude staff and classify admin owners as internal (#7528)
Francesco Bonacciebccf5a75041
diff --git a/libs/fleet/backend/accountlookup/service_test.go b/libs/fleet/backend/accountlookup/service_test.goindex e11ecd7249..9021769f58 100644--- a/libs/fleet/backend/accountlookup/service_test.go+++ b/libs/fleet/backend/accountlookup/service_test.go@@ -5,6 +5,7 @@ import ("errors""net/http""net/http/httptest"+ "os""strings""testing""time"@@ -12,8 +13,19 @@ import ("cyclops-cs-backend/auth""cyclops-cs-backend/keycloak""cyclops-cs-backend/productanalytics"+ "github.com/trycua/cloud/pkg/featureflags")+func TestMain(m *testing.M) {+ if err := os.Setenv("CYCLOPS_CS_ADMIN_SUBS", `[]`); err != nil {+ panic(err)+ }+ if err := featureflags.SetupProvider(context.Background(), "development", featureflags.AWSCredentials{}); err != nil {+ panic(err)+ }+ os.Exit(m.Run())+}+type fakeIndex struct {subject stringcomplete, limited bool@@ -124,6 +136,13 @@ func TestLookupExactMatchAndCurrentClassification(t *testing.T) {if err != nil || got.Account.IdentityClass != productanalytics.IdentityExternal {t.Fatal("unverified domain must not imply internal")}+ t.Setenv("CYCLOPS_CS_ADMIN_SUBS", `["test-account"]`)+ auth.InvalidateFeatureFlags()+ t.Cleanup(auth.InvalidateFeatureFlags)+ got, err = s.Lookup(context.Background(), "test-admin", Request{"account_id", "test-account"})+ if err != nil || got.Account.IdentityClass != productanalytics.IdentityInternal {+ t.Fatal("trusted admin membership must imply internal independently of email")+ }}func TestLookupFailuresDoNotDiscloseAccounts(t *testing.T) {diff --git a/libs/fleet/backend/auth/flags_test.go b/libs/fleet/backend/auth/flags_test.goindex e7b89f5c77..56b08f3527 100644--- a/libs/fleet/backend/auth/flags_test.go+++ b/libs/fleet/backend/auth/flags_test.go@@ -23,6 +23,32 @@ func resetFlagsCache() {flagsSF.Forget("flags")}+func TestAdminSubjectMembershipRequiresResolvedTrustedList(t *testing.T) {+ original := computeFlagsDataFn+ t.Cleanup(func() { computeFlagsDataFn = original; resetFlagsCache() })+ for _, tc := range []struct {+ name string+ flags map[string]interface{}+ member, resolved bool+ }{+ {"member", map[string]interface{}{"admin_subs": []interface{}{"owner"}}, true, true},+ {"non-member", map[string]interface{}{"admin_subs": []interface{}{"another"}}, false, true},+ {"empty resolved set", map[string]interface{}{"admin_subs": []interface{}{}}, false, true},+ {"unavailable", map[string]interface{}{}, false, false},+ {"malformed", map[string]interface{}{"admin_subs": "owner"}, false, false},+ {"malformed entry after match", map[string]interface{}{"admin_subs": []interface{}{"owner", 42}}, false, false},+ } {+ t.Run(tc.name, func(t *testing.T) {+ computeFlagsDataFn = func(context.Context) map[string]interface{} { return tc.flags }+ resetFlagsCache()+ member, resolved := AdminSubjectMembership("owner")+ if member != tc.member || resolved != tc.resolved {+ t.Fatalf("membership = %v, %v; want %v, %v", member, resolved, tc.member, tc.resolved)+ }+ })+ }+}+func unsetEnv(t *testing.T, key string) {t.Helper()value, present := os.LookupEnv(key)diff --git a/libs/fleet/backend/auth/middlewares.go b/libs/fleet/backend/auth/middlewares.goindex 0ed5e7f4bd..52717bc3ea 100644--- a/libs/fleet/backend/auth/middlewares.go+++ b/libs/fleet/backend/auth/middlewares.go@@ -435,6 +435,28 @@ func EvalIsAdmin(ctx context.Context, user *User) (bool, error) {return evalUserDecision(ctx, user, opaAdminQuery, flagsData())}+// AdminSubjectMembership exposes trusted owner membership for analytics only;+// it does not authorize a request or accept role/client claims as evidence.+// It shares the authorization cache (at most flagsTTL old). An unavailable or+// malformed list is unresolved, not proof that an account is non-admin.+func AdminSubjectMembership(subject string) (member, resolved bool) {+ if strings.TrimSpace(subject) == "" {+ return false, false+ }+ admins, ok := flagsData()["admin_subs"].([]interface{})+ if !ok {+ return false, false+ }+ for _, value := range admins {+ admin, ok := value.(string)+ if !ok || strings.TrimSpace(admin) == "" {+ return false, false+ }+ member = member || admin == subject+ }+ return member, true+}+// EvalIsAdminFresh bypasses the process-local admin membership cache. If the// feature-admin middleware already resolved membership for this request, the// handler reuses that result instead of issuing a duplicate provider call.diff --git a/libs/fleet/backend/handlers/analytics_test.go b/libs/fleet/backend/handlers/analytics_test.goindex f087083efb..51926fe74a 100644--- a/libs/fleet/backend/handlers/analytics_test.go+++ b/libs/fleet/backend/handlers/analytics_test.go@@ -4,14 +4,26 @@ import ("context""net/http""net/http/httptest"+ "os""testing""cyclops-cs-backend/auth""cyclops-cs-backend/config""cyclops-cs-backend/middlewares""cyclops-cs-backend/productanalytics"+ "github.com/trycua/cloud/pkg/featureflags")+func TestMain(m *testing.M) {+ if err := os.Setenv("CYCLOPS_CS_ADMIN_SUBS", `[]`); err != nil {+ panic(err)+ }+ if err := featureflags.SetupProvider(context.Background(), "development", featureflags.AWSCredentials{}); err != nil {+ panic(err)+ }+ os.Exit(m.Run())+}+func configAuthForAnalytics() config.AuthConfiguration {return config.AuthConfiguration{SPAClientID: "cyclops-cs-spa"}}@@ -57,3 +69,18 @@ func TestRecordAnalyticsSessionRequiresUser(t *testing.T) {t.Fatalf("status/events = %d/%#v", response.Code, capture.events)}}++func TestRecordAnalyticsSessionClassifiesAdminWithoutEmailAsInternal(t *testing.T) {+ t.Setenv("CYCLOPS_CS_ADMIN_SUBS", `["admin-owner"]`)+ auth.InvalidateFeatureFlags()+ t.Cleanup(auth.InvalidateFeatureFlags)+ capture := &analyticsCapture{}+ h := Handlers{Analytics: capture, AuthCfg: configAuthForAnalytics()}+ r := httptest.NewRequest(http.MethodPost, "/api/analytics/session", nil)+ user := &auth.User{ID: "admin-owner", AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}+ w := httptest.NewRecorder()+ h.RecordAnalyticsSession(w, r.WithContext(context.WithValue(r.Context(), auth.UserKey, user)))+ if w.Code != http.StatusNoContent || len(capture.events) != 1 || capture.events[0].Properties["identity_class"] != productanalytics.IdentityInternal {+ t.Fatalf("admin session status/events = %d/%#v", w.Code, capture.events)+ }+}diff --git a/libs/fleet/backend/productanalytics/events.go b/libs/fleet/backend/productanalytics/events.goindex bb79366dd6..5ff2561ec8 100644--- a/libs/fleet/backend/productanalytics/events.go+++ b/libs/fleet/backend/productanalytics/events.go@@ -23,10 +23,18 @@ func ClassifyIdentity(user *auth.User) IdentityClass {if user == nil || strings.TrimSpace(user.ID) == "" {return IdentityUnknown}- // Only verified company-domain evidence excludes an authenticated user from growth counts.+ // Verified company-domain evidence or trusted admin-owner membership is+ // internal regardless of the authentication client (SPA, CLI, or user key).if user.EmailVerified && strings.HasSuffix(strings.ToLower(strings.TrimSpace(user.Email)), "@trycua.com") {return IdentityInternal}+ admin, resolved := auth.AdminSubjectMembership(user.ID)+ if !resolved {+ return IdentityUnknown+ }+ if admin {+ return IdentityInternal+ }return IdentityExternal}diff --git a/libs/fleet/backend/productanalytics/events_test.go b/libs/fleet/backend/productanalytics/events_test.goindex 4e797d7834..bec61e8d13 100644--- a/libs/fleet/backend/productanalytics/events_test.go+++ b/libs/fleet/backend/productanalytics/events_test.go@@ -1,12 +1,66 @@package productanalyticsimport (+ "context"+ "os""strings""testing""cyclops-cs-backend/auth"+ "github.com/trycua/cloud/pkg/featureflags")+func TestMain(m *testing.M) {+ // External classification requires a successfully resolved empty admin set,+ // not an unavailable provider. Keep tests local and deterministic.+ if err := os.Setenv("CYCLOPS_CS_ADMIN_SUBS", `[]`); err != nil {+ panic(err)+ }+ if err := featureflags.SetupProvider(context.Background(), "development", featureflags.AWSCredentials{}); err != nil {+ panic(err)+ }+ os.Exit(m.Run())+}++func TestAdminIdentityUsesTrustedMembershipAcrossSources(t *testing.T) {+ t.Setenv("CYCLOPS_CS_ADMIN_SUBS", `["admin-owner"]`)+ auth.InvalidateFeatureFlags()+ t.Cleanup(auth.InvalidateFeatureFlags)+ for _, source := range []struct{ azp, principal string }{+ {"cyclops-cs-spa", auth.PrincipalTypeUser},+ {"cua-cli", auth.PrincipalTypeUser},+ {"ukey-example", auth.PrincipalTypeUserKey},+ {"github-oidc", auth.PrincipalTypeGitHubOIDC},+ } {+ user := &auth.User{ID: "admin-owner", AZP: source.azp, PrincipalType: source.principal}+ if got := ClassifyIdentity(user); got != IdentityInternal {+ t.Fatalf("admin owner via %s = %q", source.azp, got)+ }+ }+ spoofed := &auth.User{ID: "external-owner", Claims: map[string]string{"is_admin": "true", "roles": "admin"}}+ if got := ClassifyIdentity(spoofed); got != IdentityExternal {+ t.Fatalf("untrusted role claim = %q", got)+ }+ // Membership refresh must work without recreating a token or restarting.+ t.Setenv("CYCLOPS_CS_ADMIN_SUBS", `[]`)+ auth.InvalidateFeatureFlags()+ if got := ClassifyIdentity(&auth.User{ID: "admin-owner"}); got != IdentityExternal {+ t.Fatalf("removed admin = %q", got)+ }+}++func TestIdentityIsUnknownWhenAdminMembershipCannotBeResolved(t *testing.T) {+ t.Setenv("CYCLOPS_CS_ADMIN_SUBS", `{"invalid":"not a list"}`)+ auth.InvalidateFeatureFlags()+ t.Cleanup(auth.InvalidateFeatureFlags)+ if got := ClassifyIdentity(&auth.User{ID: "owner"}); got != IdentityUnknown {+ t.Fatalf("unresolved membership = %q", got)+ }+ if got := ClassifyIdentity(&auth.User{ID: "staff", Email: "[email protected]", EmailVerified: true}); got != IdentityInternal {+ t.Fatalf("verified domain remains independent evidence = %q", got)+ }+}+func TestSourceForUser(t *testing.T) {tests := []struct {name stringdiff --git a/libs/fleet/backend/productanalytics/middleware_test.go b/libs/fleet/backend/productanalytics/middleware_test.goindex dd3a194c17..25fb255c9c 100644--- a/libs/fleet/backend/productanalytics/middleware_test.go+++ b/libs/fleet/backend/productanalytics/middleware_test.go@@ -121,6 +121,9 @@ func TestLoginObserverIgnoresBrowserAndNonInteractivePrincipals(t *testing.T) {}func TestRouteObserverEmitsActivationForAuthenticatedNonInternalIdentity(t *testing.T) {+ t.Setenv("CYCLOPS_CS_ADMIN_SUBS", `["admin-owner"]`)+ auth.InvalidateFeatureFlags()+ t.Cleanup(auth.InvalidateFeatureFlags)users := []struct {name stringuser *auth.User@@ -131,6 +134,9 @@ func TestRouteObserverEmitsActivationForAuthenticatedNonInternalIdentity(t *test{name: "missing email user key", user: &auth.User{ID: "external-3", AZP: "ukey-proof", PrincipalType: auth.PrincipalTypeUserKey}, want: 3},{name: "unverified internal-looking email", user: &auth.User{ID: "external-4", Email: "[email protected]", AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}, want: 3},{name: "internal", user: &auth.User{ID: "internal-1", Email: "[email protected]", EmailVerified: true, AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}, want: 1},+ {name: "admin SPA without email", user: &auth.User{ID: "admin-owner", AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}, want: 1},+ {name: "admin CLI without email", user: &auth.User{ID: "admin-owner", AZP: "cua-cli", PrincipalType: auth.PrincipalTypeUser}, want: 1},+ {name: "admin SDK owner without email", user: &auth.User{ID: "admin-owner", AZP: "ukey-proof", PrincipalType: auth.PrincipalTypeUserKey}, want: 1},}for _, test := range users {t.Run(test.name, func(t *testing.T) {@@ -163,11 +169,43 @@ func TestRouteObserverEmitsActivationForAuthenticatedNonInternalIdentity(t *testif activation == nil || activation.InsertID != "" || activation.SetOnce[firstActivationProperty] == nil {t.Fatalf("activation event = %#v", activation)}+ } else {+ if events[0].Name != EventHTTPProxyRequest || events[0].Properties["identity_class"] != IdentityInternal {+ t.Fatalf("internal traffic must remain diagnostic only: %#v", events)+ }+ select {+ case event := <-sink:+ t.Fatalf("internal traffic emitted activation/workload: %#v", event)+ case <-time.After(30 * time.Millisecond):+ }}})}}+func TestUnresolvedAdminMembershipNeverStartsWorkloadQualification(t *testing.T) {+ t.Setenv("CYCLOPS_CS_ADMIN_SUBS", `invalid`)+ auth.InvalidateFeatureFlags()+ t.Cleanup(auth.InvalidateFeatureFlags)+ sink := make(eventChannel, 3)+ started := make(chan struct{}, 1)+ handler := RouteObserver("/api/svc/{namespace}/{service}/{path...}", sink, "cyclops-cs-spa", func(context.Context, *http.Request, int) bool {+ started <- struct{}{}+ return true+ })(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusOK) }))+ user := &auth.User{ID: "owner", AZP: "cua-cli", PrincipalType: auth.PrincipalTypeUser}+ handler.ServeHTTP(httptest.NewRecorder(), observedRequest(http.MethodPost, "/api/svc/{namespace}/{service}/{path...}", "tools", user))+ event := <-sink+ if event.Name != EventHTTPProxyRequest || event.Properties["identity_class"] != IdentityUnknown {+ t.Fatalf("unresolved identity counted as external: %#v", event)+ }+ select {+ case <-started:+ t.Fatal("unresolved identity started qualification")+ case <-time.After(30 * time.Millisecond):+ }+}+func TestRouteObserverDoesNotBlockOnQualification(t *testing.T) {started := make(chan struct{})release := make(chan struct{})