Asos.UserSecretsRetriever 1.1.13

Prefix Reserved
dotnet tool install --global Asos.UserSecretsRetriever --version 1.1.13                
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local Asos.UserSecretsRetriever --version 1.1.13                
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=Asos.UserSecretsRetriever&version=1.1.13                
nuke :add-package Asos.UserSecretsRetriever --version 1.1.13                

User secrets retriever

The user secrets retriever is a .NET tool that can be used to retrieve secrets from Azure Key Vault and add them via Secret Manager (user-secrets) for a project. The tool supports retrieving multiple secrets across multiple key vaults.

Why use this tool?

The .NET Secret Manager (dotnet user-secrets) is a recommended approach for storing secrets when developing on your local machine. However these secrets often have to be retrieved manually, resulting in additional overhead when getting started on an existing project and additional documentation to keep track of required secrets. This tool allows the definition (but not value) of required secrets to be stored in source control, and for the retrieval of the secrets to be automated through a single CLI command.

Why not just use the Key Vault configuration provider?

Using the Key Vault configuration provider is a valid approach to retrieving secrets in your local environment but adds additional constraints as it will query Key Vault every time you restart the application. Loading them into user-secrets prevents this and allows for a fully offline development experience.

Installation

The tool can be installed via the .NET cli:

dotnet tool install -g Asos.UserSecretsRetriever

There is a known issue you might face when installing a .NET tool if you have a private (authenticated) feed in your list of sources. You can ignore the error using the following additional flag:

dotnet tool install -g Asos.UserSecretsRetriever --ignore-failed-sources

Some users have also reported getting the following exception when installing, even after adding the above flag:

<span style="color:red"> Unhandled exception: NuGet. Protocol. Core. Types. FatalProtocolException: Unable to load the service index for source. Response status code does not indicate success: 401 (Unauthorized).</span>.

This can be normally be solved by explicitly installing the Azure Artifacts Credential Provider via the instructions on the repo.

Usage

To retrieve secrets for a project, add a appsettings.usersecrets.json configuration file in the same directory as your project file. The user secrets configuration file should define the secrets you want to retrieve and uses the following format:

{
  "Vaults": [
    {
      "Uri": "https://my-keyvault.vault.azure.net/",
      "Secrets": [
        {
          "SourceName": "MyKeyVaultSecretName",
          "DestinationName": "MyUserSecretName"
        },
        {
          "SourceName": "MySecondKeyVaultSecretName",
          "DestinationName": "MySecondUserSecretName"
        }
      ]
    },
    {
      "Uri": "https://my-second-keyvault.vault.azure.net/",
      "Secrets": [
        {
          "SourceName": "MyKeyVaultSecretName",
          "DestinationName": "MyUserSecretName"
        }
      ]
    }
  ]
}

Once the configuration file is present in the repository, any engineer with access to the key vault can retrieve the secrets using the following command:

dotnet user-secrets-retriever retrieve

Options

The tool supports the following options:

Option Mandatory Description
--project false The path to the directory containing the project you wish to retrieve secrets for. Defaults to the current directory.
--secrets-configuration false The name of the file containing the configuration for the secrets you want to retrieve. Defaults to appsettings.usersecrets.json
--diagnostics false Enables diagnostic output. Useful for understanding authentication issues.

Authentication with Key Vault

The tool uses the Azure.Identity client library to authenticate with the specified Key Vaults using a ChainedTokenCredential. The following authentication types are included and attempted in order:

  1. EnvironmentCredential
  2. VisualStudioCredential
  3. VisualStudioCodeCredential
  4. AzureCliCredential
  5. AzurePowerShellCredential
  6. InteractiveBrowserCredential

See the Azure.Identity documentation for more details. For help understanding an authentication issue and to identify which credential type has been selected, use the --diagnostics flag when running the tool.

You will need read access to secrets within the key vaults you are accessing.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
1.1.13 71 11/8/2024
1.1.12 125 6/24/2024
1.1.11 90 6/12/2024
1.1.10 99 5/28/2024
1.1.9 90 5/13/2024
1.1.8 117 4/29/2024
1.1.7 114 4/22/2024
1.1.6 153 4/12/2024
1.0.8 293 3/30/2023
1.0.6 336 1/31/2023
1.0.5 427 10/25/2022
1.0.2 374 10/25/2022
1.0.2-documentation.4 125 10/21/2022