|
本文档采用自动化机器翻译技术翻译。 尽管我们力求提供准确的译文,但不对翻译内容的完整性、准确性或可靠性作出任何保证。 若出现任何内容不一致情况,请以原始 英文 版本为准,且原始英文版本为权威文本。 |
用户
用户资源
User 资源 (users.management.cattle.io) 代表 Rancher 中的用户账户。
要获取 User 资源的字段和结构描述,请运行:
kubectl explain users.management.cattle.io
创建用户
创建本地用户是一个两步过程:您必须创建 User 资源,然后通过 Kubernetes Secret 提供密码。
只有具有足够权限的用户才能创建 User 资源。
kubectl create -f -<<EOF apiVersion: management.cattle.io/v3 kind: User metadata: name: testuser displayName: "Test User" username: "testuser" EOF
用户的密码必须在 cattle-local-user-passwords 名称空间内的 Secret 对象中提供。Rancher webhook 会自动对密码进行哈希处理并更新 Secret。
|
重要说明: |
kubectl create -f -<<EOF apiVersion: v1 kind: Secret metadata: name: testuser namespace: cattle-local-user-passwords type: Opaque stringData: password: Pass1234567! EOF
在提交明文密码后,Rancher-Webhook 会自动对其进行哈希处理,替换 Secret 的内容,确保明文密码不会被存储:
apiVersion: v1 data: password: 1c1Y4CdjlehGWFz26F414x2qoj4gch5L5OXsx35MAa8= salt: m8Co+CfMDo5XwVl0FqYzGcRIOTgRrwFSqW8yurh5DcE= kind: Secret metadata: annotations: cattle.io/password-hash: pbkdf2sha3512 name: testuser namespace: cattle-local-user-passwords ownerReferences: - apiVersion: management.cattle.io/v3 kind: User name: testuser uid: 663ffb4f-8178-46c8-85a3-337f4d5cbc2e uid: bade9f0a-b06f-4a77-9a39-4284dc2349c5 type: Opaque
更新用户密码
要更改用户的密码,请使用 PasswordChangeRequest 资源,该资源处理安全的密码更新。
kubectl create -f -<<EOF apiVersion: ext.cattle.io/v1 kind: PasswordChangeRequest spec: userID: "testuser" currentPassword: "Pass1234567!" newPassword: "NewPass1234567!" EOF
删除用户
删除用户会自动删除相应的密码 Secret。
kubectl delete user testuser user.management.cattle.io "testuser" deleted
获取当前用户的信息
客户端使用 SelfUser 资源检索当前已认证用户的信息,而无需知道其 ID。用户 ID 在 .status.userID 字段中返回。
kubectl create -o jsonpath='{.status.userID}' -f -<<EOF apiVersion: ext.cattle.io/v1 kind: SelfUser EOF testuser
刷新用户的组成员资格
用户组成员资格的更新由 GroupMembershipRefreshRequest 资源触发。
|
仅支持外部身份验证提供者的组成员资格。 |
针对单个用户
kubectl create -o jsonpath='{.status}' -f -<<EOF apiVersion: ext.cattle.io/v1 kind: GroupMembershipRefreshRequest spec: userId: testuser EOF { "conditions": [ { "lastTransitionTime": "2025-11-10T12:01:03Z", "message": "", "reason": "", "status": "True", "type": "UserRefreshInitiated" } ], "summary": "Completed" }
针对所有用户
kubectl create -o jsonpath='{.status}' -f -<<EOF apiVersion: ext.cattle.io/v1 kind: GroupMembershipRefreshRequest spec: userId: "*" EOF { "conditions": [ { "lastTransitionTime": "2025-11-10T12:01:59Z", "message": "", "reason": "", "status": "True", "type": "UserRefreshInitiated" } ], "summary": "Completed" }