Soru

Zorluk: KolayAzure Key Vault Secret, Key, and Certificate Management

You are developing a C# .NET console application that must retrieve a connection string stored as a secret in Azure Key Vault. The application will run locally during development and as a containerized app in Azure once deployed. You want to connect to the Key Vault using the modern Azure SDK. Which two components are required to successfully authenticate the client and retrieve the secret? (Select two.)

  1. The DefaultAzureCredential class from the Azure.Identity package to handle authentication.Cevap
  2. The SecretClient class from the Azure.Security.KeyVault.Secrets package to perform secret operations.Cevap
  3. C
    The KeyVaultClient class from the Microsoft.Azure.KeyVault package to establish a connection to the vault.
  4. D
    A Key Vault reference using the @Microsoft.KeyVault(SecretUri=...) format inside the application code.

Cevap

To authenticate and retrieve a secret using the modern Azure SDK, you must use the DefaultAzureCredential class from the Azure.Identity namespace and the SecretClient class from the Azure.Security.KeyVault.Secrets namespace.
To authenticate and retrieve a secret from Azure Key Vault using the modern Azure SDK, the application must construct a DefaultAzureCredential object to handle identity flow and pass it into a newly initialized SecretClient object to communicate with Key Vault.

Adım Adım Çözüm

1
Import the modern Azure SDK namespaces Azure.Identity and Azure.Security.KeyVault.Secrets.
The required client and credential types become available in the application scope.
Ensures the application uses the current, non-deprecated SDK packages.
2
Instantiate a DefaultAzureCredential object.
An authentication token source is initialized that resolves credentials dynamically depending on whether the app runs locally or in Azure.
Allows passwordless authentication using the environment's identity flow.
3
Instantiate a SecretClient object, passing the vault URI and the DefaultAzureCredential instance, and call the GetSecret or GetSecretAsync method.
The connection is established, and the secret containing the connection string is successfully retrieved from the Key Vault.
Initiates the API request using the modern client implementation to retrieve the secret payload.

Anahtar Kavram

Retrieving secrets from Azure Key Vault using the modern Azure SDK for .NET with token-based Azure Identity authentication.
Bu soruyu puanla