Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

Secure secrets by using Azure Key Vault, including rotation and retrieval

A worked example

Single answer

An AI application runs on several instances and connects to Azure Cosmos DB with the account's primary key. The key is stored in Azure Key Vault as the secret cosmosdb-key, and each instance refetches the secret from Key Vault periodically. You must rotate the key. Requirements:

  • No application instance can experience an authentication failure during the rotation.
  • The previous key value must remain retrievable from Key Vault as an earlier version of the same secret.

Which rotation sequence should you use?

Choose one answer
Why

Azure Cosmos DB supports two active keys, so the rotation can bring in the new secondary key before the old primary key is invalidated. Storing the new key with set_secret() under the same name adds a version and keeps the earlier one. Waiting until every instance has the new value before regenerating the primary key means one valid credential is always available.

  • Not correct: Generate a new secondary key, delete the secret and recreate it with the new key, wait for all instances to pick it up, and then regenerate the old primary key. Deleting the secret removes it and its existing versions. The previous key value would not be kept as an earlier version.
  • Correct: Generate a new secondary key, store it as a new secret version, wait for all instances to pick up the new value, and then regenerate the old primary key. This is the dual-credential rotation order. At least one valid key always exists, and storing a new version keeps the previous version in Key Vault.
  • Not correct: Regenerate the old primary key, store it as a new secret version, wait for all instances to pick up the new value, and then generate a new secondary key. Regenerating the primary key first invalidates the credential that instances are still using. They fail until they refetch the secret.
  • Not correct: Generate a new secondary key, store it as a new secret version, regenerate the old primary key, and then wait for all instances to pick up the new value. The old primary key is regenerated before every instance has moved to the new value. Instances still using the old key fail authentication.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free