Skip to content
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

Fix problem with runas failing to execute powershell scripts #61912

Closed

Conversation

rocklan
Copy link

@rocklan rocklan commented Apr 4, 2022

What does this PR do?

Fixes the problem when specifying runas when running a powershell script.

The issue was that the code that trying to escape characters by calling win_functions.escape_argument. However that function is for escaping characters for the cmd shell, and in this case we are using powershell to execute a script, and so powershell needs to know how to run the script. This is solved by prefixing the string with a &, and surrounding it in quotes.

What issues does this PR fix or reference?

Fixes: #61166

Previous Behavior

The output would appear something like this:

^C:\ProgramData\Salt Project\Salt\var\cache\salt\minion\tmpg02cql8w\__salt.tmp.j_yi8_ho.ps1^ : The term
                  '^C:\ProgramData\Salt Project\Salt\var\cache\salt\minion\tmpg02cql8w\__salt.tmp.j_yi8_ho.ps1^' is not recognized as
                  the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was

New Behavior

Script runs.

@rocklan rocklan requested a review from a team as a code owner April 4, 2022 02:41
@rocklan rocklan requested review from waynew and removed request for a team April 4, 2022 02:41
@welcome
Copy link

welcome bot commented Apr 4, 2022

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

@rocklan
Copy link
Author

rocklan commented Apr 4, 2022

I'm going to close this PR because I've found out it breaks other things (installing chocolatey via salt). In the short term I have a workaround, you can just set the cachedir parameter on the minion to a directory that doesn't have any spaces, and then the character escaping doesn't run, and things work ok.

@rocklan rocklan closed this Apr 4, 2022
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.

[BUG] failed to execute powershell script using "cmd.script" with "runas" parameter
1 participant