Fix HTTPS certificate/webserver not loading on first Docker start from environment variables #1574
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When starting the DNS Server in Docker for the first time with HTTPS enabled via environment variables (e.g.,
DNS_SERVER_WEB_SERVICE_ENABLE_HTTPS=true), the TLS certificates failed to load, causing HTTPS to not bind.A container restart was required for HTTPS to work properly.
Root Cause
The certificate loading process in
LoadConfigFile()was called before_dnsServerwas initialized inStartAsync(). TheCheckAndLoadSelfSignedCertificate()method requires_dnsServer.ServerDomainto generate self-signed certificates (line 2252), which caused aNullReferenceExceptionthat was silently caught during the first startup.Solution
Deferred certificate loading until after
_dnsServerinitialization by:_pendingLoadCustomCertificate- for custom certificate paths_pendingLoadSelfSignedCertificate- for self-signed certificatesLoadConfigFile()to set flags instead of immediately loading certificates when reading from environment variablesStartAsync()after_dnsServerinitialization but before web service startsTesting
Tested on first Docker container start with:
DNS_SERVER_WEB_SERVICE_USE_SELF_SIGNED_CERT=true)DNS_SERVER_WEB_SERVICE_TLS_CERTIFICATE_PATH=/path/to/cert.pfx)Log output showing successful first-start HTTPS binding: