Skip to content

Using AuthJanitor Without Automation

Anthony Turner edited this page Apr 27, 2020 · 1 revision

The AuthJanitor.Providers namespace and its children can be decoupled from the AuthJanitor Automation tools and used independently, provided the consuming application uses Microsoft.Extensions.Logging.ILogger and System.IServiceProvider (which provides an instance of AuthJanitor.Providers.MultiCredentialProvider).

New Providers must inherit from either ApplicationLifecycleProvider<TProviderConfiguration> or RekeyableObjectProvider<TProviderConfiguration>. More information about creating providers is available at "Creating an Application Lifecycle Provider" and "Creating a Rekeyable Object Provider".

If you want to invoke one or more providers to execute a key rotation, that process might look like this:

// These come from your application! (Passing in outerLogger to new RekeyingAttemptLogger instances is optional)
IServiceProvider serviceProvider;
ILogger outerLogger;

var functionsAppLifecycleLogger = new AuthJanitor.Providers.RekeyingAttemptLogger(outerLogger);
var functionsAppLifecycle = new AuthJanitor.Providers.AppServices.Functions.AppSettingsFunctionsApplicationLifecycleProvider(functionsAppLifecycleLogger, serviceProvider);
functionsAppLifecycle.Configuration = new AuthJanitor.Providers.AppServices.AppSettingConfiguration()
{
    ResourceName = "sample-app",
    ResourceGroup = "sample-resource-group",
    SettingName = "",
    CommitAsConnectionString = true
};

var storageAccountRekeyableLogger = new AuthJanitor.Providers.RekeyingAttemptLogger(outerLogger);
var storageAccountRekeyable = new AuthJanitor.Providers.Storage.StorageAccountRekeyableObjectProvider(storageAccountRekeyableLogger, serviceProvider);
storageAccountRekeyable.Configuration = new AuthJanitor.Providers.Storage.StorageAccountKeyConfiguration()
{
    ResourceName = "sample-storage",
    ResourceGroup = "sample-resource-group",
    KeyType = AuthJanitor.Providers.Storage.StorageAccountKeyConfiguration.StorageKeyTypes.Key1,
    SkipScramblingOtherKey = false
};

var workflow = new AuthJanitor.Providers.ProviderActionWorkflow(logger, new List<AuthJanitor.Providers.IAuthJanitorProvider>() {
    functionsAppLifecycle,
    storageAccountRekeyable
});

await workflow.InvokeAsync(TimeSpan.FromDays(30));

Clone this wiki locally