Microsoft Azure Developer Associate AZ-204 Practice Question
You develop a C# Azure Function that runs on a Linux Consumption plan. A Storage account connection string is stored as the secret "StorageConn" in Azure Key Vault. At runtime the function must read the secret without storing any client secrets, certificates, or other credentials in code or settings. Which code fragment should you use?
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret); var client = new SecretClient(new Uri(vaultUrl), credential); string connString = (await client.GetSecretAsync("StorageConn")).Value;
var token = Environment.GetEnvironmentVariable("ACCESS_TOKEN"); var client = new SecretClient(new Uri(vaultUrl), new TokenCredential(token)); string connString = (await client.GetSecretAsync("StorageConn")).Value;
var client = new SecretClient(new Uri(vaultUrl), new DefaultAzureCredential()); KeyVaultSecret secret = await client.GetSecretAsync("StorageConn"); string connString = secret.Value;
During CI/CD, run "az keyvault secret show" to export the secret and write it to an APPSETTING named STORAGE_CONN; read Environment.GetEnvironmentVariable("STORAGE_CONN") at runtime.