Jupyter notebook not trusted
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Jupyter Notebooks are an essential tool for data scientists and developers due to their ability to combine code execution, text, visualizations, and rich media in a web-based interface. However, a common issue users encounter is the "Notebook Not Trusted" status, which can raise concerns about the execution of notebook content and the security implications of running untrusted code.
Understanding Jupyter's Trust System
In Jupyter, trust is a mechanism designed to manage the execution of potentially unsafe code. When a notebook is opened in Jupyter, it evaluates the trustworthiness of the notebook based on signatures. A "Notebook Not Trusted" status means that Jupyter does not have a record of signing the notebook and, as a result, it disables the execution of potentially unsafe content like custom JavaScript or HTML embedded in Markdown cells.
Mechanism of Trust
- Notebook Metadata: Each notebook contains metadata, which includes a digital signature assigned by Jupyter whenever it saves a notebook that has been executed in its environment.
- Signature Verification: When a notebook is loaded, Jupyter checks if the signature in the metadata matches a record in its database of executed, trusted notebooks on the user's machine.
- Trust Decision: If a match is found, the notebook is marked as "Trusted." If not, it remains "Not Trusted."
Why Trust Matters in Jupyter
The primary reason behind the trust system is to prevent unintentional execution of malicious code. Consider a scenario where a notebook from an untrusted source includes JavaScript that could manipulate the user's browser or perform data exfiltration.
Potential Risks
- Malicious Code Execution: Embedded scripts can execute harmful operations if the notebook is trusted without verification.
- Data Breaches: Sensitive data could be compromised by unverified code that reads or modifies user's files or environment.
- System Integrity Threats: Hard-to-detect scripts might alter system configurations or even inject backdoors.
Resolving "Notebook Not Trusted" Status
To work with a notebook that is not trusted, users must manually trust the notebook. Below are steps and precautions to follow.
Trusting a Notebook
- User Interface Option:
- Open the notebook in Jupyter.
- A button or message will prompt you to trust the notebook, often labeled as "Not Trusted". Click this to trust it.
- Command Line:
- Execute the following command in the terminal:
- Review the Code: Inspect the content of the notebook thoroughly before trusting it, especially if obtained from unknown sources.
- Environment Isolation: Consider running the notebook in a controlled environment like Docker or virtual environments where its access permissions are limited.
- Version Control: Track changes with version control systems like Git to monitor and revert unauthorized modifications.
- When a notebook is saved, the content of the notebook, excluding transient outputs, is hashed.
- The generated hash is stored alongside a digital signature in a database file, usually located at `~/.local/share/jupyter/nbsignatures.db`.
- Upon loading a notebook, Jupyter re-calculates the hash and checks it against the database. A match confirms trust.
- Open Notebook: `mypythonproject.ipynb`
- Hash Check: Calculate hash of the notebook content.
- Database Lookup: Compare the hash with records in `nbsignatures.db`.
- Result:
- Match: Notebook is trusted.
- No Match: Notebook remains untrusted.
Related reading
- jupyter notebook's kernel keeps dying when I run the code
- K-means algorithm variation with equal cluster size
- k means cluster method score negative
- K Nearest-Neighbor Algorithm
- JWT decoding with Spring Security
- JWT 'module' object has no attribute 'encode
- Kafka -> Flink DataStream -> MongoDB
- kafka consumer in R

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.