Azure / azure-sdk-for-net

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

[BUG] Potential authorization issue with Confidential Ledger #27922

Closed rajdhandus closed 1 year ago

rajdhandus commented 2 years ago

Library name and version

Azure.Security.ConfidentialLedger 1.0.0-beta.2

Describe the bug

Expected behavior

Actual behavior

Reproduction Steps

Run the below code where the TokenCredentials is not present.

private static void SDKClient(StringContent request, HttpClientHandler handler)
{
    try
    {
        var options = new ConfidentialLedgerClientOptions { Transport = new HttpClientTransport(handler) };
        var ledgerClient = new ConfidentialLedgerClient(new Uri(_ledgerURI), null, options);
        RequestContent requestContent = RequestContent.Create(request);
        var responseForPost = ledgerClient.PostLedgerEntry(requestContent);
        Console.WriteLine(responseForPost.Content);
    }
    catch (HttpRequestException e)
    {
        Console.WriteLine("\nException Caught!");
        Console.WriteLine("Message :{0} ", e.Message);
    }
}

Environment

No response

jsquire commented 2 years ago

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

christothes commented 2 years ago

Hi @rajdhandus - Would the ClientCertificiateCredential work for you in this scenario? If not, could you explain a bit more about what you are trying to do?

I'm also curious - is there a reason you need to use a custom handler other than to trust the identity endpoint's certificate root?

rajdhandus commented 2 years ago

Hi @christothes - thanks for the link. ClientCertificiateCredential looks like it needs clientId and TenantId ? And also - its minting a token at the end?

I am trying to authenticate with Azure Confidential Ledger directly with certificates that were used while creating the ledger. These certificates are not necessarily uploaded to AAD.

christothes commented 2 years ago

Ah - OK, I understand now - Unfortunately, we are missing the self-signed client certificate auth support in this client. We currently only support TokenCredential auth. We'll look at adding this in an upcoming release.

rajdhandus commented 2 years ago

thanks! this seems to be available in Python SDK

https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/core/azure-core/README.md?plain=1#L181

https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/confidentialledger/azure-confidentialledger/README.md?plain=1#L237

https://azuresdkdocs.blob.core.windows.net/$web/python/azure-confidentialledger/latest/azure.confidentialledger.html?highlight=certificatecredential#azure.confidentialledger.ConfidentialLedgerCertificateCredential

christothes commented 2 years ago

tracking this in #28147