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
38
桃太郎で始める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
81
レーダーをつくる
bmf_san
0
55
契約テストと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
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
1k
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.4k
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
470
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
180
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.7k
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
510
今こそ知るべき耐量子計算機暗号(PQC)入門 / PQC: What You Need to Know Now
mackey0225
3
390
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
CSC307 Lecture 09
javiergs
PRO
1
840
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
660
生成AIを活用したソフトウェア開発ライフサイクル変革の現在値
hiroyukimori
PRO
0
110
AI時代の認知負荷との向き合い方
optfit
0
170
Featured
See All Featured
HDC tutorial
michielstock
1
400
AI: The stuff that nobody shows you
jnunemaker
PRO
2
280
Unsuck your backbone
ammeep
671
58k
The Limits of Empathy - UXLibs8
cassininazir
1
220
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
67
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
53
The SEO identity crisis: Don't let AI make you average
varn
0
330
Become a Pro
speakerdeck
PRO
31
5.8k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
72
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
130
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.3k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
440
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