インフラ系SEの技術メモ

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

(Kubernetes)privilegedとallowPrivilegeEscalationの違いを調べたメモ

PodのSecurity Context

ややこしい二つの権限ですが、まずはprivilegedはコンテナを特権モードで動作させるか否かを指定します。
これで動かすと、そのコンテナのプロセスは基本的にホスト上のrootと同等の権限を持ちます。

つまり、以下のように動かしたコンテナはiptableの書き換えなんかもできる。

spec:
  containers:
...
    securityContext:
      privileged: true

ではallowPrivilegeEscalationはどうか?
さっきの部分を置き換えてiptableを見に行こうとすると

$ k exec prime -- iptables -L
iptables v1.8.7 (legacy): can't initialize iptables table `filter': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded. command terminated with exit code 3

とのこと。つまりOSをいじるような権限ではなさそう。

ここでググるとsetuidという文言が。

AllowPrivilegeEscalation: The execve system call can grant a newly-started program privileges that its parent did not have, such as the setuid or setgid Linux flags. This is controlled by the AllowPrivilegeEscalation boolean and should be used with care and only when required.

とりあえず、privilegedの方が強い権限・・と覚えておきます。