-
Notifications
You must be signed in to change notification settings - Fork 43
Add support for secret()
function and secret extensions
#908
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
SteveL-MSFT
wants to merge
6
commits into
PowerShell:main
Choose a base branch
from
SteveL-MSFT: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
6 commits
Select commit
Hold shift + click to select a range
61845bb
Initial support for secret function and extension
SteveL-MSFT 612fa34
implement secret function to use extensions
SteveL-MSFT 1f0a19b
Add extensions to context, add tests
SteveL-MSFT cbb3dfa
add missing i18n resource
SteveL-MSFT 9336f2f
allow multiple results that have same value
SteveL-MSFT d75949b
rename `secret` to `secureString`
SteveL-MSFT 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,119 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
|
||
Describe 'Tests for the secret() function and extensions' { | ||
BeforeAll { | ||
$oldPath = $env:PATH | ||
$toolPath = Resolve-Path -Path "$PSScriptRoot/../../extensions/test/secret" | ||
$env:PATH = "$toolPath" + [System.IO.Path]::PathSeparator + $oldPath | ||
} | ||
|
||
AfterAll { | ||
$env:PATH = $oldPath | ||
} | ||
|
||
It 'Just a secret name' { | ||
$configYaml = @' | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
resources: | ||
- name: Echo | ||
type: Microsoft.DSC.Debug/Echo | ||
properties: | ||
output: "[secret('MySecret')]" | ||
'@ | ||
$out = dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json | ||
$LASTEXITCODE | Should -Be 0 -Because (Get-Content -Raw -Path $TestDrive/error.log) | ||
$out.results.Count | Should -Be 1 | ||
$out.results[0].result.actualState.Output | Should -BeExactly 'Hello' | ||
} | ||
|
||
It 'Name and vault' { | ||
$configYaml = @' | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
resources: | ||
- name: Echo | ||
type: Microsoft.DSC.Debug/Echo | ||
properties: | ||
output: "[secret('DifferentSecret', 'VaultA')]" | ||
'@ | ||
$out = dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json | ||
$LASTEXITCODE | Should -Be 0 -Because (Get-Content -Raw -Path $TestDrive/error.log) | ||
$out.results.Count | Should -Be 1 | ||
$out.results[0].result.actualState.Output | Should -BeExactly 'Hello2' | ||
} | ||
|
||
It 'Name that does not exist' { | ||
$configYaml = @' | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
resources: | ||
- name: Echo | ||
type: Microsoft.DSC.Debug/Echo | ||
properties: | ||
output: "[secret('NonExistentSecret')]" | ||
'@ | ||
dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json | ||
$LASTEXITCODE | Should -Be 2 | ||
$errorMessage = Get-Content -Raw -Path $TestDrive/error.log | ||
$errorMessage | Should -Match "Secret 'NonExistentSecret' not found" | ||
} | ||
|
||
It 'Vault that does not exist' { | ||
$configYaml = @' | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
resources: | ||
- name: Echo | ||
type: Microsoft.DSC.Debug/Echo | ||
properties: | ||
output: "[secret('MySecret', 'NonExistentVault')]" | ||
'@ | ||
dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json | ||
$LASTEXITCODE | Should -Be 2 | ||
$errorMessage = Get-Content -Raw -Path $TestDrive/error.log | ||
$errorMessage | Should -Match "Secret 'MySecret' not found" | ||
} | ||
|
||
It 'Duplicate secret' { | ||
$configYaml = @' | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
resources: | ||
- name: Echo | ||
type: Microsoft.DSC.Debug/Echo | ||
properties: | ||
output: "[secret('DuplicateSecret')]" | ||
'@ | ||
dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json | ||
$LASTEXITCODE | Should -Be 2 | ||
$errorMessage = Get-Content -Raw -Path $TestDrive/error.log | ||
$errorMessage | Should -Match "Multiple secrets with the same name 'DuplicateSecret' and different values was returned, try specifying a vault" | ||
} | ||
|
||
It 'Secret and vault to disambiguate' { | ||
$configYaml = @' | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
resources: | ||
- name: Echo | ||
type: Microsoft.DSC.Debug/Echo | ||
properties: | ||
output: "[secret('DuplicateSecret', 'Vault1')]" | ||
'@ | ||
$out = dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json | ||
$LASTEXITCODE | Should -Be 0 -Because (Get-Content -Raw -Path $TestDrive/error.log) | ||
$out.results.Count | Should -Be 1 | ||
$out.results[0].result.actualState.Output | Should -BeExactly 'World' | ||
} | ||
|
||
It 'Same secret name and value in different extensions' { | ||
$configYaml = @' | ||
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
resources: | ||
- name: Echo | ||
type: Microsoft.DSC.Debug/Echo | ||
properties: | ||
output: "[secret('DuplicateSame')]" | ||
'@ | ||
$out = dsc -l trace config get -i $configYaml 2> $TestDrive/error.log | ConvertFrom-Json | ||
$LASTEXITCODE | Should -Be 0 | ||
$out.results.Count | Should -Be 1 | ||
$out.results[0].result.actualState.Output | Should -BeExactly 'SameSecret' | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Not the point of this PR, but should we prevent leaking secrets in this way? Accidentally leaking a secure string (and the output of the
secret
function is always secure, right?) to the output seems dangerous.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.
secureString
internally is just a string (as it's a JSON type), the only control DSC has is that itself it won't write it to console or traces.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 specifically wondering whether we want to add an issue to prevent things like this - afaik there's only two ways to get a secret value into a configuration document:
secret()
function.In both cases, DSC is aware that the string value is a secret and shouldn't be emitted (consider the case where the desired state for a resource requires a credential object) - should we mask the value even in the actually-emitted JSON output?
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.
For example, internally we could keep it as a JSON object with a single
secureString
(orsecureObject
) property, but resources that receive it could unwrap it and DSC wouldn't know. I think it's best effort at best.