Last active
October 7, 2024 01:51
-
-
Save jkeam/a58d27b4ad86e6fa4991410ff518d6ac to your computer and use it in GitHub Desktop.
Add users to OpenShift via htpasswd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# create admin and user1 with password `openshift` | |
# -c for file, -n just for console | |
# -B for bcrypt | |
# -b for allowing password in command | |
htpasswd -c -B -b ./openshift.htpasswd admin openshift | |
htpasswd -B -b ./openshift.htpasswd user1 openshift | |
# add secret with username/passwords | |
oc create secret generic htpass-secret --from-file=htpasswd=./openshift.htpasswd -n openshift-config | |
# setup identity provider to use that secret | |
cat <<EOF | oc create -f - | |
apiVersion: config.openshift.io/v1 | |
kind: OAuth | |
metadata: | |
name: cluster | |
spec: | |
identityProviders: | |
- name: my_htpasswd_provider | |
mappingMethod: claim | |
type: HTPasswd | |
htpasswd: | |
fileData: | |
name: htpass-secret | |
EOF | |
# make cluster admin afterwards | |
oc adm policy add-cluster-role-to-user cluster-admin admin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Taken from: https://docs.openshift.com/container-platform/4.12/authentication/identity_providers/configuring-htpasswd-identity-provider.html