Adding an htpasswd user to OpenShift 4

10 Jun 2019

Something i’ve been doing a lot of recently and i’m sure i will need a pointer back to it. When OpenShift is using htpasswd for its authentication provider, adding new users/credentials is easier than ever.

Prerequisites

  1. shell with the oc and htpasswd commands
  2. OpenShift credentials with cluster-admin role

Procedure

  1. create an htpasswd file for the cluster. this should probably contain all the users you want to be in there, so make sure it has everything. if updating an old file, drop the -c
    htpasswd -c -B -b ./openshift.htpasswd user1 secret
    
  2. Add more users as necessary.
  3. Create the manifest for the cluster secret. This is used by the authentication provider to read the individual credentials, i am doing this as a dry run to create a file for the manifest because the secret should exist already.
    oc create secret generic htpasswd-secret \
        --from-file=htpasswd=./openshift.htpasswd \
        --namespace openshift-config \
        --dry-run \
        --output yaml > ./htpass-secret.yaml
    
  4. Replace the existing secret, this could be done as a pipe from the previous command.
    oc replace --filename ./htpass-secret.yaml
    

If everything has worked, you should now be able to login as the newly identified user.

Additional resources