Dynamically reload secrets from the key vault. #122 (#149)

This commit is contained in:
Marc 2021-03-01 12:20:47 -08:00 коммит произвёл GitHub
Родитель 5a0297b7d0
Коммит 4d674022ef
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 35 добавлений и 0 удалений

Просмотреть файл

@ -247,6 +247,22 @@ class RaftServiceCLI():
' --role "Key Vault Secrets User"'
f' --scope "{scope}"')
def create_keyvault_event_subscription(self):
print('Creating Key Vault event subscription')
kvsubscription = az('eventgrid event-subscription create'
f' --name OnSecretChanged'
f' --source-resource-id /subscriptions/{self.definitions.subscription}'
f'/resourceGroups/{self.definitions.resource_group}'
f'/providers/Microsoft.KeyVault'
f'/vaults/{self.definitions.key_vault}'
f' --endpoint /subscriptions/{self.definitions.subscription}'
f'/resourceGroups/{self.definitions.resource_group}'
f'/providers/Microsoft.Web/sites/{self.definitions.orchestrator}'
f'/functions/OnSecretChanged'
f' --endpoint-type azurefunction'
f' --included-event-types Microsoft.KeyVault.SecretNewVersionCreated'
)
def assign_resource_group_roles(self, sp_app_id):
print('Assigning Resource Group roles')
try:
@ -1057,6 +1073,7 @@ class RaftServiceCLI():
[self.assign_resource_group_roles,
self.assign_keyvault_roles])
self.create_keyvault_event_subscription()
# add service principal information to the keyvault
auth = {
'client': service_principal['appId'],

Просмотреть файл

@ -14,6 +14,8 @@ using Microsoft.Azure.Cosmos.Table;
using System.Collections.Generic;
using Microsoft.Azure.Management.AppService.Fluent.Models;
using Microsoft.Azure.Management.Monitor.Fluent.Models;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Azure.EventGrid.Models;
namespace OrchestratorFunc
{
@ -149,6 +151,21 @@ namespace OrchestratorFunc
}
}
[FunctionName("OnSecretChanged")]
public static void EventGridKeyVaultEvent([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log)
{
log.LogInformation("OnSecretChanged: " + eventGridEvent.Data.ToString());
azure = Authenticate();
var allSecrets = OrchestratorLogic.ContainerInstances.initializeSecretsFromKeyvault(azure, agentConfig);
allSecrets.Wait();
secrets = allSecrets.Result.Item1;
dockerConfigs = allSecrets.Result.Item2;
log.LogInformation("OnSecretChanged: Secrets updated from Key Vault");
}
[FunctionName(Raft.Message.ServiceBus.Queue.create)]
public static async Task CreateJob([ServiceBusTrigger(Raft.Message.ServiceBus.Queue.create, IsSessionsEnabled = true)] string createJobMessage, ILogger log)
{

Просмотреть файл

@ -8,6 +8,7 @@
<PackageReference Include="Microsoft.Azure.Management.ContainerInstance.Fluent" Version="1.34.0" />
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="5.0.0" />
<PackageReference Include="Microsoft.Azure.Storage.Common" Version="11.2.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="2.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.2.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.9" />
</ItemGroup>