一、配置本地用戶api
以前安裝的時候選擇了htpasswd驗證方式app
先建立用戶ide
# htpasswd -c /etc/origin/master/htpasswd admin
受權爲集羣管理員ui
# oc adm policy add-cluster-role-to-user cluster-admin admin
登錄到ocurl
# oc login -u admin
二、配置服務帳號spa
平時的管理能夠用本地帳號,可是若是用調用k8s接口雖然也能夠使用本地帳號TOKEN可是很快會過時,這時候就要用服務帳號了rest
建立服務用戶code
# oc project default
# oc create sa api-admin
受權爲集羣管理員blog
# oc adm policy add-cluster-role-to-user cluster-admin system:serviceaccount:default:api-admin
獲取服務帳號長期TOKENtoken
# oc get sa/api-admin --template='{{range .secrets}}{{ .name }} {{end}}' | xargs -n 1 oc get secret --template='{{ if .data.token }}{{ .data.token }}{{end}}' | head -n 1 | base64 -d -
三、使用ldap驗證用戶
人多了帳號很差管理,就須要接入ldap了
編輯/etc/origin/master/master-config.yaml
加入如下內容
oauthConfig:
assetPublicURL: https://www.oc.example.cn:8443/console/
grantConfig:
method: auto
identityProviders:
- challenge: true
login: true
mappingMethod: claim
name: Ldap_auth
provider:
apiVersion: v1
attributes:
email:
- mail
id:
- dn
name:
- cn
preferredUsername:
- uid
bindDN: uid=ldapreader,cn=users,dc=example,dc=com
bindPassword: 123456
insecure: true
kind: LDAPPasswordIdentityProvider
url: ldap://192.168.1.1:389/cn=users,dc=example,dc=com?uid
重啓master以使更改生效
# master-restart api
# master-restart controllers
同步ldap帳號
編輯/etc/origin/master/rfc2307_config.yaml
加入如下內容
kind: LDAPSyncConfig
apiVersion: v1
url: ldap://192.168.1.1:389
insecure: true
rfc2307:
groupsQuery:
baseDN: "cn=groups,dc=example,dc=com"
scope: sub
derefAliases: never
pageSize: 0
filter: (objectClass=posixGroup)
groupUIDAttribute: dn
groupNameAttributes: [ cn ]
groupMembershipAttributes: [ member ]
usersQuery:
baseDN: "dc=example,dc=com"
scope: sub
derefAliases: never
pageSize: 0
userUIDAttribute: dn
userNameAttributes: [ cn ]
tolerateMemberNotFoundErrors: false
tolerateMemberOutOfScopeErrors: false
同步命令
# oc adm groups sync --sync-config=/etc/origin/master/rfc2307_config.yaml --confirm
最好加入crontab定時同步
驗證用戶有沒有被同步過來
# oc get group