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
28
桃太郎で始める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
76
レーダーをつくる
bmf_san
0
52
契約テストとPactについて
bmf_san
0
95
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
GISエンジニアから見たLINKSデータ
nokonoko1203
0
190
re:Invent 2025 トレンドからみる製品開発への AI Agent 活用
yoskoh
0
570
CSC307 Lecture 02
javiergs
PRO
1
740
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
3
810
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
3
1.4k
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
6
1.6k
PC-6001でPSG曲を鳴らすまでを全部NetBSD上の Makefile に押し込んでみた / osc2025hiroshima
tsutsui
0
200
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
300
CSC307 Lecture 01
javiergs
PRO
0
650
GoLab2025 Recap
kuro_kurorrr
0
790
20251212 AI 時代的 Legacy Code 營救術 2025 WebConf
mouson
0
240
從冷知識到漏洞,你不懂的 Web,駭客懂 - Huli @ WebConf Taiwan 2025
aszx87410
2
3.3k
Featured
See All Featured
Skip the Path - Find Your Career Trail
mkilby
0
32
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.5k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
120
Paper Plane
katiecoart
PRO
0
45k
The agentic SEO stack - context over prompts
schlessera
0
580
Heart Work Chapter 1 - Part 1
lfama
PRO
3
35k
Everyday Curiosity
cassininazir
0
120
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
140
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
Writing Fast Ruby
sferik
630
62k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
200
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