Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.6k stars 2.82k forks source link

azure-identity | CertificateCredential fails to parse PEM certificate (Error "Failed to deserialize certificate in PEM or PKCS12 format") #38263

Open runr02 opened 2 hours ago

runr02 commented 2 hours ago

Describe the bug Getting 'Failed to deserialize certificate in PEM or PKCS12 format' error while using 'CertificateCredential' python module in 'azure.identity' python package.

Also tried passing the certificate as bytes. I have some degree of confidence that it's not the certificate causing the issue. I did get this to work by manually uploading the certificate via Kudu, but ideally, I would like to use Key Vault or even directly through the Function App using azure portal.

https://learn.microsoft.com/en-us/azure/app-service/configure-ssl-certificate-in-code?tabs=linux https://learn.microsoft.com/en-us/python/api/azure-identity/azure.identity.certificatecredential?view=azure-python#examples

To Reproduce Steps to reproduce the behavior:

  1. Create a python function app.
  2. Load pfx certificate to Key Vault.
  3. Reference the Key Vault certificate in a function app through azure portal (have not tried to upload directly without Key Vault) and set the variable WEBSITE_LOAD_CERTIFICATES to the certificate thumbprint.
  4. Reference the cert path in code in the any basic function app. This fails and does not create the credentials.
    from azure.identity import CertificateCredential

    credential = CertificateCredential( tenant_id="", client_id="", certificate_path="/var/ssl/private/.p12", password="", )

Expected behavior The credential should be created and would move on to get the API token. Instead it fails.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context a similar issue on GitHub that was marked as "resolved" back in 2022. However, if you read further in the comments, you will see that others are still facing this issue even after it was marked as resolved. https://github.com/Azure/azure-sdk-for-python/issues/24643

github-actions[bot] commented 2 hours ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.