-
Notifications
You must be signed in to change notification settings - Fork 335
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
How does builder.Configuration.AddDaprSecretStore
Work?
#1368
Comments
Host startup is intentionally delayed until the load completes. It shouldn't take that long to retrieve and populate the secrets themselves - the delay is really just waiting for healthiness to be reported, and there shouldn't be much of a delay in a healthy environment. The timeout value you mentioned puts an upper bound on waiting for failed retries to complete. |
Thanks for the explanation, but what if the application is started before Dapr? How would the secrets be fetched if Dapr is not ready. I am confused about the circular dependency/race condition I mentioned. I read this in an old issue: #452 (comment) But can't understand how it's handled, because app won't be up until this function succeeds. |
Whoops, yes, I neglected to speak to that. Put simply, you cannot use any secrets from the client which might result in such a circular dependency and that makes sense, right? Take the following example:
But of course when your code runs through So yes, you have to be careful about specifically which secrets you need and where you're sourcing them especially during startup. Personally, I put my secrets in Azure Key Vault and typically access them via the secret store functionality, except that I specifically register the Dapr API token as a referenced Key Vault Secret in the environment variables for my service (I often use Azure Container Apps here). By doing this, you can instead opt to read in your environment variables at the top (populating this as authentication happens at the infrastructure level instead): var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddEnvironmentVariables();
builder.Services.AddDaprClient((serviceProvider, daprClientBuilder) => {
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
var daprApiToken = configuration["DaprApiToken"];
daprClientBuilder.UseDaprApiToken(daprApiToken);
});
//...
var app = builder.Build();
//Provision an instance of the DaprClient to use
await using var scope = app.Services.CreateAsyncScope();
var daprClient = scope.Services.GetRequiredService<DaprClient>();
builder.Configuration. AddDaprSecretStore("my-store", [], daprClient); Now if you strictly follow this sort of structure and you're definitely not injecting (and thus not resolving) any other services that need secrets from |
Thanks for the excellent explanation. So to summarize:
So point 2 implies Dapr will serve the secrets even before |
Well, they're not going to stop As demonstrated in my example above then, that has the less-than-obvious, but helpful side effect that you can continue to populate your configuration after the container is built so long as you also don't force the resolution of anything that's going to take that Dapr will pull the secrets specified once the So I'd instead sum up with:
|
Thanks, that clears it all! |
Please don't hesitate to reach out if you have any other questions! |
When the app and Dapr start at different times the app has to wait for getting secrets and Dapr has to wait for the app to start listening if I understand it right. This appears like a circular dependency then how exactly does this function work?
There can be network delay and there is a Wait timeout option which I am guessing is for the time taken to get the secrets.
So does it pause the host startup until then? Sorry for creating this as an issue but I can't seem to find much documentation around it.
The text was updated successfully, but these errors were encountered: