mirror of https://github.com/dotnet/tye.git
Browse Source
* Use environment variables for secrets - Updating in place does not apply to connection strings specifically since they are usually configured at startup as singletons. - This brings consistency with the development experience. - Gets rid of AddTyeBindings - "Less secure", sure but to be pedantic env variables are stored in virtual file on disk while the process is running. I'd argue if you want full security then use keyvault/vault/name your secret store. Fixes #313 * Removed the last AddTyeSecrets callpull/327/head
committed by
GitHub
17 changed files with 165 additions and 329 deletions
@ -1,44 +0,0 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using Microsoft.Extensions.FileProviders; |
|||
|
|||
namespace Microsoft.Extensions.Configuration |
|||
{ |
|||
/// <summary>
|
|||
/// Contains extension methods for adding Tye's secrets to <see cref="IConfiguration" />.
|
|||
/// </summary>
|
|||
public static class TyeSecretsConfigurationBuilderExtensions |
|||
{ |
|||
/// <summary>
|
|||
/// Adds Tye's secrets to <see cref="IConfiguration" />.
|
|||
/// </summary>
|
|||
/// <param name="builder">The <see cref="IConfigurationBuilder" />.</param>
|
|||
/// <returns>The <see cref="IConfigurationBuilder" />.</returns>
|
|||
/// <remarks>
|
|||
/// The environment variable <c>TYE_SECRETS_PATH</c> is used to populate the directory used by secrets.
|
|||
/// When the environment variable is specified, and the specified directory exists, then the value of
|
|||
/// <see cref="TyeSecretsConfigurationSource.FileProvider" /> will be non-null.
|
|||
/// </remarks>
|
|||
public static IConfigurationBuilder AddTyeSecrets(this IConfigurationBuilder builder) |
|||
{ |
|||
var secretsDirectory = Environment.GetEnvironmentVariable(TyeSecretsConfigurationSource.TyeSecretsPathEnvironmentVariable); |
|||
if (Directory.Exists(secretsDirectory)) |
|||
{ |
|||
foreach (var child in Directory.EnumerateDirectories(secretsDirectory)) |
|||
{ |
|||
var source = new TyeSecretsConfigurationSource() |
|||
{ |
|||
FileProvider = new PhysicalFileProvider(child), |
|||
}; |
|||
builder.Add(source); |
|||
} |
|||
} |
|||
|
|||
return builder; |
|||
} |
|||
} |
|||
} |
|||
@ -1,37 +0,0 @@ |
|||
// Licensed to the .NET Foundation under one or more agreements.
|
|||
// The .NET Foundation licenses this file to you under the MIT license.
|
|||
// See the LICENSE file in the project root for more information.
|
|||
|
|||
using Microsoft.Extensions.Configuration.KeyPerFile; |
|||
using Microsoft.Extensions.FileProviders; |
|||
|
|||
namespace Microsoft.Extensions.Configuration |
|||
{ |
|||
/// <summary>
|
|||
/// An <see cref="IConfigurationSource" /> implementation for Tye's secrets.
|
|||
/// </summary>
|
|||
public sealed class TyeSecretsConfigurationSource : IConfigurationSource |
|||
{ |
|||
/// <summary>
|
|||
/// The environment variable used to configure the path where Tye looks for secrets.
|
|||
/// </summary>
|
|||
public static readonly string TyeSecretsPathEnvironmentVariable = "TYE_SECRETS_PATH"; |
|||
|
|||
/// <summary>
|
|||
/// Gets or sets the <see cref="IFileProvider" /> used by the configuration source.
|
|||
/// </summary>
|
|||
public IFileProvider? FileProvider { get; set; } |
|||
|
|||
public IConfigurationProvider Build(IConfigurationBuilder builder) |
|||
{ |
|||
var source = new KeyPerFileConfigurationSource() |
|||
{ |
|||
FileProvider = FileProvider, |
|||
Optional = true, |
|||
}; |
|||
|
|||
return source.Build(builder); |
|||
|
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue