Skip to content

Administrator settings overrides - #6649

Open
JohnMcPMS wants to merge 33 commits into
microsoft:masterfrom
JohnMcPMS:settings-lock
Open

JohnMcPMS wants to merge 33 commits into
microsoft:masterfrom
JohnMcPMS:settings-lock

Conversation

@JohnMcPMS

@JohnMcPMS JohnMcPMS commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

📖 Description

Add a protected, per-user administrator settings file so selected settings from the ordinary, user-writable file cannot control elevated operations. The new admin-settings.json uses the existing settings schema and protected storage, separate from the existing administrator capability controls.

  • Classify every setting by its permitted file source and execution context. With a full token, ignore ordinary-file values for module/install roots, portable package roots, the download directory, and portable-package deletion behavior.
  • Overlay eligible administrator values onto user settings. Shared overrides apply to normal and elevated runs; module and install roots support separate values for each context. An explicit eligible null selects the default. Invalid protected values do not fall back to ordinary-file values; unrecoverable protected-file load failures warn and leave both files' settings unapplied.
  • Add winget settings --admin, adminSettingsFile in settings export, -Admin on the user-setting PowerShell cmdlets, and target selection on the PowerShell and native DSC settings-file resources. Protected mutations require elevation; existing files can be opened without elevation. Headless creation supports provisioning without launching an editor.
  • Resolve implicit configuration module roots in the receiving processor. Elevated processors use a protected default module directory and remove the inherited ordinary WinGet module directory before applying explicit caller paths. Defer DSC imports until paths are configured, use CreateDefault2, and tolerate malformed inherited module-path entries with diagnostics.

Existing Group Policy precedence, explicit CLI/API path selections, and authoritative in-process settings content remain unchanged. This does not automatically migrate settings or copy ordinary modules into protected storage, and does not restrict every other PowerShell discovery path.

🔍 Validation

Added or updated native, managed, and PowerShell tests for source/context precedence, null and invalid values, backup recovery, policy behavior, protected storage permissions, management target selection, warnings, explicit module roots, inherited path cleanup, and deferred imports.

Microsoft Reviewers: Open in CodeFlow

@JohnMcPMS
JohnMcPMS requested a review from a team as a code owner November 3, 2026 23:17
@github-actions

This comment was marked as outdated.

@ranm-msft ranm-msft 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.

One ask inline: reconcile custom-content forwarding with the newly added regression test.

void SetModulePath(Execution::Context& context, IConfigurationSetProcessorFactory const& factory)
{
// Ignore settings as the server will retrieve the effective module path from the settings file if needed.
if (!context.Args.Contains(Execution::Args::Type::ConfigurationModulePath))

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.

This unconditional return appears inconsistent with the new ConfigurationModulePath_CustomContentForwarded test. With no module-path argument, both generated cases return here before Location is set, so REQUIRE(factory->LocationSet) cannot pass. Should this gate distinguish file-backed settings from authoritative custom content, or should the stated contract and test be revised?

@ranm-msft ranm-msft 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.

Please address the implicit module-root case and rerun the new null-location test.

processorEnvironment.PrependPSModulePath(wingetModulePath);
// Always add the context-specific winget path.
processorEnvironment.PrependPSModulePath(defaultModulePath);
if (this.Location == PowerShellConfigurationProcessorLocation.WinGetModulePath)

@ranm-msft ranm-msft Nov 5, 2026 •

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.

Correction: Default is an alias of WinGetModulePath, so this branch does use effectiveModulePath. My earlier concern here was incorrect, and I am withdrawing it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Default and WinGetModulePath are aliases for the same enum value.

@ranm-msft ranm-msft 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.

The x86 build is blocked by signed/unsigned mismatches in the new settings assertions.

@ranm-msft ranm-msft 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.

One policy-precedence issue to address before sign-off.

@AmelBawa-msft
AmirMS (AmelBawa-msft) requested review from ranm-msft and a balanced review from Copilot and removed request for ranm-msft November 18, 2026 19:10

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

Elevated, unpackaged PowerShell reads a different settings file than Set-WinGetUserSetting -Admin writes, causing the configured default module root to be ignored.

1 open issue
What changed in this PR

Introduces protected, per-user administrator settings so selected ordinary settings cannot control elevated WinGet operations, with management support across the CLI, PowerShell, and DSC.

Changes:

  • Adds settings-source precedence, token-specific restrictions, explicit-null defaults, recovery, and warnings.
  • Adds administrator-file targeting to settings commands, exports, PowerShell cmdlets, and DSC resources.
  • Separates elevated configuration module storage and discovery, with supporting tests, packaging, schemas, and documentation.
File Description
templates/​jobs-build.yml Packages the native module-path dependency.
src/​WindowsPackageManager/​WindowsPackageManager.h Declares the native module-path export.
src/​WindowsPackageManager/​Source.def Exports the module-path function.
src/​WindowsPackageManager/​main.cpp Resolves module paths using local settings and token context.
src/​PowerShell/​tests/​Microsoft.WinGet.DSC.Tests.ps1 Tests protected DSC target selection.
src/​PowerShell/​tests/​Microsoft.WinGet.Client.Tests.ps1 Tests protected-file management and repair.
src/​PowerShell/​scripts/​Initialize-LocalWinGetModules.ps1 Stages the additional native dependency locally.
src/​PowerShell/​Microsoft.WinGet.DSC/​Microsoft.WinGet.DSC.psm1 Adds administrator-file targeting to the resource.
src/​PowerShell/​Microsoft.WinGet.Configuration.Engine/​Helpers/​OpenConfigurationParameters.cs Tracks explicit module-path selection.
src/​PowerShell/​Microsoft.WinGet.Configuration.Engine/​Commands/​ConfigurationCommand.cs Leaves implicit module paths for processor resolution.
src/​PowerShell/​Microsoft.WinGet.Client.Engine/​Commands/​UserSettingsCommand.cs Routes protected reads and elevated writes.
src/​PowerShell/​Microsoft.WinGet.Client.Cmdlets/​Cmdlets/​TestUserSettingCmdlet.cs Adds the -Admin comparison switch.
src/​PowerShell/​Microsoft.WinGet.Client.Cmdlets/​Cmdlets/​SetUserSettingCmdlet.cs Adds the -Admin write switch.
src/​PowerShell/​Microsoft.WinGet.Client.Cmdlets/​Cmdlets/​GetUserSettingCmdlet.cs Adds the -Admin read switch.
src/​PowerShell/​Help/​Microsoft.WinGet.DSC/​WinGetUserSettings.md Documents protected targeting and update semantics.
src/​PowerShell/​Help/​Microsoft.WinGet.Client/​Test-WinGetUserSetting.md Documents protected-file comparisons.
src/​PowerShell/​Help/​Microsoft.WinGet.Client/​Set-WinGetUserSetting.md Documents elevated writes and explicit nulls.
src/​PowerShell/​Help/​Microsoft.WinGet.Client/​Get-WinGetUserSetting.md Documents protected-file reads.
src/​PowerShell/​Help/​Microsoft.WinGet.Client/​Get-WinGetSetting.md Documents administrator-file path discovery.
src/​Microsoft.Management.Deployment.InProc/​dllmain.cpp Adds annotations to COM exports.
src/​Microsoft.Management.Configuration.UnitTests/​Tests/​ProcessorEnvironmentTests.cs Tests deferred imports and module-path cleanup.
src/​Microsoft.Management.Configuration.UnitTests/​Tests/​ConfigurationProcessorTelemetryTests.cs Reorders a using alias; no behavior change.
src/​Microsoft.Management.Configuration.UnitTests/​Tests/​ConfigurationProcessorFactoryTests.cs Tests context-specific roots and explicit-path preservation.
src/​Microsoft.Management.Configuration.UnitTests/​Microsoft.Management.Configuration.UnitTests.csproj Includes the native dependency in tests.
src/​Microsoft.Management.Configuration.UnitTests/​Fixtures/​UnitTestFixture.cs Adapts fixtures to deferred DSC imports.
src/​Microsoft.Management.Configuration.Processor/​Public/​PowerShellConfigurationSetProcessorFactory.cs Resolves local roots and configures discovery paths.
src/​Microsoft.Management.Configuration.Processor/​PowerShell/​ProcessorEnvironments/​ProcessorEnvironmentFactory.cs Uses CreateDefault2 without eager DSC imports.
src/​Microsoft.Management.Configuration.Processor/​PowerShell/​ProcessorEnvironments/​HostedEnvironment.cs Normalizes module-path cleanup and diagnoses invalid entries.
src/​AppInstallerSharedLib/​Public/​winget/​Resources.h Declares additional settings-warning resources.
src/​AppInstallerCommonCore/​UserSettings.cpp Implements protected overrides, recovery, and file preparation.
src/​AppInstallerCommonCore/​Settings.cpp Adds administrator-only file mutations.
src/​AppInstallerCommonCore/​Runtime.cpp Adds protected configuration module defaults.
src/​AppInstallerCommonCore/​Public/​winget/​UserSettings.h Classifies settings and extends warning metadata.
src/​AppInstallerCommonCore/​Public/​winget/​Settings.h Defines protected primary and backup streams.
src/​AppInstallerCommonCore/​Public/​AppInstallerRuntime.h Declares the context-specific default module path.
src/​AppInstallerCommonCore/​pch.h Adds the exception header.
src/​AppInstallerCLITests/​WorkFlow.cpp Tests CLI targeting, warnings, exports, and DSC operations.
src/​AppInstallerCLITests/​UserSettings.cpp Tests precedence, nulls, recovery, and policy behavior.
src/​AppInstallerCLITests/​TestSettings.h Extends settings fixtures for custom content.
src/​AppInstallerCLITests/​TestSettings.cpp Cleans protected settings files between tests.
src/​AppInstallerCLITests/​Settings.cpp Tests protected storage and mutation permissions.
src/​AppInstallerCLITests/​Runtime.cpp Tests module defaults and protected directory permissions.
src/​AppInstallerCLIPackage/​Shared/​Strings/​en-us/​winget.resw Adds management help and source-specific warnings.
src/​AppInstallerCLICore/​Workflows/​SettingsFlow.h Declares warning and protected-file workflows.
src/​AppInstallerCLICore/​Workflows/​SettingsFlow.cpp Implements protected opening, creation, and path export.
src/​AppInstallerCLICore/​Resources.h Declares management and DSC resource strings.
src/​AppInstallerCLICore/​ExecutionArgs.h Adds administrator-file and creation argument types.
src/​AppInstallerCLICore/​ConfigurationDynamicRuntimeFactory.cpp Preserves explicit versus implicit module defaults.
src/​AppInstallerCLICore/​ConfigurationCommon.cpp Defers implicit module-path selection to the receiver.
src/​AppInstallerCLICore/​Commands/​SettingsCommand.cpp Adds and validates protected-file command options.
src/​AppInstallerCLICore/​Commands/​DscUserSettingsFileResource.cpp Supports protected DSC targets and authorized writes.
src/​AppInstallerCLICore/​Command.cpp Reports migration warnings through shared command handling.
src/​AppInstallerCLICore/​Argument.cpp Maps the --admin and --create arguments.
schemas/​JSON/​settings/​settings.schema.0.2.json Allows null values and documents restricted settings.
schemas/​JSON/​settings/​settings.export.schema.0.1.json Adds the administrator settings-file path.
doc/​specs/​Protected Settings Overlay.md Describes the design, boundaries, and validation plan.
doc/​Settings.md Explains administrator configuration and migration behavior.
doc/​release-notes/​1.31/​protected-settings-overlay.md Announces protected settings and module-storage changes.
.github/​actions/​spelling/​allow.txt Allows terminology introduced by the documentation.

Review effort: Balanced

@ranm-msft ranm-msft 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.

One concrete follow-up from the current diff.

@ranm-msft ranm-msft 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.

Thanks for clarifying. I withdraw my implicit-root branch concern: Default aliases WinGetModulePath, so ConfigureModulePaths applies the resolved effective root. The renamed custom-content test now asserts the current no-forwarding behavior rather than the former LocationSet expectation. This is not sign-off: required CI is still failing, and I am awaiting focused owner review of the protected-settings/module-path boundary.

@ranm-msft ranm-msft 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.

One administrator-write initialization concern below; otherwise the policy precedence and environment-path follow-ups look addressed. I am leaving approval pending this fix and focused owner review.

@reapergarcia057

Copy link
Copy Markdown

Copilot Fix the code for all comments in this review thread.

When a review comment includes a suggested change, apply the suggestion exactly.

Do not make changes beyond what is described in the linked review thread.

Copilot AI balanced review requested due to automatic review settings December 2, 2026 00:47

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

The parameterless WingetCLIWrapper construction fails compilation because its constructor requires a wingetPath argument.

1 open issue
1 resolved since last review

Review effort: Balanced

var settingsJson = orderedSettings.ToString(Formatting.Indented);
if (this.admin && !File.Exists(this.settingsFilePath))
{
var result = new WingetCLIWrapper().RunCommand(

@ranm-msft ranm-msft 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.

One recovery issue to address before approval.

}
else
{
CreateAdminSettingsFile();

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.

When the protected primary is missing but its backup is valid, loading selects Backup, so this branch creates an empty primary before opening the editor. The next invocation now prefers that valid empty file over the recovered overrides, even if the administrator makes no edit. Please preserve the recovered backup when preparing the primary, and cover the missing-primary/valid-backup case.

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.

4 participants