Azure KeyVault and TimeOut
My magic the gathering cards site uses Azure App Configuration with references to Azure KeyVault.
A cool thing about this, that I don't set up perfectly, is that the Azure App Config doesn't actually need permissions to the KeyVault. It's just storing references for the consuming app.
My IaC gives the App Config permissions... but whatever.
Anyway, timeouts. I don't know what the hell happened, but locally I suddenly started to get timeouts when trying to run my app. Which makes development really hard. It was pretty straight forward as an error message - Authentication to keyvault timed out.
I don't have it happening anymore, so I can't copy and paste the actual error.
The code I had was
options.Connect(confRoot["AppConfiguration:ConnectionString"])
.ConfigureKeyVault(kv =>
{
kv.SetCredential(new DefaultAzureCredential());
});
Which is currently working, and worked before... but for some reason, some small period of time, TIME OUT!!!
What I updated to was
options.Connect(confRoot["AppConfiguration:ConnectionString"])
.ConfigureKeyVault(kv =>
{
kv.SetCredential(new DefaultAzureCredential(new DefaultAzureCredentialOptions
{
Retry =
{
// Reduce retries and timeouts to get faster failures
MaxRetries = 2,
NetworkTimeout = TimeSpan.FromSeconds(5),
MaxDelay = TimeSpan.FromSeconds(5)
}
}));
});
Not a huge change, but forces things to be a little faster. There's additional options in DefaultAzureCredentialOptions
where you can turn off specific auth methods. I didn't need to limit those, you might. Check them out if needed.