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
40
桃太郎で始めるRego入門‐今日から使えるRegoの基本編
bmf_san
December 19, 2025
Tweet
Share
More Decks by bmf_san
See All by bmf_san
完璧を求めない意思決定-アクセス制御基盤における制約との向き合い方
bmf_san
5
17k
AAPについて調べてみた
bmf_san
0
82
レーダーをつくる
bmf_san
0
57
契約テストとPactについて
bmf_san
0
100
5分でわかるSLO
bmf_san
2
150
権限について考える
bmf_san
2
140
自作HTTPルーターから新しいServeMuxへ
bmf_san
3
1.8k
古くなってしまったPHPフレームワークとPHPのバージョンアップ戦略
bmf_san
1
470
アジャイルワークショップ
bmf_san
0
190
Other Decks in Programming
See All in Programming
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
22
8.1k
AIコーディングの理想と現実 2026 | AI Coding: Expectations vs. Reality 2026
tomohisa
0
770
CSC307 Lecture 12
javiergs
PRO
0
450
CSC307 Lecture 11
javiergs
PRO
0
580
Swift ConcurrencyでよりSwiftyに
yuukiw00w
0
200
Claude Codeセッション現状確認 2026福岡 / fukuoka-aicoding-00-beacon
monochromegane
3
350
CopilotKit + AG-UIを学ぶ
nearme_tech
PRO
1
110
朝日新聞のデジタル版を支えるGoバックエンド ー価値ある情報をいち早く確実にお届けするために
junkiishida
1
280
Python’s True Superpower
hynek
0
190
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
3
1.2k
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
7
1.2k
Rubyと楽しいをつくる / Creating joy with Ruby
chobishiba
0
200
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
141
7.3k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
140
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
140
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.7k
Evolving SEO for Evolving Search Engines
ryanjones
0
140
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.4k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3k
Building AI with AI
inesmontani
PRO
1
750
A better future with KSS
kneath
240
18k
[SF Ruby Conf 2025] Rails X
palkan
2
800
The SEO identity crisis: Don't let AI make you average
varn
0
400
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