Skip to content

Android provision certificates before dependent profiles - #46759

Merged
ksykulev merged 7 commits into
mainfrom
45022-android-cert-profile
Jun 4, 2026
Merged

Android provision certificates before dependent profiles#46759
ksykulev merged 7 commits into
mainfrom
45022-android-cert-profile

Conversation

@ksykulev

@ksykulev ksykulev commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Related issue: Resolves #45022

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Bug Fixes
    • Prevented intermittent Android profile failures during host/team transfers by ensuring pending Android certificates are created for transferred devices before dependent profiles are applied. Profiles now apply reliably, including when devices are moved off a team.
  • Tests
    • Added and updated tests to cover Android certificate provisioning during host transfers.

Copilot AI review requested due to automatic review settings June 3, 2026 18:25
@ksykulev
ksykulev requested a review from a team as a code owner June 3, 2026 18:25

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

This PR ensures Android certificate templates are created for transferred hosts before dependent Android/ONC profiles are applied. AddHostsToTeam and AddHostsToTeamByFilter now fetch transferred Android UUIDs, create pending certificate-template records for the destination team (using team ID 0 for no-team transfers), then proceed with bulk pending-profile logic and Android-apps queueing. Tests import the Android MDM package, stub the Android UUID lookup, and add tests verifying pending cert template creation and team-ID behavior.

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: ensuring Android certificates are provisioned before dependent profiles during team transfers.
Description check ✅ Passed The PR description references the related issue and includes completed checklist items for changes files, automated tests, and manual QA, meeting template requirements.
Linked Issues check ✅ Passed The code changes implement the objective from #45022: certificates are now provisioned before dependent Android profiles during team transfers [45022].
Out of Scope Changes check ✅ Passed All changes are scoped to addressing the certificate provisioning order issue for Android profiles during team transfers, with corresponding test coverage.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 45022-android-cert-profile

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/service/hosts.go`:
- Around line 1291-1298: The Android certificate rows are being created after
BulkSetPendingMDMHostProfiles which allows Android profiles to become pending
before their certificates exist; move the
CreatePendingCertificateTemplatesForNewHost calls to run before the
BulkSetPendingMDMHostProfiles call so certificate templates for androidUUIDs
(when teamID != nil) are created first; apply this reordering in both
AddHostsToTeam and AddHostsToTeamByFilter, ensuring
svc.ds.CreatePendingCertificateTemplatesForNewHost is invoked for each hostUUID
in androidUUIDs prior to calling BulkSetPendingMDMHostProfiles.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 628e840d-257a-4b96-9ee3-d508ef384fa2

📥 Commits

Reviewing files that changed from the base of the PR and between b9e58d5 and 4297339.

📒 Files selected for processing (3)
  • changes/45022-android-profile-cert-race-condition
  • server/service/hosts.go
  • server/service/hosts_test.go

Comment thread server/service/hosts.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a Fleet MDM Android team-transfer race where ONC profiles that depend on certificates can be applied before the certificates are available, causing a temporary enforcement failure during team transfers.

Changes:

  • Create pending Android certificate template records when hosts are transferred to a team (both direct host ID transfers and filter-based transfers).
  • Ensure Android “available apps” recalculation is still queued on transfer paths.
  • Add a changelog entry and update existing unit tests to account for the new datastore call.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
server/service/hosts.go Adds creation of pending Android certificate template records during host team transfer flows.
server/service/hosts_test.go Updates mocks to stub ListMDMAndroidUUIDsToHostIDs so existing tests continue to run.
changes/45022-android-profile-cert-race-condition Adds a user-visible changelog note describing the fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/service/hosts.go Outdated
Comment thread server/service/hosts.go Outdated
Comment thread server/service/hosts.go Outdated
Comment thread server/service/hosts_test.go
getvictor
getvictor previously approved these changes Jun 3, 2026

@getvictor getvictor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.

Comment thread server/service/hosts.go
Comment thread server/service/hosts.go
Comment thread server/service/hosts.go
Comment on lines +1265 to +1269
for hostUUID := range androidUUIDs {
if _, err := svc.ds.CreatePendingCertificateTemplatesForNewHost(ctx, hostUUID, destTeamID); err != nil {
return ctxerr.Wrap(ctx, err, "create pending certificate templates for transferred android host")
}
}
Comment thread server/service/hosts.go
Comment on lines +1437 to +1441
for hostUUID := range androidUUIDs {
if _, err := svc.ds.CreatePendingCertificateTemplatesForNewHost(ctx, hostUUID, destTeamID); err != nil {
return ctxerr.Wrap(ctx, err, "create pending certificate templates for transferred android host")
}
}
Comment thread server/service/hosts.go
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.84615% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.98%. Comparing base (2614e7f) to head (bb90ccf).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
server/service/hosts.go 53.84% 6 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #46759      +/-   ##
==========================================
+ Coverage   66.91%   66.98%   +0.06%     
==========================================
  Files        2836     2826      -10     
  Lines      225064   224556     -508     
  Branches    11619    11362     -257     
==========================================
- Hits       150611   150411     -200     
+ Misses      60788    60476     -312     
- Partials    13665    13669       +4     
Flag Coverage Δ
backend 68.62% <53.84%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

CI Feedback 🧐

A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

Action: aggregate-result

Failed stage: Check for failures [❌]

Failed test name: vuln-mysql8.0.44

Failure summary:

The action failed because one of the downloaded test job status artifacts reported a failure:
- The
status file ./vuln-mysql8.0.44-status/status contained fail, so the workflow marked the job
vuln-mysql8.0.44 as failed.
- The script then exited with code 1 after printing ❌ One or more test
jobs failed: vuln-mysql8.0.44.

Relevant error logs:
1:  ##[group]Runner Image Provisioner
2:  Hosted Compute Agent
...

119:  Artifact download completed successfully.
120:  Extracting artifact entry: /home/runner/work/fleet/fleet/fast-status/status
121:  Artifact download completed successfully.
122:  Extracting artifact entry: /home/runner/work/fleet/fleet/integration-mdm-mysql8.0.44-status/status
123:  Artifact download completed successfully.
124:  Extracting artifact entry: /home/runner/work/fleet/fleet/scripts-status/status
125:  Artifact download completed successfully.
126:  Extracting artifact entry: /home/runner/work/fleet/fleet/integration-enterprise-mysql8.0.44-status/status
127:  Artifact download completed successfully.
128:  Extracting artifact entry: /home/runner/work/fleet/fleet/integration-core-mysql8.0.44-status/status
129:  Artifact download completed successfully.
130:  Extracting artifact entry: /home/runner/work/fleet/fleet/mysql-mysql8.0.44-status/status
131:  Artifact download completed successfully.
132:  Total of 10 artifact(s) downloaded
133:  Download artifact has finished successfully
134:  ##[group]Run failed_tests=""
135:  �[36;1mfailed_tests=""�[0m
136:  �[36;1mstatus_count=0�[0m
137:  �[36;1m# Find all status files (they are in directories like 'fleetctl-mysql8.0.44-status/status')�[0m
138:  �[36;1mfor status_file in $(find ./ -type f -name 'status'); do�[0m
139:  �[36;1m  status_count=$((status_count + 1))�[0m
140:  �[36;1m  # Extract test name from parent directory (e.g., 'fleetctl-mysql8.0.44-status')�[0m
141:  �[36;1m  test_dir=$(basename $(dirname "$status_file"))�[0m
142:  �[36;1m  # Remove '-status' suffix to get the test name�[0m
143:  �[36;1m  test_name="${test_dir%-status}"�[0m
144:  �[36;1m  status_content=$(cat "$status_file")�[0m
145:  �[36;1m  echo "Processing: $status_file (Test: $test_name) with status content: $status_content"�[0m
146:  �[36;1m  if grep -q "fail" "$status_file"; then�[0m
147:  �[36;1m    echo "  ❌ Test failed: $test_name"�[0m
148:  �[36;1m    failed_tests="${failed_tests}${test_name}, "�[0m
149:  �[36;1m  else�[0m
150:  �[36;1m    echo "  ✅ Test passed: $test_name"�[0m
151:  �[36;1m  fi�[0m
152:  �[36;1mdone�[0m
153:  �[36;1mif [[ $status_count -eq 0 ]]; then�[0m
154:  �[36;1m  echo "❌ ERROR: No status files found! This indicates a workflow issue."�[0m
155:  �[36;1m  exit 1�[0m
156:  �[36;1mfi�[0m
157:  �[36;1mif [[ -n "$failed_tests" ]]; then�[0m
158:  �[36;1m  echo "❌ One or more test jobs failed: ${failed_tests%, }"�[0m
159:  �[36;1m  exit 1�[0m
160:  �[36;1mfi�[0m
161:  �[36;1mecho "✅ All test jobs succeeded."�[0m
162:  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
163:  ##[endgroup]
164:  Processing: ./integration-core-mysql8.0.44-status/status (Test: integration-core-mysql8.0.44) with status content: success
165:  ✅ Test passed: integration-core-mysql8.0.44
166:  Processing: ./vuln-mysql8.0.44-status/status (Test: vuln-mysql8.0.44) with status content: fail
167:  ❌ Test failed: vuln-mysql8.0.44
168:  Processing: ./service-mysql8.0.44-status/status (Test: service-mysql8.0.44) with status content: success
169:  ✅ Test passed: service-mysql8.0.44
170:  Processing: ./main-mysql8.0.44-status/status (Test: main-mysql8.0.44) with status content: success
171:  ✅ Test passed: main-mysql8.0.44
172:  Processing: ./fleetctl-mysql8.0.44-status/status (Test: fleetctl-mysql8.0.44) with status content: success
173:  ✅ Test passed: fleetctl-mysql8.0.44
174:  Processing: ./integration-enterprise-mysql8.0.44-status/status (Test: integration-enterprise-mysql8.0.44) with status content: success
175:  ✅ Test passed: integration-enterprise-mysql8.0.44
176:  Processing: ./fast-status/status (Test: fast) with status content: success
177:  ✅ Test passed: fast
178:  Processing: ./mysql-mysql8.0.44-status/status (Test: mysql-mysql8.0.44) with status content: success
179:  ✅ Test passed: mysql-mysql8.0.44
180:  Processing: ./integration-mdm-mysql8.0.44-status/status (Test: integration-mdm-mysql8.0.44) with status content: success
181:  ✅ Test passed: integration-mdm-mysql8.0.44
182:  Processing: ./scripts-status/status (Test: scripts) with status content: success
183:  ✅ Test passed: scripts
184:  ❌ One or more test jobs failed: vuln-mysql8.0.44
185:  ##[error]Process completed with exit code 1.
186:  Post job cleanup.

@ksykulev
ksykulev merged commit e8bd1d5 into main Jun 4, 2026
43 of 45 checks passed
@ksykulev
ksykulev deleted the 45022-android-cert-profile branch June 4, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android profiles can get applied before certs on team transfers leading to a temporary failure

3 participants