I've created a few integration tests that attempts to access the Azure Key Vault, but fails to do so due to authentication failure. This is triggered by the "Run Tests" task in Azure DevOps.
I've tried including Azure CLI login (for agent) as a preceding step, but seems like each step runs in it's own environment.
Here's a snippet of a yaml alternative I unsuccessfully attempted:
steps:
- task: UseDotNet@2
displayName: Setup .NET Core
inputs:
packageType: 'sdk'
version: '3.1.x'
- script: dotnet build --configuration Release
displayName: Build with dotnet
workingDirectory: BatchDependencyFnApp
- script: dotnet test --configuration Release --logger trx
displayName: Test with dotnet
workingDirectory: BatchDataRetriever.Tests
env:
AZURE_TENANT_ID: $(AZURE_TENANT_ID)
AZURE_CLIENT_SECRET: $(AZURE_CLIENT_SECRET)
AZURE_CLIENT_ID: $(AZURE_CLIENT_ID)
The following code is where the auth fails:
var cred = new ChainedTokenCredential(new ManagedIdentityCredential(), new AzureCliCredential(), new EnvironmentCredential());
var secretClient = new SecretClient(new Uri(keyVaultUri), cred);
var opt = new AzureKeyVaultConfigurationOptions { ReloadInterval = TimeSpan.FromHours(24) };
builder.ConfigurationBuilder
.AddAzureKeyVault(secretClient, opt)
.Build();
The underlying error message is: Original exception: AADSTS7000215: Invalid client secret is provided.
This works fine locally, as Visual Studio has the login capability. I'm new to all of this, so if somebody could please advise how this could work inside a CI job?