Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
k8sとOPAつなげてみた - Admission Controller編
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kengo Suzuki
March 18, 2019
Technology
1.1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
k8sとOPAつなげてみた - Admission Controller編
Kengo Suzuki
March 18, 2019
More Decks by Kengo Suzuki
See All by Kengo Suzuki
男(監査)はつらいよ - Policy as CodeからAIエージェントへ
ken5scal
5
1.1k
AI時代の大規模データ活用とセキュリティ戦略
ken5scal
1
520
Pwned Labsのすゝめ
ken5scal
2
1.1k
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
3
1.3k
Eventual Detection Engineering
ken5scal
0
2.9k
脆弱性対応をこの先生きのこるには
ken5scal
0
1.7k
LayerXとMDMのリスク評価と年次対応の実例(公開版)
ken5scal
2
1.5k
AWSだ! Google Cloudだ! Azureだ! 認証連携だ!
ken5scal
9
2.6k
適応し続けるプロダクトとセキュリティ
ken5scal
5
2.5k
Other Decks in Technology
See All in Technology
Agentic Web
dynamis
1
200
On-behalf-of Token exchange with AgentCore Identity
hironobuiga
2
120
2026TECHFRESH畢業分享會 - Lightning Talk - 資料也要 CI/CD? 用 Airbyte 自動化資料同步
line_developers_tw
PRO
0
130
新しいVibe Codingと”自走”について
watany
5
270
2026TECHFRESH畢業分享會 - Lightning Talk - E起 See See : 電商推薦讀心術? 數據說了算
line_developers_tw
PRO
0
130
Databricks における 生成AIガバナンスの実践
taka_aki
1
370
AWSシリコン最前線 〜AI時代のチップ選択を読み解く〜
htokoyo
2
330
作って終わりにしない タイミーのセマンティックレイヤー育成の現在地
chanyou0311
3
1.9k
Dario Amodi『Policy on the AI Exponential』を理解する
nagatsu
0
210
2026TECHFRESH畢業分享會 - AI 時代的人生存檔點
line_developers_tw
PRO
0
150
小さくはじめるSLI/SLO ~育てながら組織に定着させる実践知~ / Starting Small with SLI/SLOs: Building Adoption Through Continuous Growth
nari_ex
2
990
Reliability in the Age of AI: Engineering for AI Velocity
rrreeeyyy
0
120
Featured
See All Featured
How STYLIGHT went responsive
nonsquared
100
6.2k
How Software Deployment tools have changed in the past 20 years
geshan
0
34k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
340
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
170
The Limits of Empathy - UXLibs8
cassininazir
1
350
Technical Leadership for Architectural Decision Making
baasie
3
400
So, you think you're a good person
axbom
PRO
2
2.1k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
320
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
310
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Writing Fast Ruby
sferik
630
63k
Practical Orchestrator
shlominoach
191
11k
Transcript
k8sͱOPAͭͳ͛ͯΈͨ - Admission Controllerฤ 2019/03/18 @ken5scal
Ζ͏ͱͨ͜͠ͱ 1. k8sͷAdmission ControllerΛOPAʹ͚Δ 2. k8s APIαʔόʔͷϦΫΤετʹOPAϙϦγʔΛ ద༻͢Δ
k8s Admission Controllerͱ - k8s APIαʔόʔʹର͢ΔೝূɾೝՄ͞ΕͨϦΫΤετ ͷΦϒδΣΫτ͕ӬଓԽ͞ΕΔલʹɺ੍ޚ͢Δػߏ - ϓϥάΠϯʹΑͬͯɺͲͷΑ͏ͳ੍ޚΛ͢Δ͔ܾΊΒΕ Δ
OPAʢΦʔύʣͱ - ϦΫΤετͷਖ਼ੑΛݕূͯ͠ɺΤʔδΣϯτʹ ݁ՌΛฦ͢ɺ͍ΘΏΔϙϦγʔΤϯδϯ - ʮCloud Native Meetup Tokyo #4ʯͷൃදࢀর
https://speakerdeck.com/ken5scal/introduction-to-open-policy-agent
- ValidatingAdmissionWebhookʹOPAΛઃఆ - k8s APIαʔόʹର͢ΔͲͷΑ͏ͳΞΫγϣϯΛࢦ ఆ͢Δ͔ɺͬͪ͜ʹॻ͘ k8s Admission ControllerͱOPAɹͦͷᶃ
cat > webhook-configuration.yaml <<EOF kind: ValidatingWebhookConfiguration apiVersion: admissionregistration.k8s.io/v1beta1 metadata: name:
opa-validating-webhook webhooks: - name: validating-webhook.openpolicyagent.org rules: - operations: ["CREATE", "UPDATE"] apiGroups: ["*"] apiVersions: ["*"] resources: ["*"] clientConfig: caBundle: $(cat ca.crt | base64 | tr -d '\n') service: namespace: opa name: opa EOF https://aws.amazon.com/jp/blogs/opensource/using-open-policy-agent-on-amazon-eks/
- OPAͷϙϦγʔͦͷͷRegoͰهड़ - k8sͷConfigMapsͱͯ͠औΓࠐΉ k8s Admission ControllerͱOPAɹͦͷᶄ
ྫ1: IngressͷFQDNࢦఆ
package kubernetes.admission import data.kubernetes.namespaces deny[msg] { input.request.kind.kind = "Ingress" input.request.operation
= "CREATE" host = input.request.object.spec.rules[_].host not fqdn_matches_any(host, valid_ingress_hosts) msg = sprintf("invalid ingress host %q", [host]) } valid_ingress_hosts = {host | whitelist = namespaces[input.request.namespace].metadata.annotations["ingress- whitelist"] hosts = split(whitelist, ",") host = hosts[_] } https://www.openpolicyagent.org/docs/kubernetes-admission-control.html
% cat ingress-bad.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: name: ingress-bad
spec: rules: - host: acmecorp.com http: paths: - backend: serviceName: nginx servicePort: 80 % kubectl create -f ingress-bad.yaml -n qa Error from server (invalid ingress host "acmecorp.com"): error when creating "ingress- bad.yaml": admission webhook "validating-webhook.openpolicyagent.org" denied the request: invalid ingress host "acmecorp.com" https://www.openpolicyagent.org/docs/kubernetes-admission-control.html
ྫ1: ίϯςφϨδετϦͷࢦఆ
cat > image_source.rego <<EOF package kubernetes.admission deny[msg] { input.request.kind.kind =
"Pod" input.request.operation = "CREATE" image = input.request.object.spec.containers[_].image name = input.request.object.metadata.name not registry_whitelisted(image,whitelisted_registries) msg = sprintf("pod %q has invalid registry %q", [name, image]) } whitelisted_registries = {registry | registries = [ “602401143452.dkr.ecr.ap-northeast-1.amazonaws.com" ] registry = registries[_] } registry_whitelisted(str, patterns) { registry_matches(str, patterns[_]) } registry_matches(str, pattern) { contains(str, pattern) } https://aws.amazon.com/jp/blogs/opensource/using-open-policy-agent-on-amazon-eks/
% cat nginx.yaml kind: Pod apiVersion: v1 metadata: name: nginx
labels: app: nginx namespace: default spec: containers: - image: nginx name: nginx % kubectl apply -f nginx.yaml Error from server (pod "nginx" has invalid registry "nginx"): error when creating "nginx.yaml": admission webhook "validating-webhook.openpolicyagent.org" denied the request: pod "nginx2" has invalid registry "nginx" https://aws.amazon.com/jp/blogs/opensource/using-open-policy-agent-on-amazon-eks/
Ͱ͖ͳ͍͜ͱ - Runtimeͷ੍ޚ - APIαʔόʔʹର͢Δૢ࡞੍͔͠ޚͰ͖ͳ͍ - “ϙϦγʔ”ͷద༻ͳͷͰ੩తͳݕࠪͩͱΓͳ͍ - OPAͦͷͷͷ੍ޚ -
etc
͜͜ʹςΩετΛೖΕ·͢ɻ ͻͱͭͷεϥΠυʹ༰Λ٧Ί͗͢ ͳ͍Α͏ʹ͠·͠ΐ͏ɻ ʮ̍ຕͷεϥΠυʹ̍ͭͷҙຯʯ͕ εϥΠυ࡞ΓͷجຊͰ͢ɻ ٕज़ॻయͰOPAωλͷബ͍ຊͩ͠·͢
@ken5scal
Thank you