Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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.2k
AI時代の大規模データ活用とセキュリティ戦略
ken5scal
1
560
Pwned Labsのすゝめ
ken5scal
2
1.3k
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
3
1.4k
Eventual Detection Engineering
ken5scal
0
3k
脆弱性対応をこの先生きのこるには
ken5scal
0
1.8k
LayerXとMDMのリスク評価と年次対応の実例(公開版)
ken5scal
2
1.5k
AWSだ! Google Cloudだ! Azureだ! 認証連携だ!
ken5scal
9
2.7k
適応し続けるプロダクトとセキュリティ
ken5scal
5
2.6k
Other Decks in Technology
See All in Technology
Essential architectural thinking (revised edition)
ufried
0
110
予測不能な実行エージェントを安全にサクッと試せるサンドボックス環境の話
sansantech
PRO
0
140
AI時代のPRレビューにどう向き合うか?
kairim0
1
130
検証フェーズはAIの回答を判断するための学習機会
toru_kubota
2
560
Loop Engineering これくらいでいい
mikanichinose
0
180
AIは爆速なのに、私が詰まっていた話 ― 音声入力と鳴くマスコットでボトルネックを削る
yama3133
0
580
Datadog の学び方 - あるいは、オブザーバビリティを学ぶとは何か
mananyuki
1
520
オンラインゲームのシステム全体像 - コロプラ 2026年度 新卒研修
colopl
0
1k
20260930_Gemma4_Hands-on
tsho
0
240
1万名の社員が使う認証基盤で どう信頼性を担保するか?
kairim0
0
220
SREでアラート疲れを 解決しよう!
kairim0
1
220
使いこなすために知っておきたい Azure SRE Agent アンチパターン
torumakabe
2
440
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
72
12k
Writing Fast Ruby
sferik
630
63k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Abbi's Birthday
coloredviolet
4
10k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
620
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.6k
From π to Pie charts
rasagy
1
390
Paper Plane
katiecoart
PRO
4
54k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Test your architecture with Archunit
thirion
2
2.4k
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