Skip to content

Commit 1e27d0b

Browse files
committed
Add reference documentation for secret()
1 parent 86c3ef6 commit 1e27d0b

File tree

2 files changed

+254
-10
lines changed

2 files changed

+254
-10
lines changed

docs/reference/cli/function/index.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,7 @@ Numeric min 1 maxInt a-n-- Returns the smallest number
6565
Numeric mod 2 2 --n-- Divides the first number by the second and returns the remainder
6666
Numeric mul 2 2 --n-- Multiplies two or more numbers together
6767
Numeric sub 2 2 --n-- Subtracts the second number from the first
68-
Resource reference 1 1 ---s- Retrieves the output of a previously executed resource
69-
Resource resourceId 2 2 ---s- Constructs a resource ID from the given type and name
70-
String base64 1 1 ---s- Encodes a string to Base64 format
71-
String concat 2 maxInt a--s- Concatenates two or more strings or arrays
72-
String format 2 maxInt -bns- Formats a string using the given arguments
73-
System envvar 1 1 ---s- Retrieves the value of an environment variable
74-
System path 2 maxInt ---s- Concatenates multiple strings into a file path
75-
System secret 1 2 ---s- Retrieves a secret from a vault
76-
System systemRoot 0 0 ---s- Returns the system root path
68+
# truncated
7769
```
7870

7971
### Example 2 - List functions with JSON output
@@ -84,7 +76,7 @@ This command returns function information in pretty JSON format.
8476
dsc function list --output-format pretty-json
8577
```
8678

87-
```json
79+
```jsonc
8880
{
8981
"category": "Array",
9082
"name": "createArray",
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
---
2+
description: Reference for the 'secret' DSC configuration document function
3+
ms.date: 08/22/2025
4+
ms.topic: reference
5+
title: secret
6+
---
7+
8+
# secret
9+
10+
## Synopsis
11+
12+
Retrieves secrets from registered secret management extensions.
13+
14+
## Syntax
15+
16+
```Syntax
17+
secret(<name>)
18+
secret(<name>, <vault>)
19+
```
20+
21+
## Description
22+
23+
The `secret()` function retrieves secrets from extensions that support the
24+
secret capability. It queries all registered extensions that implement secret
25+
management and returns the requested secret value. If multiple extensions
26+
return different values for the same secret name, an error is returned unless
27+
a vault is specified to disambiguate.
28+
29+
The function supports two calling patterns:
30+
31+
- Single argument: Retrieves a secret by name from any available vault
32+
- Two arguments: Retrieves a secret by name from a specific vault
33+
34+
If multiple extensions return the same secret value, the function succeeds and
35+
returns that value. This allows for redundancy across secret management
36+
systems.
37+
38+
## Examples
39+
40+
### Example 1 - Retrieve a secret by name
41+
42+
The following example retrieves a secret named 'DatabasePassword' from any
43+
available vault.
44+
45+
```yaml
46+
# secret.example.1.dsc.config.yaml
47+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
48+
resources:
49+
- name: Database Connection
50+
type: Microsoft.DSC.Debug/Echo
51+
properties:
52+
output: "Connection string with password: [secret('DatabasePassword')]"
53+
```
54+
55+
```bash
56+
dsc config get --file secret.example.1.dsc.config.yaml
57+
```
58+
59+
```yaml
60+
results:
61+
- name: Database Connection
62+
type: Microsoft.DSC.Debug/Echo
63+
result:
64+
actualState:
65+
output: "Connection string with password: MySecretPassword123"
66+
messages: []
67+
hadErrors: false
68+
```
69+
70+
### Example 2 - Retrieve a secret from a specific vault
71+
72+
The following example retrieves a secret from a specific vault to avoid
73+
ambiguity when the same secret name exists in multiple vaults.
74+
75+
```yaml
76+
# secret.example.2.dsc.config.yaml
77+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
78+
resources:
79+
- name: API Configuration
80+
type: Microsoft.DSC.Debug/Echo
81+
properties:
82+
output: "API Key: [secret('ApiKey', 'ProductionVault')]"
83+
```
84+
85+
```bash
86+
dsc config get --file secret.example.2.dsc.config.yaml
87+
```
88+
89+
```yaml
90+
results:
91+
- name: API Configuration
92+
type: Microsoft.DSC.Debug/Echo
93+
result:
94+
actualState:
95+
output: "API Key: prod-api-key-xyz789"
96+
messages: []
97+
hadErrors: false
98+
```
99+
100+
### Example 3 - Multiple secrets in configuration
101+
102+
The following example demonstrates using multiple secrets within a single
103+
resource configuration.
104+
105+
```yaml
106+
# secret.example.3.dsc.config.yaml
107+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
108+
resources:
109+
- name: Service Configuration
110+
type: Microsoft.DSC.Debug/Echo
111+
properties:
112+
output:
113+
username: "[secret('ServiceUsername')]"
114+
password: "[secret('ServicePassword')]"
115+
connectionString: "Server=myserver;User=[secret('DbUser')];Password=[secret('DbPassword')]"
116+
```
117+
118+
```bash
119+
dsc config get --file secret.example.3.dsc.config.yaml
120+
```
121+
122+
```yaml
123+
results:
124+
- name: Service Configuration
125+
type: Microsoft.DSC.Debug/Echo
126+
result:
127+
actualState:
128+
output:
129+
username: "serviceaccount"
130+
password: "SecurePassword456"
131+
connectionString: "Server=myserver;User=dbuser;Password=DbPass789"
132+
messages: []
133+
hadErrors: false
134+
```
135+
136+
### Example 4 - Conditional secret usage
137+
138+
The following example shows using secrets conditionally based on environment
139+
parameters.
140+
141+
```yaml
142+
# secret.example.4.dsc.config.yaml
143+
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
144+
parameters:
145+
environment:
146+
type: string
147+
defaultValue: production
148+
resources:
149+
- name: Environment-specific config
150+
type: Microsoft.DSC.Debug/Echo
151+
properties:
152+
output:
153+
apiKey: >-
154+
[if(equals(parameters('environment'), 'production'),
155+
secret('ProdApiKey', 'ProdVault'),
156+
secret('DevApiKey', 'DevVault'))]
157+
```
158+
159+
```bash
160+
dsc config get --file secret.example.4.dsc.config.yaml
161+
```
162+
163+
```yaml
164+
results:
165+
- name: Environment-specific config
166+
type: Microsoft.DSC.Debug/Echo
167+
result:
168+
actualState:
169+
output:
170+
apiKey: "prod-secure-key-abc123"
171+
messages: []
172+
hadErrors: false
173+
```
174+
175+
## Parameters
176+
177+
### name
178+
179+
The name of the secret to retrieve.
180+
181+
```yaml
182+
Type: string
183+
Required: true
184+
Position: 1
185+
```
186+
187+
### vault
188+
189+
The name of the vault or secret store to retrieve the secret from. When
190+
specified, only the named vault is queried for the secret, which helps
191+
disambiguate when multiple vaults contain secrets with the same name.
192+
193+
```yaml
194+
Type: string
195+
Required: false
196+
Position: 2
197+
```
198+
199+
## Output
200+
201+
The `secret()` function returns the secret value as a string.
202+
203+
```yaml
204+
Type: string
205+
```
206+
207+
## Error conditions
208+
209+
The `secret()` function can return errors in the following situations:
210+
211+
- **No extensions available**: No secret management extensions are registered
212+
or available
213+
- **Secret not found**: The specified secret name does not exist in any
214+
available vault
215+
- **Multiple different values**: Multiple extensions return different values
216+
for the same secret name (specify a vault to disambiguate)
217+
- **Vault not found**: The specified vault does not exist or is not accessible
218+
- **Extension error**: An underlying secret management extension returns an
219+
error
220+
221+
## Security considerations
222+
223+
- Secret values are retrieved at runtime and should be handled securely
224+
- Secrets are not cached by DSC and are retrieved fresh on each function call
225+
- Secret values are not logged in trace output for security reasons
226+
- Extensions should implement appropriate authentication and authorization for
227+
secret access
228+
229+
## Extension requirements
230+
231+
To support the `secret()` function, extensions must:
232+
233+
1. Declare the `Secret` capability in their manifest
234+
2. Implement a secret retrieval method that accepts name and optional vault
235+
parameters
236+
3. Return secret values as single-line strings (multi-line values are not
237+
supported)
238+
4. Handle authentication and authorization according to their secret
239+
management system
240+
241+
## Related functions
242+
243+
- [`if()`][00] - Returns values based on a condition for conditional secret
244+
usage
245+
- [`equals()`][01] - Compares values for conditional logic
246+
- [`parameters()`][02] - Access configuration parameters that may influence
247+
secret selection
248+
249+
<!-- Link reference definitions -->
250+
[00]: ./if.md
251+
[01]: ./equals.md
252+
[02]: ./parameters.md

0 commit comments

Comments
 (0)