Skip to main content

.NET user secrets Enterprise

Kreya can resolve secrets stored by the .NET Secret Manager. This is useful when an API project and its Kreya project should use the same local development credentials.

The .NET Secret Manager is intended for development only. Its values are not encrypted and should not be treated as a production secret store.

Configure the .NET project​

Initialize user secrets in the .NET project and add a value:

dotnet user-secrets init
dotnet user-secrets set "ApiKey" "secret-value"

The first command adds a UserSecretsId property to the project file:

<PropertyGroup>
<UserSecretsId>your-user-secrets-id</UserSecretsId>
</PropertyGroup>

Configure Kreya​

  1. Open the project settings and select Vaults & Secrets.
  2. Create a vault and select .NET user secrets as its type.
  3. Keep User secrets source set to Project file (the default). Enter the path to the MSBuild file containing UserSecretsId, use the chooser next to the field, or drag a single .csproj, .fsproj, .vbproj, .props, .targets, or .proj file onto the field. Relative paths are resolved from the Kreya project directory.
  4. Enable Automatically discover secrets, save the vault, and open the Secrets tab. Kreya discovers the available configuration keys and displays them in a read-only table.

Alternatively, select User secrets ID as the source and enter the ID directly. This mode does not require access to a project file. Both the file path and direct ID support templating.

In Project file mode, Kreya stores the file path and reads UserSecretsId from the file when testing the connection, discovering secrets, or retrieving a secret. Changes to the ID in that file take effect on subsequent vault accesses. The file path also supports environment-variable expansion. Kreya reads the first UserSecretsId element directly from the selected XML file; it does not evaluate MSBuild imports, conditions, or property expressions. If the ID is declared in an imported .props or .targets file, select that file or use User secrets ID mode.

The secret values remain in the local .NET user-secrets store and are loaded when Kreya needs them, so changes made with dotnet user-secrets set are used without updating the Kreya project.

Discovered secret names are normalized for Kreya: ConnectionStrings:Default becomes connectionstrings_default. The original key is used to retrieve the value from the .NET store.

Referencing secrets​

See Referencing secrets for how to use configured secrets in templates and scripts.