-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] Add az.ps1
entry script for PowerShell
#23514
Conversation
@@ -0,0 +1,2 @@ | |||
$env:AZ_INSTALLER="MSI" | |||
& "$PSScriptRoot\..\python.exe" -IBm azure.cli $args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work correctly with WinPS 5.1, right? Unfortunately the case of az '{"test":1}'
by the time the $args
is processed, you would get {test:1}
on any PS older than 7.3 (which makes it no longer valid JSON), and there's no way to know what the original intent. So perhaps the best thing is to iterate through $args
and if |
or &
is found, throw an error that it would only work with 7.3+?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in Windows PowerShell 5.1, and indeed double quotes are lost, but luckily |
or &
isn't causing any problems to us. :)
> az2 --debug "a|b" "a&b" '"ab"'
cli.knack.cli: Command arguments: ['--debug', 'a|b', 'a&b', 'ab']
add a ps1 file as the entry script to bypass 'PowerShell -> cmd' issue. |
By the way, I am playing around by calling According to https://ss64.com/nt/syntax-esc.html
My testing:
While in Bash
No weird outer double quotes are needed. |
az.ps1
entry script for PowerShellaz.ps1
entry script for PowerShell
I also found another weird PowerShell behavior while writing this PR - PowerShell sometimes even depends on the space location to determine the behavior:
Also consider these commands:
They should be grammatically equivalent, as in Win32 API within double quotes,
In the above example, I put an extra space “on the root level” and PowerShell passed the arguments double-quoted-ly to |
$env:AZ_INSTALLER="PIP" | ||
|
||
if (Test-Path "$PSScriptRoot\python.exe") { | ||
# Perfer python.exe in venv | ||
& "$PSScriptRoot\python.exe" -m azure.cli $args | ||
} | ||
else { | ||
# Run system python.exe | ||
python.exe -m azure.cli $args | ||
} | ||
|
||
# SIG # Begin signature block | ||
# MIInqgYJKoZIhvcNAQcCoIInmzCCJ5cCAQExDzANBglghkgBZQMEAgEFADB5Bgor | ||
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one problem with az.ps1
for pip
.
- ESRP code-sign was executed on Azure DevOps's Windows agent. When
git
checks out the source code on Windows, the end of line sequence isCRLF
(\r\n
). This is the default of Windowsgit
:
so the signature was generated for theCRLF
version ofaz.ps1
. - However, wheels are built on Linux agent, converting
az.ps1
's end of line sequence toLF
(\n
). - Even when installing with
pip -e
,pip
convertsCRLF
toLF
(for simplicity I guess).
That is, on Windows,
az.ps1
in source code containsCRLF
az.ps1
installed inScripts
folder containsLF
Since the signature was generated for the CRLF
version of az.ps1
, but the installed az.ps1
is LF
version, the signature doesn't match the file content.
Even if we ESRP code sign the LF
version, az.ps1
will be checked out as CRLF
in the source code, still making the signature mismatch. That is, the signature will never match the file content of both az.ps1
s - one az.ps1
's signature must be out of place.
Hello everyone, could please explain how I should run scripts right now |
We will revert this script and roll out on 10.12. Everything will work normally by then. |
Context
Fix #20972
If an argument contains special characters like
|
and&
, even though the character is double quoted, it still gets executed. This is because PowerShell launchescmd.exe
to executeaz.cmd
script. Double quotes are parsed by PowerShell so not passed tocmd.exe
during this process.cmd.exe
sees the raw|
and&
and executes them.However, when
az.cmd
is invoked fromcmd.exe
(Command Prompt), it is launched in-process, and double quotes are preserved, leading to inconsistent behavior betweencmd.exe
and PowerShell.Change
This PR adds
az.ps1
entry script for PowerShell, so that PowerShell can natively executeaz.ps1
and no longer launchescmd.exe
to executeaz.cmd
.Since PowerShell 7.3, double quotes are now preserved correctly when calling a native executable (PowerShell/PowerShell#1995 (comment)), thus fixing #15529.
Testing Guide