Harden securityContext on the bundled postgres StatefulSet

オープン 初心者向け
#4,171 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
77/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
go, kubernetes, yaml

調査の方向性

manifests/ate-install/postgres/postgres.yaml から始め、postgres と tls-reloader の各コンテナのセキュリティコンテキストを、既存の Pod レベルの fsGroup と併せて確認します。postgres コンテナの TLS に対応した ID 設定を維持しながら、要求された制限を追加します。次に pod-certificate-controller.yaml を確認し、未使用の NET_BIND_SERVICE capability を調べます。要求されたコンテナの制限と capability の削除が manifests に反映されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

area/security kind/feature

The default install StatefulSet in manifests/ate-install/postgres/postgres.yaml already sets a careful pod-level fsGroup: 70 and documents why the postgres container must not pin runAsUser: pinning it would make the projected TLS key group-readable, and PostgreSQL would refuse to start.

The main postgres container still has no container securityContext at all, and the tls-reloader sidecar only sets runAsUser: 70:

https://github.com/agent-substrate/substrate/blob/7319f1afa2ac90c8224117463f13f7bf782f63ac/manifests/ate-install/postgres/postgres.yaml#L122-L127

https://github.com/agent-substrate/substrate/blob/7319f1afa2ac90c8224117463f13f7bf782f63ac/manifests/ate-install/postgres/postgres.yaml#L149-L151

That leaves allowPrivilegeEscalation at the Kubernetes default (true), does not drop capabilities (including NET_RAW), and does not set runAsNonRoot. The official postgres:18-alpine image already runs as UID 70, so runAsNonRoot: true without runAsUser on the main container should be compatible with the TLS constraint above.

This is leftover install hardening after #2936 / #3028, which covered the Substrate control-plane pods but not the bundled database. Authentication for that database is already in good shape (client certificates, hostssl ... cert, and a NetworkPolicy that admits only ate-api-server). This request is only about the pod security context.

Suggested container securityContext:

For postgres (do not set runAsUser):

securityContext:
  allowPrivilegeEscalation: false
  runAsNonRoot: true
  capabilities:
    drop:
    - ALL

For tls-reloader, keep runAsUser: 70 and add the same allowPrivilegeEscalation: false, runAsNonRoot: true, and capabilities.drop: [ALL].

Optional: seccompProfile: {type: RuntimeDefault} on the pod or containers.

Related: unused NET_BIND_SERVICE on podcertificate-controller

ate-api-server correctly keeps NET_BIND_SERVICE because it binds :443. The same capability is still set on podcertificate-controller:

https://github.com/agent-substrate/substrate/blob/7319f1afa2ac90c8224117463f13f7bf782f63ac/manifests/ate-install/pod-certificate-controller.yaml#L179-L187

cmd/podcertcontroller is a kube-apiserver client; it does not listen on a privileged port (or any port). Dropping the add list would leave drop: [ALL] only.

Found with Rustmaninoff (https://github.com/jose-compu/rustmaninoff), a Checkov-compatible IaC scanner; check IDs CKV_K8S_20, CKV_K8S_23, CKV_K8S_28, and CKV_K8S_25.

主要言語
Go
スター
8.7k
フォーク
969
平均マージ
5日 1時間
マージ済み PR(30日)
128

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

agent-substrate/substrate のほかの issue

agent-substrate/substrate の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。