Azure / azure-functions-core-tools

Command line tools for Azure Functions
MIT License
1.33k stars 437 forks source link

Unable to access certificate in Azure function #1889

Open Ajay-MS opened 4 years ago

Ajay-MS commented 4 years ago

I am executing my Azure function locally on HTTPS with the application arguments:

host start --useHttps --cert "server.pfx" --password ajay

where server.pfx is a self-signed certificate.

In the postman setting, I have set certificate for the URL corresponding to the function app. PostmanCertSettings

In Azure function, I am reading certificate as follow:

var clientCert = req.HttpContext.Connection.ClientCertificate;

clientCert instance is always null. Am I missing some steps here ?

anthonychu commented 4 years ago

@ahmelsayed Do you know how this would work?

ahmelsayed commented 4 years ago

in AppService the cert if is passed to the application using X-ARR-ClientCert header. I don't know if there is anything specific in AppService, Functions, or dotnet core that will automatically populate HttpContext.Connection.ClientCertificate for you.

Locally, I think this will work if we update https://github.com/Azure/azure-functions-core-tools/blob/6478ce04fd380c113cff659d0e36eea5a42aff3b/src/Azure.Functions.Cli/Actions/HostActions/StartHostAction.cs#L166

to

listenOptins.UseHttps(new HttpsConnectionAdapterOptions
{
    ClientCertificateMode = ClientCertificateMode.AllowCertificate,
    ClientCertificateValidation = (_, __, ___) => true,
    ServerCertificate = certificate
});

but we should follow up with @fabiocav about that.

DONAR144 commented 1 year ago

Same issue here... Was there ever any update to this