Skip to content

Add credential support on PowerShell adapters #758

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
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Gijsreyn
Copy link
Contributor

PR Summary

This PR addresses #328. It adds a like check for credentials and searches the username and password fields as input.

PR Context

PowerShell adapters currently don't support creating PSCredential objects. Most DSC community-based DSC resources have the $Credential as input. Some others may vary; that's why the -Like operator is used.

Copy link
Collaborator

@michaeltlombardi michaeltlombardi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation seems to use the following snippet to determine whether to convert the input to a credential:

$_.Name -like '*Credential*' -and
$_.Value.Username -and
$_.Value.Password

However, I think we should probably consider checking the target property for whether it's expecting a credential or a secure string and then trigger handling.

@Gijsreyn
Copy link
Contributor Author

If so, should we still check if the username/password is provided in such a way?

@Gijsreyn Gijsreyn marked this pull request as draft April 21, 2025 14:58
@Gijsreyn Gijsreyn marked this pull request as ready for review April 21, 2025 15:19
@Gijsreyn
Copy link
Contributor Author

Just rewrote the part, but I'm struggling a little with the following error message from the pipeline:

Exception calling "Invoke" with "4" argument(s): "The 'ConvertTo-SecureString' command was found in the module
2025-04-21T14:56:29.911181Z TRACE dsc_lib::dscresources::command_resource: 890: PID 6992: 'Microsoft.PowerShell.Security', but the module could not be loaded. For more information, run 'Import-Module
2025-04-21T14:56:29.911238Z TRACE dsc_lib::dscresources::command_resource: 890: PID 6992: Microsoft.PowerShell.Security'."

The test I wrote earlier for Windows PowerShell seems to fail on this part. I have commented it out for now. I have seen this issue before with other modules that run under the agent and wasn't able to find a workaround for it. Any suggestions are welcome.

@Gijsreyn
Copy link
Contributor Author

@SteveL-MSFT or @michaeltlombardi Do you perhaps have time to take another stab at this PR? The logic has changed to validate against the target property that is passed in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants