0
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?

RBAC Serviceaccountを理解する

Last updated at Posted at 2025-10-06

目的

  • RBAC Serviceaccount を理解する

手段

killercodaで手を動かす

環境

killercoda

RBAC Serviceaccout とは

KubernetesのRBAC(Role-Based Access Control)における**ServiceAccount(サービスアカウント)**とは、**PodなどのKubernetesリソースがAPIサーバーにアクセスするための「身分証明書」**のようなものです。以下にわかりやすく説明します。

Kubernetesでは、PodがAPIサーバーにアクセスしてリソースを操作することがあります(例:他のPodの情報取得、ConfigMapの読み込みなど)。このとき、誰がアクセスしているのかを識別する必要があります。
ServiceAccountは、PodやJobなどの「非人間ユーザー」のためのアカウントです。
デフォルトでは、Podには自動的にdefaultというServiceAccountが割り当てられます。

つまり、Serviceaccount に対して RBAC を設定する話です。

気を付ける点は以下の通りです

  • clusterrole 及び clusterrolebinding は namespace を指定しないで作成する
  • clusterrolebinding 作成時に2つの serviceaccountを紐づける場合、--serviceaccout=ns1:pipeline --serviceaccout=ns1:pipeline と記述する
  • secretの名前を参照できて、かつ中身を参照できない verb は watch を利用

それぞれサンプル設定を確認します。

  • clusterrole 及び clusterrolebinding は namespace を指定しないで作成する
  • clusterrolebinding 作成時に2つの serviceaccountを紐づける場合、--serviceaccout=ns1:pipeline --serviceaccout=ns1:pipeline と記述する
k create clusterrolebinding pipeline-view --clusterrole view --serviceaccount ns1:pipeline --serviceaccount ns2:pipeline
  • secretの名前を参照できて、かつ中身を参照できない verb は watch を利用
controlplane:~$ k describe -n applications role smoke-secret                      
Name:         smoke-secret
Labels:       <none>
Annotations:  <none>
PolicyRule:
  Resources  Non-Resource URLs  Resource Names  Verbs
  ---------  -----------------  --------------  -----
  secrets    []                 []              [watch]

# verb 確認

k auth can-i list secrets --as smoke -n applications # NO
k auth can-i get secrets --as smoke -n applications # NO
no
no

watch権限を持つと、Kubernetes APIからリソースの変更イベント(追加・更新・削除)をリアルタイムで受け取ることができます。このとき、以下のようなメタデータ情報は含まれる可能性があります:

つまり、watch 権限は対象リソースの変更イベントをリアルタイムで確認可能です。

kubectl get secrets --watch

具体的な動作

動詞 説明 内容取得可能?
list 一覧取得 ✅(内容含む)
get 個別取得 ✅(内容含む)
watch 変更の監視 ❌(内容は見えない)

あとがき

Kubernetes は奥が深い...

ソース

0
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
0
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?