Skip to content

Commit 68a5b10

Browse files
committed
Readme update
1 parent 8f94cf4 commit 68a5b10

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,51 @@ VaultSharp.Extensions.Configuration can be installed using the Nuget package man
1111
`dotnet add package VaultSharp.Extensions.Configuration`
1212

1313
It can be injected as a [IConfigurationProvider](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration.iconfigurationprovider?view=dotnet-plat-ext-3.1)
14-
to load configuration from HashiCorp Vault.
14+
to load configuration from HashiCorp Vault:
1515

16+
```csharp
17+
public static IHostBuilder CreateHostBuilder(string[] args) =>
18+
Host.CreateDefaultBuilder(args)
19+
.ConfigureAppConfiguration((hostingContext, config) =>
20+
{
21+
config.AddJsonFile("appsettings.json")
22+
.AddVaultConfiguration(() => new VaultOptions("http://localhost:8200", "root"), "sampleapp", "secret");
23+
})
24+
.ConfigureWebHostDefaults(webBuilder =>
25+
{
26+
webBuilder.UseStartup<Startup>();
27+
});
28+
```
1629

30+
The `AddVaultConfiguration` method accepts several parameters:
31+
32+
1. Function to provide VaultOptions with Vault connection configuration (optional).
33+
34+
2. Application alias in Vault data. It's used a part of the path to read secrets.
35+
36+
3. Mount point of KV secrets. The default value is `secret` (optional).
37+
38+
## Configuration using environmnt variables
39+
40+
Alternatively, you can configure Vault connection using next environmnt variables:
41+
42+
- `VAULT_ADDR` : Address of the Vault instance. Default value is `"http://locahost:8200`.
43+
- `VAULT_TOKEN` : Vault token. Used for token-based authentication. Default value is `root`.
44+
- `VAULT_ROLEID` : Vault AppRole ID. Used for AppRole-based authentication.
45+
- `VAULT_SECRET` : Vault AppRole secret. Used for AppRole-based authentication.
46+
47+
## Preparing secrets in Vault
48+
49+
You need to store your secrets with special naming rules.
50+
First of all, all secrets should use KV2 storage and have prefix `data/{app_alias}/`.
51+
For example, if your app has alias `sampleapp` and you want to have configuration option `ConnectionString` your secret path would be `data/sampleapp/ConnectionString`.
52+
53+
All secret data should use JSON format with the only key `value` and secret data inside:
54+
```json
55+
{
56+
"value": "secret value"
57+
}
58+
```
1759

1860
## Limitations
1961

0 commit comments

Comments
 (0)