Skip to content

jdkelley/Configuration.DockerSecrets

Repository files navigation

Configuration.DockerSecrets

Nuget Version Nuget Downloads

This project is be able to pull docker secrets into a DotNetCore configuration. Originally, I tried writing this from scratch and then came across Microsoft's implementation on GitHub. It is slated to be released with dotnetcore 2.0. Regardless of Microsoft's final implementation, our team needed to use this as soon as possible.

The primary use case that inspired pulling this together is using a dockerized NancyFx api as a service on Docker Swarm. As such, our example application is a NancyFx api.

Background

Docker secrets are data that "should not be transmitted over a network or stored unencrypted in a Dockerfile or in your application’s source code." [1] The data is encrypted at rest and in transit on the swarm. The default mount point is /run/secrets/<secret-name>.

Installing Configuration.DockerSecrets

Using Nuget, install the Configuration.DockerSecrets package. Your .csproj should include the following:

<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.1' ">
    <PackageReference Include="Configuration.DockerSecrets" Version="1.0.0"/>
</ItemGroup>

Usage

Pull in the docker secrets into your config.

    var config = new ConfigurationBuilder()
                    .AddDockerSecrets()
                    .Build();

Access your secrets where you need them using:

    var secret = config["secret-name"];

Maintenance and Contributions

Contributions are always welcome. When dotnetcore is released, this package will not longer be maintained.

License and Acknowledgements

Most of this code is directly taken from Microsoft's ASP.NET Configuration repo. As a result, this repo is under the Apache License, Version 2.0.