Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new module for OrchardCore.KeyVault.Azure #6422

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions OrchardCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.ShortCodes", "s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.ShortCodes.Abstractions", "src\OrchardCore\OrchardCore.ShortCodes.Abstractions\OrchardCore.ShortCodes.Abstractions.csproj", "{901DA1A3-E5C7-4965-80EA-A1780BE1B820}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrchardCore.KeyVault.Azure", "src\OrchardCore\OrchardCore.KeyVault.Azure\OrchardCore.KeyVault.Azure.csproj", "{13A89FAE-EDEA-4ED1-8C8E-13AB78F1FD03}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1010,6 +1012,10 @@ Global
{901DA1A3-E5C7-4965-80EA-A1780BE1B820}.Debug|Any CPU.Build.0 = Debug|Any CPU
{901DA1A3-E5C7-4965-80EA-A1780BE1B820}.Release|Any CPU.ActiveCfg = Release|Any CPU
{901DA1A3-E5C7-4965-80EA-A1780BE1B820}.Release|Any CPU.Build.0 = Release|Any CPU
{13A89FAE-EDEA-4ED1-8C8E-13AB78F1FD03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13A89FAE-EDEA-4ED1-8C8E-13AB78F1FD03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13A89FAE-EDEA-4ED1-8C8E-13AB78F1FD03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13A89FAE-EDEA-4ED1-8C8E-13AB78F1FD03}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1186,6 +1192,7 @@ Global
{38EE0258-F010-425B-949F-9ECCE886584B} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{9EEEB83D-85C5-4025-8367-CD7D1ACBBB1A} = {90030E85-0C4F-456F-B879-443E8A3F220D}
{901DA1A3-E5C7-4965-80EA-A1780BE1B820} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
{13A89FAE-EDEA-4ED1-8C8E-13AB78F1FD03} = {F23AC6C2-DE44-4699-999D-3C478EF3D691}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46A1D25A-78D1-4476-9CBF-25B75E296341}
Expand Down
1 change: 1 addition & 0 deletions src/OrchardCore.Build/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageManagement Include="MailKit" Version="2.6.0" />
<PackageManagement Include="Markdig" Version="0.20.0" />
<PackageManagement Include="MessagePack" Version="2.1.115" />
<PackageManagement Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.3" />
JoshLefebvre marked this conversation as resolved.
Show resolved Hide resolved
<PackageManagement Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageManagement Include="MimeKit" Version="2.7.0" />
<PackageManagement Include="MiniProfiler.AspNetCore.Mvc" Version="4.1.0" />
Expand Down
7 changes: 7 additions & 0 deletions src/OrchardCore.Cms.Web/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,12 @@
// "BlobName": "", // Optional, defaults to Sites/tenant_name/DataProtectionKeys.xml. Templatable, refer docs.
// "CreateContainer": true // Creates the container during app startup if it does not already exist.
//},
// Uncomment to load app configuration values from Azure Key Vault.
// Add '.UseOrchardCoreAzureKeyVault()' to the Generic Host in CreateHostBuilder()
//"OrchardCore_Azure_KeyVault": {
// "KeyVaultName": "", // Set the name of your Azure Key Vault.
// "AzureADApplicationId": "", // Set the Azure AD Application Id
// "AzureADApplicationSecret": "" //The Azure AD Application Secret should never be checked into source control. Instead use an environment variable.
// }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using OrchardCore.Azure.KeyVault.Services;

namespace OrchardCore.Azure.KeyVault.Extensions
{
public static class AzureKeyVaultWebHostBuilderExtension
{
/// <summary>
/// Adds Azure Key Vault as a Configuration Source.
/// </summary>
/// <param name="builder">The web host builder to configure.</param>
/// <returns>The web host builder.</returns>
public static IHostBuilder UseOrchardCoreAzureKeyVault(this IHostBuilder builder)
JoshLefebvre marked this conversation as resolved.
Show resolved Hide resolved
{
if (builder == null) throw new ArgumentNullException(nameof(builder));

builder.ConfigureAppConfiguration((context, configuration) =>
{
var builtConfig = configuration.Build();
var keyVaultName = builtConfig["OrchardCore:OrchardCore_Azure_KeyVault:KeyVaultName"];
var clientId = builtConfig["OrchardCore:OrchardCore_Azure_KeyVault:AzureADApplicationId"];
var clientSecret = builtConfig["OrchardCore:OrchardCore_Azure_KeyVault:AzureADApplicationSecret"];

var keyVaultEndpoint = "https://" + keyVaultName + ".vault.azure.net";
configuration.AddAzureKeyVault(
keyVaultEndpoint,
clientId,
clientSecret,
new CustomKeyVaultSecretManager()
);
});

return builder;
}


JoshLefebvre marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(AspNetCoreTargetFramework)</TargetFramework>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OrchardCore.Abstractions\OrchardCore.Abstractions.csproj" />
</ItemGroup>


JoshLefebvre marked this conversation as resolved.
Show resolved Hide resolved
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.Azure.KeyVault.Models;
using Microsoft.Extensions.Configuration.AzureKeyVault;

namespace OrchardCore.Azure.KeyVault.Services
{
/// <summary>
/// A custom override of the DefaultKeyVaultManger class that retrieves secrets from azure keyvault and translates ---
/// to the OC format using single underscore (illegal character in Azure KeyVault) and -- to : to define a section
/// Examples:
/// Key Vault Input: "OrchardCore--OrchardCore---Shells---Database--ConnectionString".
/// Output: "OrchardCore:OrchardCore_Shells_Database:ConnectionString".
/// See https://github.com/OrchardCMS/OrchardCore/issues/6359.
JoshLefebvre marked this conversation as resolved.
Show resolved Hide resolved
/// </summary>
public class CustomKeyVaultSecretManager : DefaultKeyVaultSecretManager
JoshLefebvre marked this conversation as resolved.
Show resolved Hide resolved
{
public override string GetKey(SecretBundle secret)
{
var key = secret.SecretIdentifier.Name.Replace("---", "_").Replace("--", ":");
return key;
JoshLefebvre marked this conversation as resolved.
Show resolved Hide resolved
}

JoshLefebvre marked this conversation as resolved.
Show resolved Hide resolved
}
}