OKD 4 : Identity プロバイダーを設定 : HTPasswd2022/04/21 |
|
クラスター構成直後のデフォルトでは [kubeadmin] ユーザーのみが存在しています。
Identity プロバイダーを設定して、任意のユーザーがクラスターを利用できるようにします。
当例では HTPasswd ファイルを Identity プロバイダーとして設定します。
OKD 4 クラスターは以下の通り構成しています。
--------------+----------------+-----------------+--------------
|10.0.0.25 | |10.0.0.24
+-------------+-------------+ | +--------------+-------------+
| [mgr.okd4.srv.world] | | | [bootstrap.okd4.srv.world] |
| Manager Node | | | Bootstrap Node |
| DNS | | | |
| Nginx | | | |
+---------------------------+ | +----------------------------+
|
--------------+----------------+-----------------+--------------
|10.0.0.40 | |10.0.0.41
+-------------+-------------+ | +--------------+-------------+
| [master-0.okd4.srv.world] | | | [master-1.okd4.srv.world] |
| Control Plane#1 | | | Control Plane#2 |
| | | | |
| | | | |
+---------------------------+ | +----------------------------+
|
--------------+----------------+
|10.0.0.42
+-------------+-------------+
| [master-2.okd4.srv.world] |
| Control Plane#3 |
| |
| |
+---------------------------+
|
| [1] | Manager ノードで Identity プロバイダー設定を追加します。 |
|
[root@mgr ~]#
dnf -y install httpd-tools # [serverworld] ユーザーを htpasswd ファイルに追加 [root@mgr ~]# htpasswd -Bbc ~/okd4/auth/users.htpasswd serverworld userpassword Adding password for user serverworld # HTPasswd シークレットを生成 [root@mgr ~]# oc create secret generic htpass-secret --from-file=htpasswd=/root/okd4/auth/users.htpasswd -n openshift-config secret/htpass-secret created # 新規作成
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: HTPasswdIdentityProvider
mappingMethod: claim
type: HTPasswd
htpasswd:
fileData:
name: htpass-secret
oc apply -f ~/okd4/auth/oauth.yaml Warning: resource oauths/cluster is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by oc apply. oc apply should only be used on resources created declaratively by either oc create --save-config or oc apply. The missing annotation will be patched automatically. oauth.config.openshift.io/cluster configured |
| [2] | ユーザーを追加する場合は以下のように実行します。 |
|
# 現行の HTPasswd シークレットをファイルに書き出す [root@mgr ~]# oc get secret htpass-secret -ojsonpath={.data.htpasswd} -n openshift-config | base64 --decode > ~/okd4/auth/users.htpasswd
# htpasswd ファイルにユーザー追加 [root@mgr ~]# htpasswd -bB ~/okd4/auth/users.htpasswd centos userpassword Adding password for user centos [root@mgr ~]# htpasswd -bB ~/okd4/auth/users.htpasswd redhat userpassword Adding password for user redhat # HTPasswd シークレットをアップデート [root@mgr ~]# oc create secret generic htpass-secret --from-file=htpasswd=/root/okd4/auth/users.htpasswd --dry-run=client -o yaml -n openshift-config | oc replace -f - secret/htpass-secret replaced |
| [3] | ユーザーを削除する場合は以下のように実行します。 |
|
# 現行の HTPasswd シークレットをファイルに書き出す [root@mgr ~]# oc get secret htpass-secret -ojsonpath={.data.htpasswd} -n openshift-config | base64 --decode > ~/okd4/auth/users.htpasswd
# htpasswd ファイルからユーザー削除 [root@mgr ~]# htpasswd -D ~/okd4/auth/users.htpasswd centos Deleting password for user centos # HTPasswd シークレットをアップデート [root@mgr ~]# oc create secret generic htpass-secret --from-file=htpasswd=/root/okd4/auth/users.htpasswd --dry-run=client -o yaml -n openshift-config | oc replace -f - secret/htpass-secret replaced # 削除対象ユーザーのリソース削除 [root@mgr ~]# oc delete user centos user.user.openshift.io "centos" deleted |
| Sponsored Link |
|
|