-
Notifications
You must be signed in to change notification settings - Fork 57
win_psDscAdapter and psDscAdapter PScredentials fix for passing username and password #1308
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?
Changes from all commits
61f4b85
cd5df41
98e7099
0a7c6aa
82aeec4
506ba9f
49c381c
403e6b5
352dd69
4af004e
dd7425e
b8cff4a
63cd935
73dacde
34b6b73
877ee8b
7984d06
661259b
f6b366e
6763c23
779e259
2d10057
3c57cf8
3542591
4400c8f
46dc975
6ecf98d
980f2bc
17bd44a
6342821
802704c
f8ce2bf
0d2647c
c4e1e2f
12e18c1
132c31f
c71240f
35613e2
466a595
3ea45e9
76a8990
aff99b5
67717e0
1397b2e
6cbe62e
d2d3d1c
c3b118d
99da2c8
2823483
2826fba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,6 @@ on: | |
| - "*.md" | ||
| - ".vscode/*.json" | ||
| - ".github/ISSUE_TEMPLATE/**" | ||
|
|
||
| env: | ||
| CARGO_TERM_COLOR: always | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| $VerbosePreference = 'SilentlyContinue' | ||
| $InformationPreference = 'SilentlyContinue' | ||
| $ProgressPreference = 'Continue' | ||
| $ErrorActionPreference = 'SilentlyContinue' | ||
|
|
||
| function Get-TargetResource { | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')] | ||
| [OutputType([Hashtable])] | ||
| param ( | ||
| [Parameter(Mandatory)] | ||
| [string] $Name, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [System.Management.Automation.PSCredential] | ||
| $Credential | ||
| ) | ||
| Write-Verbose "[GET] Get Function running" | ||
| return @{ | ||
| Name = $Name | ||
| Credential = $Credential | ||
| } | ||
|
|
||
| } | ||
|
|
||
| function Test-TargetResource { | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')] | ||
| [OutputType([System.Boolean])] | ||
| param ( | ||
| [Parameter(Mandatory)] | ||
| [string] $Name, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [System.Management.Automation.PSCredential] | ||
| $Credential | ||
|
|
||
| ) | ||
| Write-Verbose "[TEST]Checking credentials" | ||
| Write-Verbose "[TEST]Checking credentials UserName: $($Credential.UserName)" | ||
| Write-Verbose "[TEST]Checking credentials Password: <redacted>" | ||
|
|
||
| if ($null -eq $Credential) { | ||
| throw 'Credential property is required' | ||
| $inDesiredState = $false | ||
| return $false | ||
| } | ||
|
|
||
| if ($Credential.UserName -ne 'MyUser') { | ||
| throw 'Invalid user name' | ||
| $inDesiredState = $false | ||
| } else { | ||
| $inDesiredState = $true | ||
| } | ||
|
|
||
|
|
||
| return $inDesiredState | ||
|
|
||
| } | ||
|
|
||
| function Set-TargetResource { | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '')] | ||
| [CmdletBinding()] | ||
| param ( | ||
| [Parameter(Mandatory)] | ||
| [string] $Name, | ||
|
|
||
| [Parameter(Mandatory = $true)] | ||
| [System.Management.Automation.PSCredential] | ||
| $Credential | ||
|
|
||
| ) | ||
|
|
||
| if ($null -eq $Credential) { | ||
| throw 'Credential property is required' | ||
| $inDesiredState = $false | ||
| return $false | ||
| } | ||
|
|
||
| if ($Credential.UserName -ne 'MyUser') { | ||
| throw 'Invalid user name' | ||
| $inDesiredState = $false | ||
|
Comment on lines
+78
to
+80
|
||
| } else { | ||
| $inDesiredState = $true | ||
| } | ||
|
|
||
| Write-Verbose "[SET]Credential cannot be remediated by DSC." | ||
| return $inDesiredState | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [ClassVersion("1.0.0.0"), FriendlyName("CredentialValidation")] | ||
| class CredentialValidation : OMI_BaseResource | ||
| { | ||
| [Key] string Name; | ||
| [Required, Description("Test Credentials for Script Base"), EmbeddedInstance("MSFT_Credential")] String Credential; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| @{ | ||
| # Script module or binary module file associated with this manifest. | ||
| RootModule = 'TestScriptBaseDSC.psm1' | ||
|
|
||
| # Version number of this module. | ||
| moduleVersion = '0.0.1' | ||
|
|
||
| # ID used to uniquely identify this module | ||
| GUID = 'c3775be8-84a1-43f5-a99c-1b9f2d6bc178' | ||
|
|
||
| # Author of this module | ||
| Author = '' | ||
|
|
||
| # Company or vendor of this module | ||
| CompanyName = '' | ||
|
|
||
| # Copyright statement for this module | ||
| Copyright = '' | ||
|
|
||
| # Description of the functionality provided by this module | ||
| Description = '' | ||
|
|
||
| # Minimum version of the Windows PowerShell engine required by this module | ||
| PowerShellVersion = '5.0' | ||
|
|
||
| # Cmdlets to export from this module | ||
| CmdletsToExport = @() | ||
|
|
||
| # Variables to export from this module | ||
| VariablesToExport = @() | ||
|
|
||
| # Aliases to export from this module | ||
| AliasesToExport = @() | ||
|
|
||
| # Dsc Resources to export from this module | ||
| DscResourcesToExport = @('CredentialValidation') | ||
|
|
||
| # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. | ||
| PrivateData = @{ | ||
|
|
||
| PSData = @{ | ||
|
|
||
| # Tags applied to this module. These help with module discovery in online galleries. | ||
| Tags = @('DesiredStateConfiguration', 'DSC', 'DSCResourceKit', 'DSCResource') | ||
|
|
||
| # A URL to the license for this module. | ||
| LicenseUri = '' | ||
|
|
||
| # A URL to the main website for this project. | ||
| ProjectUri = '' | ||
|
|
||
| # A URL to an icon representing this module. | ||
| IconUri = '' | ||
|
|
||
| # ReleaseNotes of this module | ||
| ReleaseNotes = '' | ||
|
|
||
| # Set to a prerelease string value if the release should be a prerelease. | ||
| Prerelease = '' | ||
| } # End of PSData hashtable | ||
| } # End of PrivateData hashtable | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Root module for CredentialValidationDsc | ||
| # No code required |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| parameters: | ||
| showSecrets: | ||
| type: bool | ||
| defaultValue: true | ||
| cred: | ||
| type: secureObject | ||
| metadata: | ||
| Microsoft.DSC: | ||
| requiredSecurityContext: elevated # this is the default and just used as an example indicating this config works for admins and non-admins | ||
| resources: | ||
| - name: Working with classic DSC resources | ||
| type: Microsoft.DSC/PowerShell | ||
| properties: | ||
| resources: | ||
| - name: Class-resource Info | ||
| type: TestClassResource/TestClassResource | ||
| properties: | ||
| Name: TestClassResource1 | ||
| Prop1: ValueForProp1 | ||
| Credential: "[parameters('cred')]" | ||
| - name: SecureObject | ||
| type: Microsoft.DSC.Debug/Echo | ||
| properties: | ||
| output: "[parameters('cred')]" | ||
| showSecrets: "[parameters('showSecrets')]" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| parameters: | ||
| cred: | ||
| username: admin | ||
| password: {To be Override} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json | ||
| parameters: | ||
| cred: | ||
| type: secureObject | ||
| defaultValue: | ||
| username: MyUser | ||
| password: Password | ||
| resources: | ||
| - name: Working with classic DSC resources | ||
| type: Microsoft.Windows/WindowsPowerShell | ||
| properties: | ||
| resources: | ||
| - name: Script-resource Info | ||
| type: TestScriptBaseDSC/CredentialValidation | ||
| properties: | ||
| Name: TestScriptResource1 | ||
| Credential: "[parameters('cred')]" |
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.
Unreachable code after throw: Lines 43-44 are unreachable because the
throwstatement on line 42 will exit the function immediately. Consider removing these lines or restructuring the logic to avoid the throw if you want to continue execution.