Configuring an htpasswd identity provider

    To define an htpasswd identity provider, perform the following tasks:

    1. Create an htpasswd file to store the user and password information.

    2. to represent the htpasswd file.

    3. Define an htpasswd identity provider resource that references the secret.

    4. to the default OAuth configuration to add the identity provider.

    By default, only a kubeadmin user exists on your cluster. To specify an identity provider, you must create a custom resource (CR) that describes that identity provider and add it to the cluster.

    About htpasswd authentication

    Using htpasswd authentication in OKD allows you to identify users based on an htpasswd file. An htpasswd file is a flat file that contains the user name and hashed password for each user. You can use the htpasswd utility to create this file.

    See one of the following sections for instructions about how to create the htpasswd file:

    To use the htpasswd identity provider, you must generate a flat file that contains the user names and passwords for your cluster by using htpasswd.

    Prerequisites

    • Have access to the htpasswd utility. On Red Hat Enterprise Linux this is available by installing the httpd-tools package.

    Procedure

    1. Create or update your flat file with a user name and hashed password:

      The command generates a hashed version of the password.

      For example:

      1. $ htpasswd -c -B -b users.htpasswd user1 MyPassword!

      Example output

      1. Adding password for user user1
    2. Continue to add or update credentials to the file:

      1. $ htpasswd -B -b </path/to/users.htpasswd> <user_name> <password>

    Creating an htpasswd file using Windows

    To use the htpasswd identity provider, you must generate a flat file that contains the user names and passwords for your cluster by using htpasswd.

    Prerequisites

    • Have access to htpasswd.exe. This file is included in the \bin directory of many Apache httpd distributions.

    Procedure

    1. Create or update your flat file with a user name and hashed password:

      1. > htpasswd.exe -c -B -b <\path\to\users.htpasswd> <user_name> <password>

      For example:

      1. > htpasswd.exe -c -B -b users.htpasswd user1 MyPassword!

      Example output

      1. Adding password for user user1
    2. Continue to add or update credentials to the file:

      1. > htpasswd.exe -b <\path\to\users.htpasswd> <user_name> <password>

    Creating the htpasswd secret

    To use the htpasswd identity provider, you must define a secret that contains the htpasswd user file.

    Prerequisites

    • Create an htpasswd file.

    Procedure

    The following custom resource (CR) shows the parameters and acceptable values for an htpasswd identity provider.

    htpasswd CR

    1. apiVersion: config.openshift.io/v1
    2. kind: OAuth
    3. metadata:
    4. name: cluster
    5. spec:
    6. identityProviders:
    7. - name: my_htpasswd_provider (1)
    8. mappingMethod: claim (2)
    9. type: HTPasswd
    10. htpasswd:
    11. fileData:
    12. name: htpass-secret (3)

    Additional resources

    • See for information on parameters, such as mappingMethod, that are common to all identity providers.

    Adding an identity provider to your cluster

    After you install your cluster, add an identity provider to it so your users can authenticate.

    Prerequisites

    • Create an OKD cluster.

    • Create the custom resource (CR) for your identity providers.

    • You must be logged in as an administrator.

    Procedure

    1. Apply the defined CR:

      1. $ oc apply -f </path/to/CR>
    2. Log in to the cluster as a user from your identity provider, entering the password when prompted.

      1. $ oc login -u <username>
    3. Confirm that the user logged in successfully, and display the user name.

      1. $ oc whoami

    You can add or remove users from an existing htpasswd identity provider.

    Prerequisites

    • You have configured an htpasswd identity provider. This procedure assumes that it is named .

    • You have access to the htpasswd utility. On Red Hat Enterprise Linux this is available by installing the httpd-tools package.

    • You have cluster administrator privileges.

    Procedure

    1. Retrieve the htpasswd file from the htpass-secret Secret object and save the file to your file system:

      1. $ oc get secret htpass-secret -ojsonpath={.data.htpasswd} -n openshift-config | base64 --decode > users.htpasswd
    2. Add or remove users from the users.htpasswd file.

      • To add a new user:

        1. $ htpasswd -bB users.htpasswd <username> <password>

        Example output

      • To remove an existing user:

        1. $ htpasswd -D users.htpasswd <username>

        Example output

        1. Deleting password for user <username>
    3. Replace the htpass-secret Secret object with the updated users in the users.htpasswd file:

      1. $ oc create secret generic htpass-secret --from-file=htpasswd=users.htpasswd --dry-run=client -o yaml -n openshift-config | oc replace -f -
    4. If you removed one or more users, you must additionally remove existing resources for each user.

      1. Delete the User object:

        1. $ oc delete user <username>

        Example output

        1. user.user.openshift.io "<username>" deleted

        Be sure to remove the user, otherwise the user can continue using their token as long as it has not expired.

      2. Delete the object for the user:

        1. $ oc delete identity my_htpasswd_provider:<username>

        Example output

    Configuring identity providers using the web console

    Configure your identity provider (IDP) through the web console instead of the CLI.

    Prerequisites

    • You must be logged in to the web console as a cluster administrator.

    Procedure

    1. Navigate to AdministrationCluster Settings.

    2. Under the Configuration tab, click OAuth.