インフラ系SEの技術メモ

雑なエンジニアが低信頼性のメモを書いています。参考程度にとどめてください。

(Kubernetes)Podに対してexecを実行するのに必要な権限がややこしい

何が必要?

こんな感じで権限紐付けがされている時に

# kubectl describe rolebinding testrb
Name:         testrb
Labels:       <none>
Annotations:  <none>
Role:
  Kind:  Role
  Name:  testrole
Subjects:
  Kind  Name      Namespace
  ----  ----      ---------
  User  testuser

以下のRoleがあればexecできました。

# kubectl describe role
Name:         testrole
Labels:       <none>
Annotations:  <none>
PolicyRule:
  Resources  Non-Resource URLs  Resource Names  Verbs
  ---------  -----------------  --------------  -----
  pods/exec  []                 []              [create get]
  pods       []                 []              [create get]

ポイント

getとcleateが必要なんですよね。
直感的には

pods/exec

になにかあればいるんだろうな?とは思いつつ片方だけであれば

Error from server (Forbidden): pods "xx" is forbidden: User "testuser" cannot get resource "pods" in API group "" in the namespace "default"

というエラーになります。