Skip to content

Commit cc55242

Browse files
committed
allow explicit traefik_api_hashed_password, use bcrypt for hashing api password
instead of passlib md5 use default generator for traefik_api_hashed_password
1 parent 1c32ff1 commit cc55242

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

jupyterhub_traefik_proxy/proxy.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,19 +293,30 @@ def _warn_empty_username(self):
293293
)
294294
return ""
295295

296-
traefik_api_hashed_password = Unicode()
296+
traefik_api_hashed_password = Unicode(
297+
config=True,
298+
help="""
299+
Set the hashed password to use for the API
300+
301+
If unspecified, `traefik_api_password` will be hashed with bcrypt.
302+
ref: https://doc.traefik.io/traefik/middlewares/http/basicauth/
303+
""",
304+
)
305+
306+
@default("traefik_api_hashed_password")
307+
def _generate_htpassword(self):
308+
import bcrypt
309+
310+
return bcrypt.hashpw(
311+
self.traefik_api_password.encode("utf8"), bcrypt.gensalt()
312+
).decode("ascii")
297313

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

304-
def _generate_htpassword(self):
305-
from passlib.hash import apr_md5_crypt
306-
307-
self.traefik_api_hashed_password = apr_md5_crypt.hash(self.traefik_api_password)
308-
309320
async def _check_for_traefik_service(self, routespec, kind):
310321
"""Check for an expected router or service in the Traefik API.
311322
@@ -508,7 +519,6 @@ async def _setup_traefik_static_config(self):
508519

509520
async def _setup_traefik_dynamic_config(self):
510521
self.log.debug("Setting up traefik's dynamic config...")
511-
self._generate_htpassword()
512522
api_url = urlparse(self.traefik_api_url)
513523
api_path = api_url.path if api_url.path.strip("/") else '/api'
514524
api_credentials = (

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
aiohttp
2+
bcrypt
23
escapism
34
jupyterhub>=0.9
4-
passlib
55
toml

0 commit comments

Comments
 (0)