about blog github

20 Jul 2020
ocp4.3配置htpasswd用户

配置htpasswd用户

$ yum install httpd-tools -y
$ htpasswd -c -B -b /share/git/k8s_practice/ocp-user/users.htpasswd admin admin
Adding password for user admin
$ htpasswd -B -b /share/git/k8s_practice/ocp-user/users.htpasswd user1 user1
Adding password for user user1
$ htpasswd -B -b /share/git/k8s_practice/ocp-user/users.htpasswd user2 user2
Adding password for user user2
$ cat users.htpasswd
admin:$2y$05$kpnumQTeKIRcf1M9yLd.eOIYwB1n5EIVvQCLsRYFyiJyo6Rgte.pG
user1:$2y$05$2CqayROvTizI7CD1jocx5OHNqb/CZxJAPRhNldGaenAkgtzW3QLOW
user2:$2y$05$sY7NRSNbn94dlYtXSbIvE.GrImWj.2BIIqAQ.s4ctGxeUaH8UXfpm
$ oc create secret generic htpass-user-test --from-file=htpasswd=/share/git/k8s_practice/ocp-user/users.htpasswd -n openshift-config
secret/htpass-user-test created

$ oc apply -f htpasswd-cr.yaml

htpasswd-cr.yaml如下:

apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
  name: cluster
spec:
  identityProviders:
  - name: htpasswd_provider
    mappingMethod: claim
    type: HTPasswd
    htpasswd:
      fileData:
        name: htpass-user-test

使用新用户登陆

$ oc login -u admin -p admin
$ oc login -u user1 -p user1
$ oc login -u user2 -p user2
$ oc whoami


LEo at 12:12

about blog github