ปัญหา
การใช้ Jupyter Notebook/Lab (aka. Jupyter) นั้นมีข้อดีคือ เราสามารถจำกัดการเข้าถึงข้อมูลที่ละเอียดอ่อนได้ อย่างเช่นเราสามารถตั้งค่าการ access ของ database user ได้จาก private ip ของ Jupyter ได้ แต่ก็ยังมีช่องโหว่คือ ผู้ใช้สามารถ Export file แล้ว download ออกไปได้
** Caution: บันทึกนี้ไม่สามารถป้องการการ scp และ API call เพื่อ upload ไปยัง Google Drive, Owncloud ได้ **
ในที่นี้ ใช้ Jupyter ผ่าน Docker/Kubernetes
แนวทางการแก้ไข
Credit:
- https://stackoverflow.com/questions/54425431/disabling-downloads-on-jupyter-notebooks
- https://ujjwalbhardwaj.me/post/disable-download-button-on-the-sagemaker-jupyter-notebook/
เปิด Terminal แล้วพิมพ์คำสั่งต่อไปนี้ เพื่อปิด เมนู
# disable downloads from File > Download jupyter labextension disable @jupyterlab/docmanager-extension:download # disable downloads from the context menu in the file browser jupyter labextension disable @jupyterlab/filebrowser-extension:download

แต่ก็ยังมีทางให้เรียกผ่าน URL ได้อยู่ดี จึงต้อง disable การเรียกผ่าน HTTP protocol ได้ จึงต้องปิดด้วยการปิดการเรียก File handler อีกชั้น โดยประกอบด้วย 2 ขั้นตอน
1. การแก้ไขไฟล์ $HOME/.jupyter/jupyter_notebook_config.py
import os, sys sys.path.append('$HOME/.jupyter/') c.ContentsManager.files_handler_class = 'handlers.ForbidFilesHandler' c.ContentsManager.files_handler_params = {}
2. สร้างไฟล์ $HOME/.jupyter/handlers.py
# Creating ForbidFilesHandler class, overriding the default files_handler_class cat <<END >$HOME/.jupyter/handlers.py from tornado import web from notebook.base.handlers import IPythonHandler class ForbidFilesHandler(IPythonHandler): @web.authenticated def head(self, path): self.log.info("HEAD: File download forbidden.") raise web.HTTPError(403) @web.authenticated def get(self, path, include_body=True): self.log.info("GET: File download forbidden.") raise web.HTTPError(403) END
จากนั้น restart jupyter container
ผลคือ
หวังว่าจะเป็นประโยชน์ครับ