fix(lambda-nodejs): local bundling fails under AllSigned PowerShell execution policy - #38447
fix(lambda-nodejs): local bundling fails under AllSigned PowerShell execution policy#38447vishwakt wants to merge 1 commit into
Conversation
…xecution policy Local bundling on Windows runs each spawn step as powershell.exe -NoProfile -Command "& 'npm' 'ci'". Passing a bare command name to the call operator lets PowerShell's command discovery select the npm.ps1 shim, and .ps1 scripts are subject to the execution policy. Under AllSigned, typically set at MachinePolicy scope by Group Policy, the shim is refused and bundling fails with no developer-side workaround, since MachinePolicy overrides the Process scope that -ExecutionPolicy Bypass would set. The executable is now resolved with Get-Command -CommandType Application, which matches only external programs such as npm.cmd, so the .ps1 shim is never a candidate. Arguments and the command name are still individually quoted, preserving the argument handling from the command injection fix, and spawn steps still route through PowerShell, preserving the EINVAL fix from aws#37412. Closes aws#38439.
|
Exemption Request for the integration test requirement. This changes only the PowerShell command line used by the local bundling spawn path on Windows. There is no CloudFormation template change, no new resource types or properties, and nothing deployable for an integration test to exercise. Coverage is by unit tests asserting the generated command line, both of which fail against the previous implementation. The local bundling path this touches has no integration test coverage today. |
aws-cdk-automation
left a comment
There was a problem hiding this comment.
The pull request linter fails with the following errors:
❌ Fixes must contain a change to an integration test file and the resulting snapshot.
If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.
✅ A exemption request has been requested. Please wait for a maintainer's review.
Issue # (if applicable)
Closes #38439.
Reason for this change
Local bundling on Windows runs
powershell.exe -NoProfile -Command "& 'npm' 'ci'". Because the call operator receives a bare command name, PowerShell's command discovery can select thenpm.ps1shim overnpm.cmd, and.ps1scripts are subject to the execution policy. UnderAllSignedthere is no developer-side workaround:MachinePolicyscope overrides theProcessscope that-ExecutionPolicy Bypasswould set.Description of changes
Resolve the executable with
Get-Command <name> -CommandType Applicationbefore invoking it.Applicationmatches only external programs (.cmd,.exe), so the.ps1shim is never a candidate.Both prior fixes are preserved: the command name and all arguments are still individually quoted via
powershellEscape(command injection fix), and spawn steps still route through PowerShell rather than spawning.cmddirectly (EINVALfix from #37412).Behavior note: a missing executable now surfaces as PowerShell's
CommandNotFoundExceptioninstead of a spawn failure. The message still names the command.Describe any new or updated permissions being added
None.
Description of how you validated changes
The existing Windows spawn test now also asserts the resolved-application form, and a new test over a
nodeModulesinstall asserts every spawn resolves its executable, none uses the bare& '...'form, and thenpm cistep is present. Both assertions fail against the current implementation and pass with the fix. Fullaws-lambda-nodejssuite passes (154 tests);docker.test.tswas not run as it requires a Docker daemon.I do not have a Windows machine with
MachinePolicy: AllSigned, so the fix is verified by asserting the generated command line rather than by executing it. @jeham, if you are able to confirm on your environment that would be valuable.No integration test: local bundling path, no template or deployable behavior change. Exemption Request will follow if the linter requires one.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license