dapr / dapr/dotnet-sdk

Unable to fetch secret as daprClient.GetSecretAsync returning error

Open
#952 6 comments 0 reactions 0 assignees View on GitHub
area/client/secrets kind/bug
Dominant language
C#
Stars
1.2k
Forks
378
Avg merge
1d 22h
Merged PRs (30d)
5

Description

## Expected Behavior

Should fetch the secret from azure key vault using c sharp dapr client SDK

## Actual Behavior

Getting below error when executing daprClient.GetSecretAsync function

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

1) Install dapr, configure azure key vault yaml file.
2) run dapr side car engine
3) Verify if you are able to fetch the secret using dapr secret API in postman
4) 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 { ["version_id"] = "3" };
var secret = await daprClient.GetSecretAsync("azuresecretstore", "appcs-id-Primary", metadata, cancellationToken); //error line
Console.WriteLine($"Result: {string.Join(", ", secret)}");

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.