When connecting to an API from an Azure Function or Web App I can upload the public key certificate (.cer file) to the LocalMachine store of the App and add the thumbprints to the configuration using the key "WEBSITE_LOAD_ROOT_CERTIFICATES". When doing this with a self signed certitifcate for an internal organisational API I usually have to specify the Root and Intermediate thumbrints and upload the Root and Intermediate certificate to the Function App.
I like the idea of having the organisational self signed certificates stored in Key Vault so the API that is secured can use the certificate and the consumers of the API can just grab the public key during their deployment.
Is there a way to store these certificates in KeyVault, reference them from an Azure Function (or equivalent) so that I do not have to manually load the certificates and associate them with the HttpClient using code? I like simplicity of using the "WEBSITE_LOAD_ROOT_CERTIFICATES" configuration key.
I would like to configure this in the Azure Devops Pipeline.
First create a
Azure Key Vaultand provide the requiredaccess policiesto retrieve theSecretsorCertificates.For this , we need
Service Principal.Create
Service Principalusing theAzure CLIcommand.Next Provide the
Access Policies.Certificate permissions, select the operation based on your requirement.Service Principalwhich you have created and continue with next steps toCreate an access policy.Yes, we can use
Azure Functionsto retrieve the Certificate from Key Vault.Install the NuGet packages.
We can use the
Azure CLIorPowershellcommand in the Azure Pipelines to get theCertificate.Use
Get-AzKeyVaultCertificate, in the Pipeline.OR
We can use
WEBSITE_LOAD_CERTIFICATESby providing the thumbprint values.References taken from MSDoc and retrieve Azure Key Vault Secrets using Azure Functions