Skip to content

bpo-41192: Add documentation to some undocumented audit events #21308

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 5 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions Doc/c-api/file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ the :mod:`io` APIs instead.

This function is safe to call before :c:func:`Py_Initialize`.

.. audit-event:: setopencodehook "" c.PyFile_SetOpenCodeHook

.. versionadded:: 3.8


Expand Down
26 changes: 26 additions & 0 deletions Doc/library/audit_events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,29 @@ information on handling these events.
specific documentation for actual events raised.

.. audit-event-table::

The following events are raised internally and do not correspond to any
public API of CPython:

+--------------------------+-------------------------------------------+
| Audit event | Arguments |
+==========================+===========================================+
| _winapi.CreateFile | ``file_name``, ``desired_access``, |
| | ``share_mode``, ``creation_disposition``, |
| | ``flags_and_attributes`` |
+--------------------------+-------------------------------------------+
| _winapi.CreateJunction | ``src_path``, ``dst_path`` |
+--------------------------+-------------------------------------------+
| _winapi.CreateNamedPipe | ``name``, ``open_mode``, ``pipe_mode`` |
+--------------------------+-------------------------------------------+
| _winapi.CreatePipe | |
+--------------------------+-------------------------------------------+
| _winapi.CreateProcess | ``application_name``, ``command_line``, |
| | ``current_directory`` |
+--------------------------+-------------------------------------------+
| _winapi.OpenProcess | ``process_id``, ``desired_access`` |
+--------------------------+-------------------------------------------+
| _winapi.TerminateProcess | ``handle``, ``exit_code`` |
+--------------------------+-------------------------------------------+
| ctypes.PyObj_FromPtr | ``obj`` |
+--------------------------+-------------------------------------------+
3 changes: 1 addition & 2 deletions Doc/library/ctypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ They are instances of a private class:
``ctypes.seh_exception`` with argument ``code`` will be raised, allowing an
audit hook to replace the exception with its own.

.. audit-event:: ctypes.call_function func_pointer,arguments ctype-foreign-functions
.. audit-event:: ctypes.call_function func_pointer,arguments foreign-functions

Some ways to invoke foreign function calls may raise an auditing event
``ctypes.call_function`` with arguments ``function pointer`` and ``arguments``.
Expand Down Expand Up @@ -2545,4 +2545,3 @@ Arrays and pointers

Returns the object to which to pointer points. Assigning to this
attribute changes the pointer to point to the assigned object.

2 changes: 2 additions & 0 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,8 @@ are always available. They are listed here in alphabetical order.

.. impl-detail:: This is the address of the object in memory.

.. audit-event:: builtins.id id id


.. function:: input([prompt])

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/poplib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The :mod:`poplib` module provides two classes:

.. audit-event:: poplib.connect self,host,port poplib.POP3_SSL

.. audit-event:: poplib.putline self,line popplib.POP3_SSL
.. audit-event:: poplib.putline self,line poplib.POP3_SSL

All commands will raise an :ref:`auditing event <auditing>`
``poplib.putline`` with arguments ``self`` and ``line``,
Expand Down
10 changes: 8 additions & 2 deletions Doc/library/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ Standard names are defined for the following types:
The type of user-defined functions and functions created by
:keyword:`lambda` expressions.

.. audit-event:: function.__new__ code types.FunctionType

The audit event only occurs for direct instantiation of function objects,
and is not raised for normal compilation.


.. data:: GeneratorType

Expand Down Expand Up @@ -138,10 +143,11 @@ Standard names are defined for the following types:

The type for code objects such as returned by :func:`compile`.

.. audit-event:: code.__new__ code,filename,name,argcount,posonlyargcount,kwonlyargcount,nlocals,stacksize,flags CodeType
.. audit-event:: code.__new__ code,filename,name,argcount,posonlyargcount,kwonlyargcount,nlocals,stacksize,flags types.CodeType

Note that the audited arguments may not match the names or positions
required by the initializer.
required by the initializer. The audit event only occurs for direct
instantiation of code objects, and is not raised for normal compilation.

.. method:: CodeType.replace(**kwargs)

Expand Down
18 changes: 18 additions & 0 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,12 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances.
result of implicit invocation via language syntax or built-in functions.
See :ref:`special-lookup`.

.. audit-event:: object.__getattr__ obj,name object.__getattribute__

For certain sensitive attribute accesses, raises an
:ref:`auditing event <auditing>` ``object.__getattr__`` with arguments
``obj`` and ``name``.


.. method:: object.__setattr__(self, name, value)

Expand All @@ -1551,12 +1557,24 @@ access (use of, assignment to, or deletion of ``x.name``) for class instances.
call the base class method with the same name, for example,
``object.__setattr__(self, name, value)``.

.. audit-event:: object.__setattr__ obj,name,value object.__setattr__

For certain sensitive attribute assignments, raises an
:ref:`auditing event <auditing>` ``object.__setattr__`` with arguments
``obj``, ``name``, ``value``.


.. method:: object.__delattr__(self, name)

Like :meth:`__setattr__` but for attribute deletion instead of assignment. This
should only be implemented if ``del obj.name`` is meaningful for the object.

.. audit-event:: object.__delattr__ obj,name object.__delattr__

For certain sensitive attribute deletions, raises an
:ref:`auditing event <auditing>` ``object.__delattr__`` with arguments
``obj`` and ``name``.


.. method:: object.__dir__(self)

Expand Down
2 changes: 1 addition & 1 deletion Doc/using/cmdline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ conflict.
the interactive session. You can also change the prompts :data:`sys.ps1` and
:data:`sys.ps2` and the hook :data:`sys.__interactivehook__` in this file.

.. audit-event:: cpython.run_startup filename PYTHONSTARTUP
.. audit-event:: cpython.run_startup filename envvar-PYTHONSTARTUP

Raises an :ref:`auditing event <auditing>` ``cpython.run_startup`` with
the filename as the argument when called on startup.
Expand Down