Auditing in jupyterhub

How can I audit Python commands/functions, along with the terminal commands run by users on spawned notebooks?
I have tried using Jupyter Telemetry, but it provides a very high-level of logging. Any help would be greatly appreciated.


If you’re looking for more detailed auditing of Python commands and terminal commands run by users in Jupyter notebooks, you might need to implement a custom solution. Here’s a general approach you can take:

  1. Custom Logging: Implement custom logging within your Jupyter environment. This involves intercepting and logging Python commands and terminal commands before they are executed.
  2. Hooks and Interception: You can utilize hooks and interception mechanisms provided by Jupyter or Python itself to intercept and log commands before execution. For Python code, you can use tools like sys.settrace() to trace function calls and code execution. For terminal commands, you might need to intercept system calls.
  3. Kernel-Level Logging: Since Jupyter notebooks run Python code through kernels, you might need to implement logging at the kernel level to capture Python commands. This could involve modifying or extending the Jupyter kernel.
  4. Custom Extensions: Develop custom Jupyter extensions or plugins to handle logging and auditing. These extensions can intercept and log commands at various stages of execution.
  5. External Monitoring: Consider using external monitoring tools or services that specialize in auditing and monitoring Python code execution and terminal commands. These tools can provide more detailed logging and analysis capabilities.
  6. Privacy and Security Considerations: Ensure that your auditing solution respects privacy and security concerns. Avoid logging sensitive information unless absolutely necessary, and implement appropriate access controls for the audit logs.

By combining these approaches, you can create a comprehensive auditing solution tailored to your specific requirements for logging Python commands and terminal commands in Jupyter notebooks.

1 Like

I ready this community post discussion but there doesn’t seem to be any solution to audit python commands. Kernel level logging seems like an option but doing that will require a really good understanding of its code base. Can you be bit more specific about what can be done.

Hey @Ayush_Singla,

You have to implement a custom logging within your jupyter environment.

I have tried logging via telemetry but other than that no. Are there any docs to implement this? If so can you point me to them.

I have a document related to this which I share with you. May be it will be helpful for you.
See this: Downloading and Analyzing Data Logs in Mission Planner — Copter documentation

Hope this will help you in solving your query.