Slide 1

Slide 1 text

Presented by @makocchi GKE Autopilot Gatekeeper の Rego を眺めてみる GCPUG Tokyo GKE Day March 2021

Slide 2

Slide 2 text

2 Makoto Hasegawa Working at // CIU, CyberAgent, Inc Currently // Develop and maintain private OpenStack cloud. Develop and maintain Kubernetes as a Service platform. CKA / CKAD / CKS Job Title // Technical Lead Infrastructure Engineer WHO am I Twitter // @makocchi Facebook // makocchi0923 Hobby // Playing bass

Slide 3

Slide 3 text

GCPUG Tokyo GKE Day March 2021 | @makocchi 3 💪 本日のゴール💪 GKE Autopilot では どんな Rego が書かれているか知ろう GKE Autopilot では様々なポリシーが Rego として記述されています その中身を見ていきましょう💪

Slide 4

Slide 4 text

GCPUG Tokyo GKE Day March 2021 | @makocchi 4 そもそも Rego とは?

Slide 5

Slide 5 text

GCPUG Tokyo GKE Day March 2021 | @makocchi 5 の前に

Slide 6

Slide 6 text

GCPUG Tokyo GKE Day March 2021 | @makocchi 6 Gatekeeper とは? から説明していきます

Slide 7

Slide 7 text

@makocchi GCPUG Tokyo GKE Day March 2021 7 Gatekeeperとは? Open Policy Agent(OPA)を使用して Kubernetes クラスタで様々なリソースを作成および更新するリクエストを検証 するためのアドミッションコントローラ 似たような機能で Pod Security Policy (PSP) がありますが、PSP は Kubernetes コミュニティで廃止を進めているので今 のうちに Gatekeeper に慣れて起きましょう GCP のドキュメントに記載されているのがチュートリアルも載っていてわかりやすいです 📝 👉「Gatekeeper を使用した Pod セキュリティ ポリシーの適用」

Slide 8

Slide 8 text

@makocchi GCPUG Tokyo GKE Day March 2021 8 Gatekeeperとは? https://kubernetes.io/blog/2019/08/06/opa-gatekeeper-policy-and-governance-for-kubernetes/

Slide 9

Slide 9 text

@makocchi GCPUG Tokyo GKE Day March 2021 9 Gatekeeperとは? Gatekeeper にはクラスターを強力かつ柔軟に制御する方法を管理者に提供するための 2 つのコンセプトがあります 制約 (Constraints) 制約テンプレート (Constraint templates) どちらも Kubernetes の CRD として使用することが可能 制約テンプレート内で記述する実際のポリシーは Rego を使って記述します Rego は Datalog の言語を元に作られた宣言型言語です JSON 等の構造化されたドキュメントを扱えるように拡張されています

Slide 10

Slide 10 text

@makocchi GCPUG Tokyo GKE Day March 2021 10 Rego について 実際の Rego の書き方や読み方は公式のドキュメントが分かりやすいと思います https://www.openpolicyagent.org/docs/latest/policy-language/ 過去に Kubernetes Fest Tokyo 2020で発表した資料も合わ せて御覧ください! https://speakerdeck.com/makocchi/best-practice-as- code-with-open-policy-agent

Slide 11

Slide 11 text

GCPUG Tokyo GKE Day March 2021 | @makocchi 11 GKE Autopilot で 定義されているポリシー(Rego)を 見ていきましょう

Slide 12

Slide 12 text

@makocchi GCPUG Tokyo GKE Day March 2021 12 どんな Constraint templatesがあるのか $ kubectl get constrainttemplates NAME AGE autogkeallowlistedworkloadlimitation 26h autogkecsrlimitation 26h autogkegpulimitation 26h autogkehostnamespaceslimitation 26h autogkehostpathvolumes 26h autogkehostportlimitation 26h autogkelinuxcapabilitieslimitation 26h autogkemanagednamespaceslimitation 26h autogkenodeaffinityselectorlimitation 26h autogkenodelimitation 26h autogkepodaffinitylimitation 26h autogkepodlimitconstraints 26h autogkepolicycrdlimitation 26h autogkeprivilegedpodlimitation 26h autopilotexternaliplimitation 26h autopilotvolumetypelimitation 26h さっそくですが、”kubectl get constrainttemplates” で見て みましょう “autogke*” と “autopilot*” の名前で様々なテンプレートが 定義されているのがわかると思います

Slide 13

Slide 13 text

@makocchi GCPUG Tokyo GKE Day March 2021 13 どんな Constraint templatesがあるのか さて、ここで GKE Autopilot にはいろいろな制約があるのですが、、、 https://cloud.google.com/kubernetes-engine/docs/concepts/autopilot-overview hostPath に関する制約がここでは書かれています 書き込み可能な状態で hostPath を使うことができない 読み込み可能なのは /var/log/ 配下のみ

Slide 14

Slide 14 text

@makocchi GCPUG Tokyo GKE Day March 2021 14 どんな Constraint templatesがあるのか というわけで早速違反してみましょう👿 ⏩ のような hostPath を “readOnly: false” にした yaml を 適用しようとすると・・・ apiVersion: v1 kind: Pod metadata: name: busybox-with-hostpath-write spec: containers: - name: busybox image: busybox command: ["sleep", “86400"] volumeMounts: - name: log-volume mountPath: /host-log readOnly: false volumes: - name: log-volume hostPath: path: /var/log/

Slide 15

Slide 15 text

@makocchi GCPUG Tokyo GKE Day March 2021 15 どんな Constraint templatesがあるのか というわけで早速違反してみましょう👿 ⏩ のような hostPath を “readOnly: false” にした yaml を 適用しようとすると・・・ ちゃんと怒られる! $ kubectl apply -f busybox_with_hostpath_write.yaml Error from server ([denied by autogke-no-write-mode-hostpath] hostPath volume log-volume in container busybox is accessed in write mode; disallowed in Autopilot. Requesting user: and groups: <["system:authenticated"]>): error when creating "busybox_with_hostpath_write.yaml": admission webhook "validation.gatekeeper.sh" denied the request: [denied by autogke-no-write-mode-hostpath] hostPath volume log- volume in container busybox is accessed in write mode; disallowed in Autopilot. Requesting user: and groups: <["system:authenticated"]>

Slide 16

Slide 16 text

@makocchi GCPUG Tokyo GKE Day March 2021 16 どんな Constraint templatesがあるのか いろいろエラーメッセージに出てきますが、ここで重要なのは “denied by autogke-no-write-mode- hostpath” という部分とその後の実際の内容です つまりどこかで定義されている “autogke-no-write-mode-hostpath” のポリシーによって弾かれたことになり ます $ kubectl apply -f busybox_with_hostpath_write.yaml Error from server ([denied by autogke-no-write-mode-hostpath] hostPath volume log-volume in container busybox is accessed in write mode; disallowed in Autopilot. Requesting user: and groups: <["system:authenticated"]>): error when creating "busybox_with_hostpath_write.yaml": admission webhook "validation.gatekeeper.sh" denied the request: [denied by autogke-no-write-mode-hostpath] hostPath volume log- volume in container busybox is accessed in write mode; disallowed in Autopilot. Requesting user: and groups: <["system:authenticated"]>

Slide 17

Slide 17 text

@makocchi GCPUG Tokyo GKE Day March 2021 17 どんな Constraint templatesがあるのか $ kubectl get constrainttemplates NAME AGE autogkeallowlistedworkloadlimitation 26h autogkecsrlimitation 26h autogkegpulimitation 26h autogkehostnamespaceslimitation 26h autogkehostpathvolumes 26h autogkehostportlimitation 26h autogkelinuxcapabilitieslimitation 26h autogkemanagednamespaceslimitation 26h autogkenodeaffinityselectorlimitation 26h autogkenodelimitation 26h autogkepodaffinitylimitation 26h autogkepodlimitconstraints 26h autogkepolicycrdlimitation 26h autogkeprivilegedpodlimitation 26h autopilotexternaliplimitation 26h autopilotvolumetypelimitation 26h さて、先程の Constraint templates 一覧に戻りましょう この中でそれっぽいやつがあるかというと・・

Slide 18

Slide 18 text

@makocchi GCPUG Tokyo GKE Day March 2021 18 どんな Constraint templatesがあるのか さて、先程の Constraint templates 一覧に戻りましょう この中でそれっぽいやつがあるかというと・・ $ kubectl get constrainttemplates NAME AGE autogkeallowlistedworkloadlimitation 26h autogkecsrlimitation 26h autogkegpulimitation 26h autogkehostnamespaceslimitation 26h autogkehostpathvolumes 26h autogkehostportlimitation 26h autogkelinuxcapabilitieslimitation 26h autogkemanagednamespaceslimitation 26h autogkenodeaffinityselectorlimitation 26h autogkenodelimitation 26h autogkepodaffinitylimitation 26h autogkepodlimitconstraints 26h autogkepolicycrdlimitation 26h autogkeprivilegedpodlimitation 26h autopilotexternaliplimitation 26h autopilotvolumetypelimitation 26h これじゃね?(確信)

Slide 19

Slide 19 text

@makocchi GCPUG Tokyo GKE Day March 2021 19 どんな Constraint templatesがあるのか さっそくこの “autogkehostpathvolumes” のテンプレート の中身を見ていきましょう 中身を見るには “describe” もしくは “get -o yaml” で見ると いいでしょう $ kubectl describe constrainttemplates autogkehostpathvolumes $ kubectl get constrainttemplates autogkehostpathvolumes -o yaml $ kubectl get constrainttemplates NAME AGE autogkeallowlistedworkloadlimitation 26h autogkecsrlimitation 26h autogkegpulimitation 26h autogkehostnamespaceslimitation 26h autogkehostpathvolumes 26h autogkehostportlimitation 26h autogkelinuxcapabilitieslimitation 26h autogkemanagednamespaceslimitation 26h autogkenodeaffinityselectorlimitation 26h autogkenodelimitation 26h autogkepodaffinitylimitation 26h autogkepodlimitconstraints 26h autogkepolicycrdlimitation 26h autogkeprivilegedpodlimitation 26h autopilotexternaliplimitation 26h autopilotvolumetypelimitation 26h

Slide 20

Slide 20 text

@makocchi GCPUG Tokyo GKE Day March 2021 apiVersion: templates.gatekeeper.sh/v1beta1 kind: ConstraintTemplate metadata: name: autogkehostpathvolumes spec: targets: rego: |- violation_pod[{"msg": msg}] { spec := helpers.get_spec(input.review.object) spec["volumes"] hostPathVolumes := {vol.name | vol := spec.volumes[_]; vol["hostPath"]} containers := array.concat(object.get(spec, "initContainers", []), object.get(spec, "containers", [])) container := containers[_] container["volumeMounts"] volumeMount := container.volumeMounts[_] hostPathVolume := hostPathVolumes[_] hostPathVolume == volumeMount.name not object.get(volumeMount, "readOnly", false) msg := sprintf("hostPath volume %s in container %s is accessed in write mode; disallowed in Autopilot. Requesting user: <%s> and groups: <%v>", [hostPathVolume, container.name, input.review.userInfo.username, input.review.userInfo.groups]) } 20 どんな Constraint templatesがあるのか 中身を見るとこんな感じです ※実際の中身はもっといろいろ書かれているんです が、書ききれないので省略して書いてあります

Slide 21

Slide 21 text

@makocchi GCPUG Tokyo GKE Day March 2021 apiVersion: templates.gatekeeper.sh/v1beta1 kind: ConstraintTemplate metadata: name: autogkehostpathvolumes spec: targets: rego: |- violation_pod[{"msg": msg}] { spec := helpers.get_spec(input.review.object) spec["volumes"] hostPathVolumes := {vol.name | vol := spec.volumes[_]; vol["hostPath"]} containers := array.concat(object.get(spec, "initContainers", []), object.get(spec, "containers", [])) container := containers[_] container["volumeMounts"] volumeMount := container.volumeMounts[_] hostPathVolume := hostPathVolumes[_] hostPathVolume == volumeMount.name not object.get(volumeMount, "readOnly", false) msg := sprintf("hostPath volume %s in container %s is accessed in write mode; disallowed in Autopilot. Requesting user: <%s> and groups: <%v>", [hostPathVolume, container.name, input.review.userInfo.username, input.review.userInfo.groups]) } 21 どんな Constraint templatesがあるのか 先程のエラーメッセージはここから生成されていることが分かります hostPath volume log-volume in container busybox is accessed in write mode; disallowed in Autopilot. Requesting user: and groups: <["system:authenticated"]>

Slide 22

Slide 22 text

@makocchi GCPUG Tokyo GKE Day March 2021 22 どんな Constraint templatesがあるのか ちなみに “readOnly: true” に変更することで先程の Pod は問題なく起動させることが可能です さらにちなみにどんな log が host 側の “/var/log” にあるのかというと・・・ /host-log # ls -F alternatives.log cloud-init-output.log containers/ journal/ lastlog pods/ wtmp btmp cloud-init.log fluentbit.log kube-proxy.log metrics/ private/

Slide 23

Slide 23 text

@makocchi GCPUG Tokyo GKE Day March 2021 23 どんな Constraint templatesがあるのか 各コンテナの log は containers/ 配下にきちんと履かれているようです (実際には /var/log/pods/ への symlink) /host-log/containers # ls busybox-with-hostpath-read_default_busybox-9b5e3324bac7442bc10b4f8d59a7a71f721d236b2ec5d363ea66c49355aac7d9.log fluentbit-gke-kfw96_kube-system_fluentbit-96c87727478cfc0810b1d152b605af4c87459b6baf00c51f8d2bdc224f0f760b.log fluentbit-gke-kfw96_kube-system_fluentbit-gke-e8f155cad0ea48aa7cd372ad05418bff3d8d850b8f2d46abba56ee144959527b.log gke-metadata-server-p957p_kube-system_gke-metadata-server-a118ef45690be5424ec82358f1882d84ffc6b2ce27e014b02bdce453887462ca.log gke-metrics-agent-lg9tz_kube-system_gke-metrics-agent-cfec2dd2d1d99041ba6b6765959edc032e89437389cabf6ee96bd9fc78dcff74.log kube-proxy-gk3-makocchi-ap-default-pool-299f5e3f-gk35_kube-system_kube- proxy-8b3e73275e1814174d8d3b3b488f67e2bcd8f7dd7ff5437d2fae8ae45e398613.log netd-2r9d6_kube-system_install-cni-bc03fc54612292f9cf45370aca2cfdc10751f3ddbcb5f9fb5bfc88ee9de5f171.log netd-2r9d6_kube-system_netd-59cc778b980a9169610784554350edb87114895b31702007e87a9dc25fd5eb6b.log node-local-dns-tgshb_kube-system_node-cache-fb941fec3f187a2ab2857236ee630ab14533e7c40cda11f6eb7dc261d4d11318.log pdcsi-node-px9sq_kube-system_csi-driver-registrar-c8f185e87332e9e63114cddcdc09ceb95c199df20101e373768b293d078a4d9a.log pdcsi-node-px9sq_kube-system_gce-pd-driver-634a0cd6a0f8c616ea9ceea6e18c5438a81ba1911880ea823347264d758a339e.log

Slide 24

Slide 24 text

@makocchi GCPUG Tokyo GKE Day March 2021 24 どんな Constraint templatesがあるのか 話を戻しましょう 先程の autogkehostpathvolumes テンプレートには他にも いろいろなポリシーが定義されています 例えば先程のマニフェストを編集して “/var/log” 以外の hostPath を指定してみましょう apiVersion: v1 kind: Pod metadata: name: busybox-with-hostpath-tmp-read spec: containers: - name: busybox image: busybox command: ["sleep", “86400"] volumeMounts: - name: tmp-volume mountPath: /host-tmp readOnly: true volumes: - name: tmp-volume hostPath: path: /var/tmp # /var/log ͔Βมߋ

Slide 25

Slide 25 text

@makocchi GCPUG Tokyo GKE Day March 2021 25 どんな Constraint templatesがあるのか “readOnly: false” の時とは違ったエラーメッセージが出てきますが、ポリシーは autogke-no-write-mode- hostpath で同じですね $ kubectl apply -f busybox_with_hostpath_read_tmp.yaml Error from server ([denied by autogke-no-write-mode-hostpath] hostPath volume tmp-volume used in container busybox uses path /var/tmp which is not allowed in Autopilot. Allowed path prefixes for hostPath volumes are: ["/var/ log/"]. Requesting user: and groups: <["system:authenticated"]>): error when creating "busybox_with_hostpath_read_tmp.yaml": admission webhook "validation.gatekeeper.sh" denied the request: [denied by autogke-no-write-mode-hostpath] hostPath volume tmp-volume used in container busybox uses path /var/tmp which is not allowed in Autopilot. Allowed path prefixes for hostPath volumes are: ["/var/log/"]. Requesting user: and groups: <["system:authenticated"]>

Slide 26

Slide 26 text

@makocchi GCPUG Tokyo GKE Day March 2021 apiVersion: templates.gatekeeper.sh/v1beta1 kind: ConstraintTemplate metadata: name: autogkehostpathvolumes spec: targets: rego: |- violation_pod[{"msg": msg}] { spec := helpers.get_spec(input.review.object) spec["volumes"] hostPathVolumes := {vol | vol := spec.volumes[_]; vol["hostPath"]} containers := array.concat(object.get(spec, "initContainers", []), object.get(spec, "containers", [])) container := containers[_] container["volumeMounts"] volumeMount := container.volumeMounts[_] hostPathVolume := hostPathVolumes[_] hostPathVolume.name == volumeMount.name object.get(volumeMount, "readOnly", false) count({x | x := input.parameters.allowedPrefixes[_]; startswith(helpers.path(hostPathVolume.hostPath.path), x)}) == 0 msg := sprintf("hostPath volume %s used in container %s uses path %s which is not allowed in Autopilot. Allowed path prefixes for hostPath volumes are: %v. Requesting user: <%s> and groups: <%v>", [hostPathVolume.name, container.name, hostPathVolume.hostPath.path, input.parameters.allowedPrefixes, input.review.userInfo.username, input.review.userInfo.groups]) } 26 どんな Constraint templatesがあるのか 例によって抜粋していますが、先程の hostPath の prefix に関する チェックはこの Rego で行われていますね

Slide 27

Slide 27 text

@makocchi GCPUG Tokyo GKE Day March 2021 apiVersion: templates.gatekeeper.sh/v1beta1 kind: ConstraintTemplate metadata: name: autogkehostpathvolumes spec: targets: rego: |- violation_pod[{"msg": msg}] { spec := helpers.get_spec(input.review.object) spec["volumes"] hostPathVolumes := {vol | vol := spec.volumes[_]; vol["hostPath"]} containers := array.concat(object.get(spec, "initContainers", []), object.get(spec, "containers", [])) container := containers[_] container["volumeMounts"] volumeMount := container.volumeMounts[_] hostPathVolume := hostPathVolumes[_] hostPathVolume.name == volumeMount.name object.get(volumeMount, "readOnly", false) count({x | x := input.parameters.allowedPrefixes[_]; startswith(helpers.path(hostPathVolume.hostPath.path), x)}) == 0 msg := sprintf("hostPath volume %s used in container %s uses path %s which is not allowed in Autopilot. Allowed path prefixes for hostPath volumes are: %v. Requesting user: <%s> and groups: <%v>", [hostPathVolume.name, container.name, hostPathVolume.hostPath.path, input.parameters.allowedPrefixes, input.review.userInfo.username, input.review.userInfo.groups]) } 27 どんな Constraint templatesがあるのか エラーメッセージを見ると ”Allowed path prefixes for hostPath volumes are: [“/var/log/“]" となっていました つまり、こちらの input.paramters.allowedPrefixes に /var/log が渡されているということになります

Slide 28

Slide 28 text

@makocchi GCPUG Tokyo GKE Day March 2021 28 どんな Constraint templatesがあるのか allowedPrefixes はどこから設定されているのでしょうか? これは autogkehostpathvolumes のテンプレートを呼び出す時にパラメーターとして渡されています テンプレートを適用する対象は制約 (Constraints) で定義するのですが、そこでパラメーターが指定されています autogkehostpathvolumes の Constraint template を定義すると、Gatekeeper によりそれに対応する Constraints の CRD が自動で作成されます ⏩ のような感じで Constraint template 内で定義されています これにより “AutoGKEHostPathVolumes” という CRD が作成されます apiVersion: templates.gatekeeper.sh/v1beta1 kind: ConstraintTemplate metadata: name: autogkehostpathvolumes spec: crd: spec: names: kind: AutoGKEHostPathVolumes ※ 抜粋

Slide 29

Slide 29 text

@makocchi GCPUG Tokyo GKE Day March 2021 29 どんな Constraint があるのか さっそく制約(Constraint) の CRD を見てみましょう $ kubectl get crd | grep -i AutoGKEHostPathVolumes autogkehostpathvolumes.constraints.gatekeeper.sh 2021-03-06T14:09:45Z 対応する CR も作られていることが分かります $ kubectl get AutoGKEHostPathVolumes NAME AGE autogke-no-write-mode-hostpath 28h ※ちなみに autogkehostpathvolumes 以外にもいろいろな種類の定義がされているので要チェック

Slide 30

Slide 30 text

@makocchi GCPUG Tokyo GKE Day March 2021 30 どんな Constraint があるのか 例によって中身を見てみましょう (get -o yaml か describe で OK!) spec.parameters のところを見ると allowedPrefixes が定義されてい て “/var/log/“ が書かれています 他にもパラメーターとして privilegedGroups や privilegedUsers み たいなものも定義されています apiVersion: constraints.gatekeeper.sh/v1beta1 kind: AutoGKEHostPathVolumes metadata: name: autogke-no-write-mode-hostpath spec: ... parameters: allowedPrefixes: - /var/log/ ... ※ 抜粋

Slide 31

Slide 31 text

@makocchi GCPUG Tokyo GKE Day March 2021 31 どんな Constraint があるのか 例によって中身を見てみましょう (get -o yaml か describe で OK!) spec.parameters のところを見ると allowedPrefixes が定義されてい て “/var/log/“ が書かれています 他にもパラメーターとして privilegedGroups や privilegedUsers み たいなものも定義されています spec.match.kinds では適用対象のリソースを設定します 実際には Pod/Deployment/DaemonSet/ReplicaSet/ReplicationController/ StatefulSet/Job/CronJob/PersistentVolume が kinds で指定されています apiVersion: constraints.gatekeeper.sh/v1beta1 kind: AutoGKEHostPathVolumes metadata: name: autogke-no-write-mode-hostpath spec: match: kinds: - apiGroups: - apps - "" - batch apiVersions: - v1 - v1beta1 kinds: - Pod - Deployment ... ※ 抜粋

Slide 32

Slide 32 text

GCPUG Tokyo GKE Day March 2021 | @makocchi 32 Gatekeeper を通す設定は どこでされているのか?

Slide 33

Slide 33 text

@makocchi GCPUG Tokyo GKE Day March 2021 33 Gatekeeper を通す設定はどこでされているのか? 結論から言ってしまうと ValidatingWebhookConfiguration で定義されています 先程紹介したエラーメッセージにも書かれていましたね $ kubectl get ValidatingWebhookConfiguration NAME WEBHOOKS AGE gatekeeper-validating-webhook-configuration 1 29h nodelimit.config.common-webhooks.networking.gke.io 1 29h policycontroller.config.common-webhooks.networking.gke.io 1 29h こちらの “gatekeeper-validating-webhook-configuration” にて設定されています

Slide 34

Slide 34 text

@makocchi GCPUG Tokyo GKE Day March 2021 34 Gatekeeper を通す設定はどこでされているのか? 定義の中を見ると webhook 先に “https://localhost:8787/ v1/admit” が設定されていることが分かります クラスター外の endpoint になっているので Google が管理し ているコントロールプレーン内で kube-apiserver と一緒に Gatekeeper が動いているんだろうと思われます (もしかした ら Gatekeeper ではない可能性もありますが・・) apiVersion: admissionregistration.k8s.io/v1 kind: ValidatingWebhookConfiguration metadata: name: gatekeeper-validating-webhook-configuration webhooks: - admissionReviewVersions: - v1beta1 clientConfig: url: https://localhost:8787/v1/admit name: validation.gatekeeper.sh rules: ... ※ 抜粋

Slide 35

Slide 35 text

@makocchi GCPUG Tokyo GKE Day March 2021 35 Gatekeeper を通す設定はどこでされているのか? Webhook の rule に関しては 3 つ定義されています すべてのリソースの CREATE/UPDATE 及び CRD と node の DELETE の時に hook されるようですね rules: - apiGroups: - '*' apiVersions: - '*' operations: - CREATE - UPDATE resources: - '*' scope: '*' ※ 抜粋 rules: - apiGroups: - apiextensions.k8s.io apiVersions: - v1 operations: - CREATE - UPDATE - DELETE resources: - customresourcedefinitions scope: '*' rules: - apiGroups: - "" apiVersions: - v1 operations: - CREATE - UPDATE - DELETE resources: - nodes scope: '*'

Slide 36

Slide 36 text

@makocchi GCPUG Tokyo GKE Day March 2021 36 Gatekeeper を通す設定はどこでされているのか? 試しに消そうとしてみた👿 $ kubectl delete crd autogkehostpathvolumes.constraints.gatekeeper.sh Error from server ([denied by autogke-policy-crd-limitation] Operations on Policy related CRDs are not allowed in Autopilot. Requesting user: and groups: <["system:authenticated"]>): admission webhook "validation.gatekeeper.sh" denied the request: [denied by autogke-policy-crd-limitation] Operations on Policy related CRDs are not allowed in Autopilot. Requesting user: and groups: <["system:authenticated"]> しっかりと拒否されましたね 今度は autogke-policy-crd-limitation のポリシーが適用されたというのが分かります どんな Rego が書かれているかは Constraint template の autogkepolicycrdlimitation を見てみてください

Slide 37

Slide 37 text

GCPUG Tokyo GKE Day March 2021 | @makocchi 37 本日のまとめ

Slide 38

Slide 38 text

GCPUG Tokyo GKE Day March 2021 | @makocchi 38 GKE Autopilot の様々な制約は Gatekeeper によって制御されている GKE Autopilot 用に作られた定義は “autogke*” や “autopilot*” の Constraint template を見ると分かる Gatekeeper はクラスター内ではなく Google マネージドのコントロールプレー ン側で稼働していると思われる ひょっとしたら公式のドキュメントに書かれていない制約が Gatekeeper 側で設 定されているかもしれない ポリシー自体はユーザーから操作できないので、ポリシーの更新はどうやって 行われるのか(or 行われないのか)が気になるところ みんなもいろんな Rego を眺めてみましょう! まとめだよ

Slide 39

Slide 39 text

GCPUG Tokyo GKE Day March 2021 | @makocchi 39 達成できましたでしょうか? おぼえてね 💪 本日のゴール💪 GKE Autopilot では どんな Rego が書かれているか知ろう

Slide 40

Slide 40 text

Presented by @makocchi GKE Autopilot Gatekeeper の Rego を眺めてみる GCPUG Tokyo GKE Day March 2021 FINISH ご清聴ありがとうございました!! GKE Autopilot Gatekeeper の Rego を眺めてみる All background images in this presentation are picked from pixabay.com