首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在OKD 4.7中重置kubeadmin密码

在OKD 4.7中重置kubeadmin密码
EN

Server Fault用户
提问于 2022-03-08 07:17:21
回答 2查看 936关注 0票数 0

我试图在.openshift_install.log文件中找到密码,但发现了一些东西,但没有起作用。我试着用oc get secrets kubeadmin -n kube-system -ojsonpath='{.data.kubeadmin}' | base64 --decode && echo "",但也没有用。如何用oc重置kubeadmin密码??谢谢

EN

回答 2

Server Fault用户

发布于 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用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-6Sdvz
  • htpasswd -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=="}}'将修补程序应用于集群
  • 现在,您应该能够使用新密码登录到集群。
票数 0
EN

Server Fault用户

发布于 2023-02-05 10:01:39

首先,让我们提醒您,如果您仔细地遵循安装步骤,您需要安装“oc”CLI工具,并通过以下方法将其用于“登录”到集群

代码语言:javascript
复制
$ 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路径非常容易,只需执行以下操作:

代码语言:javascript
复制
$ oc whoami --show-console

您的中也有安装程序丢弃的文件:

代码语言:javascript
复制
$ cat /auth/kubeadmin-password

最后一个文件实际上被看作是一个安全弱点,并可能在以后的版本中消失(RedHat建议您使用删除该帐户 )。

因此,还有一种方法可以从' OC‘命令行中定义一些额外的“admin”用户帐户,这对于与同事共享OC群集管理任务(每个用户都有自己的身份而不是共享kubeadmin密码)来说要好得多,还可以使用一个登录方法,该方法不会依赖于IDP的可用性,以防后者因任何原因而不可用(您可以结合多种身份验证方法)。

路线路径:

  1. ‘htpasswd’身份提供者添加到内置身份验证荚中。
  2. 向用户添加“集群管理”角色是这样创建的

请查看上述链接文档中的详细步骤,以了解您正在做什么。这是一个简短的总结。

代码语言:javascript
复制
#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

如果您只需要更新现有配置中的用户/密码,以上就足够了。

代码语言:javascript
复制
#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

最后,向用户添加群集管理角色。

代码语言:javascript
复制
#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

享受本地控制台登录!

票数 0
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1095618

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档