Fixed: CORS Error by providing user server with necessary policies, also removed dead code

This commit is contained in:
2025-09-15 21:55:33 +02:00
parent 6606b874e5
commit ded70d1c71

View File

@@ -1,16 +1,9 @@
import os import os
import sys
from dockerspawner import DockerSpawner from dockerspawner import DockerSpawner
from jupyterhub.utils import random_port
from nativeauthenticator import NativeAuthenticator from nativeauthenticator import NativeAuthenticator
import subprocess
# from nbgrader.auth import JupyterHubAuthPlugin
from traitlets import Unicode, Bool, Int, Float
import secrets import secrets
import string import string
from datetime import datetime, timedelta
from typing import Optional from typing import Optional
@@ -40,21 +33,6 @@ def generate_api_token(
return token return token
def is_service_available_cmd(host, port):
"""Check service using system commands"""
try:
subprocess.run(
["nc", "-z", host, str(port)],
check=True,
timeout=3,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
return True
except (subprocess.TimeoutExpired, subprocess.CalledProcessError):
return False
# Configuration file for JupyterHub # Configuration file for JupyterHub
c = get_config() c = get_config()
@@ -139,60 +117,18 @@ c.Spawner.ip = "0.0.0.0"
c.DockerSpawner.mem_limit = os.environ.get("NOTEBOOK_MEMORY_LIMIT", "500M") c.DockerSpawner.mem_limit = os.environ.get("NOTEBOOK_MEMORY_LIMIT", "500M")
c.DockerSpawner.cpu_limit = float(os.environ.get("NOTEBOOK_CPU_LIMIT", "1.0")) c.DockerSpawner.cpu_limit = float(os.environ.get("NOTEBOOK_CPU_LIMIT", "1.0"))
# Fixing CORS because Nginx
""" # this isn't a security risk because the container is served behind nginx
# Services configuration for NBGrader # this only affects the traffic within the docker network itself
c.JupyterHub.services = [ c.Spawner.args = [
{ "--ServerApp.allow_origin=*",
'name': 'nbgrader-formgrader', "--ServerApp.allow_credentials=True",
'url': 'http://127.0.0.1:9999', "--ServerApp.disable_check_xsrf=True",
'command': [ "--NotebookApp.allow_origin=*",
'jupyter-nbgrader', "--NotebookApp.allow_credentials=True",
'--port=9999', "--NotebookApp.disable_check_xsrf=True",
'--no-browser', '--ServerApp.tornado_settings={"headers": {"Access-Control-Allow-Origin": "*"}}',
'--log-level=INFO'
],
'cwd': '/srv/jupyterhub/courses',
'user': 'root',
'environment': {
'PYTHONPATH': '/srv/nbgrader',
'NBGRADER_CONFIG_FILE': '/srv/jupyterhub/nbgrader/nbgrader_config.py'
}
}
] ]
"""
"""
# NBGrader configuration
c.JupyterHub.load_groups = {
'nbgrader-instructors': ['instructor'],
'nbgrader-students': []
}
"""
"""
# NBGrader Config
c.JupyterHub.services = [
{
'name': 'nbgrader-formgrader',
'url': 'http://127.0.0.1:9999',
'api_token': generate_api_token(prefix='nbgrader'),
'command': [
'python', '-m', 'nbgrader', 'formgrader',
#'--port=9999',
#'--no-browser',
'--log-level=INFO',
#'--base_url=/jupyter/services/nbgrader-formgrader',
'--debug'
],
'environment': {
'JUPYTERHUB_SERVICE_URL': 'http://127.0.0.1:8081/jupyter/hub/api',
'NBGRADER_CONFIG_FILE': '/srv/nbgrader/nbgrader_config.py',
'PYTHONPATH': '/srv/nbgrader'
},
'cwd': '/srv/nbgrader/courses',
'user': 'root'
}
]
"""
# Security settings # Security settings
c.JupyterHub.cookie_secret_file = "/srv/jupyterhub/cookie_secret" c.JupyterHub.cookie_secret_file = "/srv/jupyterhub/cookie_secret"