feat: Add user management utilities and run-as-user functionality for…#27
feat: Add user management utilities and run-as-user functionality for…#27adrianlasota wants to merge 1 commit into
Conversation
|
We don't publish DEVs .whl. |
There was a problem hiding this comment.
Pull request overview
Adds Windows-only "run command as another user" support to RPyCConnection, plus local user create/delete utilities. The run-as-user path uploads a small WinAPI helper script (using CreateProcessWithLogonW, plus WinSta/Desktop ACL grants) to the remote host and executes the user-supplied command via a generated cmd.exe runner batch file, capturing stdout/stderr/return code through files.
Changes:
- New
mfd_connect/util/runas_winapi_script.pyhelper that runs on the remote host and launches a process under another account via WinAPI. - New
mfd_connect/util/account_utils.pywithcreate_user/delete_user(Windowsnet user) and a newRunAsUserErrorexception. RPyCConnectiongainsexecute_command_as_user,create_user,delete_user, plus the_ensure_remote_winapi_helperupload helper; documentation and unit tests added.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| mfd_connect/util/runas_winapi_script.py | Remote WinAPI helper using CreateProcessWithLogonW with WinSta/Desktop ACL grants. |
| mfd_connect/util/account_utils.py | OS-dispatching create_user/delete_user utilities (Windows net user). |
| mfd_connect/exceptions.py | Adds RunAsUserError. |
| mfd_connect/rpyc.py | New run-as-user flow, helper upload, and user management methods on RPyCConnection. |
| README.md | Documents the new run-as-user / user management API with an example. |
| tests/unit/test_mfd_connect/test_utils/test_runas_winapi_script.py | Unit tests for the WinAPI helper script. |
| tests/unit/test_mfd_connect/test_utils/test_account_utils.py | Unit tests for create_user/delete_user utilities. |
| tests/unit/test_mfd_connect/test_rpyc.py | Tests for _ensure_remote_winapi_helper, run-as-user dispatch, and user management delegation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f330f95 to
2eff6cc
Compare
2eff6cc to
123b044
Compare
123b044 to
90abe12
Compare
90abe12 to
ff3dc93
Compare
ff3dc93 to
4e85b89
Compare
… Windows Signed-off-by: Lasota, Adrian <adrian.lasota@intel.com>
4e85b89 to
9296e3e
Compare
| :return: Completed process result for executed command. | ||
| :raises RunAsUserError: If called on non-Windows host or credentials are missing. | ||
| """ | ||
| if self._os_type != OSType.WINDOWS: |
There was a problem hiding this comment.
It won't be called in any case as check is already done before call of this method. IMHO if method is called windows, this os check shouldn't be here but level up only
This pull request adds comprehensive support for running commands as another user and managing local users on Windows targets via the
RPyCConnectionclass. It introduces new methods for user lifecycle operations, ensures robust handling and cleanup of temporary resources, and improves documentation and error handling for these features.Windows run-as-user and user management features:
execute_command_as_user,create_user, anddelete_usermethods toRPyCConnectionfor running commands as another user and managing local users on Windows. These methods include detailed error handling and dispatch to platform-specific implementations._ensure_remote_winapi_helper) to upload and manage a WinAPI-based script on the remote host for secure run-as-user execution.RunAsUserError, for handling invalid run-as-user execution scenarios.Documentation updates:
README.mdto document the new Windows run-as-user and user management features, including usage examples and notes on platform support. [1] [2]Internal improvements and refactoring: