# Can't Change jupyter/datascience-notebook UID and GID

**URL:** <https://discourse.jupyter.org/t/cant-change-jupyter-datascience-notebook-uid-and-gid/24672>\
**Category:** JupyterHub\
**Created:** [March 21, 2024, 2:45am UTC](https://discourse.jupyter.org/t/cant-change-jupyter-datascience-notebook-uid-and-gid/24672 "2024-03-21T02:45:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![edp](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@edp](https://discourse.jupyter.org/u/edp)\
**Post date:** [March 21, 2024, 2:45am UTC](https://discourse.jupyter.org/t/cant-change-jupyter-datascience-notebook-uid-and-gid/24672/1 "2024-03-21T02:45:08Z")

</div>

Dear @manics

I deploy jupyter datascience-notebook on my k8s. and I have a lit bit problem with NB\_USER;NB\_UID;NB\_GID  
the image from: docker pull jupyter/datascience-notebook  
Our Notebook are use linux OpenLDAP authenticator.  
But When User Login. The notebook always jovyan and user id is 1000(I want use Users LDAP’s UID and GID)  
below is my helm value.yaml config.  
If you have free time , please help me to check

Thanks

# value.yaml

hub:  
revisionHistoryLimit:  
config:  
JupyterHub:  
# JupyterHub:  
authenticator\_class: ldapauthenticator.LDAPAuthenticator  
Authenticator:  
enable\_auth\_state: true  
LDAPAuthenticator:  
# See [GitHub - rroemhild/docker-test-openldap: Docker OpenLDAP Server for testing LDAP applications](https://github.com/rroemhild/docker-test-openldap#ldap-structure)  
# for users  
server\_address: 192.168.13.206  
lookup\_dn: True  
bind\_dn\_template: “uid={username},ou=People,dc=contoso,dc=local”  
allowed\_groups: “cn=jupyterhub,ou=Groups,dc=contoso,dc=local”  
user\_search\_base: “dc=contoso,dc=local”  
user\_attribute: uid  
lookup\_dn\_user\_dn\_attribute: cn  
escape\_userdn: True  
auth\_state\_attributes: [“uid”, “uidNumber”, “gidNumber”, “homeDirectory”]  
use\_lookup\_dn\_username: False

extraConfig:  
# copy from [Z2JH Hot to change NB\_UID/NB\_GID using authenticator\_class? - #14 by hiroyuki-sato](https://discourse.jupyter.org/t/z2jh-hot-to-change-nb-uid-nb-gid-using-authenticator-class/21777/14)  
SpawnerCustomConfig: |  
from ldapauthenticator import LDAPAuthenticator  
from hashlib import md5

```
  class LDAPAuthenticatorInfo(LDAPAuthenticator):
      async def pre_spawn_start(self, user, spawner):
          auth_state = await user.get_auth_state()

          if not auth_state:
              return

          self.log.info(f"pre_spawn_start auth_state: {auth_state}")
		  
          spawner.environment["NB_UID"] = str(auth_state["uidNumber"][0])
          spawner.environment["NB_USER"] = auth_state["uid"][0]
          spawner.environment["NB_GID"] = str(auth_state["gidNumber"][0])
          spawner.environment["CHOWN_HOME"] = "yes"
          spawner.environment["GRANT_SUDO"] = "yes"

          self.log.info(f"environment: {spawner.environment}")

CustomHubConfig: |
  c.JupyterHub.cleanup_servers = True

```

debug:  
enabled: true  
singleuser:

uid: 0  
fsGid: 100

---

<div class="post-metadata">

**Author:** ![hiroyuki-sato](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/hiroyuki-sato/32/10809_2.png) [@hiroyuki-sato](https://discourse.jupyter.org/u/hiroyuki-sato)\
**Post date:** [March 21, 2024, 7:35am UTC](https://discourse.jupyter.org/t/cant-change-jupyter-datascience-notebook-uid-and-gid/24672/2 "2024-03-21T07:35:24Z")

</div>

Hello, @edp

Have you ever tried set `cmd` part?

```auto
singleuser:
  cmd: #emtpy

```

> [@Z2JH Hot to change NB\_UID/NB\_GID using authenticator\_class?](https://discourse.jupyter.org/t/z2jh-hot-to-change-nb-uid-nb-gid-using-authenticator-class/21777/14):
>
> Hello, @manics. Thank you for your reply. It worked as I expected when I set belows: singieluser.cmd: (empty) don’t set NB\_UID explicitly Remove: c.Spawner.args = ['--allow-root'] singleuser.cmd worked as I expected if I set below. singleuser.cmd Result NG/OK no entry UID never changed NG cmd: (empty) UID changed OK cmd: start-singleuser.sh UID changed OK Removing NB\_UID I expect /home/bob links to /home/jovyan, but It create the new directory /home/bob. NFS mount point is /h…

---

<div class="post-metadata">

**Author:** ![edp](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@edp](https://discourse.jupyter.org/u/edp)\
**Post date:** [March 21, 2024, 9:43am UTC](https://discourse.jupyter.org/t/cant-change-jupyter-datascience-notebook-uid-and-gid/24672/3 "2024-03-21T09:43:50Z")

</div>

Thank for you reply @manics

> hub:  
> revisionHistoryLimit:  
> config:  
> JupyterHub:  
> # JupyterHub:  
> authenticator\_class: ldapauthenticator.LDAPAuthenticator  
> Authenticator:  
> enable\_auth\_state: true  
> LDAPAuthenticator:  
> # See [GitHub - rroemhild/docker-test-openldap: Docker OpenLDAP Server for testing LDAP applications](https://github.com/rroemhild/docker-test-openldap#ldap-structure)  
> # for users  
> server\_address: 192.168.13.206  
> lookup\_dn: True  
> bind\_dn\_template: “uid={username},ou=People,dc=contoso,dc=local”  
> allowed\_groups: “cn=jupyterhub,ou=Groups,dc=contoso,dc=local”  
> user\_search\_base: “dc=contoso,dc=local”  
> user\_attribute: uid  
> lookup\_dn\_user\_dn\_attribute: uid  
> escape\_userdn: True  
> auth\_state\_attributes: [“uid”, “uidNumber”, “gidNumber”, “homeDirectory”]  
> use\_lookup\_dn\_username: False  
> extraConfig:  
> SpawnerCustomConfig: |  
> #c.Spawner.cmd = [‘start.sh’,‘jupyterhub-singleuser’,‘–allow-root’]  
> #c.KubeSpawner.args = [‘–allow-root’]

```
  from ldapauthenticator import LDAPAuthenticator
  from ldapauthenticator import LDAPAuthenticator

  class LDAPAuthenticatorInfo(LDAPAuthenticator):
      async def pre_spawn_start(self, user, spawner):
          auth_state = await user.get_auth_state()

          print(f"--------------------------------------------------------")
          self.log.debug(f"-----------------------------------------------")
          self.log.debug(f"pre_spawn_start auth_state: {auth_state}")
          self.log.debug(f"-----------------------------------------------")
          print(f"--------------------------------------------------------")

          if not auth_state:
              return

          spawner.environment["NB_UID"] = str(auth_state["uidNumber"][0])
          spawner.environment["NB_GID"] = str(auth_state["gidNumber"][0])
          spawner.environment["NB_USER"] = auth_state["uid"][0]
          spawner.environment["CHOWN_HOME"] = "yes"
          spawner.environment["GRANT_SUDO"] = "yes"
          #self.log.debug(f"pre_spawn_start spawner.env: {spawner.environment}")

  c.JupyterHub.authenticator_class = LDAPAuthenticatorInfo

CustomHubConfig: |
  c.JupyterHub.cleanup_servers = True

```

if i setup  
singleuser:  
cmd: jupyterhub-singleuser # this is values.yaml’s default value  
the notebook default user is jovyan and uid:1000

if i setup:  
singleuser:  
cmd: # ← here i leave it blank  
the notebook default user is jovyan and uid:1000

also i can’t use kubectl logs or kubectl logs \<user’s-jupyter-pod-name\> find self.log.debug information. is this right configuration?

Thank you again @manics @hiroyuki-sato
