Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions server/mdm/android/service/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ func (r *profileReconciler) ReconcileProfiles(ctx context.Context, cursor string
bulkHostProfs = append(bulkHostProfs, bulkProfs...)
}

if hostCount > 0 {
r.Logger.DebugContext(ctx, "android profile reconciler processed hosts", "host_count", hostCount, "profile_count", len(bulkHostProfs))
}
Comment thread
Copilot marked this conversation as resolved.

if err := r.DS.BulkUpsertMDMAndroidHostProfiles(ctx, bulkHostProfs); err != nil {
return 0, ctxerr.Wrap(ctx, err, "bulk upsert android host profiles")
}
Expand Down Expand Up @@ -443,6 +447,12 @@ func (r *profileReconciler) sendHostProfiles(
}
}
}

if skip && !policyReq.PolicyVersion.Valid {
r.Logger.WarnContext(ctx, "android policy patch returned not-modified without a version; profiles will have nil IncludedInPolicyVersion",
"host_uuid", hostUUID, "policy_request_uuid", policyReq.RequestUUID, "status_code", policyReq.StatusCode,
"profile_count", len(bulkProfilesByUUID))
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if patchPolicyReqFailed {
appendWithheld()
return slices.Collect(maps.Values(bulkProfilesByUUID)), nil
Expand Down
23 changes: 22 additions & 1 deletion server/mdm/android/service/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,8 @@ func (svc *Service) getPolicyID(ctx context.Context, device *androidmanagement.D
func (svc *Service) verifyDevicePolicy(ctx context.Context, hostUUID string, device *androidmanagement.Device) {
appliedPolicyVersion := device.AppliedPolicyVersion

svc.logger.DebugContext(ctx, "Verifying Android device policy", "host_uuid", hostUUID, "applied_policy_version", appliedPolicyVersion)
svc.logger.DebugContext(ctx, "Verifying Android device policy", "host_uuid", hostUUID, "applied_policy_version", appliedPolicyVersion,
"non_compliance_count", len(device.NonComplianceDetails))

// Get all host_mdm_android_profiles that are pending or failed due to non compliance reasons,
// and included_in_policy_version <= device.AppliedPolicyVersion. That way we can either fully
Expand All @@ -1080,6 +1081,9 @@ func (svc *Service) verifyDevicePolicy(ctx context.Context, hostUUID string, dev
return
}

svc.logger.DebugContext(ctx, "pending install profiles for verification", "host_uuid", hostUUID,
"pending_count", len(pendingInstallProfiles), "applied_policy_version", appliedPolicyVersion)

// First case, if nonComplianceDetails is empty, verify all profiles that are pending or failed install, and remove the pending remove ones.
if len(device.NonComplianceDetails) == 0 {
var verifiedProfiles []*fleet.MDMAndroidProfilePayload
Expand Down Expand Up @@ -1121,6 +1125,23 @@ func (svc *Service) verifyDevicePolicy(ctx context.Context, hostUUID string, dev
}
}

if policyRequestUUID == "" {
var nilPolicyReqCount, nilVersionCount int
for _, p := range pendingInstallProfiles {
if p.PolicyRequestUUID == nil {
nilPolicyReqCount++
}
if p.IncludedInPolicyVersion == nil {
nilVersionCount++
}
}
svc.logger.WarnContext(ctx, "no matching policy request UUID found for non-compliance verification",
"host_uuid", hostUUID, "applied_policy_version", appliedPolicyVersion,
"pending_profiles", len(pendingInstallProfiles),
"nil_policy_request_uuid", nilPolicyReqCount, "nil_included_in_policy_version", nilVersionCount,
"non_compliance_count", len(device.NonComplianceDetails))
}
Comment on lines +1128 to +1143

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still want the info log for "policy request not found". Not a big deal querying the db one extra time.


// Iterate over all policy request uuids, fetch them and unmarshal the payload into the type.
// Then re-use the map above, so we can iterate over it again, but now the payload is already unmarshalled.
policyRequest, err := svc.ds.GetAndroidPolicyRequestByUUID(ctx, policyRequestUUID)
Expand Down
Loading