Skip to content

Add configuration documents as reusable DSC resources - #1838

Open
Steve Lee (SteveL-MSFT) wants to merge 9 commits into
mainfrom
stevel-msft-proposal-configuration-as-resource
Open

Steve Lee (SteveL-MSFT) wants to merge 9 commits into
mainfrom
stevel-msft-proposal-configuration-as-resource

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
Member

Summary

Reusable configurations currently require consumers to duplicate their nested resource definitions or expose group result trees. This adds configuration-backed document resources with a parameterized input contract and output-only public state.

  • Discover versioned .dsc.document.json, .dsc.document.yaml, and .dsc.document.yml definitions with an embedded manifest and document kind.
  • Validate effective parameters after defaults against an inline JSON Schema, including local $defs/$ref, then run explicitly declared get, set, and test operations in isolated configuration contexts.
  • Project declared outputs into standard resource responses while preserving aggregate child compliance, changes, and restart requirements. Reject recursion, including across group subprocesses, and keep child diagnostics in tracing.
  • Add schema export support, authoring documentation, a reusable greeting example, and focused coverage.

This initial implementation intentionally excludes export, delete, resolve, what-if, and graph expansion. Execution retains ordinary configuration failure semantics without transactional rollback; historical generated schemas are unchanged.

Validation

  • Targeted repository builds, Clippy, and document-resource Rust tests.
  • Document-resource integration tests and existing group, include, discovery, restart, and JSON-RPC regressions.
  • Generated schema validation, including invalid contracts, and example execution for get, set, and test.

Fixes: #1499

Discover dedicated document definitions and run declared get, set, and test operations in isolated configuration contexts. Validate effective inputs against inline JSON Schema and expose declared outputs as public state while preserving child change and restart signals.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 02:15
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

😁 Code Coverage Report

Changed Code Coverage

96% (90%+ coverage)

Metric Value
Changed lines analyzed 712
Lines covered by tests 687
Coverage percentage 96%

🔵 Full Codebase Coverage

83% (good)

Metric Value
Total executable lines 23454
Lines covered by tests 19570
Coverage percentage 83%

Changed code coverage measures only Rust lines added/modified in this PR.
Full codebase coverage measures all instrumented Rust lines across the project.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Expression string conversion can expose plaintext secrets in public state and logs, while group result handling misreports compliance and changes and drops restart requirements.

6 open issues
What changed in this PR

Adds configuration-backed DSC resources for #1499, allowing consumers to reuse parameterized configurations through a versioned resource interface with declared outputs as public state.

Changes:

  • Adds document-resource discovery, manifests, operation declarations, and input-schema validation.
  • Implements isolated get/set/test execution, output projection, recursion checks, and context propagation.
  • Adds schema export support, authoring documentation, examples, and focused tests.
File Description
xtask/​src/​schemas/​export.rs Registers document-resource schemas for export.
lib/​dsc-lib/​src/​functions/​envvar.rs Reads configuration roots from execution context.
lib/​dsc-lib/​src/​extensions/​discover.rs Recognizes document-resource file extensions.
lib/​dsc-lib/​src/​dscresources/​resource_manifest.rs Adds the document resource kind.
lib/​dsc-lib/​src/​dscresources/​mod.rs Exposes the document-resource module.
lib/​dsc-lib/​src/​dscresources/​jsonrpc.rs Passes scoped roots and recursion stacks to resource processes.
lib/​dsc-lib/​src/​dscresources/​dscresource.rs Dispatches document operations, validation, and schema requests.
lib/​dsc-lib/​src/​dscresources/​document_resource.rs Implements document loading, execution, projection, and unit tests.
lib/​dsc-lib/​src/​dscresources/​command_resource.rs Propagates document context through subprocess environments.
lib/​dsc-lib/​src/​discovery/​command_discovery.rs Discovers and loads document definitions.
lib/​dsc-lib/​src/​configure/​mod.rs Integrates document change and restart outcomes.
lib/​dsc-lib/​src/​configure/​context.rs Stores document execution context and outcomes.
lib/​dsc-lib/​locales/​en-us.toml Adds localized document-resource diagnostics.
dsc/​tests/​config/​dsc_document_resource.tests.ps1 Adds document-resource integration coverage.
dsc/​src/​subcommand.rs Supports document description and tag filtering.
dsc/​examples/​document-resources/​greeting.dsc.document.yaml Defines a reusable greeting resource.
dsc/​examples/​document-resource.dsc.config.yaml Demonstrates consuming the greeting resource.
docs/​reference/​schemas/​document/​document.md Documents authoring, inputs, outputs, and supported operations.
docs/​reference/​schemas/​definitions/​resourceKind.md Describes the new document resource kind.
docs/​reference/​schemas/​config/​document.md Links configuration authors to the document-resource format.
docs/​concepts/​resources/​kinds.md Introduces document resources alongside existing resource kinds.

Review effort: Balanced

Initialize the optional document definition to None in all three command-resource fixtures so full-workspace CI builds compile.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve secure-value boundaries, nested group execution signals, adapter context, and object parameter shapes.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active issues expose secure values in trace logs, drop restart requirements from compliant groups, and reject valid expression-based parameters during validation.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Resolve or defer consumer expressions during validation

lib/​dsc-lib/​src/​dscresources/​dscresource.rs:872

This branch binds unevaluated consumer expressions as literal input, so an int parameter supplied as [variables('count')] fails validation even though execution would resolve it correctly. This also blocks execution inside Microsoft.DSC/Group, whose validate operation runs dsc config validate on the raw child properties (dsc/src/subcommand.rs:533–538). Separate static validation from runtime binding: evaluate expressions with the consumer context where possible, and defer checks that require runtime values.

6 resolved since last review

Review effort: Balanced

Preserve Assertion state responses when normalizing Group results. Verify the adapter's received resource path without depending on sensitive argument traces.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Redact secure transport values in payload diagnostics and keep literal wrappers opaque. Preserve execution information and metadata during nested test-to-set conversion, with forwarding and compliant-pretest regressions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Omitted secure-string defaults can leak through trace logs, while observed-only outputs and expression-valued inputs can cause incorrect execution or validation failures.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

High severity Redact secure parameter defaults before trace logging

lib/​dsc-lib/​src/​dscresources/​document_resource.rs:188

Omitting a secureString parameter can expose its default under -l trace: set_parameters() evaluates it before wrapping it, while the parser logs literals and unwrapped expression results. Make secure-default evaluation sensitivity-aware so these diagnostics are suppressed or redacted before entering the parser. Add trace regressions for omitted secure parameters with both literal and envvar() defaults.

Medium severity Preserve observed-only properties in no-op before_state

lib/​dsc-lib/​src/​dscresources/​command_resource.rs:211

When a compliant child returns an observed property omitted from its desired input, such as a generated id, this no-op path drops that property from before_state. A document output referencing it then fails during the before-state projection at document_resource.rs:246–249, so an idempotent set returns an error. Build before_state from the observed pretest state, retaining redaction, and add a regression with an observed-only output.

Medium severity Defer validation of unresolved document input expressions

lib/​dsc-lib/​src/​dscresources/​dscresource.rs:872

dsc config validate passes unevaluated properties with a fresh context, so this runtime-binding path rejects [variables('port')] as a string for an integer parameter even though execution resolves it successfully. Separate static validation from execution preparation and defer value checks that depend on unresolved consumer expressions. Add a configuration-validation regression using expression-valued document inputs.

2 resolved since last review

Review effort: Balanced

Suppress sensitive default-evaluation diagnostics, preserve observed state for actual compliant pretests without changing what-if, and defer unresolved document inputs during static validation. Add focused Rust and CLI regressions and document the validation contract.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@SteveL-MSFT

Copy link
Copy Markdown
Member Author

Addressed all three previously missed issues from the latest review in d8761b0:

  • Secure defaults: evaluate secure defaults under a scoped no-subscriber dispatcher, before wrapping, and return a sanitized error on evaluation failure. Trace regressions cover omitted literal and envvar() defaults during get/set/test, plus a malformed secure default.
  • Observed-only outputs: normalize compliant actual pretests from their observed state, recursively through groups, retaining before-state redaction and reporting no change. Synthetic what-if conversion remains unchanged. Regressions project a generated id from direct and grouped compliant children whose set commands must never run.
  • Expression-valued inputs: static document validation no longer performs runtime preparation. It checks declared names, known values and constraints, and defers unresolved expressions/defaults and dependent schema checks until full runtime validation. Regressions cover integer inputs supplied through variables, including Group validation/execution, nested expressions, and invalid known inputs.

Validation: repository build and Clippy passed; 11 document Rust tests and 150 focused Pester tests passed. Broader registry-dependent checks are blocked locally by the missing registry executable / Microsoft.Windows/Registry resource.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Secure defaults pass document validation but fail execution because constraints are checked after wrapping, causing omitted defaults to behave differently from identical explicitly supplied values.

1 open issue

Review effort: Balanced

Check default constraints against their unwrapped values while retaining secure transport wrappers for storage. Cover omitted and explicit values, wrapped defaults, invalid constraints, and trace-safe constrained document defaults.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Human assessment is needed because resource listings and evaluation logs expose secrets, while document-test projections can discard fields required by valid outputs.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.

Proposal: Configuration as resource

2 participants