question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Azure.Extensions.AspNetCore.Configuration.Secrets load expired secrets in IConfiguration.

See original GitHub issue

Library name and version

Azure.Extensions.AspNetCore.Configuration.Secrets [1.2.2]

Describe the bug

ASP Net Core document for Key Vault Configuration is misleading when it says Disabled and Expired Secrets are excluded from configuration provider. However, in reality they are included.

So, if documentation is correct and I would argument that it is correct, then then the code shown below must be fixed.

KeyVaultSecretManager.cs#L74

  /// <summary>
  /// Checks if <see cref="KeyVaultSecret"/> value should be retrieved.
  /// </summary>
  /// <param name="secret">The <see cref="SecretProperties"/> instance.</param>
  /// <returns><code>true</code> if secrets value should be loaded, otherwise <code>false</code>.</returns>
  public virtual bool Load(SecretProperties secret)
  {
      return true;
  }

Details

Expected behavior

Let’s say I have 3 secrets in my key vault:

  1. SecretA - Expired
  2. SecretB - No Expiration Set
  3. SecretC - Expiring in Future.

I expected SecretB and SecretC should be loaded into IConfiguration but NOT SecretA because it has expiration date that is in past.

Actual behavior

All Secrets are loaded including expired secrets.

Reproduction Steps

Here is how I’m loading secrets in IConfiguration

   configurationBuilder.AddAzureKeyVault(
          new Uri("https://my-app-secrets-kv.vault.azure.net/"),
          new DefaultAzureCredential(),
          new AzureKeyVaultConfigurationOptions{
              ReloadInterval = TimeSpan.FromSeconds(30),
          }
      );

However I found a work around which help me exclude expired secret.

Created KeyVaultSecertManagerSkipsExpiredSecrets.cs to override the default Load method on KeyVaultSecretManager.

    public class KeyVaultSecertManagerSkipsExpiredSecrets : KeyVaultSecretManager
    {
        public override bool Load(SecretProperties secret)
        {
            return secret.ExpiresOn == null || secret.ExpiresOn >= DateTimeOffset.Now;
        }
    }

Then used it as follows:

   configurationBuilder.AddAzureKeyVault(
          new Uri("https://my-app-secrets-kv.vault.azure.net/"),
          new DefaultAzureCredential(),
          new AzureKeyVaultConfigurationOptions{
              ReloadInterval = TimeSpan.FromSeconds(30),
              Manager = new KeyVaultSecertManagerSkipsExpiredSecrets()
          }
      );

Please suggest if I am doing something wrong. What is expected behavior? Should the expired secrets not be excluded?

Environment

  • ASP Net Core 3.1
  • Service Fabric 7.2.477.9590 [This is irrelevant though]

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
heathscommented, Aug 11, 2022

Separate properties for disabled and expired should be added. Rarely would I expect disabled secrets to be needed, but there are plenty of scenarios that may still need expired secrets. As secrets (keys, etc.) rotate, those older ones are still need in many scenarios.

0reactions
heathscommented, Oct 3, 2022

If we make these changes, should update the docs referenced in dotnet/AspNetCore.Docs#26714

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Key Vault configuration provider in ASP.NET Core
This article explains how to use the Azure Key Vault configuration provider to load app configuration values from Azure Key Vault secrets.
Read more >
Tutorial: Use dynamic configuration in an ASP.NET Core app
This tutorial shows how you can enable dynamic configuration updates in an ASP. ... Load configuration from Azure App Configuration builder.
Read more >
Azure Key Vault Secrets configuration provider for ...
The Azure.Extensions.AspNetCore.Configuration.Secrets package allows storing configuration values using Azure Key Vault Secrets.
Read more >
Tutorial: Use dynamic configuration in a .NET app - Azure ...
In this tutorial, you learn how to dynamically update the configuration data for .NET apps.
Read more >
Client secret key is expired error - Azure
This article provides a solution for a "Client secret key is expired" error that occurs when you deploy or terminate virtual machines (VMs)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found