Kubernetes (kubectl)에 사용자를 추가하는 방법은 무엇입니까?
kops를 사용 하여 AWS에서 Kubernetes 클러스터를 생성했으며 kubectl
로컬 머신에서 성공적으로 관리 할 수 있습니다 .
다음과 kubectl config view
같이 에서 현재 구성을 볼 수 있을뿐만 아니라에서 저장된 상태에 직접 액세스 할 수 있습니다 ~/.kube/config
.
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: REDACTED
server: https://api.{CLUSTER_NAME}
name: {CLUSTER_NAME}
contexts:
- context:
cluster: {CLUSTER_NAME}
user: {CLUSTER_NAME}
name: {CLUSTER_NAME}
current-context: {CLUSTER_NAME}
kind: Config
preferences: {}
users:
- name: {CLUSTER_NAME}
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
password: REDACTED
username: admin
- name: {CLUSTER_NAME}-basic-auth
user:
password: REDACTED
username: admin
다른 사용자도 관리 할 수 있도록해야합니다. 이 사용자 가이드 는 다른 사용자 컴퓨터에서이를 정의하는 방법을 설명하지만 실제로 클러스터 자체 내에서 사용자의 자격 증명을 만드는 방법은 설명하지 않습니다. 어떻게하나요?
또한 공유하는 것이 안전 cluster.certificate-authority-data
합니까?
인증에 대한 전체 개요는 인증 및 권한 부여 에 대한 공식 Kubernetes 문서를 참조하십시오.
사용자의 경우 이상적으로는 Kubernetes 용 ID 공급자 (OpenID Connect)를 사용합니다.
GKE / ACS를 사용하는 경우 각 ID 및 액세스 관리 프레임 워크와 통합합니다.
kubernetes를 자체 호스팅하는 경우 (kops를 사용하는 경우) coreos / dex 를 사용 하여 LDAP / OAuth2 ID 공급자와 통합 할 수 있습니다. 이 세부적인 Kubernetes 용 2 부 SSO 문서를 참조하세요.
kops (1.10+)에는 이제 AWS를 사용하는 경우 자격 증명 공급자로서 AWS IAM과 쉽게 통합 할 수있는 내장 인증 지원 이 있습니다.
Dex의 경우 다음과 같은 몇 가지 오픈 소스 CLI 클라이언트가 있습니다.
빠르고 쉬운 (장기적으로는 가장 안전하고 관리하기 쉽지 않은) 시작 방법을 찾고 있다면 serviceaccounts
액세스를 제어하는 특수 정책에 대한 두 가지 옵션을 사용하여 남용 할 수 있습니다. (아래 참조)
참고 1.6 역할 기반 액세스 제어를 강력히 권장합니다! 이 답변은 RBAC 설정을 다루지 않습니다.
편집 : RBAC를 사용한 사용자 설정 에 대한 Bitnami의 훌륭한 가이드 도 사용할 수 있습니다.
서비스 계정 액세스를 활성화하는 단계는 다음과 같습니다 (클러스터 구성에 RBAC 또는 ABAC 정책이 포함되어 있는지에 따라 이러한 계정은 전체 관리자 권한을 가질 수 있습니다!).
편집 : 여기에 서비스 계정 생성을 자동화하는 bash 스크립트가 있습니다-아래 단계 참조
사용자를위한 서비스 계정 만들기
Alice
kubectl create sa alice
관련 비밀 얻기
secret=$(kubectl get sa alice -o json | jq -r .secrets[].name)
가져 오기
ca.crt
비밀에서 (OSX를 사용base64
하여-D
디코딩에 대한 플래그)kubectl get secret $secret -o json | jq -r '.data["ca.crt"]' | base64 -D > ca.crt
보안 비밀에서 서비스 계정 토큰 가져 오기
user_token=$(kubectl get secret $secret -o json | jq -r '.data["token"]' | base64 -D)
kubectl 구성 (현재 컨텍스트, 서버 ..)에서 정보 가져 오기
# get current context c=`kubectl config current-context` # get cluster name of context name=`kubectl config get-contexts $c | awk '{print $3}' | tail -n 1` # get endpoint of current context endpoint=`kubectl config view -o jsonpath="{.clusters[?(@.name == \"$name\")].cluster.server}"`
새 컴퓨터에서 다음 단계를 따르십시오 ( 위에서 검색된
ca.cert
및$endpoint
정보가 제공되면 :설치
kubectl
brew install kubectl
클러스터 설정 (
ca.crt
저장된 디렉토리에서 실행 )kubectl config set-cluster cluster-staging \ --embed-certs=true \ --server=$endpoint \ --certificate-authority=./ca.crt
사용자 자격 증명 설정
kubectl config set-credentials alice-staging --token=$user_token
alice 사용자와 스테이징 클러스터의 조합 정의
kubectl config set-context alice-staging \ --cluster=cluster-staging \ --user=alice-staging \ --namespace=alice
현재 컨텍스트를
alice-staging
사용자로 전환kubectl config use-context alice-staging
정책 ( ABAC 사용 )으로 사용자 액세스를 제어하려면 policy
파일 을 생성해야 합니다 (예 :
{
"apiVersion": "abac.authorization.kubernetes.io/v1beta1",
"kind": "Policy",
"spec": {
"user": "system:serviceaccount:default:alice",
"namespace": "default",
"resource": "*",
"readonly": true
}
}
policy.json
모든 마스터 노드에서 이를 프로비저닝 --authorization-mode=ABAC --authorization-policy-file=/path/to/policy.json
하고 API 서버 에 플래그를 추가 합니다.
This would allow Alice (through her service account) read only rights to all resources in default namespace only.
You say :
I need to enable other users to also administer.
But according to the documentation
Normal users are assumed to be managed by an outside, independent service. An admin distributing private keys, a user store like Keystone or Google Accounts, even a file with a list of usernames and passwords. In this regard, Kubernetes does not have objects which represent normal user accounts. Regular users cannot be added to a cluster through an API call.
You have to use a third party tool for this.
== Edit ==
One solution could be to manually create a user entry in the kubeconfig file. From the documentation :
# create kubeconfig entry
$ kubectl config set-cluster $CLUSTER_NICK \
--server=https://1.1.1.1 \
--certificate-authority=/path/to/apiserver/ca_file \
--embed-certs=true \
# Or if tls not needed, replace --certificate-authority and --embed-certs with
--insecure-skip-tls-verify=true \
--kubeconfig=/path/to/standalone/.kube/config
# create user entry
$ kubectl config set-credentials $USER_NICK \
# bearer token credentials, generated on kube master
--token=$token \
# use either username|password or token, not both
--username=$username \
--password=$password \
--client-certificate=/path/to/crt_file \
--client-key=/path/to/key_file \
--embed-certs=true \
--kubeconfig=/path/to/standalone/.kube/config
# create context entry
$ kubectl config set-context $CONTEXT_NAME \
--cluster=$CLUSTER_NICK \
--user=$USER_NICK \
--kubeconfig=/path/to/standalone/.kube/config
bitnami guide works for me, even if you use minikube. Most important is you cluster supports RBAC. https://docs.bitnami.com/kubernetes/how-to/configure-rbac-in-your-kubernetes-cluster/
참고URL : https://stackoverflow.com/questions/42170380/how-to-add-users-to-kubernetes-kubectl
'Development Tip' 카테고리의 다른 글
Android의 Parcelable 및 상속 (0) | 2020.12.01 |
---|---|
목록 이해력을 사용하여 튜플 작성 (0) | 2020.12.01 |
pycharm에서 Conda 환경 사용 (0) | 2020.12.01 |
Spring-동일한 애플리케이션에서 여러 트랜잭션 관리자를 사용할 수 있습니까? (0) | 2020.12.01 |
html5 : 머리글 또는 바닥 글 태그를 두 번 사용합니까? (0) | 2020.12.01 |