-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for KeyVault.Azure and minor code fixes
- Loading branch information
JoshL
committed
Jun 15, 2020
1 parent
1a92632
commit 584b72b
Showing
7 changed files
with
50 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/OrchardCore/OrchardCore.KeyVault.Azure/Services/AzureKeyVaultSecretManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using Microsoft.Azure.KeyVault.Models; | ||
using Microsoft.Extensions.Configuration.AzureKeyVault; | ||
|
||
namespace OrchardCore.Azure.KeyVault.Services | ||
{ | ||
public class AzureKeyVaultSecretManager : DefaultKeyVaultSecretManager | ||
{ | ||
public override string GetKey(SecretBundle secret) => | ||
secret.SecretIdentifier.Name.Replace("---", "_").Replace("--", ":"); | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
src/OrchardCore/OrchardCore.KeyVault.Azure/Services/CustomKeyVaultSecretManager.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Azure Key Vault (`OrchardCore.Azure.KeyVault`) | ||
The Azure Key Vault configuration provider adds app configuration values from the Azure Key Vault in order to safeguared your cryptographic keys and secrets used by your app. It also contains custom override of the DefaultKeyVaultManger class that retrieves secrets from Azure Key Vault and translates --- | ||
to an underscore (_) and -- to a colon (:). Both underscores and colons are illegal characters in Azure KeyVault. | ||
|
||
Example: | ||
Key Vault Input: "OrchardCore--OrchardCore---Shells---Database--ConnectionString". | ||
Output: "OrchardCore:OrchardCore_Shells_Database:ConnectionString". | ||
See https://github.com/OrchardCMS/OrchardCore/issues/6359. | ||
|
||
|
||
# Configuration: | ||
You'll need to specify the name of your Azure Key Vault and [register a service principle](https://docs.microsoft.com/en-us/azure/key-vault/general/group-permissions-for-apps) in Active Directory for accessing your key vault using an access control policy. | ||
```json | ||
"OrchardCore_Azure_KeyVault": { | ||
"KeyVaultName": "", // Set the name of your Azure Key Vault. | ||
"AzureADApplicationId": "", // Set the Azure AD Application Id | ||
"AzureADApplicationSecret": "" //Set the Azure AD Application Secret | ||
} | ||
``` | ||
You should **never check in your client secret into source control** as this defeats the purpose of using a key vault in the first place. Instead set your client secret as an environmnet variable on your machine, or create a seperate azurekeyvault.json file and add it to your gitignore. | ||
|
||
In the `program.cs`, add UseOrchardCoreAzureKeyVault() to the Generic Host in CreateHostBuilder(). | ||
```csharp | ||
using OrchardCore.KeyVault.Azure; | ||
public class Program | ||
{ | ||
public static Task Main(string[] args) | ||
=> BuildHost(args).RunAsync(); | ||
|
||
public static IHost BuildHost(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.UseOrchardCoreAzureKeyVault() | ||
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>()) | ||
.Build(); | ||
} | ||
``` | ||
|