Ory Keto 是 Ory Corp 以 Go 撰寫的權限伺服器。其 README 稱它為 “an open source implementation of ‘Zanzibar: Google’s Consistent, Global Authorization System’”(「Zanzibar:Google 的一致性全球授權系統」的開源實作)(README)。Ory 也將它作為託管服務營運:“Ory Permissions is powered by the open source Ory Keto”(Ory Permissions 由開源的 Ory Keto 驅動),提供於 Ory Network 上(同一份 README)。
Keto 一開始並不是 Zanzibar 系統。Zanzibar 的設計是在 2021-04-07 的 v0.6.0-alpha.1 中引入的;版本說明指出,先前的 Keto 移到了 legacy-0.5 分支,且 “the architectures are vastly different”(兩者的架構截然不同)(release notes)。以 Ory Permission Language 撰寫的使用者集合改寫,則在 2022-09-27 的 v0.10.0-alpha.0 中跟進(release notes)。
論文與 Keto 並列對照
| 論文中 | Ory Keto 中 |
|---|---|
| 命名空間設定(§2.3) | Ory Permission Language(OPL,TypeScript 的子集)中 implements Namespace 的一個 class(OPL reference) |
關係元組 object#relation@user(§2.1) |
namespace:object#relation@subject,例如 Group:eng#members@User:beto(relation tuples、parser) |
_this |
this.related.viewers.includes(ctx.subject) |
computed_userset |
this.permits.edit(ctx):“A permission can call another permission defined on the same namespace”(一個權限可以呼叫同一命名空間中定義的另一個權限) |
tuple_to_userset |
this.related.parents.traverse((p) => p.permits.view(ctx)) |
| 聯集、交集、排除 | ||、&&、! |
| zookie(§2.2、§2.4) | API 中存在 snaptoken 欄位,但每一個都 “not implemented yet and has no effect”(尚未實作,沒有作用)(check_service.proto) |
| Check(§2.4.4) | CheckService.Check、BatchCheck |
| Read(§2.4.1) | ReadService.ListRelationTuples(read_service.proto) |
| Write(§2.4.2) | WriteService.TransactRelationTuples、DeleteRelationTuples(write_service.proto) |
| Watch(§2.4.3) | API 中沒有 |
| Expand(§2.4.5) | ExpandService.Expand(expand_service.proto) |
| Leopard(§3.2.4) | 文件中未記載對應物 |
| Spanner(§3.1) | PostgreSQL、MySQL 或 CockroachDB;SQLite 僅供開發使用(production guide) |
以 OPL 表示貫穿全站的範例
論文的圖 1 讓擁有者成為編輯者、編輯者成為檢視者,並讓上層資料夾的檢視者成為文件的檢視者(§2.3.1)。在 OPL 中,每個命名空間都是一個 class:related 宣告各個關係及其接受的主體型別,permits 則存放針對 ctx.subject 傳回真或假的函式。
import { Namespace, SubjectSet, Context } from "@ory/keto-namespace-types"
class User implements Namespace {}
class Group implements Namespace {
related: {
members: User[]
}
}
class Folder implements Namespace {
related: {
viewers: (User | SubjectSet<Group, "members">)[]
}
permits = {
view: (ctx: Context): boolean => this.related.viewers.includes(ctx.subject),
}
}
class Doc implements Namespace {
related: {
parents: Folder[]
owners: User[]
editors: (User | SubjectSet<Group, "members">)[]
viewers: (User | SubjectSet<Group, "members">)[]
}
permits = {
edit: (ctx: Context): boolean =>
this.related.owners.includes(ctx.subject) ||
this.related.editors.includes(ctx.subject),
view: (ctx: Context): boolean =>
this.related.viewers.includes(ctx.subject) ||
this.permits.edit(ctx) ||
this.related.parents.traverse((p) => p.permits.view(ctx)),
}
}
SubjectSet<Group, "members"> 是 OPL 中表示「某個群組的成員」的型別,也就是論文的使用者集合。關係一律是陣列,因為 “an object can have many subjects”(一個物件可以有許多主體)(OPL reference)。
以 Keto 文字形式表示的貫穿全站範例的五筆元組。寫成 User:anne 的主體是一個關係為空的 subject set;維護者的範例元組就是這樣寫使用者的(tuples.json)。
Doc:readme#owners@User:anne
Group:eng#members@User:beto
Doc:readme#viewers@Group:eng#members
Doc:readme#parents@Folder:A
Folder:A#viewers@User:chen
哪一筆元組與哪一個 OPL 運算式決定了每個人對 readme 的存取權?
請注意,被儲存的只有箭頭。每一個將擁有者轉為檢視者、或將資料夾檢視者轉為文件檢視者的步驟,都位於 permits 函式中,並在檢查時執行。
架構
Keto 部署中的哪些部分彼此溝通?
- 每個容器都提供 Read API(預設連接埠 4466)、Write API(4467)與 OPL 語法 API(4469),各自支援 HTTP 與 gRPC(config schema)。
- “A good practice is to not expose the Write API at all to the public internet”(良好的做法是完全不將 Write API 暴露於公開網際網路),以及 “The Read API should also be protected”(Read API 也應該受到保護)(production guide)。
- 擴展:“There are no additional requirements for scaling when self-hosting Ory Keto, just spin up another container!”(自行託管 Ory Keto 時,擴展沒有額外的要求,只要再啟動一個容器就行了!)(同一份指南)。各容器共用資料庫。
一致性
論文的 zookie 讓客戶端可以要求在 “at a consistent snapshot no earlier than the given zookie”(不早於給定 zookie 的一致性快照上)進行檢查(§2.4.4)。Keto 的 protobuf API 在欄位名稱中帶有相同的概念:Check、Expand 與 ListRelationTuples 上的 snaptoken,TransactRelationTuples 上的 snaptokens,以及用於內容變更檢查的 latest 旗標。這些欄位每一個都被記載為 “not implemented yet and has no effect”(尚未實作,沒有作用)(check_service.proto)。
客戶端目前送出的權杖會怎麼樣?
請注意,論文以 zookie 建立的保證,也就是保護內容免於「new enemy」問題(§2.2),因此取決於底層 SQL 資料庫的行為。此處查核的 Keto 文件頁面對一致性沒有任何陳述。
與論文的差異
- 沒有 zookie。 欄位存在,但行為不存在(見上文)。
- 沒有 Watch。 v1alpha2 API 有 Check、Expand、Read、Write、Namespaces 與 Version 服務,以及一個獨立的 OPL 語法服務(
opl/v1alpha1),但沒有變更串流(proto directory)。論文的 Watch 為次要索引與 Leopard 提供資料(§2.4.3、§3.2.4)。 - 沒有 Leopard。 文件中沒有記載任何反正規化的集合索引。
- 程式語言式的語法。 OPL 是 TypeScript 的子集,因此 “users can get context help from their IDE”(使用者可以從其 IDE 取得情境說明)(OPL specification)。論文的圖 1 以類似 protocol buffer 的文字語法撰寫設定(§2.3.1);論文沒有說明這種格式的名稱。
- SQL 儲存。 一個共用的 SQL 資料庫,而非 Spanner(§3.1)。
- 檢查深度。 Check 請求帶有
max_depth,“The maximum depth to search for a relation”(搜尋關係時的最大深度)(check_service.proto)。
狀態
- 首個版本發布於 2018-11-13(Zanzibar 之前的設計);Zanzibar 設計始於 2021-04-07 的 v0.6.0-alpha.1;OPL 始於 2022-09-27 的 v0.10.0-alpha.0(releases)。
- 版本編號在 v0.14.0(2025-03-06)之後改變了規則:下一個版本是 v25.4.0(2025-11-07),接著是 v26.2.0(2026-03-20),即 2026-11-13 時的最新版本。
- 預設分支最後一次 commit:2026-07-29。GitHub 星數約 5.4k(GitHub API,2026-11-13)。
資料來源
- Ory Keto repository and README: github.com/ory/keto
- Release v0.6.0-alpha.1: github.com/ory/keto/releases/tag/v0.6.0-alpha.1
- Release v0.10.0-alpha.0: github.com/ory/keto/releases/tag/v0.10.0-alpha.0
- Ory Keto docs: ory.com/docs/keto
- OPL reference: ory.com/docs/keto/reference/ory-permission-language
- OPL specification: github.com/ory/keto/blob/master/docs/ory_permission_language_spec.md
- Relation tuples: ory.com/docs/keto/concepts/relation-tuples
- Tuple string format: github.com/ory/keto/blob/master/ketoapi/enc_string.go
- Sample namespaces and tuples: namespaces.keto.ts, tuples.json
- gRPC services: github.com/ory/keto/tree/master/proto/ory/keto
- Configuration schema: github.com/ory/keto/blob/master/embedx/config.schema.json
- Production guide: ory.com/docs/keto/guides/production