web-dev-qa-db-ja.com

RBAC APIを使用してKubernetesで名前空間に制限されたユーザー/グループを作成するにはどうすればよいですか?

問題

私はすべてdevグループ内の多くの異なる開発者(異なるサブジェクト)に証明書を発行し、それらすべてにdev名前空間内の物を作成および変更するためのアクセス権を持たせたいが、外部の何かには触れず、外部の秘密は絶対に見ないようにしたいそれ。役割、役割バインディングなどが疑われます。以下のステップ2で作成しているものが正しくありません。誰かが訂正を提案できますか?

試み

  1. APIサーバーフラグを使用してKubernetesをデプロイし、「RBAC、AlwaysAllow」承認モードをサポートし、RBACスーパーユーザーを設定し、--runtime-configを介してRBAC APIを有効にしました。
  2. 名前空間、ロール、およびロールバインディングを作成し、(a)サービスアカウントとシステムコンポーネントに「AlwaysAllow」アクセスを引き続き効果的に許可し、(b)グループdevのエンティティは、名前空間devのすべてにアクセスできます このYAMLファイル注:このリンクの内容は変更されています。質問の最後にあるYAMLファイルを参照してください。
  3. 「RBAC」承認モードのみを許可するようにKubernetesを更新しました。
  4. 証明書のサブジェクトフラグ(opensslの場合)が-subj "/[email protected]/O=dev"である生成されたクライアントTLSデータ。
  5. このテンプレート に従ってkubeconfigファイルを生成しました。

実結果

実行中に次のエラーが表示されます:kubectl -v 8 --kubeconfig=/tmp/dev-kube-config.yml create -f /tmp/busybox.yml

I1219 16:12:37.584657   44323 loader.go:354] Config loaded from file /tmp/dev-kube-config.yml
I1219 16:12:37.585953   44323 round_trippers.go:296] GET https://api.kubernetes.click/api
I1219 16:12:37.585968   44323 round_trippers.go:303] Request Headers:
I1219 16:12:37.585983   44323 round_trippers.go:306]     Accept: application/json, */*
I1219 16:12:37.585991   44323 round_trippers.go:306]     User-Agent: kubectl/v1.5.1+82450d0 (    darwin/AMD64) kubernetes/82450d0
I1219 16:12:38.148994   44323 round_trippers.go:321] Response Status: 403 Forbidden in 562     milliseconds
I1219 16:12:38.149056   44323 round_trippers.go:324] Response Headers:
I1219 16:12:38.149070   44323 round_trippers.go:327]     Content-Type: text/plain; charset=utf-    8
I1219 16:12:38.149081   44323 round_trippers.go:327]     Content-Length: 17
I1219 16:12:38.149091   44323 round_trippers.go:327]     Date: Tue, 20 Dec 2016 00:12:38 GMT
I1219 16:12:38.149190   44323 request.go:904] Response Body: Forbidden: "/api"
I1219 16:12:38.149249   44323 request.go:995] Response Body: "Forbidden: \"/api\""
I1219 16:12:38.149567   44323 request.go:1151] body was not decodable (unable to check for     Status): Object 'Kind' is missing in 'Forbidden: "/api"'
...
I1219 16:12:38.820672   44323 round_trippers.go:296] GET https://api.kubernetes.    click/swaggerapi/api/v1
I1219 16:12:38.820702   44323 round_trippers.go:303] Request Headers:
I1219 16:12:38.820717   44323 round_trippers.go:306]     User-Agent: kubectl/v1.5.1+82450d0 (    darwin/AMD64) kubernetes/82450d0
I1219 16:12:38.820731   44323 round_trippers.go:306]     Accept: application/json, */*
I1219 16:12:38.902256   44323 round_trippers.go:321] Response Status: 403 Forbidden in 81     milliseconds
I1219 16:12:38.902306   44323 round_trippers.go:324] Response Headers:
I1219 16:12:38.902327   44323 round_trippers.go:327]     Content-Type: text/plain; charset=utf-    8
I1219 16:12:38.902345   44323 round_trippers.go:327]     Content-Length: 31
I1219 16:12:38.902363   44323 round_trippers.go:327]     Date: Tue, 20 Dec 2016 00:12:38 GMT
I1219 16:12:38.902456   44323 request.go:904] Response Body: Forbidden: "/swaggerapi/api/v1"
I1219 16:12:38.902512   44323 request.go:995] Response Body: "Forbidden:     \"/swaggerapi/api/v1\""
F1219 16:12:38.903025   44323 helpers.go:116] error: error validating "/tmp/busybox.yml": error validating data: the server does not allow access to the requested resource; if you choose to ignore these errors, turn validation off with --validate=false

期待される結果

dev名前空間にbusyboxポッドを作成する必要があります。

さらなる詳細:

  • $ kubectl version

    Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.1+82450d0", GitCommit:"82450d03cb057bab0950214ef122b67c83fb11df", GitTreeState:"not a git tree", BuildDate:"2016-12-14T04:09:31Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"darwin/AMD64"}
    Server Version: version.Info{Major:"1", Minor:"4", GitVersion:"v1.4.6", GitCommit:"e569a27d02001e343cb68086bc06d47804f62af6", GitTreeState:"clean", BuildDate:"2016-11-12T05:16:27Z", GoVersion:"go1.6.3", Compiler:"gc", Platform:"linux/AMD64"}
    
  • GitHubの問題: https://github.com/kubernetes/kubernetes/issues/38997

  • メーリングリストの投稿: https://groups.google.com/forum/#!topic/kubernetes-dev/6TBTu1AC2L8

編集:回答およびコメントに基づく実用的なソリューション

以下のジョーダンの回答に基づいて、Kubernetes v1.5.1にアップグレードし、次の2つのYAMLファイルを取得して名前空間とすべての正しいRBACリソースを構築し、すべてが希望どおりに機能するようにしました。

system-access.yml (すぐに使用できるクラスターロールとクラスターロールバインディングが機能していないため):

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
  name: system:node--kubelet
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:node
subjects:
- kind: User
  name: kubelet
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
  name: cluster-admin--kube-system:default
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: default
  namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
  name: system:node-proxier--kube-proxy
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:node-proxier
subjects:
- kind: User
  name: kube-proxy

dev-access.yml

kind: Namespace
apiVersion: v1
metadata:
  name: dev
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
  namespace: dev
  name: dev-all
rules:
  - apiGroups: ["*"]
    resources: ["*"]
    verbs: ["*"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1alpha1
metadata:
  name: dev-role-dev-all-members
  namespace: dev
subjects:
  - kind: Group
    name: dev
  - kind: Group
    name: system:serviceaccounts:dev
roleRef:
  kind: Role
  name: dev-all
  apiGroup: "rbac.authorization.k8s.io"
17

最初に、kubectlがAPIの検出と検証に使用するURL(swagger、APIグループとリソースタイプのリストなど)へのアクセスを許可する必要があります。

これを行う最も簡単な方法は、デフォルトのbootstrap cluster roles および cluster role bindings をロードすることです。

kubectl create -f https://raw.githubusercontent.com/kubernetes/kubernetes/master/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-roles.yaml
kubectl create -f https://raw.githubusercontent.com/kubernetes/kubernetes/master/plugin/pkg/auth/authorizer/rbac/bootstrappolicy/testdata/cluster-role-bindings.yaml

system:discovery ClusterRoleを使用して、すべてのユーザー(認証済みおよび未認証)をバインドし、swaggerおよびAPIグループ情報にアクセスできるようにします。

2番目に、allクラスターロールバインディングにdevサービスアカウントを含めないでください。これにより、そのサービスアカウント(およびdevサービスアカウントの資格情報を含むdev名前空間のシークレットにアクセスできるユーザー)のクラスター全体のアクセスが可能になります

7
Jordan Liggitt