Skip to content
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
23 changes: 16 additions & 7 deletions jupyterhub_traefik_proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from subprocess import Popen, TimeoutExpired
from urllib.parse import urlparse, urlunparse

import bcrypt
from jupyterhub.proxy import Proxy
from jupyterhub.utils import exponential_backoff, new_token, url_path_join
from tornado.httpclient import AsyncHTTPClient, HTTPClientError
Expand Down Expand Up @@ -293,19 +294,28 @@ def _warn_empty_username(self):
)
return ""

traefik_api_hashed_password = Unicode()
traefik_api_hashed_password = Unicode(
config=True,
help="""
Set the hashed password to use for the API

If unspecified, `traefik_api_password` will be hashed with bcrypt.
ref: https://doc.traefik.io/traefik/middlewares/http/basicauth/
""",
)

@default("traefik_api_hashed_password")
def _generate_htpassword(self):
return bcrypt.hashpw(
self.traefik_api_password.encode("utf8"), bcrypt.gensalt()
).decode("ascii")

check_route_timeout = Integer(
30,
config=True,
help="""Timeout (in seconds) when waiting for traefik to register an updated route.""",
)

def _generate_htpassword(self):
from passlib.hash import apr_md5_crypt

self.traefik_api_hashed_password = apr_md5_crypt.hash(self.traefik_api_password)

async def _check_for_traefik_service(self, routespec, kind):
"""Check for an expected router or service in the Traefik API.

Expand Down Expand Up @@ -508,7 +518,6 @@ async def _setup_traefik_static_config(self):

async def _setup_traefik_dynamic_config(self):
self.log.debug("Setting up traefik's dynamic config...")
self._generate_htpassword()
api_url = urlparse(self.traefik_api_url)
api_path = api_url.path if api_url.path.strip("/") else '/api'
api_credentials = (
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
aiohttp
bcrypt
escapism
jupyterhub>=0.9
passlib
toml