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
桃太郎で始めるRego入門‐今日から使えるRegoの基本編
Search
bmf_san
December 19, 2025
Programming
0
34
桃太郎で始めるRego入門‐今日から使えるRegoの基本編
bmf_san
December 19, 2025
Tweet
Share
More Decks by bmf_san
See All by bmf_san
完璧を求めない意思決定-アクセス制御基盤における制約との向き合い方
bmf_san
5
16k
AAPについて調べてみた
bmf_san
0
78
レーダーをつくる
bmf_san
0
53
契約テストとPactについて
bmf_san
0
96
5分でわかるSLO
bmf_san
2
140
権限について考える
bmf_san
2
140
自作HTTPルーターから新しいServeMuxへ
bmf_san
3
1.8k
古くなってしまったPHPフレームワークとPHPのバージョンアップ戦略
bmf_san
1
460
アジャイルワークショップ
bmf_san
0
180
Other Decks in Programming
See All in Programming
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
3
1.4k
コントリビューターによるDenoのすゝめ / Deno Recommendations by a Contributor
petamoriken
0
160
CSC307 Lecture 05
javiergs
PRO
0
470
KIKI_MBSD Cybersecurity Challenges 2025
ikema
0
150
クラウドに依存しないS3を使った開発術
simesaba80
0
230
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
350
PC-6001でPSG曲を鳴らすまでを全部NetBSD上の Makefile に押し込んでみた / osc2025hiroshima
tsutsui
0
210
CSC307 Lecture 04
javiergs
PRO
0
640
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
110
The Art of Re-Architecture - Droidcon India 2025
siddroid
0
160
生成AIを利用するだけでなく、投資できる組織へ
pospome
2
450
はじめてのカスタムエージェント【GitHub Copilot Agent Mode編】
satoshi256kbyte
0
170
Featured
See All Featured
Chasing Engaging Ingredients in Design
codingconduct
0
97
Un-Boring Meetings
codingconduct
0
180
GraphQLとの向き合い方2022年版
quramy
50
14k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
420
Facilitating Awesome Meetings
lara
57
6.7k
For a Future-Friendly Web
brad_frost
180
10k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
58
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
47
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.5k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
200
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
110
Ruling the World: When Life Gets Gamed
codingconduct
0
120
Transcript
© SmartHR, Inc. 桃太郎で始めるRego⼊⾨ 今⽇から使えるRegoの基本編 ⽵内 健太 / X @bmf_san
SmartHR プロダクト基盤開発本部 権限基盤ユニット アーキテクチャチーム 2025/12/19 第14回 SmartHR LT大会
1スライド10秒くら いで話します🙏 時間ガガガ 2
Regoとは • ポリシー(≒認可ロジック)を記述するための宣⾔型⾔語 • Open Policy Agentというポリシーエンジンで採⽤ 3
基本要素 • Input : 評価対象となる⼊⼒データ • Rule : 評価基準。ルール名は⾃由。 4
基本構⽂ # Input {"user": "admin"} # Policy allow if {
input.user == "admin" } 5 # Output {"allow": true}
桃太郎のストーリーで Regoの基本を紹介し ます!! 6
7
8
9
おばあさんの脳内 { "peach": { "size": "large", "from": "upstream", "content": "boy"
} } allow if { input.peach.size == "large" input.peach.from == "upstream" input.peach.content == "boy" } allow if { input.peach.has_special_mark == true } allow if { input.peach.size == "large" not input.peach.is_rotten } allow if { not input.peach.is_poisonous } {"allow": true} 10
おばあさんの脳内 # ルール内はAND:全ての条件を満たす必要がある allow if { input.peach.size == "large" #
大きい桃か? input.peach.from == "upstream" # 川上から来たか? input.peach.content == "boy" # 中身は男の子か? } 11
おばあさんの脳内 # ルールとルールはOR:どれかのルールが成立すればOK allow if { input.peach.has_special_mark == true #
特別な印がある } 12
おばあさんの脳内 # NOT: 否定を使った条件 allow if { input.peach.size == "large"
not input.peach.is_rotten # 腐っていないことを確認 } 13
おばあさんの脳内 # undefinedのNOT: 属性が未定義ならtrueになる allow if { not input.peach.is_poisonous #
is_poisonousが未定義ならtrue } 14
おばあさんの脳内 allow if { input.peach.size == "large" input.peach.from == "upstream"
input.peach.content == "boy" } allow if { input.peach.has_special_mark == true } allow if { input.peach.size == "large" not input.peach.is_rotten } allow if { not input.peach.is_poisonous } 15 • (⼤きい かつ 川上から来た か つ 中⾝が男の⼦) • または (特別な印がある) • または (⼤きい かつ 腐ってい ない) • または (毒がない)
おばあさんの脳内 allow if { input.peach.size == "large" input.peach.from == "upstream"
input.peach.content == "boy" } allow if { input.peach.has_special_mark == true } allow if { input.peach.size == "large" not input.peach.is_rotten } allow if { not input.peach.is_poisonous } 16 • (⼤きい かつ 川上から来た かつ 中⾝が男の⼦) または (特別な印がある) または (⼤ きい かつ 腐っていない) ま たは (毒がない) 毒がなければTrue!
17
18
桃太郎の脳内 { "name": "dog", "traits": ["obedient", "serious", "good_natured"] } default
allow := false good_traits := [trait | trait := input.traits[_] trait in {"obedient", "serious", "good_natured"} ] allow if { count(good_traits) == 3 } 19 {"allow": true}
桃太郎の脳内 # デフォルトは拒否 default allow := false 20
桃太郎の脳内 # 配列内包表記:求める特性だけを抽出 good_traits := [trait | trait := input.traits[_]
trait in {"obedient", "serious", "good_natured"} ] 21
桃太郎の脳内 22 # 3つ全ての特性を持っているか判定 allow if { count(good_traits) == 3
}
桃太郎の脳内 23 • 従順で • 真⾯⽬で • いいやつ • だったら採⽤!
default allow := false good_traits := [trait | trait := input.traits[_] trait in {"obedient", "serious", "good_natured"} ] allow if { count(good_traits) == 3 }
24
25
桃太郎の脳内 { "user": {"origin": "peach"}, "targets": [{"type": "oni"}], "companions": ["dog"],
"fed_companions": [] } has_oni_target if { some target in input.targets target.type == "oni" } all_companions_fed if { count(input.companions) > 0 every companion in input.companions { companion in input.fed_companions } } allow if { input.user.origin == "peach" has_oni_target all_companions_fed } 26 {"allow": false}
桃太郎の脳内 # some量化子:ターゲットの中に少なくとも1体は鬼 がいるか確認 has_oni_target if { some target in
input.targets target.type == "oni" } 27
桃太郎の脳内 # every量化子:全ての仲間がきびだんごを食べたか確認 all_companions_fed if { count(input.companions) > 0 every
companion in input.companions { companion in input.fed_companions } } 28
桃太郎の脳内 { "user": {"origin": "peach"}, "targets": [{"type": "oni"}], "companions": ["dog"],
"fed_companions": [] } 29 {"allow": false} ⾷べてない!
30
桃太郎の脳内 { "user": {"origin": "peach"}, "targets": [{"type": "oni"}], "companions": ["dog"],
"fed_companions": ["dog"] } 31 {"allow": true} ⾷べさせる!
32
まとめ • ANDやOR、NOTなどの演算 • defaultキーワード • 配列内包 [x | x
:= list[_]; 条件] • someやeveryの量化 • データとロジックは分離 33
Rego Playground 34 • 桃太郎の脳内を追体験できる! • https://play.openpolicyagent. org/
めでたしめでたし 35