Skip to content

Running script from WSL with noninteractive flag will show "SecurityError: AuthorizationManager check failed." #17623

Closed

Description

@leoleoasd

Prerequisites

Steps to reproduce

 /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -file ./xxx.ps1

Expected behavior

runs successfully since there is a -executionpolicy unrestricted flag

Actual behavior

SecurityError: AuthorizationManager check failed.

Error details

I don't know how to provide this since I'm starting a .ps1 file and the session ends before the file's execution

Environment data

Name                           Value
----                           -----
PSVersion                      7.2.5
PSEdition                      Core
GitCommitId                    7.2.5
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

Activity

  1. added
    Needs-Triage
    on Jul 4, 2022
  2. fMichaleczek commented on Jul 5, 2022

    @fMichaleczek
    Contributor

    I can't reproduce it.

    image

    Could you try with -noprofile argument ?
    /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -noprofile -file test.ps1

    Could you try to unblock your script file ?
    https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0713009

  3. added
    WG-Security
    on Jul 5, 2022
  4. leoleoasd commented on Jul 5, 2022

    @leoleoasd
    Author

    doesn't work either.

    (win/x64)  ➜  ~ echo "Write-Host Test" > test.ps1
    (win/x64)  ➜  ~ /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -file ./test.ps1
    SecurityError: AuthorizationManager check failed.
    (win/x64)  ➜  ~ /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -noprofile -file ./test.ps1
    SecurityError: AuthorizationManager check failed.
    (win/x64)  ➜  ~ unblock-file
    zsh: command not found: unblock-file
    (win/x64)  ➜  ~ /mnt/c/Program\ Files/PowerShell/7/pwsh.exe
    PowerShell 7.2.5
    Copyright (c) Microsoft Corporation.
    
    https://aka.ms/powershell
    Type 'help' to get help.
    
    PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Distrod\home\leo> Unblock-File .\test.ps1
    PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Distrod\home\leo> .\test.ps1
    .\test.ps1: File \\wsl.localhost\Distrod\home\leo\test.ps1 cannot be loaded. The file \\wsl.localhost\Distrod\home\leo\test.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
    PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Distrod\home\leo> ^C
    PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Distrod\home\leo> exit
    (win/x64)  ➜  ~ /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -noprofile -file ./test.ps1
    SecurityError: AuthorizationManager check failed.
    
  5. leoleoasd commented on Jul 5, 2022

    @leoleoasd
    Author

    My WSL version:

    (win/x64)  ➜  ~ wsl.exe --version
    WSL 版本: 0.61.4.0
    内核版本: 5.10.102.1
    WSLg 版本: 1.0.39
    MSRDC 版本: 1.2.3213
    Direct3D 版本: 1.601.0
    DXCore 版本: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
    Windows版本: 10.0.22000.739
    
  6. suntt2019 commented on Jul 5, 2022

    @suntt2019

    I can reproduce.
    image

    sun123t2@G15:~/code/tries/ps$ /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -file ./test.ps1
    SecurityError: AuthorizationManager check failed.
    sun123t2@G15:~/code/tries/ps$ /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -noprofile -file ./test.ps1
    SecurityError: AuthorizationManager check failed.
    sun123t2@G15:~/code/tries/ps$ unblock-file
    -bash: unblock-file: command not found
    sun123t2@G15:~/code/tries/ps$ /mnt/c/Program\ Files/PowerShell/7/pwsh.exe
    PowerShell 7.2.5
    Copyright (c) Microsoft Corporation.
    
    https://aka.ms/powershell
    Type 'help' to get help.
    
    PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Distrod\home\sun123t2\code\tries\ps> Unblock-File .\test.ps1
    PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Distrod\home\sun123t2\code\tries\ps> .\test.ps1
    .\test.ps1: File \\wsl.localhost\Distrod\home\sun123t2\code\tries\ps\test.ps1 cannot be loaded. The file \\wsl.localhost\Distrod\home\sun123t2\code\tries\ps\test.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.
    PS Microsoft.PowerShell.Core\FileSystem::\\wsl.localhost\Distrod\home\sun123t2\code\tries\ps> exit
    sun123t2@G15:~/code/tries/ps$ /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -noprofile -file ./test.ps1
    SecurityError: AuthorizationManager check failed.
    sun123t2@G15:~/code/tries/ps$
    
  7. fMichaleczek commented on Jul 5, 2022

    @fMichaleczek
    Contributor

    The PR #13120 declared \\wsl$ as a security zone when analysing a script.

    internal const string WslRootPath = @"\\wsl$";

    But starting WSL Build 20175, they change the \\wsl$ prefix to \\wsl
    WSL/release-notes#build-20175

    But starting WSL Build 21354, they change the \\wsl prefix to \\wsl.localhost
    WSL/release-notes#build-21354

    So the issue #13106 is came back.

    The WSL >20175 need a improvement to declare the new path and handle security (don't trust \\wslfake by example)

  8. fMichaleczek commented on Jul 5, 2022

    @fMichaleczek
    Contributor
  9. leoleoasd commented on Jul 5, 2022

    @leoleoasd
    Author

    Is there any temporary workaround for this?

  10. leoleoasd commented on Jul 5, 2022

    @leoleoasd
    Author

    Piping script into pwsh's stdin seems working. Is there any way to disable the prompt (version, path, help, etc.) when piping, just like opening it with -file?

  11. fMichaleczek commented on Jul 5, 2022

    @fMichaleczek
    Contributor

    Yuxuan Lu (@leoleoasd) the \\WSL$ is still working, so if you force the path, PowerShell should be OK with that.

    home> echo "Write-Host Test" > test.ps1
    home> /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -file '\\wsl$\Ubuntu-20.04\home\flavien\test.ps1'
    
  12. daxian-dbw commented on Jul 5, 2022

    @daxian-dbw
    Member

    /mnt/c/Program\ Files/PowerShell/7/pwsh.exe

    You are running powershell built for Windows on Linux, and I'm afraid you will get undefined behaviors. Different code paths are enabled when building for Unix platforms, and thus the Windows build powershell is bound to have issues when running in Linux environment. The recommendation is to install PowerShell in WSL and use that instead.

  13. added
    Resolution-Answered
    and removed
    Needs-Triage
    on Jul 5, 2022
  14. fMichaleczek commented on Jul 5, 2022

    @fMichaleczek
    Contributor

    /mnt/c/Program\ Files/PowerShell/7/pwsh.exe

    You are running powershell built for Windows on Linux, and I'm afraid you will get undefined behaviors. Different code paths are enabled when building for Unix platforms, and thus the Windows build powershell is bound to have issues when running in Linux environment. The recommendation is to install PowerShell in WSL and use that instead.

    I Agree with you but the issue is related to specific PR #13120 , do you want another PR to remove the 13120 ? I don't understand.

  15. daxian-dbw commented on Jul 5, 2022

    @daxian-dbw
    Member

    I think it's different. #13120 is to address an issue that happened when running pwsh.exe from Windows within the WSL file system. But this issue is about running pwsh.exe directly in WSL.

  16. fMichaleczek commented on Jul 5, 2022

    @fMichaleczek
    Contributor

    I think it's different. #13120 is to address an issue that happened when running pwsh.exe from Windows within the WSL file system. But this issue is about running pwsh.exe directly in WSL.

    Yes but the new default WSL Host has been changed, so the PR13120 need an update to declare the new set (\\wsl\, \\wsl.localhost\) for Windows Build > 20175. (\\wsl$\ is still present for retro-compatible)

    I could create a new issue if you prefer, showing that I can't execute a script if the path is '\wsl.localhost\Ubuntu-20.04\home\flavien\test.ps1 on the last Windows Version, because it's not declared in the security zone. (I haven't test)

    And after, it will maybe solve the current issue :

    /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -file '\\wsl\Ubuntu-20.04\home\flavien\test.ps1' => KO, path is not trusted
    /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -file '\\wsl.localhost\Ubuntu-20.04\home\flavien\test.ps1' => KO, path is not trusted
    /mnt/c/Program\ Files/PowerShell/7/pwsh.exe -noninteractive -executionpolicy unrestricted -file '\\wsl$\Ubuntu-20.04\home\flavien\test.ps1' => OK, path is trusted
    
  17. ghost closed this as completedon Jul 7, 2022
  18. daxian-dbw commented on Jul 7, 2022

    @daxian-dbw
    Member

    for Windows Build > 20175. (\wsl$\ is still present for retro-compatible)

    Flavien MICHALECZEK (@fMichaleczek) Is that Windows 11? Please open a new issue for that, thanks!

  19. fMichaleczek commented on Jul 7, 2022

    @fMichaleczek
    Contributor

    Dongbo Wang (@daxian-dbw) At this moment, it think it's Windows 10 Insider and Windows 11.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-AnsweredWG-Security

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions