Resolve the "TLS Failed to Verify Certificate" error in Azure DevOps pipelines when connecting to an Azure Container Registry (ACR) via a Private Endpoint by ensuring the pipeline agent can resolve internal DNS names and trusts the correct root certificates. This issue typically stems from network isolation or missing certificate trust stores on the build agents.
Understanding the Network Isolation
When you configure an Azure Container Registry with a Private Endpoint, standard public internet routes are blocked for that registry. The registry becomes accessible only through your Virtual Network (VNet). In an Azure DevOps self-hosted agent scenario, this creates a complex networking topology. The agent must be able to reach the private IP address assigned to the ACR Private Endpoint. If the agent is running on a different subnet or outside the VNet without proper peering, it cannot establish the TCP connection required for TLS handshake. Even if the network path exists, the TLS verification failure indicates that the client (the agent) does not recognize the certificate presented by the ACR. ACR uses managed identity and automatically provisions SSL/TLS certificates. These certificates are signed by Microsoft’s internal certificate authorities. For a secure connection to succeed, the machine running the Azure DevOps agent must have these specific CA certificates in its trusted store. Without them, the operating system rejects the connection as untrusted, resulting in the generic TLS error message.Verifying DNS Resolution
Before diving into certificates, confirm that the agent can resolve the ACR domain name to the private IP. Public DNS servers will return the public IP or fail entirely because the Private Endpoint disables public access. You need to ensure that the agent is using the VNet’s internal DNS server. On Linux agents, check the/etc/resolv.conf file. On Windows agents, verify the network adapter settings. If the agent relies on public DNS like Google's 8.8.8.8, it will never find the private endpoint.
Use the following command to test resolution from the agent machine:
nslookup <your-registry-name>.azurecr.io
The response should show an IP address within your VNet’s CIDR range, not a public Azure IP. If it returns a public IP or times out, the DNS configuration is incorrect. Ensure that Azure DNS integration is enabled for your VNet or that you have configured conditional forwarders correctly. This step is critical because even with perfect certificates, a DNS mismatch prevents the initial connection attempt.
Configuring Trusted Root Certificates
The core of the "TLS Failed to Verify Certificate" error is often a missing trust anchor. Self-hosted agents do not always come pre-loaded with the latest Microsoft enterprise CA certificates, especially in minimal containerized environments. You must explicitly add the Azure infrastructure certificates to the agent’s trust store. For Linux-based agents, you can update the certificate store using the package manager. Run the following commands to install and update the CA certificates:sudo apt-get update
sudo apt-get install ca-certificates
sudo update-ca-certificates
On Windows agents, you may need to manually import the relevant certificates into the "Trusted Root Certification Authorities" store. Microsoft provides documentation on which specific certificates are required for Azure services. Often, simply updating the OS and applying the latest security patches ensures that the necessary root CAs are present. However, in hardened or custom-built images, you might need to download the specific Microsoft IT TLS CA certificates and import them programmatically during the agent initialization phase.
Checking Agent Network Configuration
If DNS and certificates are correct, verify the agent’s network interface. Ensure that the agent is connected to the same VNet or a peered VNet that has a route to the ACR subnet. Use PowerShell or CLI tools to inspect the routing table. Look for a default route or a specific route pointing to the Private Endpoint’s gateway. If the agent is in a different subscription, ensure that VNet peering is bidirectional and that resource locks or NSG rules are not blocking traffic on port 443. You can also usecurl or Invoke-WebRequest from the agent to test connectivity directly to the ACR URL. This isolates whether the issue is with the Azure DevOps task runner or the underlying network stack. If curl fails with the same TLS error, the problem is definitely at the OS or network level, not the pipeline configuration.