-
Notifications
You must be signed in to change notification settings - Fork 882
Android agent: retry DNS #43464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android agent: retry DNS #43464
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import androidx.datastore.preferences.core.stringPreferencesKey | |
| import com.fleetdm.agent.scep.ScepClient | ||
| import com.fleetdm.agent.scep.ScepClientImpl | ||
| import java.math.BigInteger | ||
| import java.net.UnknownHostException | ||
| import java.security.PrivateKey | ||
| import java.security.cert.Certificate | ||
| import java.text.SimpleDateFormat | ||
|
|
@@ -824,6 +825,10 @@ class CertificateOrchestrator( | |
| * (template fetch, SCEP enrollment, status update), so sequential processing avoids | ||
| * overwhelming the server and the device's network stack. | ||
| * | ||
| * If DNS resolution fails for a certificate (after exhausting in-call retries), we abort the | ||
| * remaining certs since DNS failures are network-level, not cert-specific. The worker will | ||
| * return Result.retry() and WorkManager's backoff handles the DNS recovery. | ||
| * | ||
| * @param context Android context for certificate installation | ||
| * @param hostCertificates List of certificate templates to enroll | ||
| * @return Map of certificate ID to enrollment result | ||
|
|
@@ -835,11 +840,28 @@ class CertificateOrchestrator( | |
| ): Map<Int, CertificateEnrollmentHandler.EnrollmentResult> { | ||
| Log.d(TAG, "Starting batch certificate enrollment for ${hostCertificates.size} certificates") | ||
|
|
||
| return hostCertificates.associate { cert -> | ||
| cert.id to enrollCertificate(context, cert.id, cert.uuid, certificateInstaller) | ||
| val results = mutableMapOf<Int, CertificateEnrollmentHandler.EnrollmentResult>() | ||
| for (cert in hostCertificates) { | ||
| val result = enrollCertificate(context, cert.id, cert.uuid, certificateInstaller) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a little confused why we have
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ksykulev This is arguably more complex than it should be. Maybe an eng-init issue to simplify it? DNS failures do not cause the cert to fail permanently. Three retry levels handle failures at different time scales during certificate enrollment. Level 1: DNS retry in makeRequest (
|
||
| results[cert.id] = result | ||
| if (result is CertificateEnrollmentHandler.EnrollmentResult.Failure && result.isDnsFailure()) { | ||
| Log.w( | ||
| TAG, | ||
| "DNS resolution failed for certificate ${cert.id}, aborting batch (${hostCertificates.size - results.size} certs deferred to next run)", | ||
| ) | ||
| break | ||
| } | ||
| } | ||
| return results | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if this failure was caused by a DNS resolution problem, either directly or wrapped in | ||
| * another exception (e.g. SCEP wraps UnknownHostException in ScepNetworkException). | ||
| */ | ||
| private fun CertificateEnrollmentHandler.EnrollmentResult.Failure.isDnsFailure(): Boolean = | ||
| generateSequence(exception as Throwable?) { it.cause }.any { it is UnknownHostException } | ||
|
|
||
| /** | ||
| * Android-specific certificate installer using DevicePolicyManager. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Fixed Android agent to retry DNS resolution failures when waking from Doze mode, and to defer remaining certificates in a batch to the next enrollment cycle when a DNS failure persists. |
Uh oh!
There was an error while loading. Please reload this page.