8000 gh-135543: emit ``sys.remote_exec`` audit event when ``sys.remote_exec`` has been called by Zheaoli · Pull Request #135544 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-135543: emit sys.remote_exec audit event when sys.remote_exec has been called #135544

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

Merged
merged 24 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/library/sys.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,11 @@ always available. Unless explicitly noted otherwise, all variables are read-only
interpreter is pre-release (alpha, beta, or release candidate) then the
local and remote interpreters must be the same exact version.

.. audit-event:: remove_exec pid script_path

When the code is executed in the remote process, an :ref:`auditing event <auditing>`
``remove_exec`` is raised with the *pid* and the path to the script file.

.. audit-event:: remote_debugger_script script_path

When the script is executed in the remote process, an
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -2114,11 +2114,18 @@ def audit_hook(event, arg):
script = '''
print("Remote script executed successfully!")
'''
remote_exec_event_triggered = False
def audit_hook(event, arg):
if event == "remote_exec":
nonlocal remote_exec_event_triggered
remote_exec_event_triggered = True
sys.addaudithook(audit_hook)
returncode, stdout, stderr = self._run_remote_exec_test(script, prologue=prologue)
self.assertEqual(returncode, 0)
self.assertIn(b"Remote script executed successfully!", stdout)
self.assertIn(b"Audit event: remote_debugger_script, arg: ", stdout)
self.assertEqual(stderr, b"")
self.assertTrue(remote_exec_event_triggered)

def test_remote_exec_with_exception(self):
"""Test remote exec with an exception raised in the target process
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
emit ``sys.remote_exec`` audit event when ``sys.remote_exec`` has been
called
4 changes: 4 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,10 @@ sys_remote_exec_impl(PyObject *module, int pid, PyObject *script)
PyObject *path;
const char *debugger_script_path;

if (PySys_Audit("remote_exec", "iO", pid, script) < 0) {
return NULL;
}

if (PyUnicode_FSConverter(script, &path) == 0) {
return NULL;
}
Expand Down
Loading
0