叢集這麼貴,不太可能作為個人使用,團隊共用才是最常見合理。 多人共用叢集,必定會有權限分配的議題,允許誰可以做什麼事情,就是本篇要探討的內容。
認證(Authentication)是驗證「你是誰」的過程,驗證通過後才會再進入 RBAC 授權(Authorization)。
這篇先寫 認證(Authentication)的部分
先看看 OCP 的 OAuth 設定
oc get oauth cluster -o yaml
這會顯示目前叢集的 OAuth 設定,包括:
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: ldap_provider
mappingMethod: claim
type: LDAP
ldap:
url: "ldaps://ldap.example.com:636/ou=users,dc=example,dc=com"
bindDN: "cn=admin,dc=example,dc=com"
bindPassword:
name: ldap-secret
attributes:
id: ["dn"]
email: ["mail"]
name: ["cn"]
修改設定方式
oc edit oauth cluster
以下列出常見的 OAuth 選項及適用的場景或理由。
identityProviders:
- name: ldap_provider
mappingMethod: claim
type: LDAP
ldap:
url: "ldaps://ldap.example.com:636/ou=users,dc=example,dc=com"
bindDN: "cn=admin,dc=example,dc=com"
bindPassword:
name: ldap-secret # 事先建立的 secret,內容為 bind 密碼
insecure: false
attributes:
id: ["dn"]
preferredUsername: ["uid"]
name: ["cn"]
email: ["mail"]
oc create secret generic ldap-secret \
--from-literal=bindPassword='你的密碼' -n openshift-config
identityProviders:
- name: github
mappingMethod: claim
type: GitHub
github:
clientID: your-client-id
clientSecret:
name: github-client-secret # Secret 中包含 clientSecret
hostname: "" # 空代表 github.com
organizations:
- your-github-org
oc create secret generic github-client-secret \
--from-literal=clientSecret='你的 GitHub secret' -n openshift-config
identityProviders:
- name: localusers
mappingMethod: claim
type: HTPasswd
htpasswd:
fileData:
name: htpasswd-secret
htpasswd -c -B -b users.htpasswd user1 password123
oc create secret generic htpasswd-secret \
--from-file=htpasswd=users.htpasswd -n openshift-config
oc edit oauth cluster
後,OpenShift 會自動重新部署 oauth-openshift pods
,不用手動重啟。oauth-openshift
Pods 的狀態,檢查啟用時間。
oc get pods -n openshift-authentication
LDAP
和 HTPassword
設定oc get oauth cluster -o yaml
拿回來的內容如下:apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
annotations:
include.release.openshift.io/ibm-cloud-managed: "true"
include.release.openshift.io/self-managed-high-availability: "true"
include.release.openshift.io/single-node-developer: "true"
kubectl.kubernetes.io/last-applied-configuration: |
{}
release.openshift.io/create-only: "true"
creationTimestamp:
generation: 4
name: cluster
resourceVersion: "773055770"
uid: xxxxxxxx
spec:
identityProviders:
- htpasswd:
fileData:
name: htpass-secret
mappingMethod: claim
name: ocp_htpasswd_provider
type: HTPasswd
- ldap:
attributes:
email:
- mail
id:
- sAMAccountName
name:
- cn
preferredUsername:
- sAMAccountName
bindDN: CN=admin xxxxx,CN=Users,DC=xxxxxxxxx,DC=tw
bindPassword:
name: ldap-secret
insecure: true
url: ldap://xxxxxxxxxxx
mappingMethod: claim
name: xxxxx-ldap
type: LDAP
tokenConfig:
accessTokenMaxAgeSeconds: 172800
功能面向 | Kubernetes 原生身份驗證 | OpenShift 的 openshift-authentication |
---|---|---|
身份驗證元件 | 無獨立模組,交由 kube-apiserver 處理 |
專屬模組:openshift-authentication (OAuth server + console login) |
支援 OAuth | (需 OIDC 參數設定) | (開箱即用,完整流程) |
SSO 整合能力 | 手動設定 OIDC、Webhook | 內建支援 GitHub / LDAP / OIDC / htpasswd 等 |
登入頁面 | 無 web login(需額外套件) | 提供網頁登入介面 |
使用者註冊 / 角色管理 | 不提供 | 搭配 oc + RoleBinding 提供完整權限控管 |
身份提供者(IdP)設定方式 | 修改 kube-apiserver 參數 |
透過 oc edit oauth cluster 管理 CR |
群組支援 | 僅支援 OIDC 群組 claim | 支援 IdP 群組(LDAP, GitHub orgs)+ Group Mapping |
組織式身份管理 | 無中央元件 | 提供 centralized OAuth server,集中管理 |