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
入門Open Policy Agent: Policy as Codeを目指して / intr...
Search
Kurochan
September 16, 2021
Technology
0
520
入門Open Policy Agent: Policy as Codeを目指して / introduction-to-open-policy-agent
サイバーエージェントの社内エンジニアカンファレンス CA BASE CAMP 2021で発表した資料です
Kurochan
September 16, 2021
Tweet
Share
More Decks by Kurochan
See All by Kurochan
入門 電気通信事業者
kurochan
12
5k
AWS x さくらのクラウドのハイブリッドクラウドによる安価なフレッツ閉域網接続の実装
kurochan
9
4.9k
GoでTCP Proxyを実装してみよう
kurochan
1
750
サイバーエージェントの広告配信におけるIPoEトラフィックの概況
kurochan
0
330
スケールするというのはどういうことなのか
kurochan
14
4.4k
サイバーエージェントのGitHub Copilot導入と 開発生産性
kurochan
44
41k
Cloudflare Zero Trustを利用したセキュアな開発環境へのアクセス手法の確立
kurochan
10
2.8k
セキュキャンを卒業してその後
kurochan
0
1.2k
サイバーエージェントの実践×実験Snowflake 導入の経緯から最新機能のトライアルまで / How Snowflake Is Used In CyberAgent - Go To the Future
kurochan
0
960
Other Decks in Technology
See All in Technology
RAGHack: Building RAG apps in Python
pamelafox
0
110
手軽に始める? おうちサーバーのすゝめ
nyagasan
0
180
リクルートのデータマネジメント組織に 求められてきたコト
recruitengineers
PRO
4
340
Oracle Database 23ai 新機能 #3 Oracle Globally Distributed Database(GDD)
oracle4engineer
PRO
1
160
Discover Your Tailored Platform Strategy with Real-World Practice
hhiroshell
1
130
PlaywrightによるE2Eテスト入門 / Introduction to E2E Testing with Playwright
rhumie
3
930
Dive Deep in Cloud Run: Automatic Base Image update
aoto
PRO
0
900
CRTO/CRTL/OSEPの比較・勉強法とAV/EDRの検知実験
chayakonanaika
0
450
Building Static Websites with Sculpin
opdavies
0
1.4k
「名前解決」から振り返るAmazon VPC
yuki_ink
0
320
Eventual Detection Engineering
ken5scal
0
440
React Aria で実現する次世代のアクセシビリティ
ryo_manba
4
560
Featured
See All Featured
Building Applications with DynamoDB
mza
89
5.9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
58
3.4k
Thoughts on Productivity
jonyablonski
65
4.2k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
41
6.4k
Visualization
eitanlees
142
15k
Build your cross-platform service in a week with App Engine
jlugia
228
18k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
25
1.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
22
1.7k
The Mythical Team-Month
searls
218
43k
[RailsConf 2023] Rails as a piece of cake
palkan
44
4.6k
Mobile First: as difficult as doing things right
swwweet
220
8.8k
Speed Design
sergeychernyshev
18
400
Transcript
גࣜձࣾαΠόʔΤʔδΣϯτ AIࣄۀຊ෦ ೖOpen Policy Agent Policy as CodeΛࢦͯ͠ ࠇ࡚ ༏ଠ
ࠇ࡚ ༏ଠ 2015 ৽ଔೖࣾ AIࣄۀຊ෦ DXຊ෦ ΞϓϦӡ༻ηϯλʔ @kurochan @kuro_m88 ج൫ٕज़ऀ
🆕 αΠόʔΤʔδΣϯτ CTO౷ׅࣨ #times_kurochan
ࠓճ͓͢Δ༰ • Open Policy Agentͱ͍͏ιϑτΣΞʹ͍ͭͯͷհ • Open Policy AgentೝՄͷจ຺Ͱհ͞ΕΔ͜ͱ͕ଟ͍͕ɺ ͏গ͠Ҿ͍ͯʮϙϦγʔʯͱ͍͏ࢹ͔Βհ
• ΞϓϦӡ༻ηϯλʔͰಋೖ͢Δ༧ఆ͕͋ΔͷͰ ఆ͍ͯ͠ΔϢʔεέʔεͷհ
1.Open Policy Agentͱ 2.Policy as Code 3.Open Policy Agentͷ͍ํ 4.Open
Policy Agentͷ͍ॴ 5.ΞϓϦӡ༻ηϯλʔͰͷ Open Policy Agentͷಋೖ༧ఆ
Open Policy Agentͱ
Open Policy Agentͱ • ܰྔͳ൚༻ͷʮϙϦγʔΤϯδϯʯ • ಠཱͯ͠ಈ͔͢͜ͱͰ͖Δ͠ɺαʔϏεʹϥΠϒϥϦͱͯ͠౷߹͢Δ͜ͱՄೳ • WebAssemblyαϙʔτͯͨ͠Γ •
OPAͱུ͞ΕΔ͜ͱ͕ଟ͍ • ΫΤϦʹରͯ͠ϙϦγʔΛద༻ɺ݁ՌΛੜ͢Δ • ϙϦγʔRegoͱ͍͏ݴޠͰੜ͢Δ
"Policy"ͱ • ϧʔϧͷू߹ • ೖྗΛ݅Ͱൺֱͨ͠Γ • rate limitͷΑ͏ʹಈతʹมΘΔΑ͏ͳͷͩͬͨΓ • ͦΕΒΛΈ߹ΘͤͨΓ
• ࠷ऴతʹԿ͔͠ΒͷҙࢥܾఆΛ͢Δ
ϙϦγʔΤϯδϯΛ͢Δͱ͍͏͜ͱ • ϙϦγʔͷ࣮͍͠ • ਖ਼࣮͘͠Ͱ͖·͔͢…ʁ • ෳࡶͳϙϦγʔϙϦγʔࣗମͷڍಈΛςετ͍ͨ͠ • ࠓճʮϙϦγʔΤϯδϯʯͱ͍͏෦͕༷ʑͳϢʔεέʔεʹద༻Մ ೳͰ͋Δ͜ͱΛ͓͠·͢
Policy as Code
Policy as Code • XXX as Code • Infrastructure as
CodeͳͲ • ϙϦγʔͦΕࣗମ͕γεςϜͷٕज़తͳ੍ηΩϡϦςΟͳͲɺ ॏཁͳࣝΛแ͍ͯ͠Δ • ΞϓϦέʔγϣϯίʔυதʹຒΊࠐ·ΕΔΑΓϙϦγʔͱͯ͠ ಠཱͯ͠ఆٛ͢Δ͜ͱͰ҉Խ͢Δ͜ͱ͙͜ͱ͕Ͱ͖Δ
Rego • ϙϦγʔΛهड़͢ΔͨΊͷݴޠ • ߏԽ͞Ε͍ͯͯ֊తͳσʔλߏΛ࣋ͯΔ • JSONͷΑ͏ͳߏѻ͑Δ • ϙϦγʔͷద༻݁Ռಉ༷ʹॊೈͳσʔλߏͰදݱͰ͖Δ •
ೖग़ྗͷσʔλߏ͕͔ͳΓࣗ༝ • ݅ࣜؔॆ࣮
Regoͷจ๏ྫ • งғؾ͚ͩհ͠·͢ • ਖ਼͍͠จ๏ެࣜυΩϡϝϯτΛࢀর͍ͯͩ͘͠͞ https://www.openpolicyagent.org/docs/latest/policy-language/
Regoͷจ๏ྫ: ม
Regoͷจ๏ྫ: Object
Regoͷจ๏ྫ: Rule
Regoͷจ๏ྫ: Rule
Regoͷจ๏ྫ: ݅ • ࢛ଇԋࢉɺ߸ɺෆ߸ɺϏοτԋࢉͳͲͪΖΜఆٛ͞Ε͍ͯΔ͕ ͜ΕΒͯ͢ϏϧτΠϯؔͱͯ͠ѻΘΕΔ
Regoͷจ๏ྫ: ϏϧτΠϯؔ • Ϗοτԋࢉɺू߹ԋࢉɺਖ਼نදݱɺจࣈྻૢ࡞ • Base64ɺURLɺJSON/YAMLɺUUID • ࣌ࠁ • άϥϑ
• ωοτϫʔΫ • τʔΫϯ(JWTͳͲ) • ଞʹศརͳ͕ؔ࠷ॳ͔Βͨ͘͞Μ༻ҙ͞Ε͍ͯΔ
؆୯ͳྫ • HTTPϦΫΤετͷೝՄ • user "alice" /hello ʹରͯ͠GETϦΫΤετ͕Ͱ͖Δ
The Rego Playground • ϒϥβ্ͰRegoΛॻ͍ͯࢼͤͯศར https://play.openpolicyagent.org/
Testable • ςετ͕ॻ͚Δʂ
Testable • ςετ͕ॻ͚Δʂ
Open Policy Agentͷ͍ํ
REST API
ೝՄػೳΛඋ͑ͨAPI • ೝূͱೝՄ • ೝূ(Authenticate) • ʮ୭ͳͷ͔ʯΛࣝผ͢Δ • ೝՄ(Authorize) •
ʮԿ͕Ͱ͖Δͷ͔(Ͱ͖ͳ͍ͷ͔)ʯΛஅ͢Δ
RBACΛ࣮ͯ͠ΈΔ
External Data • ͜͜·Ͱͷྫͩͱuser_rolesrole_permissions૬ݻఆ • ࣮༻్ͰಈతʹมԽͤͨ͞Γ૿ݮ͍ͤͨ͞ • ϙϦγʔΛධՁ͢Δʹ͋ͨͬͯඞཁͳใΛ֎෦͔Βऔಘ͢ΔΈ
ϦΫΤετʹຒΊࠐΉ • ϦΫΤετΛૹ৴͢Δଆ͕ՃใΛૹ৴͢Δ • ͪΖΜૹΒΕͯ͘Δ͕৴༻Ͱ͖ͳ͍ͱμϝ • ৴༻Ͱ͖Δͱ͍͏લఏ͔ɺ JWTͳͲͰॺ໊͞ΕͨΛݕূͯ͠͏͔ https://www.openpolicyagent.org/docs/latest/external-data/
σʔλΛ͢(push) • ֎෦͔Βߋ৽͕͋Δʹpush͢Δ • ಉظ࿙Εͱ͔ϥά͕ى͖Δͱ͜Θ͍͔ • ͋·Γେ͖ͳσʔλΕͳ͍ https://www.openpolicyagent.org/docs/latest/external-data/
σʔλΛΒ͏(pull) • OPA͕ಈతʹ֎෦ͷAPIΛݺͼग़ͤΔ(B) • OPAͷϨεϙϯελΠϜ૿Ճ͢Δ • ॊೈʹ࿈ܞͦ͢͠͏ https://www.openpolicyagent.org/docs/latest/external-data/
Testing
ςετ • ϙϦγʔͱಉ͡σΟϨΫτϦʹςετϑΝΠϧΛஔ͘ • "test_"Ͱ࢝·Δϧʔϧ͕ධՁ͞ΕɺͦΕ͕ςετʹͳΔ • opa testίϚϯυͰςετ͕࣮ߦͰ͖Δ • ΧόϨοδܭଌՄೳ
ͷϞοΫ • withΩʔϫʔυͰΛஔ͖͑ΒΕΔ
Open Policy Agentͷ͍Ͳ͜Ζ
Open Policy Agentͷ͍Ͳ͜Ζ • Kubernetesͷݖݶཧͷจ຺Ͱհ͞ΕΔ͜ͱ͕ଟ͍ҹ • ͦΕҎ֎ͷ༻్Λத৺ʹհ͠·͢
Envoy
Envoyͱ https://speakerdeck.com/kurochan/ru-men-envoy
Envoyͱ • OSSͷL4/L7ϓϩΩγ • ʮϞμϯͳαʔϏεࢦΞʔΩςΫνϟʯ͚ • ʮϢχόʔαϧσʔλϓϨʔϯʯΛࢦͯ͠։ൃ͞Ε͍ͯΔ • ύϑΥʔϚϯεʹ༏Εɺ֦ுੑ͕ߴ͘ɺAPIܦ༝ͰίϯτϩʔϧՄೳ https://www.envoyproxy.io/docs/envoy/latest/intro/what_is_envoy
Envoy࿈ܞ • EnvoyͱOPAΛ࿈ܞͤͯ͞ೝՄػೳ͖ͷήʔτΣΠΛߏՄೳ https://www.openpolicyagent.org/docs/latest/envoy-introduction/
Envoy࿈ܞ • EnvoyͱOPAΛ࿈ܞͤͯ͞ೝՄػೳ͖ͷήʔτΣΠΛߏՄೳ • ೝՄ͞ΕͨτϥϑΟοΫ͔͠௨ա͠ͳ͍ • ޙஈͷΞϓϦέʔγϣϯαʔόͷָ࣮͕ʹͳΔ
Terraform
TerraformʹϙϦγʔΛద༻͢Δʁ • terraform.analysisͱ͍͏ύοέʔδ͕༻ҙ͞Ε͍ͯΔ • terraform planͷ݁Ռ͕ҙਤ͍ͯ͠Δ͔Ͳ͏͔ͷνΣοΫ͕Ͱ͖Δ • CIͳͲʹΈࠐΉͱࣄނࢭͷνΣοΫʹͳΔ • ྫ
• ෆ༻ҙʹIAMͷઃఆมߋ͕͞Ε͍ͯͳ͍͔ʁ • ࣮ߦͨ͠ਓ͕ཧऀͰ͋ΕOKͳͲͷίϯςΩετ࣋ͨͤΒΕͦ͏ • ҰఆͷᮢҎ্ͷมߋ͕Ұʹͳ͞Ε͍ͯͳ͍͔ʁ • ޡͬͯڥΛഁյ͞Εͳ͍Α͏ʹͰ͖ͦ͏
Terraform࿈ܞͷྫ • terraform planͷ݁Ռʹରͯ͠ϙϦγʔΛద༻͢Δ
ϩάࢹ
ϩάʹϙϦγʔΛద༻͢ΔͱͲ͏ͳΔͷ͔ • ϩάࢹͰΑ͘Δ͜ͱ • ΤϥʔΧϯτ • ҟৗͷݕग़ • ෳࡶͳ݅Ͱͷϩάࢹ •
ಛఆͷIPΞυϨε͔Βͷෆਖ਼ͳΞΫηε • S3όέοτͷՄࢹൣғͷઃఆมߋ • ͳͲ • ͦΕɺOPAͰݕग़Ͱ͖ΔͷͰ…ʁ • Կ͔ͷҙࢥܾఆΛ͢ΔҎ֎ʹɺಛఆ݅ͷΞΫςΟϏςΟͷݕग़ʹ͔ͭ͑Δʂ
ΧελϚΠζ
͜͜·ͰͰ͔ͬͨ͜ͱ • Open Policy Agentҙͷೖྗʹରͯ͠ϙϦγʔΛద༻ͨ݁͠ՌΛ ฦ͢ύʔπͱ͔ͯ͠ͳΓ൚༻ੑ͕ߴ͍ • Open Policy AgentΛαʔϏεʹΈࠐΜͰ͏ʹ
Ͳ͏͢ΕΑ͍ͷ͔
REST API • input JSONͰPOST͢ΔͱɺϨεϙϯε͕JSONͰฦͬͯ͘Δ
Go API • GolangͷϥΠϒϥϦͱͯ͠ݺͼग़͢͜ͱ͕Մೳ
ΞϓϦӡ༻ηϯλʔͰͷ Open Policy AgentͷಋೖΞΠσΞ
ΞϓϦӡ༻ηϯλʔͱ • 140ஹԁͷڊେࢢɺখചۀքͷ࠶ൃ໌ʹΉ։ൃϓϩδΣΫτ https://speakerdeck.com/kurochan/retail-dx-project
ΞϓϦӡ༻ηϯλʔͰ։ൃ͍ͯ͠ΔγεςϜͨͪ • ڠಇൢଅ͚γεςϜ • ձһΞϓϦ • ECαΠτ • σʔλج൫ •
͜ΕΒͷཧը໘ • ༷ʑͳϙϦγʔͰΞΫηε੍ޚΛ͍ͨ͠
ΞϓϦӡ༻ηϯλʔͱ • খചۀքͷDXΛਪਐ͢ΔϓϩμΫτΛ։ൃ͢Δ෦ॺ • ͍ΖΜͳγεςϜΛ։ൃ͢Δ • ͍ΖΜͳγεςϜ = ͍ΖΜͳAPI •
ೝূೝՄ͕༷ʑͳγʔϯͰൃੜ͢Δ • ͦΕͧΕϏδωεཁ݅ඍົʹҟͳΔͷͰ͖ͪΜͱϧʔϧͱͯ͠ཧ͍ͨ͠ • Policy as Codeͷػӡ…ʂ • ೝূ => IdP, ೝՄ => ???
Open Policy AgentΛ༻͍ͨRBAC ڋ൱ ڐՄ ڐՄ ϦιʔεA ϦιʔεB A͞Μ B͞Μ
σʔλϕʔεͷͳͲʹԠͯ͡ಈతʹΞΫηεΛڐՄ͢Δ͔அ͍ͨ͠
Open Policy AgentΛ༻͍ͨRBAC https://www.openpolicyagent.org/docs/latest/external-data/ • ϢʔβA͕ϦιʔεBͷΞΫηεΛͯ͠Α͍͔͕ಈతʹมΘΔέʔε • External DataΛ༻͍ͯղܾ
൚༻తͳΞʔΩςΫνϟ • ೝূೝՄͷ͘͠ΈΛςϯϓϨʔτԽ͍ͨ͠ • Envoy + OPA + Backend API
• Envoy: ೝՄήʔτΣΠ • OPA: ೝՄϙϦγʔΤϯδϯ • Backend API: ϏδωεϩδοΫ
൚༻తͳΞʔΩςΫνϟ ΫϥΠΞϯτ ೝՄใ όοΫΤϯυ
ϦΫΤετ ϨεϙϯεͷྲྀΕ ϦΫΤετ ΫϥΠΞϯτ ೝՄใ όοΫΤϯυ ڐՄ͞ΕΔύλʔϯ
ϦΫΤετ ϨεϙϯεͷྲྀΕ ϦΫΤετ ΫϥΠΞϯτ ೝՄใ όοΫΤϯυ ڐՄ͞ΕΔύλʔϯ
ϦΫΤετ ϨεϙϯεͷྲྀΕ ϦΫΤετ ΫϥΠΞϯτ ೝՄใ όοΫΤϯυ ڐՄ ೝՄใ Ճใ ڐՄ͞ΕΔύλʔϯ
ϦΫΤετ ϨεϙϯεͷྲྀΕ ϦΫΤετ ΫϥΠΞϯτ ೝՄใ όοΫΤϯυ ϦΫΤετ ڐՄ ೝՄใ Ճใ
ڐՄ͞ΕΔύλʔϯ
ϦΫΤετ ϨεϙϯεͷྲྀΕ ϦΫΤετ ΫϥΠΞϯτ ೝՄใ όοΫΤϯυ ϦΫΤετ ڐՄ ೝՄใ Ճใ
ڐՄ͞ΕΔύλʔϯ
ϦΫΤετ ϨεϙϯεͷྲྀΕ ϦΫΤετ ΫϥΠΞϯτ ೝՄใ όοΫΤϯυ ೝՄใ Ճใ ڋ൱ ڋ൱͞ΕΔύλʔϯ
·ͱΊ
·ͱΊ • Open Policy Agentͱ͍͏OSSʹ͍ͭͯհ͠·ͨ͠ • ϙϦγʔΤϯδϯͷ൚༻ੑʹ͍ͭͯհ͠·ͨ͠ • ΞϓϦӡ༻ηϯλʔͰͷಋೖΞΠσΞʹ͍͓ͭͯ͠·ͨ͠ •
࣮ࡍʹಋೖࣄྫ͕Ͱ͖ͨΒͲ͔͜Ͱൃද͍ͨ͠ͱࢥ͍·͢
͝ࢹௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ