Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(analytics): count unverified Fleet identities as external (#7293)

Francesco Bonaccieaf234f3fc00
diff --git a/libs/fleet/backend/handlers/analytics_attribution_test.go b/libs/fleet/backend/handlers/analytics_attribution_test.go
index e254593af6..3bd6f14ee5 100644
--- a/libs/fleet/backend/handlers/analytics_attribution_test.go
+++ b/libs/fleet/backend/handlers/analytics_attribution_test.go
@@ -54,10 +54,24 @@ func TestRecordFleetAttributionBindsExternalFirstTouch(t *testing.T) {
}
}
-func TestRecordFleetAttributionExcludesInternalAndUnknownIdentities(t *testing.T) {
+func TestRecordFleetAttributionBindsMissingEmailIdentity(t *testing.T) {
+ capture := &analyticsCapture{}
+ h := Handlers{Analytics: capture, AuthCfg: configAuthForAnalytics()}
+ response := httptest.NewRecorder()
+ h.RecordFleetAttribution(response, attributionRequest(t, fleetAttributionRecord{
+ Version: 1, CapturedAt: time.Now().UnixMilli(), Values: map[string]string{"utm_source": "x"},
+ }, &auth.User{ID: "subject-1", AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}))
+ if response.Code != http.StatusNoContent || len(capture.events) != 1 {
+ t.Fatalf("status/events = %d/%#v", response.Code, capture.events)
+ }
+ if capture.events[0].Properties["identity_class"] != productanalytics.IdentityExternal {
+ t.Fatalf("properties = %#v", capture.events[0].Properties)
+ }
+}
+
+func TestRecordFleetAttributionExcludesVerifiedInternalIdentity(t *testing.T) {
for _, user := range []*auth.User{
{ID: "internal-1", Email: "[email protected]", EmailVerified: true, AZP: "cyclops-cs-spa"},
- {ID: "unknown-1", AZP: "cyclops-cs-spa"},
} {
capture := &analyticsCapture{}
h := Handlers{Analytics: capture, AuthCfg: configAuthForAnalytics()}
diff --git a/libs/fleet/backend/productanalytics/events.go b/libs/fleet/backend/productanalytics/events.go
index 6ef64ca851..3a0d96a90d 100644
--- a/libs/fleet/backend/productanalytics/events.go
+++ b/libs/fleet/backend/productanalytics/events.go
@@ -19,10 +19,11 @@ const (
)
func ClassifyIdentity(user *auth.User) IdentityClass {
- if user == nil || !user.EmailVerified || strings.TrimSpace(user.Email) == "" {
+ if user == nil || strings.TrimSpace(user.ID) == "" {
return IdentityUnknown
}
- if strings.HasSuffix(strings.ToLower(strings.TrimSpace(user.Email)), "@trycua.com") {
+ // Only verified company-domain evidence excludes an authenticated user from growth counts.
+ if user.EmailVerified && strings.HasSuffix(strings.ToLower(strings.TrimSpace(user.Email)), "@trycua.com") {
return IdentityInternal
}
return IdentityExternal
diff --git a/libs/fleet/backend/productanalytics/events_test.go b/libs/fleet/backend/productanalytics/events_test.go
index 1ffee7469f..41ecc13553 100644
--- a/libs/fleet/backend/productanalytics/events_test.go
+++ b/libs/fleet/backend/productanalytics/events_test.go
@@ -35,12 +35,15 @@ func TestClassifyIdentity(t *testing.T) {
user *auth.User
want IdentityClass
}{
- {name: "verified internal domain", user: &auth.User{Email: "[email protected]", EmailVerified: true}, want: IdentityInternal},
- {name: "domain case is normalized", user: &auth.User{Email: "[email protected]", EmailVerified: true}, want: IdentityInternal},
- {name: "lookalike domain is external", user: &auth.User{Email: "[email protected]", EmailVerified: true}, want: IdentityExternal},
- {name: "unverified internal-looking email is unknown", user: &auth.User{Email: "[email protected]"}, want: IdentityUnknown},
- {name: "missing email is unknown", user: &auth.User{ID: "user-1"}, want: IdentityUnknown},
- {name: "verified external email", user: &auth.User{Email: "[email protected]", EmailVerified: true}, want: IdentityExternal},
+ {name: "missing user", user: nil, want: IdentityUnknown},
+ {name: "missing stable id", user: &auth.User{Email: "[email protected]", EmailVerified: true}, want: IdentityUnknown},
+ {name: "verified internal domain", user: &auth.User{ID: "user-1", Email: "[email protected]", EmailVerified: true}, want: IdentityInternal},
+ {name: "domain case is normalized", user: &auth.User{ID: "user-1", Email: "[email protected]", EmailVerified: true}, want: IdentityInternal},
+ {name: "lookalike domain is external", user: &auth.User{ID: "user-1", Email: "[email protected]", EmailVerified: true}, want: IdentityExternal},
+ {name: "unverified internal-looking email is external", user: &auth.User{ID: "user-1", Email: "[email protected]"}, want: IdentityExternal},
+ {name: "missing email is external", user: &auth.User{ID: "user-1"}, want: IdentityExternal},
+ {name: "unverified external email is external", user: &auth.User{ID: "user-1", Email: "[email protected]"}, want: IdentityExternal},
+ {name: "verified external email", user: &auth.User{ID: "user-1", Email: "[email protected]", EmailVerified: true}, want: IdentityExternal},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
diff --git a/libs/fleet/backend/productanalytics/middleware_test.go b/libs/fleet/backend/productanalytics/middleware_test.go
index c216b246c9..a377b85b7c 100644
--- a/libs/fleet/backend/productanalytics/middleware_test.go
+++ b/libs/fleet/backend/productanalytics/middleware_test.go
@@ -32,15 +32,17 @@ func observedRequest(method, route, path string, user *auth.User) *http.Request
return request.WithContext(ctx)
}
-func TestRouteObserverEmitsActivationOnlyForExternalIdentity(t *testing.T) {
+func TestRouteObserverEmitsActivationForAuthenticatedNonInternalIdentity(t *testing.T) {
users := []struct {
name string
user *auth.User
want int
}{
- {name: "external", user: &auth.User{ID: "external-1", Email: "[email protected]", EmailVerified: true, AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}, want: 3},
+ {name: "verified external", user: &auth.User{ID: "external-1", Email: "[email protected]", EmailVerified: true, AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}, want: 3},
+ {name: "missing email", user: &auth.User{ID: "external-2", AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}, want: 3},
+ {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: "unknown", user: &auth.User{ID: "unknown-1", AZP: "cyclops-cs-spa", PrincipalType: auth.PrincipalTypeUser}, want: 1},
}
for _, test := range users {
t.Run(test.name, func(t *testing.T) {
diff --git a/libs/fleet/docs/fleet-attribution-phase1.md b/libs/fleet/docs/fleet-attribution-phase1.md
index 4db3b06f2c..6656012632 100644
--- a/libs/fleet/docs/fleet-attribution-phase1.md
+++ b/libs/fleet/docs/fleet-attribution-phase1.md
@@ -10,7 +10,7 @@ The five stable fields are acquisition-channel neutral. They can represent email
## Binding and qualification
-After Keycloak authentication, the SPA submits the validated record to the authenticated `/api/analytics/attribution` endpoint. The backend repeats the version, size, age, key, and value checks and accepts only the Fleet SPA principal. Verified external identities emit `fleet_attribution_bound`; internal and unknown identities are discarded. PostHog receives the five fields only as set-once first-touch person properties under the keyed-HMAC pseudonym. The endpoint never accepts a URL, referrer, email, raw identity, arbitrary property, or provider payload, and attribution delivery cannot affect authentication or application readiness.
+After Keycloak authentication, the SPA submits the validated record to the authenticated `/api/analytics/attribution` endpoint. The backend repeats the version, size, age, key, and value checks and accepts only the Fleet SPA principal. Stable authenticated identities emit `fleet_attribution_bound` unless verified `@trycua.com` evidence classifies them as internal. Missing or unverified email evidence is treated as external for growth measurement; unauthenticated identities or identities without a stable user ID remain unknown. PostHog receives the five fields only as set-once first-touch person properties under the keyed-HMAC pseudonym. The endpoint never accepts a URL, referrer, email, raw identity, arbitrary property, or provider payload, and attribution delivery cannot affect authentication or application readiness.
`QualifiesFleetAttribution` is a deterministic, side-effect-free predicate over explicit facts. Qualification requires authenticated namespace authorization, an exact SDK-provided claim matching a Bound claim with a sandbox identity, service exactly `<sandbox>-server`, an exact namespace pool, and a 2xx upstream response. Probe paths, redirects, upgrades, HEAD/OPTIONS, non-service routes, and Kubernetes/orchestration routes are excluded.