mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Add debug logs when attempting to link host to SCIM user (#38183)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** For #37271 # Details Even after patching and verifying #37271 we're still seeing a case of a host not being successfully paired with the correct SCIM user after enrolling. Deleting and re-enrolling the host did not fix the issue. See recent posts in https://fleetdm.slack.com/archives/C019WG4GH0A/p1765376152824949 for details. This PR adds logging to attempt to diagnose the exact issue. # Checklist for submitter ## Testing - [X] QA'd all new/changed functionality manually Enrolled a host locally and saw logs in various scenarios.
This commit is contained in:
parent
3907243881
commit
02f3bb65e0
2 changed files with 6 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue