Skip to content

Key vault secret refresh #175

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

Open
wants to merge 63 commits into
base: main
Choose a base branch
from
Open

Conversation

zhiyuanliang-ms
Copy link
Contributor

@zhiyuanliang-ms zhiyuanliang-ms commented Feb 24, 2025

Why this PR?

Usage:

const settings = await load("connection-string", {
  keyvaultOptions: {
    credential: credential,
    secretRefreshIntervalInMs: 120_000 // cannot less than 60 seconds
  }
});

Allow periodic reload of key vault secrets. In this case, even if there is no change on App Configuration key-values. This feature is targeted on the scenario where user is using latest version of a secret. In this case, the key vault reference url will not change, but the secret value will change if user rotates their secret.

Secret cache

Secret with version will be cached after the initial load and whenever a secret reference of that secret is resolved, the value will always be served from the cache.

Secret with no version (which means latest), will be cached after the initial load, and it will be served from cache if the secret refresh interval is configured and not expired. Otherwise, the provider will reload it from the Key Vault.

reference: #249

@zhiyuanliang-ms zhiyuanliang-ms requested a review from Copilot May 7, 2025 02:50
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces periodic key vault secret refresh functionality along with updates to refresh intervals, error messages, and tracing tags. Key changes include:

  • Adjusting timeout and interval constants across tests and production code.
  • Incorporating secret refresh support into the key vault secret providers and configuration implementations.
  • Updating error messages and tracing tags to include key vault secrets.

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/utils/testHelper.ts Updated MAX_TIME_OUT constant to support longer waiting time during tests.
test/refresh.test.ts Updated error messages regarding refresh enabling to include key vault secrets.
test/keyvault.test.ts Added tests covering the secret refresh interval and behavior when secrets update.
src/requestTracing/utils.ts & constants.ts Introduced new tag (KEY_VAULT_REFRESH_CONFIGURED_TAG) for secret refresh configuration.
src/refresh/RefreshTimer.ts, refreshOptions.ts, load.ts Updated naming for time constants and interval handling.
src/keyvault/* Extended options, providers, and adapters to support secret refresh functionality.
src/ConfigurationClientManager.ts & AzureAppConfigurationImpl.ts Integrated secret refresh logic into configuration loading and client management.
src/IKeyValueAdapter.ts & JsonKeyValueAdapter.ts Added and updated onChangeDetected method in the key/value adapters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants