jupyterhub / kubespawner

Kubernetes spawner for JupyterHub
https://jupyterhub-kubespawner.readthedocs.io
BSD 3-Clause "New" or "Revised" License
541 stars 303 forks source link

Usernames that begin with special characters lead to k8s labels that are invalid. #730

Closed cniessigma closed 1 year ago

cniessigma commented 1 year ago

Bug description

Once of our users signed up to JupyterHub with an email that began with an underscore character. _@example.com. The Kuberspawner then takes this username and escapes it to am ostensibly Kubernetes friendly name by escaping it to -5f-40example-2ecom, which is not a valid label value since it starts with a hyphen.

Expected behaviour

The spawner to spawn a PVC and a Pod the user can access.

Actual behaviour

{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"PersistentVolumeClaim \"claim--5f-example-2ecom\" is invalid: metadata.labels: Invalid value: \"-5f-40example-2ecom\": a valid label must be an empty string or consist of alphanumeric c
haracters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')","reason":"Invalid","details":{"name":"claim--5f-40example-2ecom","kind":"Persistent
VolumeClaim","causes":[{"reason":"FieldValueInvalid","message":"Invalid value: \"-5f-40example-2ecom\": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or
 '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')","field":"metadata.labels"}]},"code":422

How to reproduce

  1. Create a user with a special character that needs escaping at the beginning of the email
  2. Attempt to spawn a pod

I have attempted to update the config to overwrite the labels by adding a prefix, but then I hit 403s when trying to log into the server, so I assume it needs to be set the way it is right now in the code itself

    labels.py: |
      c.KubeSpawner.extra_labels = {
        "hub.jupyter.org/username": "user-{username}",
      }

      c.KubeSpawner.storage_extra_labels = {
        "hub.jupyter.org/username": "user-{username}",
      }

Your personal set up

Zero to Jupyterhub (Chart version 2.0.0, app version 3.0.0), using the stock image.

welcome[bot] commented 1 year ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

hiteshbedre commented 1 year ago

Thanks for highlighting the issue. This issue is already reported: https://github.com/jupyterhub/kubespawner/issues/498