==============
Managing users
==============

Managing access to Data Science & AI Workbench involves adding and removing users, setting passwords, 
:doc:`mapping users to roles, and optionally assigning them to groups <groups>`. To help expedite the process of authorizing large groups of users at once, you can :doc:`connect to an external identity provider <external-id-prov>` using LDAP, Active Directory, SAML, or Kerberos to federate those users.

.. note::

   To be able to perform these actions, you'll need the appropriate login credentials required to access the Administrative Console's Authentication Center. 

The process of authorizing Operations Center Admins is slightly different. See :doc:`admins` for more information.

Creating and configuring users
==============================

.. _access_kc:

**To access the Authentication Center:**

#. Open the |circle-user| **My Account** dropdown menu and select *Admin Console*.
#. Select |link-out| **Manage Users** to access the Keycloak user interface (UI). 
#. Log in using your Keycloak admin account credentials. 

    .. note::

        To create and manage other Authentication Center Admins, use the realm selector in the upper-left corner to switch to the **Master** realm before proceeding. 


        .. thumbnail:: ../../images/master-realm.png
            :align: center

#. Select **Users** from the left-hand navigation.
#. On the **Lookup** tab, click **View all users** to list every user in the system, or search the user database for all users that match the criteria you enter, based on their first name, last name, or email address.
   
   .. note::
      This will search the local user database and not the federated database (such as LDAP) because not all external identity provider systems include a way to page through users. If you want users from a federated database to be synced into the local database, select **User Federation** in the Configure menu on the left, and adjust the **Sync Settings** for your user federation provider.

#. **To create a new Workbench user**, click **Add user** and specify a user name---and optionally provide values for the other fields---before clicking **Save**. 

   .. note::
      Usernames containing unicode characters---special characters, punctuation, symbols, spaces---are not permitted.

#. **To configure a user**, click the user's ID in the list and use the available tabs as follows:

   * Use the **Details** tab to specify information for the user, optionally enable :ref:`user registration<user-reg>` and :ref:`required actions<required-actions>` and :ref:`impersonate the user<user-impersonation>`. If you include an email address, an invitation to join Workbench will be sent to the email address specified. 

   * Use the **Credentials** tab to manage the user's password. If the **Temporary** switch is on, this new password can only be used once---the user will be asked to change their password after they use it to log in to Workbench.

   * Use the **Role Mappings** tab to assign the user one or more roles, and the **Groups** tab to add them to one or more groups. See :doc:`managing roles and groups <groups>` for more information.
   
   .. note::
      To grant **Authentication Center Administrators** sufficient authority to manage Workbench users, you'll need to assign them the ``admin`` role. 

   .. thumbnail:: ../../images/admin-role.png
      :align: center

   * Use the **Sessions** tab to view a summary of all sessions the user has started, and log them out of all sessions in a single click. This is handy if a user goes on vacation without logging out of their sessions. You can use the Operations Center to view a summary of all sessions running on specific nodes or by specific users. See :doc:`monitoring sessions and deployments<../resources/gravity/monitor-sessions-deps>` for more information.

**To view and edit a set of fine grain permissions** that you can enable and use to define policies for allowing other users to manage users in the selected realm, return to the Users list and select the **Permissions** tab: 

.. thumbnail:: ../../images/users-permissions.png
   :align: center
   
--------------

.. |icon| image:: ../../images/icons/menu.png
          :width: 25 px

Add a new master realm admin user/Reset password 
================================================

Follow these steps from the command line to add a new admin user to the master realm *or* to reset your admin password if you're locked out or have forgotten your password.
 
#. Exec into the Keycloak container::

    # Replace <KEYCLOAK_CONTAINER_ID> with your keycloak container ID
    docker exec -it <KEYCLOAK_CONTAINER_ID> /bin/bash

#. Create a user::

    # Replace <USERNAME> with your username and <PASSWORD> with your password
    /opt/jboss/keycloak/bin/add-user-keycloak.sh -u <USERNAME> -p <PASSWORD> -r master --roles=admin

#. Restart the server. Restarting the server will delete the container and any current state::

    /opt/jboss/keycloak/bin/standalone.sh -Djboss.socket.binding.port-offset=100

#. Log in to Keycloak from the following URL::

    # Replace <FQDN> with your fully qualified domain name
    <https://<FQDN>/auth/admin/master/console>.

--------------      

.. _user-reg:

Enabling user registration
==========================

You can use the Authentication Center to enable users to self register and create their own account. When enabled, the login page will have a **Register** link users can click to open the registration page where they can enter the user profile information and password required to create their new account.

#. Click **Realm Settings** under Configure in the menu on the left menu.

#. Click the **Login** tab, and enable the **User registration** switch.

.. thumbnail:: ../../images/user-registration.png
   :align: center

You can change the look and feel of the registration form as well as
removing or adding additional fields that must be entered. See the
`Server Developer Guide
<https://www.keycloak.org/docs/latest/server_development/index.html>`_
for more information.

--------------

.. _required-actions:

Enabling required actions
=========================

You can use the **Required User Actions** drop-down list---on the **Details** tab for each user---to select the tasks that a user must complete (after providing their credentials) before they are allowed to log in to Workbench:

Update Profile
    This requires the user to update their profile information, such as their name, address, email, and phone number.

Update Password
    When set, a user must change their password.

Configure OTP
    When set, a user must configure a one-time password generator on
    their mobile device using either the Free OTP or Google
    Authenticator application.

Setting default required actions
--------------------------------

You can specify default required actions that will be added to all new user accounts. Select **Authentication** from the Configure menu on the left and use the **Required Actions** tab to specify whether you want each required action to be enabled---available for selection---or also pre-populated as a default for all new users. 

.. note::
   A required action must be enabled to be specified as a default.

.. thumbnail:: ../../images/default-required-actions.png
   :align: center

Using terms and conditions
--------------------------

Many organizations have a requirement that when a new user logs in for
the first time, they need to agree to the terms and conditions of the
website. This functionality can be implemented as a
required action, but it requires some configuration. In addition to enabling
**Terms and Conditions** as a required action, you must also edit the ``terms.ftl`` file
in the *base* login theme. See the `Server Developer Guide
<https://www.keycloak.org/docs/latest/server_development/index.html>`_
for more information on extending and creating themes.

--------------

.. _user-impersonation:

Impersonating users
===================

It is often useful for an Administrator to impersonate a user. For example, a
user may be experiencing an issue using an application and an Admin
may want to impersonate the user to see if they can duplicate the
problem. 

.. note::
   Any user with the realm's ``impersonation`` role can impersonate a user.

The **Impersonate** command is available from both the Users list and the **Details** tab for a user.

.. thumbnail:: ../../images/impersonate.png
   :align: center

Click **Impersonate** to display a list of applications the user has accessed on the platform, including editor sessions and deployments. 

.. thumbnail:: ../../images/applications.png
   :align: center

Click the ``Anaconda Platform`` link to interact with Workbench as the impersonated user.

.. thumbnail:: ../../images/anaconda_platform.png
   :align: center

.. note::
   If the Admin and the user are in the same realm, the Admin will be logged out and automatically logged in as the user being impersonated. If the Admin and user are not in the same realm, the Admin will remain logged in and be logged in as the user in that user's realm.

.. |circle-user| raw:: html
   
   <svg height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 496c-54 0-103.9-17.9-144-48v0c0-61.9 50.1-112 112-112h64c61.9 0 112 50.1 112 112v0c5.3-4 10.4-8.2 15.4-12.6C409.1 370.6 354.5 320 288 320H224c-66.5 0-121.1 50.6-127.4 115.4C47.2 391.5 16 327.4 16 256C16 123.5 123.5 16 256 16s240 107.5 240 240s-107.5 240-240 240zm0 16A256 256 0 1 0 256 0a256 256 0 1 0 0 512zm80-304a80 80 0 1 0 -160 0 80 80 0 1 0 160 0zm-80-64a64 64 0 1 1 0 128 64 64 0 1 1 0-128z"/></svg>

.. |link-out| raw:: html

    <svg height="1em" width="1em" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M320 33c0-18.2 14.8-33 33-33H480c17.7 0 32 14.3 32 32V159c0 18.2-14.8 33-33 33c-8.7 0-17.1-3.5-23.3-9.7L404 130.6 235.3 299.3c-6.2 6.2-16.4 6.2-22.6 0s-6.2-16.4 0-22.6L381.4 108 329.7 56.3C323.5 50.1 320 41.7 320 33zm33-1c-.5 0-1 .4-1 1c0 .3 .1 .5 .3 .7L478.3 159.7c.2 .2 .4 .3 .7 .3c.5 0 1-.4 1-1V32H353zM0 96C0 60.7 28.7 32 64 32H208c8.8 0 16 7.2 16 16s-7.2 16-16 16H64C46.3 64 32 78.3 32 96V448c0 17.7 14.3 32 32 32H416c17.7 0 32-14.3 32-32V304c0-8.8 7.2-16 16-16s16 7.2 16 16V448c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64V96z"/></svg>