-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
azure-identity | CertificateCredential fails to parse PEM certificate (Error "Failed to deserialize certificate in PEM or PKCS12 format") #38263
Comments
Thank you for your feedback. Tagging and routing to the team member best able to assist. |
Thanks for reaching out. Can you enable logging and share the trac by adding import logging ? |
Hi @runr02. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue. |
See attached sanitized version Exception while executing function: Functions.function-name Result: Failure |
Thanks for the details. We use cryptography library to load the certificate. Can you try the code to see if you can repro the issue? from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.serialization import Encoding, NoEncryption, pkcs12, PrivateFormat
private_key, cert, additional_certs = pkcs12.load_key_and_certificates(certificate_data, password, backend=default_backend()) |
Hi @runr02. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue. |
Hi @runr02, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you! |
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:
Create a python function app.
Load pfx certificate to Key Vault.
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.
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="<tenant_id>",
client_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. #24643
The text was updated successfully, but these errors were encountered: