C#C
C#13mo ago
v0fbu1vm

Azure Managed Identity

        if (!builder.Environment.IsProduction()) return;

        // Retrieve configuration settings
        var configuration = builder.Configuration;

        try
        {
            // Add Azure Key Vault
            var keyVaultEndpoint = new Uri(configuration[Configs.KeyVaultUrl]!);
            var azureCredential = new DefaultAzureCredential(new DefaultAzureCredentialOptions
            {
                ManagedIdentityClientId = Configs.ManagedIdentityClientId,
            });
            var secretClient = new SecretClient(keyVaultEndpoint, azureCredential);
            configuration.AddAzureKeyVault(secretClient, new KeyVaultSecretManager());
        }
        catch (Exception e)
        {
            Log.Error(e.Message);
        }
I have spent almost 8 hours trying to find the issue. For some reason managed identity is not working in production mode. It seems to be unable to load the secrets. Even though I have successfully defined the resource access polices. The code was working fine before I went to sleep. All of a sudden when I woke up its not working? Can anyone please help?
Was this page helpful?