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
18k
AAPについて調べてみた
bmf_san
0
83
レーダーをつくる
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
Python’s True Superpower
hynek
0
200
今、アーキテクトとして 品質保証にどう関わるか
nealle
0
200
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
180
AWS Infrastructure as Code の新機能 2025 総まとめ 〜SA 4人による怒涛のデモ祭り〜
konokenj
10
3.2k
AIコーディングの理想と現実 2026 | AI Coding: Expectations vs. Reality 2026
tomohisa
0
1k
Unity6.3 AudioUpdate
cova8bitdots
0
110
Claude Code の Skill で複雑な既存仕様をすっきり整理しよう
yuichirokato
1
290
Premier Disciplin for Micro Frontends Multi Version/ Framework Scenarios @OOP 2026, Munic
manfredsteyer
PRO
0
210
オブザーバビリティ駆動開発って実際どうなの?
yohfee
3
690
encoding/json/v2のUnmarshalはこう変わった:内部実装で見る設計改善
kurakura0916
0
310
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
170
AIプロダクト時代のQAエンジニアに求められること
imtnd
2
700
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
331
21k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
140
Music & Morning Musume
bryan
47
7.1k
The SEO Collaboration Effect
kristinabergwall1
0
380
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Unsuck your backbone
ammeep
672
58k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
200
The Curse of the Amulet
leimatthew05
1
9.6k
Skip the Path - Find Your Career Trail
mkilby
1
72
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
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