Skip to content

Commit

Permalink
Prioritize AzureCliCredential for secret-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
garath committed Mar 1, 2024
1 parent b5ecc31 commit c411d0a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;
using Azure.Core;

namespace Microsoft.DncEng.SecretManager;

public interface ITokenCredentialProvider
{
public Task<TokenCredential> GetCredentialAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static Task<int> Main(string[] args)

protected override void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<ITokenCredentialProvider, SecretManagerCredentialProvider>();
services.AddSingleton<SecretTypeRegistry>();
services.AddSingleton<StorageLocationTypeRegistry>();
services.AddSingleton<SettingsFileValidator>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Threading.Tasks;
using Azure.Core;
using Azure.Identity;

namespace Microsoft.DncEng.SecretManager;

public sealed class SecretManagerCredentialProvider : ITokenCredentialProvider
{
// Expect AzureCliCredential for CI and local dev environments.
// Use InteractiveBrowserCredential as a fallback for local dev environments.
private readonly Lazy<TokenCredential> _credential = new(() =>
new ChainedTokenCredential(
new AzureCliCredential(new AzureCliCredentialOptions { TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" }),
new InteractiveBrowserCredential(new InteractiveBrowserCredentialOptions() { TenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47" })
));

public Task<TokenCredential> GetCredentialAsync()
{
return Task.FromResult(_credential.Value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class AzureKeyVaultParameters
public class AzureKeyVault : StorageLocationType<AzureKeyVaultParameters>
{
public const string NextRotationOnTag = "next-rotation-on";
private readonly TokenCredentialProvider _tokenCredentialProvider;
private readonly ITokenCredentialProvider _tokenCredentialProvider;
private readonly IConsole _console;

public AzureKeyVault(TokenCredentialProvider tokenCredentialProvider, IConsole console)
public AzureKeyVault(ITokenCredentialProvider tokenCredentialProvider, IConsole console)
{
_tokenCredentialProvider = tokenCredentialProvider;
_console = console;
Expand Down

0 comments on commit c411d0a

Please sign in to comment.