Updating users for an htpasswd identity provider
Update users in the htpasswd identity provider so login credentials in Red Hat OpenShift Container Platform stay in sync when you add or remove accounts.
-
You have created a
Secretobject namedhtpass-secretthat contains thehtpasswduser file. -
You have configured an
htpasswdidentity provider namedmy_htpasswd_provider. -
You have access to the
htpasswdutility. On Red Hat Enterprise Linux (RHEL), this is available by installing thehttpd-toolspackage. -
You have cluster administrator privileges.
-
Retrieve the
htpasswdfile from thehtpass-secretSecretobject and save it to your local machine by running the following command:$ oc get secret htpass-secret -ojsonpath={.data.htpasswd} -n openshift-config | base64 --decode > users.htpasswd -
Add or remove users from the
users.htpasswdfile by running the following commands:-
To add a new user:
$ htpasswd -bB users.htpasswd <username> <password>Example outputAdding password for user <username> -
To remove an existing user:
$ htpasswd -D users.htpasswd <username>Example outputDeleting password for user <username>
-
-
Replace the
htpass-secretSecretobject with the updated users in theusers.htpasswdfile by running the following command:$ oc create secret generic htpass-secret --from-file=htpasswd=users.htpasswd --dry-run=client -o yaml -n openshift-config | oc replace -f -You can also apply the following YAML to replace the secret:
apiVersion: v1 kind: Secret metadata: name: htpass-secret namespace: openshift-config type: Opaque data: htpasswd: <base64_encoded_htpasswd_file_contents> -
If you removed one or more users, you must remove the existing resources for each user by running the following commands:
-
Delete the
Userobject:$ oc delete user <username>Example outputuser.user.openshift.io "<username>" deletedBe sure to remove the user, otherwise the user can continue using their token as long as it has not expired.
-
Delete the
Identityobject for the user:$ oc delete identity my_htpasswd_provider:<username>Example outputidentity.user.openshift.io "my_htpasswd_provider:<username>" deleted
-