Пример #1
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var logger = LoggerFactory.Create(builder =>
            {
                builder.SetMinimumLevel(LogLevel.Debug)
                .AddConsole();
            }).CreateLogger <Startup>();

            builder.Services.AddOptions();

            logger.LogDebug("Registering Azure AD Identity Service");
            builder.Services.AddAJAzureActiveDirectory <AzureADIdentityServiceConfiguration>(o =>
            {
                o.ClientId     = "clientId";
                o.ClientSecret = "clientSecret";
                o.TenantId     = "tenantId";
            });

            logger.LogDebug("Registering Event Sinks");

            // TODO: Register IEventSinks here, before the EventDispatcherService
            //       This is where we offload to Azure Sentinel, send emails, etc.
            //       The *entire system* offloads to the EventDispatcherService to generalize events.

            logger.LogDebug("Registering Cryptographic Implementation");
            builder.Services.AddAJDefaultCryptographicImplementation <DefaultCryptographicImplementationConfiguration>(o =>
            {
                o.MasterEncryptionKey = "weakkey";
            });

            logger.LogDebug("Registering Secure Storage Provider");
            builder.Services.AddAJAzureKeyVault <KeyVaultSecureStorageProviderConfiguration>(o =>
            {
                o.VaultName = "vault";
            });

            logger.LogDebug("Registering AuthJanitor MetaServices");
            AuthJanitorServiceRegistration.RegisterServices(builder.Services);

            // -----

            logger.LogDebug("Registering DataStores");
            builder.Services.AddAJAzureBlobStorage <AzureBlobStorageDataStoreConfiguration>(o =>
            {
                o.ConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage", EnvironmentVariableTarget.Process);
                o.Container        = "authjanitor";
            });

            // -----

            logger.LogDebug("Registering ViewModel generators");
            ViewModelFactory.ConfigureServices(builder.Services);

            // -----

            logger.LogDebug("Scanning for Provider modules at {ProviderSearchPath}\\{ProviderSearchMask} recursively", PROVIDER_SEARCH_PATH, PROVIDER_SEARCH_MASK);

            var providerTypes = Directory.GetFiles(PROVIDER_SEARCH_PATH, PROVIDER_SEARCH_MASK, new EnumerationOptions()
            {
                RecurseSubdirectories = true
            })
                                .SelectMany(libraryFile => PluginLoader.CreateFromAssemblyFile(libraryFile, PROVIDER_SHARED_TYPES)
                                            .LoadDefaultAssembly()
                                            .GetTypes()
                                            .Where(type => !type.IsAbstract && typeof(IAuthJanitorProvider).IsAssignableFrom(type)))
                                .ToArray();

            logger.LogInformation("Found {ProviderCount} providers: {ProviderTypeNames}", providerTypes.Length, string.Join("  ", providerTypes.Select(t => t.Name)));
            logger.LogInformation("Registering Provider Manager Service");
            ProviderManagerService.ConfigureServices(builder.Services, providerTypes);
        }
Пример #2
0
        public void Configure(IWebJobsBuilder builder)
        {
            var logger = new LoggerFactory().CreateLogger(nameof(Startup));

            logger.LogDebug("Registering LoggerFactory");
            builder.Services.AddSingleton <ILoggerFactory>(new LoggerFactory());

            // TODO: Load this from somewhere?
            logger.LogDebug("Registering Service Configuration");
            builder.Services.AddSingleton(ServiceConfiguration);

            logger.LogDebug("Registering Notification Provider");
            builder.Services.AddSingleton <INotificationProvider>(new EmailNotificationProvider(
                                                                      Environment.GetEnvironmentVariable("SENDGRID_API_KEY", EnvironmentVariableTarget.Process),
                                                                      "http://*****:*****@bitoblivion.com"));

            logger.LogDebug("Registering Secure Storage Provider");
            builder.Services.AddSingleton <ISecureStorageProvider>(s =>
                                                                   new KeyVaultSecureStorageProvider(
                                                                       new Rfc2898AesPersistenceEncryption(
                                                                           s.GetRequiredService <AuthJanitorServiceConfiguration>()
                                                                           .SecurePersistenceEncryptionKey),
                                                                       s.GetRequiredService <MultiCredentialProvider>(),
                                                                       s.GetRequiredService <AuthJanitorServiceConfiguration>()
                                                                       .SecurePersistenceContainerName));

            // -----

            logger.LogDebug("Registering DataStores");
            var connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage", EnvironmentVariableTarget.Process);

            builder.Services.AddSingleton <IDataStore <ManagedSecret> >(
                new AzureBlobDataStore <ManagedSecret>(
                    connectionString,
                    ServiceConfiguration.MetadataStorageContainerName,
                    MANAGED_SECRETS_BLOB_NAME));
            builder.Services.AddSingleton <IDataStore <RekeyingTask> >(
                new AzureBlobDataStore <RekeyingTask>(
                    connectionString,
                    ServiceConfiguration.MetadataStorageContainerName,
                    REKEYING_TASKS_BLOB_NAME));
            builder.Services.AddSingleton <IDataStore <Resource> >(
                new AzureBlobDataStore <Resource>(
                    connectionString,
                    ServiceConfiguration.MetadataStorageContainerName,
                    RESOURCES_BLOB_NAME));
            builder.Services.AddSingleton <IDataStore <ScheduleWindow> >(
                new AzureBlobDataStore <ScheduleWindow>(
                    connectionString,
                    ServiceConfiguration.MetadataStorageContainerName,
                    SCHEDULES_BLOB_NAME));

            // -----

            logger.LogDebug("Registering ViewModel generators");
            ViewModelFactory.ConfigureServices(builder.Services);

            // -----

            logger.LogDebug("Scanning for Provider modules at {0}\\{1} recursively", PROVIDER_SEARCH_PATH, PROVIDER_SEARCH_MASK);

            var providerTypes = Directory.GetFiles(PROVIDER_SEARCH_PATH, PROVIDER_SEARCH_MASK, new EnumerationOptions()
            {
                RecurseSubdirectories = true
            })
                                .SelectMany(libraryFile => PluginLoader.CreateFromAssemblyFile(libraryFile, PROVIDER_SHARED_TYPES)
                                            .LoadDefaultAssembly()
                                            .GetTypes()
                                            .Where(type => !type.IsAbstract && typeof(IAuthJanitorProvider).IsAssignableFrom(type)));

            logger.LogInformation("Found {0} providers: {1}", providerTypes.Count(), string.Join("  ", providerTypes.Select(t => t.Name)));
            logger.LogInformation("Registering providers and service principal default credentials");
            ProviderFactory.ConfigureProviderServices(builder.Services, providerTypes);

            // -----

            ServiceProvider = builder.Services.BuildServiceProvider();
        }
Пример #3
0
        public void Configure(IWebJobsBuilder builder)
        {
            var logger = LoggerFactory.Create(builder =>
            {
                builder.SetMinimumLevel(LogLevel.Debug)
                .AddConsole();
            }).CreateLogger <Startup>();

            REMOVE_ME_LOGGER = logger;

            builder.Services.AddOptions();

            builder.Services.AddHttpContextAccessor();

            logger.LogDebug("Registering Azure AD Identity Service");
            builder.Services.AddAJAzureActiveDirectory <AzureADIdentityServiceConfiguration>(o =>
            {
                o.ClientId     = Environment.GetEnvironmentVariable("CLIENT_ID", EnvironmentVariableTarget.Process);
                o.ClientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET", EnvironmentVariableTarget.Process);
                o.TenantId     = Environment.GetEnvironmentVariable("TENANT_ID", EnvironmentVariableTarget.Process);
            });

            builder.Services.AddAJAzureActiveDirectoryManager <AzureADIdentityServiceConfiguration>(o =>
            {
                o.ClientId     = Environment.GetEnvironmentVariable("CLIENT_ID", EnvironmentVariableTarget.Process);
                o.ClientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET", EnvironmentVariableTarget.Process);
                o.TenantId     = Environment.GetEnvironmentVariable("TENANT_ID", EnvironmentVariableTarget.Process);
            });

            logger.LogDebug("Registering Event Sinks");

            // TODO: Register IEventSinks here, before the EventDispatcherService
            //       This is where we offload to Azure Sentinel, send emails, etc.
            //       The *entire system* offloads to the EventDispatcherService to generalize events.

            logger.LogDebug("Registering Cryptographic Implementation");
            builder.Services.AddAJDefaultCryptographicImplementation <DefaultCryptographicImplementationConfiguration>(o =>
            {
                o.PublicKey  = new byte[0];
                o.PrivateKey = new byte[0];
            });

            logger.LogDebug("Registering Secure Storage Provider");
            builder.Services.AddAJAzureKeyVault <KeyVaultSecureStorageProviderConfiguration>(o =>
            {
                o.VaultName = "vault";
            });

            builder.Services.AddTransient <DashboardService>();
            builder.Services.AddTransient <SystemService>();
            builder.Services.AddTransient <IdentityManagementService>();
            builder.Services.AddTransient <ManagedSecretsService>();
            builder.Services.AddTransient <RekeyingTasksService>();
            builder.Services.AddTransient <ScheduleRekeyingTasksService>();
            builder.Services.AddTransient <ProvidersService>();
            builder.Services.AddTransient <ResourcesService>();

            // -----

            logger.LogDebug("Registering DataStores");
            builder.Services.AddAJAzureBlobStorage <AzureBlobStorageDataStoreConfiguration>(o =>
            {
                o.ConnectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage", EnvironmentVariableTarget.Process);
                o.Container        = "authjanitor";
            });

            // -----

            logger.LogDebug("Registering ViewModel generators");
            ViewModelFactory.ConfigureServices(builder.Services);

            // -----

            logger.LogDebug("Scanning for Provider modules at {ProviderSearchPath}\\{ProviderSearchMask} recursively", PROVIDER_SEARCH_PATH, PROVIDER_SEARCH_MASK);

            var providerTypes = Directory.GetFiles(PROVIDER_SEARCH_PATH, PROVIDER_SEARCH_MASK, new EnumerationOptions()
            {
                RecurseSubdirectories = true
            })
                                .SelectMany(libraryFile => PluginLoader.CreateFromAssemblyFile(libraryFile, PROVIDER_SHARED_TYPES)
                                            .LoadDefaultAssembly()
                                            .GetTypes()
                                            .Where(type => !type.IsAbstract && typeof(IAuthJanitorProvider).IsAssignableFrom(type)))
                                .ToArray();

            logger.LogInformation("Found {ProviderCount} providers: {ProviderTypeNames}", providerTypes.Length, string.Join("  ", providerTypes.Select(t => t.Name)));
            logger.LogInformation("Registering Provider Manager Service");
            builder.Services.AddAuthJanitorService("admin-service", providerTypes);
        }