Skip to content

feat: Add user management utilities and run-as-user functionality for…#27

Open
adrianlasota wants to merge 1 commit into
mainfrom
low_permission
Open

feat: Add user management utilities and run-as-user functionality for…#27
adrianlasota wants to merge 1 commit into
mainfrom
low_permission

Conversation

@adrianlasota
Copy link
Copy Markdown
Contributor

@adrianlasota adrianlasota commented May 13, 2026

This pull request adds comprehensive support for running commands as another user and managing local users on Windows targets via the RPyCConnection class. 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:

  • Added execute_command_as_user, create_user, and delete_user methods to RPyCConnection for running commands as another user and managing local users on Windows. These methods include detailed error handling and dispatch to platform-specific implementations.
  • Implemented a helper method (_ensure_remote_winapi_helper) to upload and manage a WinAPI-based script on the remote host for secure run-as-user execution.
  • Introduced a new exception, RunAsUserError, for handling invalid run-as-user execution scenarios.

Documentation updates:

  • Updated the README.md to 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:

  • Improved docstrings for several internal methods, clarifying their purpose and error handling. [1] [2] [3]
  • Added necessary imports and internal utility function usage for user management. [1] [2]

Copilot AI review requested due to automatic review settings May 13, 2026 15:59
@mfd-intel-bot
Copy link
Copy Markdown
Contributor

We don't publish DEVs .whl.
To build .whl, run 'pip install git+https://github.com/intel/mfd-connect@low_permission'

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.py helper that runs on the remote host and launches a process under another account via WinAPI.
  • New mfd_connect/util/account_utils.py with create_user / delete_user (Windows net user) and a new RunAsUserError exception.
  • RPyCConnection gains execute_command_as_user, create_user, delete_user, plus the _ensure_remote_winapi_helper upload 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.

Comment thread mfd_connect/rpyc.py Outdated
Comment thread mfd_connect/rpyc.py
Comment thread mfd_connect/rpyc.py Outdated
Comment thread mfd_connect/rpyc.py Outdated
@coveralls-official
Copy link
Copy Markdown

coveralls-official Bot commented May 13, 2026

Coverage Status

coverage: 78.58% (+0.4%) from 78.209% — low_permission into main

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Comment thread mfd_connect/rpyc.py Outdated
Comment thread mfd_connect/rpyc.py Outdated
Comment thread mfd_connect/util/runas_winapi_script.py
Comment thread mfd_connect/rpyc.py
Comment thread mfd_connect/util/account_utils.py
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread mfd_connect/rpyc.py Outdated
Comment thread mfd_connect/rpyc.py
Comment thread mfd_connect/rpyc.py
Comment thread mfd_connect/rpyc.py
… Windows

Signed-off-by: Lasota, Adrian <adrian.lasota@intel.com>
Comment thread mfd_connect/rpyc.py
: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:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

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.

5 participants