diff --git a/server/datastore/mysql/hosts.go b/server/datastore/mysql/hosts.go index e216894beb..a9f0a749e0 100644 --- a/server/datastore/mysql/hosts.go +++ b/server/datastore/mysql/hosts.go @@ -4427,6 +4427,7 @@ func (ds *Datastore) MaybeAssociateHostWithScimUser(ctx context.Context, hostID checkExistingSQL := `SELECT scim_user_id FROM host_scim_user WHERE host_id = ?` err := sqlx.GetContext(ctx, ds.reader(ctx), &existingSCIMUserID, checkExistingSQL, hostID) if err == nil { + level.Debug(ds.logger).Log("msg", "MaybeAssociateHostWithScimUser: existing SCIM user association found for host", "host_id", hostID, "scim_user_id", existingSCIMUserID) // Existing SCIM user association found, nothing to do. // Bail early so that we don't trigger side-effects downstream like resending profiles. return nil @@ -4455,6 +4456,7 @@ WHERE if err != nil { if errors.Is(err, sql.ErrNoRows) { // No MDM IdP account for this host, nothing to do. + level.Debug(ds.logger).Log("msg", "MaybeAssociateHostWithScimUser: no MDM IdP account found for host", "host_id", hostID) return nil } return ctxerr.Wrap(ctx, err, "MaybeAssociateHostWithScimUser: get MDM IdP account for host") @@ -4469,6 +4471,7 @@ WHERE func maybeAssociateHostMDMIdPWithScimUser(ctx context.Context, tx sqlx.ExtContext, logger log.Logger, hostID uint, idp *fleet.MDMIdPAccount) error { if idp == nil { // TODO: confirm desired behavior here + level.Debug(logger).Log("msg", "maybeAssociateHostMDMIdPWithScimUser: MDM IdP account is nil, skipping association", "host_id", hostID) return nil } @@ -4478,6 +4481,7 @@ func maybeAssociateHostMDMIdPWithScimUser(ctx context.Context, tx sqlx.ExtContex return ctxerr.Wrap(ctx, err, "get scim user") case fleet.IsNotFound(err) || scimUser == nil: // There is no SCIM association possible at this time + level.Debug(logger).Log("msg", "maybeAssociateHostMDMIdPWithScimUser: no SCIM user found for MDM IdP account", "host_id", hostID, "mdm_idp_username", idp.Username, "mdm_idp_email", idp.Email) return nil } @@ -4485,6 +4489,7 @@ func maybeAssociateHostMDMIdPWithScimUser(ctx context.Context, tx sqlx.ExtContex if err != nil { return ctxerr.Wrap(ctx, err, "associate host with scim user") } + level.Debug(logger).Log("msg", "maybeAssociateHostMDMIdPWithScimUser: associated host with SCIM user", "host_id", hostID, "scim_user_id", scimUser.ID) return nil } diff --git a/server/service/orbit.go b/server/service/orbit.go index 14223a9260..dab6a5f961 100644 --- a/server/service/orbit.go +++ b/server/service/orbit.go @@ -241,6 +241,7 @@ func (svc *Service) EnrollOrbit(ctx context.Context, hostInfo fleet.OrbitHostInf // are associated during MDM enrollment. platform := host.FleetPlatform() if platform == "linux" || platform == "windows" { + level.Debug(svc.logger).Log("msg", "attempting to associate enrolled host with SCIM user", "host_id", host.ID, "platform", platform) if err := svc.ds.MaybeAssociateHostWithScimUser(ctx, host.ID); err != nil { level.Error(svc.logger).Log("msg", "failed to associate enrolled host with SCIM user", "err", err, "host_id", host.ID) }