Content-Length: 535914 | pFad | https://github.com/saltstack/salt/pull/68156

7F cmdmod enhancements for Windows by xsmile · Pull Request #68156 · saltstack/salt · GitHub
Skip to content

cmdmod enhancements for Windows #68156

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

Open
wants to merge 9 commits into
base: 3006.x
Choose a base branch
from
Open

Conversation

xsmile
Copy link

@xsmile xsmile commented Jul 7, 2025

What does this PR do?

Change the behavior of the cmdmod execution module.

shell / python_shell

Respect user input for the shell parameter. Same as python_shell, it is disabled by default for all functions except cmd.shell. This prevents unnecessary calls to the shell and possibly unsafe command executions. cmd.run and other similar functions now require shell to be specified explicitly if shell functionality is required.

cmd._run

  • the command list / string is kept as is without altering the command behaviour. Special characters and whitespaces are handled by subprocess.list2cmdline only if required in case the shell is cmd.exe or if impersonating another user and passing the command string to CreateProcess.
  • run PowerShell scripts via -File instead of -Command. This makes it possible to pass arguments as a list and not having to worry about escaping characters. In contrast to the previous behavior with -Command, the arguments are not evaluated as commands. When PowerShell commands are a requirement, cmd.shell or cmd.powershell should be used instead, e.g. Windows: Using inline powershell in args with cmd.script and shell: powershell #56195 .

cmd.script

  • always remove the temporary script, even if it fails to be executed
  • automatically suggest a shell when a Windows script with a known file extension is found
  • allow to pass arguments as a list

cmd.powershell

  • do not silently fail and report success when a PowerShell command fails to run

What issues does this PR fix or reference?

#56195
#68096
#68118

Merge requirements satisfied?

Commits signed with GPG?

No

@xsmile xsmile requested a review from a team as a code owner July 7, 2025 13:32
Copy link

welcome bot commented Jul 7, 2025

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 saltproject.pdl@broadcom.com. We’re glad you’ve joined our community and look forward to doing awesome things with you!

Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few questions about some of the tests. Also, this needs a changelog. Additionally, please make these changes against the 3006.x branch as these issue also exist there.

@twangboy twangboy added the test:full Run the full test suite label Jul 7, 2025
@twangboy twangboy added this to the Sulfur v3006.14 milestone Jul 7, 2025
@twangboy twangboy added needs-changelog needs-rebase Needs to be rebased, against either the current branch or a different one labels Jul 9, 2025
@xsmile xsmile changed the base branch from 3007.x to 3006.x July 9, 2025 18:29
Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few questions and changes. Thanks for adding a changelog.

@twangboy
Copy link
Contributor

twangboy commented Jul 9, 2025

Got some pre-commit failures

--- a/tests/integration/modules/test_cmdmod.py
+++ b/tests/integration/modules/test_cmdmod.py
@@ -590,9 +590,7 @@ class CMDModuleTest(ModuleCase):
         self.assertEqual(out, "")
 
         # cmd.run_stderr
-        out = self.run_function(
-            "cmd.shell", ls_command, shell=shell, hide_output=True
-        )
+        out = self.run_function("cmd.shell", ls_command, shell=shell, hide_output=True)
         self.assertEqual(out, "")

@xsmile
Copy link
Author

xsmile commented Jul 11, 2025

Would it do any harm to disable python_shell in the state module?

cmd=name, timeout=timeout, python_shell=True, **cmd_kwargs

cmd_all = __salt__["cmd.script"](source, python_shell=True, **cmd_kwargs)

twangboy
twangboy previously approved these changes Jul 15, 2025
@xsmile
Copy link
Author

xsmile commented Jul 17, 2025

Fixed tests and added two changes:

Thanks for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test:full Run the full test suite
Projects
None yet
2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/saltstack/salt/pull/68156

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy