Fail to add new users form UI

I get the following error when I try to add a new user form the admin panel:

[I 2024-10-28 11:48:48.073 JupyterHub auth:963] Creating user: adduser -q --gecos '""' --disabled-password test
[E 2024-10-28 11:48:48.099 JupyterHub users:225] Failed to create user: test
    Traceback (most recent call last):
      File "/usr/local/lib/python3.11/site-packages/jupyterhub/apihandlers/users.py", line 223, in post
        await maybe_future(self.authenticator.add_user(user))
      File "/usr/local/lib/python3.11/site-packages/jupyterhub/auth.py", line 902, in add_user
        await maybe_future(self.add_system_user(user))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.11/site-packages/jupyterhub/auth.py", line 968, in add_system_user
        raise RuntimeError(f"Failed to create system user {name}: {err}")
    RuntimeError: Failed to create system user test: adduser: Only root may add a user or group to the system.

I am admin and the config is the following:

config:
      AzureAdOAuthenticator:
        allow_all: true
        username_claim: unique_name
        oauth_callback_url: https://jupyterhub.test.run/hub/oauth_callback
        enable_auth_state: true
        admin_users:
            - admin_test
extraConfig:
    username_map: |
            import os
            from oauthenticator.azuread import LocalAzureAdOAuthenticator, AzureAdOAuthenticator
            c.LocalAzureAdOAuthenticator.create_system_users = True

            class subAzureAuthenticator(LocalAzureAdOAuthenticator):
                  
              def normalize_username(self, username):
                """Normalize the given username and return it
              
                Override in subclasses if usernames need different normalization rules.
        
                The default attempts to lowercase the username and apply `username_map` if it is
                set.
                """  
                username = username.lower().split('@')[0]
                clean_username = username.replace('.', '')
                clean_username =clean_username.replace('_', '')
                return clean_username
            c.JupyterHub.authenticator_class = subAzureAuthenticator

You’re subclassing LocalAzureAdOAuthenticator which creates local operating system users. Try subclassing AzureAdOAuthenticator instead.

1 Like