3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWSマネジメントコンソールでEKSリソースを見れるようにする

Last updated at Posted at 2023-07-15

背景

Amazon EKSで作成したクラスタ上のk8sリソースをAWSマネジメントコンソールから閲覧できるようにしたい。
今更感あるが、アウトプットの一環として共有。

結論

AWSマネジメントコンソールにサインインにするIAMユーザ(もしくはIAMロール)に、Kubernetesの然るべきロールを関連付ける

環境

Client Version: v1.26.4
Kustomize Version: v4.5.7
Server Version: v1.26.6

作業前

  • Amazon EKSクラスタへの完全なアクセス権はクラスタを作成したIAMにしか与えられない
  • したがって、作成したIAM以外のIAMでEKSの情報を参照しようとすると、例えIAMポリシーでEKSに関するフルアクセス権限を付与していようとも参照することはできない
    スクリーンショット 2023-07-15 151736.png

作業概要

  • ConfigMap「aws-auth」に、権限を付与させたいIAMとそれに対応するk8s上のユーザを関連付ける
  • 上記で作成したユーザに対して、組み込みClusterRoleである「view」を関連付けるClusterRoleBindingを作成する

前提条件

使用するIAMには「eks:AccessKubernetesApi」を付与しておく

aws-authのアップデート

EKSクラスタを作成したIAM(ここではIAMユーザ)のクレデンシャルを使って、aws-auth の情報を取得する

kubectl get configmap -n kube-system aws-auth -o yaml > ~/aws-auth.yml

リダイレクトで作成したyamlファイルをエディタで開き、data.mapRolesにk8sへの参照権限を付与したいIAMのARNとk8s上のユーザ名を追記する

aws-auth.yml
data:
  mapRoles: |
    - rolearn: arn:aws:iam::XXXXXXXXXXXX:user/XXXXX
      username: eks-user

変更を適用する

kubectl apply -f aws-auth.yml

適用されていることを確認する

kubectl get configmap -n kube-system aws-auth -o yaml

ClusterRoleと関連付ける

以下のClusterRoleBindingを定義するマニフェストを作成する

clusterrolebinding.yml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: eks-user-view
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: view
subjects:
- kind: User
  name: eks-user
  apiGroup: rbac.authorization.k8s.io

作成したマニフェストを適用する

kubectl apply -f clusterrolebinding.yml

適用されていることを確認する

kubectl get clusterrolebinding eks-user-view -o wide
NAME            ROLE               AGE   USERS      GROUPS   SERVICEACCOUNTS
eks-user-view   ClusterRole/view   43s   eks-user

作業後

k8sの参照権限が使用できるようになったので、AWSマネジメントコンソールからk8sリソースの情報を参照できるようになった
スクリーンショット 2023-07-15 154030.png

備考

今回使用したClusterRole「view」は以下の権限が設定されている。

kubectl describe clusterrole view
Name:         view
Labels:       kubernetes.io/bootstrapping=rbac-defaults
              rbac.authorization.k8s.io/aggregate-to-edit=true
Annotations:  rbac.authorization.kubernetes.io/autoupdate: true
PolicyRule:
  Resources                                    Non-Resource URLs  Resource Names  Verbs
  ---------                                    -----------------  --------------  -----
  bindings                                     []                 []              [get list watch]
  configmaps                                   []                 []              [get list watch]
  endpoints                                    []                 []              [get list watch]
  events                                       []                 []              [get list watch]
  limitranges                                  []                 []              [get list watch]
  namespaces/status                            []                 []              [get list watch]
  namespaces                                   []                 []              [get list watch]
  persistentvolumeclaims/status                []                 []              [get list watch]
  persistentvolumeclaims                       []                 []              [get list watch]
  pods/log                                     []                 []              [get list watch]
  pods/status                                  []                 []              [get list watch]
  pods                                         []                 []              [get list watch]
  replicationcontrollers/scale                 []                 []              [get list watch]
  replicationcontrollers/status                []                 []              [get list watch]
  replicationcontrollers                       []                 []              [get list watch]
  resourcequotas/status                        []                 []              [get list watch]
  resourcequotas                               []                 []              [get list watch]
  serviceaccounts                              []                 []              [get list watch]
  services/status                              []                 []              [get list watch]
  services                                     []                 []              [get list watch]
  controllerrevisions.apps                     []                 []              [get list watch]
  daemonsets.apps/status                       []                 []              [get list watch]
  daemonsets.apps                              []                 []              [get list watch]
  deployments.apps/scale                       []                 []              [get list watch]
  deployments.apps/status                      []                 []              [get list watch]
  deployments.apps                             []                 []              [get list watch]
  replicasets.apps/scale                       []                 []              [get list watch]
  replicasets.apps/status                      []                 []              [get list watch]
  replicasets.apps                             []                 []              [get list watch]
  statefulsets.apps/scale                      []                 []              [get list watch]
  statefulsets.apps/status                     []                 []              [get list watch]
  statefulsets.apps                            []                 []              [get list watch]
  horizontalpodautoscalers.autoscaling/status  []                 []              [get list watch]
  horizontalpodautoscalers.autoscaling         []                 []              [get list watch]
  cronjobs.batch/status                        []                 []              [get list watch]
  cronjobs.batch                               []                 []              [get list watch]
  jobs.batch/status                            []                 []              [get list watch]
  jobs.batch                                   []                 []              [get list watch]
  endpointslices.discovery.k8s.io              []                 []              [get list watch]
  daemonsets.extensions/status                 []                 []              [get list watch]
  daemonsets.extensions                        []                 []              [get list watch]
  deployments.extensions/scale                 []                 []              [get list watch]
  deployments.extensions/status                []                 []              [get list watch]
  deployments.extensions                       []                 []              [get list watch]
  ingresses.extensions/status                  []                 []              [get list watch]
  ingresses.extensions                         []                 []              [get list watch]
  networkpolicies.extensions                   []                 []              [get list watch]
  replicasets.extensions/scale                 []                 []              [get list watch]
  replicasets.extensions/status                []                 []              [get list watch]
  replicasets.extensions                       []                 []              [get list watch]
  replicationcontrollers.extensions/scale      []                 []              [get list watch]
  ingresses.networking.k8s.io/status           []                 []              [get list watch]
  ingresses.networking.k8s.io                  []                 []              [get list watch]
  networkpolicies.networking.k8s.io            []                 []              [get list watch]
  poddisruptionbudgets.policy/status           []                 []              [get list watch]
  poddisruptionbudgets.policy                  []                 []              [get list watch]

Node等のリソースは定義されていないので注意。(必要な場合は自分でClusterRoleを作ればOK)

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?