-
Couldn't load subscription status.
- Fork 52
Add support for [SecureString] in PowerShell adapter
#1208
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
base: main
Are you sure you want to change the base?
Add support for [SecureString] in PowerShell adapter
#1208
Conversation
a13082c to
5e08a3e
Compare
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.
Pull Request Overview
This pull request adds support for [SecureString] type properties in PowerShell class-based DSC resources and fixes handling of fully qualified PSCredential property types.
- Adds conversion logic to handle
[SecureString]properties by converting plain text values to secure strings - Updates
PSCredentialtype checking to use wildcard matching for fully qualified type names - Adds test coverage for
SecureStringproperty handling
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| adapters/powershell/psDscAdapter/psDscAdapter.psm1 | Implements SecureString conversion logic and updates PSCredential type matching to handle fully qualified names |
| adapters/powershell/Tests/powershellgroup.resource.tests.ps1 | Adds test case to verify SecureString property processing |
| adapters/powershell/Tests/TestClassResource/0.0.1/TestClassResource.psm1 | Adds SecureStringProp property to test resource for validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # handle input objects by converting them to a hash table | ||
| $validateProperty = $cachedDscResourceInfo.Properties | Where-Object -Property Name -EQ $_.Name | ||
| if ($_.Value -is [System.Management.Automation.PSCustomObject]) { | ||
| $validateProperty = $cachedDscResourceInfo.Properties | Where-Object -Property Name -EQ $_.Name |
Copilot
AI
Oct 24, 2025
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.
The $validateProperty variable is being assigned twice - once at line 427 and again at line 429 inside the if block. This results in a redundant Where-Object query when the value is a PSCustomObject. Consider removing the duplicate assignment at line 429 since line 427 already retrieves the same value.
| $validateProperty = $cachedDscResourceInfo.Properties | Where-Object -Property Name -EQ $_.Name |
| } | ||
| else { | ||
| $dscResourceInstance.$($_.Name) = $_.Value | ||
| if ($validateProperty -and $validateProperty.PropertyType -like '*SecureString' -and -not [string]::IsNullOrEmpty($_.Value)) { |
Copilot
AI
Oct 24, 2025
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.
The condition checks for non-empty string values, but doesn't verify that $_.Value is actually a string type. If $_.Value is a different type (e.g., an integer or boolean), ConvertTo-SecureString -AsPlainText could fail or produce unexpected results. Consider adding a type check to ensure $_.Value -is [string] before attempting the conversion.
| if ($validateProperty -and $validateProperty.PropertyType -like '*SecureString' -and -not [string]::IsNullOrEmpty($_.Value)) { | |
| if ($validateProperty -and $validateProperty.PropertyType -like '*SecureString' -and $_.Value -is [string] -and -not [string]::IsNullOrEmpty($_.Value)) { |
5e08a3e to
cc35c35
Compare
PR Summary
This pull request adds support for
[SecureString]in class-based DSC resources. Small remediation fix if a user uses the fully qualified property name on[PSCredential].PR Context
Fix #1207.