PowerShell / PowerShell/DSC

Script based resources do not enforce schema validation

Open
#236 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
523
Forks
75
Avg merge
3d 16h
Merged PRs (30d)
24

Description

Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.
Steps to reproduce

'{"Name": "bits","State": "Running"}' | dsc resource get -r PsDscResources/MSFT_ServiceResource

Expected behavior
actualState:
  DesktopInteract: false
  Name: bits
  BuiltInAccount: LocalSystem
  State: Stopped
  Ensure: Present
  Description: Transfers files in the background using idle network bandwidth. If the service is disabled, then any applications that depend on BITS, such as Windows Update or MSN Explorer, will be unable to automatically download programs and other information.
  StartupType: Manual
  Dependencies:
  - RpcSs
  Path: C:\WINDOWS\System32\svchost.exe -k netsvcs -p
  DisplayName: Background Intelligent Transfer Service
Actual behavior
Error: Command: Resource 'DSC/PowerShellGroup' [Exit code 1] Get-TargetResource: A parameter cannot be found that matches parameter name 'State'.
Error details
This happens because script based resources do not enforce parameter validation, and in many cases "Get" does not implement all parameters.
Example:
https://github.com/PowerShell/PSDscResources/blob/7064eda52d939a4a3ce40e1f38756cfe6a09acfd/DscResources/MSFT_ServiceResource/MSFT_ServiceResource.psm1#L37

We could solve this issue in PSDesiredStateConfiguration, but then DSCv3 would require that version or later. When we have created dependencies like that in the past, it made adoption more difficult.
Environment data
7.3.8
Version

0.2.0

Visuals

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown dsc resource get command, then inspect the linked MSFT_ServiceResource.psm1 example and the PSDesiredStateConfiguration boundary. Determine where schema validation for script-based resources belongs and how the dependency concern affects the design. Done means unsupported parameters are consistently rejected for script-based resources without requiring an unspecified version change.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
devops
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.