Expected Behavior
- Working fine when access with dapr API using postman to access key vault secret.
- Should fetch the secret from azure key vault using c sharp dapr client SDK.
Actual Behavior
- Azure key vault with service principal YAML:
apiVersion: dapr.io/v1alpha1 kind: Component metadata: name: azuresecretstore namespace: default spec: type: secretstores.azure.keyvault version: v1 metadata: - name: vaultName value: "kv-xxxx-dev-xxx" - name: azureTenantId value: "5xxxxaf-bxx8-4xxe4-xxxc-a0fxxxxc36" - name: azureClientId value: "e01xxxxf-8xxx-xxxx-9axx-3f12xxxxce5" - name: azureClientSecret value : "aCK8Q~xxxxxxxxxxxxxxLixFKe1ZD__u6a_v"
- When executing daprClient.GetSecretAsync function in c# web api code getting below error
Dapr.DaprException HResult=0x80131500 Message=Secret operation failed: the Dapr endpoint indicated a failure. See InnerException for details. Source=Dapr.Client StackTrace: at Dapr.Client.DaprClientGrpc.d__48.MoveNext() at Program.<$>d__0.MoveNext() in C:\Users\DmonteN\source\repos\touchstone-svc-template\src\Touchstone.Api\Program.cs:line 120
This exception was originally thrown at this call stack: [External Code]
Inner Exception 1: RpcException: Status(StatusCode="Unavailable", Detail="Error connecting to subchannel.", DebugException="System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it. at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Sockets.Socket.g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken) at Grpc.Net.Client.Balancer.Internal.SocketConnectivitySubchannelTransport.TryConnectAsync(CancellationToken cancellationToken)")
Steps to Reproduce the Problem
- Install dapr, configure azure key vault yaml file.
- Run dapr side car engine
- Verify if you are able to fetch the secret using dapr secret API in postman
- If yes, then execute below code in c sharp
// Create Dapr Client var daprClient = new DaprClientBuilder().UseHttpEndpoint("http://127.0.0.1:50001/").UseJsonSerializationOptions(default).Build();
// Add the DaprClient to DI.
builder.Services.AddSingleton(daprClient);
var noProxy = Environment.GetEnvironmentVariable("no_proxy");
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken cancellationToken = source.Token;
//Using Dapr SDK to invoke a method
var metadata = new Dictionary<string, string> { ["version_id"] = "3" };
var secret = await daprClient.GetSecretAsync("azuresecretstore", "appcs-id-Primary", metadata, cancellationToken); <= Getting error at this line
Console.WriteLine($"Result: {string.Join(", ", secret)}");