我试图在.openshift_install.log文件中找到密码,但发现了一些东西,但没有起作用。我试着用oc get secrets kubeadmin -n kube-system -ojsonpath='{.data.kubeadmin}' | base64 --decode && echo "",但也没有用。如何用oc重置kubeadmin密码??谢谢
发布于 2023-01-21 15:23:32
To找到加密密码
kubeadmin用户的密码存储在名称空间kube-system中的D1秘密中。您应该能够使用oc get secret kubeadmin -n kubesystem -ojsonpath='{.data.kubeadmin}' | base64 -d看到bcrypt编码的值。加密密码以$2y$10$开头,指定它使用的是bcrypt算法,成本为10。
要重置密码,您需要生成一个新的编码密码并更新该秘密。请注意密码必须是至少23个字符。
Steps替换密码
htpasswd实用程序加密密码。base64 -w0对编码密码进行编码。-w0将禁用行包装。oc patch secret/kubeadmin -n kube-system -p '{"data": {"kubeadmin": "[value for the base64 encoded, bcrypt encrypted password]"}}'修补集群中的秘密。A完整示例
w9dYJ-00Je7-K2A0H-ED5ku-6Sdvzhtpasswd -bnBC 10 "" w9dYJ-00Je7-K2A0H-ED5ku-6Sdvz | tr -d ':\n'加密echo $2y$10$c9zxzleI5pvNXdWNHD3bT.vdqpJY2cI752YLswMydZR2VoIudbtti | base64 -w0进行编码oc patch secret/kubeadmin -n kube-system -p '{"data": {"kubeadmin": "JDJ5JDEwJGM5enh6bGVJNXB2TlhkV05IRDNiVC52ZHFwSlkyY0k3NTJZTHN3TXlkWlIyVm9JdWRidHRpCg=="}}'将修补程序应用于集群发布于 2023-02-05 10:01:39
首先,让我们提醒您,如果您仔细地遵循安装步骤,您需要安装“oc”CLI工具,并通过以下方法将其用于“登录”到集群:
$ export KUBECONFIG=/auth/kubeconfig
# replace by the directory where you created your
# installation artefacts with the openshift-install prog
$ oc whoami这将确认您处于“system:admin”状态。
从那时起,查找到web控制台的URL路径非常容易,只需执行以下操作:
$ oc whoami --show-console您的中也有安装程序丢弃的文件:
$ cat /auth/kubeadmin-password最后一个文件实际上被看作是一个安全弱点,并可能在以后的版本中消失(RedHat建议您使用删除该帐户 )。
因此,还有一种方法可以从' OC‘命令行中定义一些额外的“admin”用户帐户,这对于与同事共享OC群集管理任务(每个用户都有自己的身份而不是共享kubeadmin密码)来说要好得多,还可以使用一个登录方法,该方法不会依赖于IDP的可用性,以防后者因任何原因而不可用(您可以结合多种身份验证方法)。
路线路径:
请查看上述链接文档中的详细步骤,以了解您正在做什么。这是一个简短的总结。
#ensure you are properly logged in for the next 'oc' CLI commands
$ export KUBECONFIG=/auth/kubeconfig
$ oc whoami
system:admin
#ensure the authentication operator is up and running
$ oc get clusteroperators
NAME VERSION AVAILABLE etc...
authentication 4.12.0 True etc...
...
#ensure authentication API pods are deployed
$ oc get pods -n openshift-authentication
NAME READY STATUS etc...
oauth-openshift-84955b4d7c-4d2dc 1/1 Running
oauth-openshift-84955b4d7c-4wx8v 1/1 Running
oauth-openshift-84955b4d7c-7pnqj 1/1 Running
# create an initial htpasswd file (if you already have one, or want to update passwords, omit the 'c' arg)
$ htpasswd -cB users.htpasswd
# your are prompted for a password twice
# repeat the command for additional users' login names
# prepare the file for inclusion as a string attribute in YAML
$ base64 -w0 users.htpasswd >users.htpasswd.b64
# edit a inject-htpass-secret.yaml file with the following content
apiVersion: v1
kind: Secret
metadata:
name: htpass-secret
namespace: openshift-config
type: Opaque
data:
htpasswd: 'YmVybmFyZG... you paste here between quotes the B64 content of your users.htpasswd.b64 file ... ZtQ1MwaEdDCg=='
# create or update the secret 'htpass-secret' with the new htpasswd artefact
$ oc apply -f inject-htpass-secret.yaml如果您只需要更新现有配置中的用户/密码,以上就足够了。
#check you don't have yet a htpasswd identity provider configured
$ oc describe oauth.config.openshift.io/cluster
# or alternatively:
$ oc edit oauth.config.openshift.io cluster
# and you shall see that the Spec attribute is an empty object
#Then, add the provider. Edit an config-OAuth-id-provider.yaml file as below.
# you can only customize the name for your provider, here 'htpasswd_provider'
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: htpasswd_provider
mappingMethod: claim
type: HTPasswd
htpasswd:
fileData:
name: htpass-secret
# and apply (or update the htpasswd_provider ! ...or add it!)
$ oc apply -f config-OAuth-id-provider.yaml最后,向用户添加群集管理角色。
#each user must login once first,
# which is the way for the authentication operator to discover that a new user exists
#then, add the cluster role
$ oc adm policy add-cluster-role-to-user cluster-admin
#if you are already logged in, you may see your web console updating its display instantly享受本地控制台登录!
https://serverfault.com/questions/1095618
复制相似问题