Azure DevOps Server pipeline build fails when using self-signed SSL certificate with "unable to get local issuer certificate" during NuGet restore

2 min read 06-10-2024
Azure DevOps Server pipeline build fails when using self-signed SSL certificate with "unable to get local issuer certificate" during NuGet restore


Azure DevOps Server Pipeline Build Fails: "Unable to Get Local Issuer Certificate" During NuGet Restore

Understanding the Problem

Have you ever encountered an error message like "Unable to get local issuer certificate" during a NuGet restore step in your Azure DevOps Server pipeline? This error typically arises when your pipeline is trying to access a NuGet feed secured with a self-signed SSL certificate. This article delves into the causes of this error and provides practical solutions to ensure smooth NuGet package restoration in your build process.

The Scenario and Code Example

Imagine you have a private NuGet feed hosted on a server within your network. For security purposes, you've opted to use a self-signed SSL certificate to secure the feed. When you try to restore NuGet packages from this feed in your Azure DevOps Server pipeline, the build fails with the error "Unable to get local issuer certificate."

Here's a simplified example of an Azure DevOps Server pipeline that might trigger this error:

trigger:
- master

pool:
  vmImage: 'Ubuntu-latest'

steps:
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '$(solution)'
    feedsToUse: '$(NuGetFeedUrl)'
    nugetCommand: '$(NuGetPath)'

This pipeline attempts to restore packages from a NuGet feed defined in the $(NuGetFeedUrl) variable. If this URL points to a feed secured with a self-signed SSL certificate, the build might fail with the error we discussed.

Analyzing the Error

The "Unable to get local issuer certificate" error indicates a trust issue. Essentially, the Azure DevOps Server build agent doesn't trust the self-signed certificate used to secure your NuGet feed. This is because the certificate hasn't been issued by a trusted Certificate Authority (CA) like Let's Encrypt or DigiCert.

Solutions to the Problem

Here are three common solutions to address this error:

  1. Import the Certificate into the Trusted Root Certificate Store:

    • On the Azure DevOps Server build agent: Import the self-signed certificate into the Trusted Root Certification Authorities store. This allows the build agent to trust the certificate and establish a secure connection with your NuGet feed.
  2. Bypass SSL Verification (Not Recommended):

    • In your NuGet command: Add the --skip-validation option to the NuGet restore command. This tells NuGet to bypass SSL certificate verification, effectively disabling security checks. However, this approach is strongly discouraged in production environments due to security risks.
  3. Use a Certificate Issued by a Trusted CA:

    • For your NuGet feed server: Obtain a certificate from a reputable CA. This guarantees that the certificate is trusted by most systems, including Azure DevOps Server build agents.

Best Practices

  • Prioritize security: While bypassing SSL verification might seem like a quick fix, it significantly compromises the security of your NuGet feed.
  • Use a trusted CA: For production environments, obtaining a certificate from a trusted CA is the most robust and secure solution.
  • Implement a robust certificate management strategy: Regularly update certificates and monitor their expiration dates.

Additional Value

By understanding the underlying causes and implementing appropriate solutions, you can prevent "Unable to get local issuer certificate" errors and ensure smooth and secure NuGet package restoration within your Azure DevOps Server build pipelines.

References and Resources

Remember, prioritizing security and adopting best practices are key to maintaining a reliable and secure build process.