-
Notifications
You must be signed in to change notification settings - Fork 50
Add reference documentation for secret() #1075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Gijsreyn
wants to merge
9
commits into
PowerShell:main
Choose a base branch
from
Gijsreyn:reference-doc-secret
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1e27d0b
Add reference documentation for secret()
Gijsreyn ddd7bb2
Add reference documentation for secret()
Gijsreyn e4d5516
Lowercase secret
Gijsreyn 2a2e12b
Test/WhatIf
Gijsreyn 61920a8
Add reference documentation for secret()
Gijsreyn 59091fa
Lowercase secret
Gijsreyn f2e4096
Secret values are logged in trace output
Gijsreyn 89b7a35
Merge branch 'reference-doc-secret' of https://github.com/Gijsreyn/op…
Gijsreyn 33189d4
Rewrite examples
Gijsreyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
--- | ||
description: Reference for the 'secret' DSC configuration document function | ||
ms.date: 08/22/2025 | ||
ms.topic: reference | ||
title: secret | ||
--- | ||
|
||
# secret | ||
|
||
## Synopsis | ||
|
||
Retrieves secrets from registered secret management extensions. | ||
|
||
## Syntax | ||
|
||
```Syntax | ||
secret(<name>) | ||
secret(<name>, <vault>) | ||
``` | ||
|
||
## Description | ||
|
||
The `secret()` function retrieves secrets from extensions that support the | ||
secret capability. It queries all registered extensions that implement secret | ||
management and returns the requested secret value. If multiple extensions | ||
return different values for the same secret name, an error is returned unless | ||
a vault is specified to disambiguate. | ||
|
||
The function supports two calling patterns: | ||
|
||
- Single argument: Retrieves a secret by name from any available vault | ||
- Two arguments: Retrieves a secret by name from a specific vault | ||
|
||
If multiple extensions return the same secret value, the function succeeds and | ||
returns that value. This allows for redundancy across secret management | ||
systems. | ||
|
||
## Examples | ||
|
||
### Example 1 - Retrieve a secret by name | ||
|
||
The following example retrieves a secret named 'DatabasePassword' from any | ||
available vault. The secret expression is used directly as the output value. | ||
|
||
```yaml | ||
# secret.example.1.dsc.config.yaml | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
resources: | ||
- name: Database Connection | ||
type: Microsoft.DSC.Debug/Echo | ||
properties: | ||
output: "[secret('DatabasePassword')]" | ||
``` | ||
|
||
```bash | ||
dsc config get --file secret.example.1.dsc.config.yaml | ||
``` | ||
|
||
```yaml | ||
results: | ||
- name: Database Connection | ||
type: Microsoft.DSC.Debug/Echo | ||
result: | ||
actualState: | ||
output: "MySecretPassword123" | ||
messages: [] | ||
hadErrors: false | ||
``` | ||
|
||
### Example 2 - Pass a secret through a parameter default | ||
|
||
The following example defines a secureString parameter whose default value | ||
is the secret. The resource then uses the parameter value for the output | ||
property. | ||
|
||
```yaml | ||
# secret.example.2.dsc.config.yaml | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
parameters: | ||
myString: | ||
type: secureString | ||
defaultValue: "[secret('MySecret')]" | ||
resources: | ||
- name: Database Connection | ||
type: Microsoft.DSC.Debug/Echo | ||
properties: | ||
output: "[parameters('myString')]" | ||
``` | ||
|
||
```bash | ||
dsc config get --file secret.example.2.dsc.config.yaml | ||
``` | ||
|
||
```yaml | ||
results: | ||
- name: Database Connection | ||
type: Microsoft.DSC.Debug/Echo | ||
result: | ||
actualState: | ||
output: "MySecretPassword123" | ||
messages: [] | ||
hadErrors: false | ||
``` | ||
|
||
## Parameters | ||
|
||
### name | ||
|
||
The name of the secret to retrieve. | ||
|
||
```yaml | ||
Type: string | ||
Required: true | ||
Position: 1 | ||
``` | ||
|
||
### vault | ||
|
||
The name of the vault or secret store to retrieve the secret from. When | ||
specified, only the named vault is queried for the secret, which helps | ||
disambiguate when multiple vaults contain secrets with the same name. | ||
|
||
```yaml | ||
Type: string | ||
Required: false | ||
Position: 2 | ||
``` | ||
|
||
## Output | ||
|
||
The `secret()` function returns the secret value as a string. | ||
|
||
```yaml | ||
Type: string | ||
``` | ||
|
||
## Error conditions | ||
|
||
The `secret()` function can return errors in the following situations: | ||
|
||
- **No extensions available**: No secret management extensions are registered | ||
or available | ||
- **Secret not found**: The specified secret name does not exist in any | ||
available vault | ||
- **Multiple different values**: Multiple extensions return different values | ||
for the same secret name (specify a vault to disambiguate) | ||
- **Vault not found**: The specified vault does not exist or is not accessible. | ||
- **Extension error**: An underlying secret management extension returns an | ||
error | ||
|
||
## Security considerations | ||
|
||
- Secret values are retrieved at runtime and should be handled securely | ||
- Secrets are not cached by DSC and are retrieved fresh on each function call | ||
- Secret values are logged when `--trace-level` is "TRACE" | ||
- Extensions should implement appropriate authentication and authorization for | ||
secret access | ||
|
||
## Extension requirements | ||
|
||
To support the `secret()` function, extensions must: | ||
|
||
1. Declare the `secret` capability in their manifest | ||
2. Implement a secret retrieval method that accepts name and optional vault | ||
parameters | ||
3. Return secret values as single-line strings (multi-line values are not | ||
supported) | ||
4. Handle authentication and authorization according to their secret | ||
management system | ||
|
||
## Related functions | ||
|
||
- [`parameters()`][00] - Access configuration parameters that may influence | ||
secret selection | ||
|
||
<!-- Link reference definitions --> | ||
[00]: ./parameters.md |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to address this, but if you can currently use the
Echo
resource to emit secrets retrieved with thesecret()
function, that's probably something we need to fix.I'm not sure exactly how to manage this problem yet - but if all you need to do to dump secrets from someone's vault is guess the name and invoke a config, that's not good.
CC @SteveL-MSFT
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can access the secret (meaning authenticated in some way), you already have access to the secret in memory (or other means). Resources need the secret itself in plaintext and we can only prevent accidental exposure of it, we aren't a security boundary to prevent access to something that have to use.
If we want to add a layer of defense, we could say that secrets are always passed as JSON:
But now anything that needs it needs to parse the JSON and would also need to handle it appropriately anyways, so I'm not sure it adds value since the recipient would already know it's a sensitive string.