Skip to content

Commit 4a510b2

Browse files
authored
Merge pull request #3721 from minrk/warn-invalid-config
raise on invalid top-level keys in hub.config
2 parents 151bd28 + 7e6c118 commit 4a510b2

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

jupyterhub/files/hub/jupyterhub_config.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,16 +478,33 @@ def camelCaseify(s):
478478
c.CryptKeeper.keys = get_secret_value("hub.config.CryptKeeper.keys").split(";")
479479

480480
# load hub.config values, except potentially seeded secrets already loaded
481-
for app, cfg in get_config("hub.config", {}).items():
482-
if app == "JupyterHub":
481+
for section, cfg in get_config("hub.config", {}).items():
482+
if section == "JupyterHub":
483483
cfg.pop("proxy_auth_token", None)
484484
cfg.pop("cookie_secret", None)
485485
cfg.pop("services", None)
486-
elif app == "ConfigurableHTTPProxy":
486+
elif section == "ConfigurableHTTPProxy":
487487
cfg.pop("auth_token", None)
488-
elif app == "CryptKeeper":
488+
elif section == "CryptKeeper":
489489
cfg.pop("keys", None)
490-
c[app].update(cfg)
490+
491+
if not section[:1].isupper():
492+
# traitlets config sections are Configurable class names
493+
# that MUST start with upper-case
494+
# if it starts with lowercase, it must be a mistake
495+
# (e.g. putting `hub.loadRoles` under `hub.config.loadRoles`),
496+
# and will have no effect, so warn or raise here
497+
print(
498+
f"FATAL: Invalid hub.config section name: {section}."
499+
" hub.config sections must be Configurable class names (e.g. JupyterHub)."
500+
" Maybe misplaced or misspelled config?",
501+
file=sys.stderr,
502+
)
503+
# make this fatal:
504+
sys.exit(1)
505+
506+
print(f"Loading pass-through config section hub.config.{section}")
507+
c[section].update(cfg)
491508

492509
# load /usr/local/etc/jupyterhub/jupyterhub_config.d config files
493510
config_dir = "/usr/local/etc/jupyterhub/jupyterhub_config.d"

jupyterhub/values.schema.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ properties:
207207
for more info.
208208
config:
209209
type: object
210-
additionalProperties: true
210+
additionalProperties: false
211211
description: |
212212
JupyterHub and its components (authenticators, spawners, etc), are
213213
Python classes that expose its configuration through
@@ -271,6 +271,18 @@ properties:
271271
the `--values` or `-f` flag. During merging, lists are replaced while
272272
dictionaries are updated.
273273
```
274+
# check that the first character is Capital,
275+
# which is required for valid section names
276+
# can't know all possible Configurable class names in advance, though
277+
patternProperties:
278+
"^[A-Z].*$":
279+
type: object
280+
additionalProperties: true
281+
description: |
282+
Pass-through traitlets configuration of Configurable classes.
283+
Keys must always be class names that start with capitals,
284+
and values must be objects.
285+
274286
properties:
275287
JupyterHub:
276288
type: object

0 commit comments

Comments
 (0)