As the title suggests, the values for clientId and clientSecret that get populated in the AddAzureKeyVault method below only work when I put the clientId and clientSecret in plain text in the VSTS Variables section. It doesn't work if I use a Variable Group that pulls those values from key vault, or if I set the values as secrets in the normal Variables section. It says those values are null if they are not in plain text.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
.AddEnvironmentVariables();
var configuration = builder.Build();
var azureServiceTokenProvider = new AzureServiceTokenProvider($"RunAs=App;AppId={Environment.GetEnvironmentVariable("clientId")};TenantId={Environment.GetEnvironmentVariable("tenantId")};AppKey={Environment.GetEnvironmentVariable("clientSecret")}");
KeyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));
builder.AddAzureKeyVault(Environment.GetEnvironmentVariable("keyVaultUri"),
Environment.GetEnvironmentVariable("clientId"),
Environment.GetEnvironmentVariable("clientSecret"),
new DefaultKeyVaultSecretManager());
This is not secure as I do not want the clientId and clientSecret values in plain text. Any help here?
EDIT: I am using the above code in a .NET Core VSTS task (dotnet run). I am not passing any arguments in the task either. Am I supposed to be?
EDIT 2: I may have found my own answer here. But does that mean I need to have my Main method expecting arguments be passed? Like clientId and clientSecret in the Arguments section of the .NET Core VSTS task?
EDIT 3: I tried doing ##[debug]arguments=##vso[task.setvariable variable=clientId]$(clientId) ##vso[task.setvariable variable=clientSecret]$(clientSecret)
and -clientId $(clientId) -clientSecret $(clientSecret)
in the Arguments section of the .NET Core VSTS task and it still resolves clientId and clientSecret to null...