microsoft / microsoft/winget-cli

`securityContext: elevated` does not have an effect with the PowerShell module

Open
#5,369 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Command-Configure Issue-Bug PowerShell
Dominant language
C++
Stars
26.4k
Forks
1.8k
Avg merge
1d 11h
Merged PRs (30d)
15

Description

Brief description of your issue

When using Invoke-WinGetConfiguration in Microsoft.WinGet.Configuration PowerShell module, the execution does not ask for elevation when securityContext: elevated is present in the configuration. Any module that requires elevation thus fails if the session is not run in elevated permissions manually

Steps to reproduce
  1. Install Microsoft.WinGet.Configuration PowerShell module
  2. Test against a configuration.winget file like
# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  resources:
    - resource: Microsoft.Windows.Developer/DeveloperMode
      directives:
        description: Enable Developer Mode
        # Only requires elevation for the set operation. To reproduce the issue
        # make sure developer mode is currently disabled
        securityContext: elevated
        allowPrerelease: true
      settings:
        Ensure: Present
  configurationVersion: 0.2.0

Microsoft.Windows.Developer/DeveloperMode requires elevation only for SET, so to reproduce make sure developer mode is currently disabled

  1. Run Get-WinGetConfiguration -File configuration.winget | Invoke-WinGetConfiguration
Expected behavior

Configuration asks for UAC, applies desired state and returns with a success code

Actual behavior

Does not ask with UAC and since the config requires admin, it fails with an error code. If I elevate manually with sudo, the configuration applies the desired state successfully

Image

Environment
~ Get-Module Microsoft.WinGet.Configuration | Select Version

Version
-------
1.10.340

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

Start by reproducing the issue with Invoke-WinGetConfiguration and the provided configuration.winget file, using Microsoft.WinGet.Configuration 1.10.340 and the Microsoft.Windows.Developer/DeveloperMode resource. Trace how the PowerShell module handles securityContext: elevated during the SET operation; done means an unelevated session prompts for UAC and applies the configuration successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.