Skip to content

Commit cd6c807

Browse files
docs(skills): objectstack-data security.md teaches that a package's sharing rule resolves its queue recipient from its package (#31777)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} --> _Requested by **Steedos** · [project thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbFxEKiXgxakmwSrdiRAhytb)_ Fixes #31735 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:发布的 `objectstack-data` 技能 `rules/security.md` 补了一条:软件包里声明的共享规则把队列当接收方时,队列名先找本包的队列,再找它声明依赖的包(加 `sys`)里唯一的那个;都没有包声明时才落到组织自建的 `sys_queue` 行。三种拒绝各带例子和引擎的拒绝码:范围外 `outside-closure`(含只有环境项持有);两个依赖都持有 `ambiguous-in-closure`;规则能找到的那个之外还有一个非依赖包持有 `ambiguous-in-environment`。eval 加了第 18 个用例。 - 为什么改:ADR-0150 E4(PR #31728)合并后引擎已这样解析,但技能没写,AI 会写出能加载、运行时却被拒、谁也不授权的规则。 - 风险与回滚:只改技能文字和 eval,不改任何运行时代码。为不超 token 上限,删了 9 处(共 459 字节)来抵付新段落(446 字节):8 处是文件内别处已讲过的重复或作者用不到的包名指针,1 处是实质删减「旧 SQL 风格谓词仍经弃用桥编译」。逐条清单见下文和 changeset。回滚即 revert 本 PR。 - 先看:`skills/objectstack-data/rules/security.md` 第 169–175 行新段落;同文件其余删减;`evals/hooks-security-seeds-datasources.json` 的 id 18。 - 两分钟验证:`node scripts/check-skills-token-ratchet.mjs`,预期 security.md 一行显示 3764 tokens、ceiling 3768,退出 0。 - 需要你做的:审阅后批准本 PR(Tier H,`skills/**`)。 ## What changes - **`skills/objectstack-data/rules/security.md`** gains one bullet under the membership-key "Choose by what the rows are keyed on" bullet, the one that sends a team's records to a sharing rule with `sharedWith: { type: 'queue', value: QUEUE_NAME }`. It teaches what the merged engine does (`packages/plugins/plugin-sharing/src/sharing-rule-service.ts` `assertQueueRecipientReachable`, `packages/objectql/src/package-scoped-resolver.ts` `resolvePackageScopedName`): - a package's rule reads the queue name as its own package's queue, else the one holder in its declared `dependencies` closure plus `sys`, else, when no package or environment item declares the name, an organization's `sys_queue` row (the resolver's not-found passes through to the queue service); - refusal `outside-closure` (resolver L198, L408): the only holder is a package outside the closure, or an environment-authored item (D3 (a)); example: only a non-dependency holds `support`; - refusal `ambiguous-in-closure` (resolver L194, L399): two dependencies hold the name, and step 2 refuses before anything else is asked; - refusal `ambiguous-in-environment` (resolver L196, L360): the holder the rule reaches (its own package or one dependency) and a non-dependency both hold it; the package check passes, then the queue service, which has no caller package, refuses a name two packages hold (`package-scoped-declarations.ts` `resolveDeclaredName`; PR #31728's acceptance note, carrier #31734); - a refused rule grants no one new; the throw is `PackageScopedNameRefusedError`, `code = 'RESOURCE_CONFLICT'` (`package-scoped-declarations.ts` L181), warned once (`reportRefusedDeclaration`), and each recompute keeps the rule's standing grants (`sharing-rule-service.ts` L1511–1527). - **Paid inside the file.** The token ceiling is 3768 and had 0 headroom on main. The new bullet (446 B) is paid for by nine cuts in the same file (459 B; 15069 → 15056 bytes, 3764 tokens): - `(PermissionSetSchema.rowLevelSecurity)` after "permission set / profile" (41 B). Survivor: the same sentence names `rowLevelSecurity` on a permission set. - "(the tenant wall still applies)" in the RLS default-deny sentence (32 B). Survivor: the Layer 0 bullet, "AND-composed ahead of all business RLS". - The sentence that a legacy SQL-style `=` / `IN (...)` predicate still compiles through a deprecated bridge (98 B). **Not a restatement**: the file now teaches canonical CEL only. - The four "(for `IN`)" notes in the `current_user.*` table (42 B). Survivor: `field in current_user.ARRAY` in the predicate list above. - The membership-key section intro, shortened to "Declare the set on the roster object, not one policy per record." (80 B). Survivors: the section heading and the "Choose by" bullet's "a named record → a membership key". - "(`isDefault` sets)" after the `everyone` baseline in the Positions section (19 B). Survivor: the `isDefault: true` bullet that defines it. - The admin-only recipe's `tenancy` comment "not a tenant object → Layer 0 contributes nothing" (55 B). Survivor: the blockquote below it. - The blockquote's "it is the half that holds however permissive the grants" (59 B). Survivor: the `requiredPermissions` paragraph (AND-gate, strictest-wins). - "(`@objectstack/plugin-security`)" after `sys_user_permission_set` (33 B), a package pointer an author never writes (seat ruling A). - Kept on the seat's rework: the `(definePermissionSet)` example comment and the field-lock recipe docs link. - **`skills/objectstack-data/evals/hooks-security-seeds-datasources.json`** gains case **18**, placed right after the queue case 8: `com.acme.crm` shares escalated cases with `support_tier2`, the queue `com.acme.helpdesk` ships. `must_contain`: `type: 'queue'`, `dependencies`, `outside-closure`; `must_not_contain`: `name: 'support_tier2'` (redeclaring the queue in the rule's package makes a second holder, refused too). Ids 1–17 keep their numbers because changesets cite them. - `SKILL.md` § Ownership queues (L425) read, not edited: no sentence there is false after E4 (it names the queue, the claim and the move; it says nothing about how a rule resolves the name). - Changeset: `'@objectstack/skills': patch`. ## Tests Docs and eval only; no runtime code moved, so no package suite is owed. ## Acceptance notes - `ui/scripts/check-skill-eval-tokens.mjs` (exit 0) reads `skills/objectui/evals` only, so it does not grade case 18. Its three `must_contain` tokens were checked by hand as whole tokens of the bundle: all three are in `rules/security.md`, `dependencies` also in `references/_index.md`. - Case 18 sits between ids 8 and 9 in the array, so the file's ids are no longer ascending; no reader in the repo indexes evals by position. - `check:skill-examples` is not in the derived set and was not run: no `os:check` block was touched (the one edited code block, the admin-only recipe, is unmarked). - Eval case 18 asserts `outside-closure` only, so the rework's split of the two ambiguity codes leaves it unchanged. ## Verification Readings at head `bdbe806f` (`objectstack-ai/objectstack`; `origin/main` `c2bb879f`): | file | lines before → after | bytes before → after | tokens / ceiling | |:--|:--|:--|:--| | `skills/objectstack-data/rules/security.md` | 314 → 317 | 15069 → 15056 | 3768 → 3764 / 3768 | | `skills/objectstack-data/evals/hooks-security-seeds-datasources.json` | 175 → 185 | 14669 → 15672 | eval fixture, not ratcheted | | all `skills/**/SKILL.md` | 4599 → 4599 | unchanged | — | | `skills/objectstack-data/**/*.md` | 3803 → 3806 | — | — | <details><summary>Derived gates (dispatch-gates --commands, 44 families)</summary> 43 exit 0. `pnpm check:dual-build-cjs-loads` exits 3 (PREREQUISITE NOT MET, needs every package's dist): NOT MEASURED, left to CI. `pnpm check:lean-entry-closure` exited 3 first and 0 after building `@objectstack/objectql`. `dispatch-gates --ran`: 44 derived, 43 run, 1 NOT-MEASURED, 0 UNRUN. Prerequisite builds: formula + lint (5 tasks), objectql (14 tasks). </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01QsR2jRBKizw1wwxaE5fdqj)_ <!-- signed: domain:skills#2 · zhuangjianguo · session_01QsR2jRBKizw1wwxaE5fdqj --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent f25414e commit cd6c807

3 files changed

Lines changed: 53 additions & 16 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
'@objectstack/skills': patch
3+
---
4+
5+
docs(skills): objectstack-data `security.md` teaches that a package's sharing rule resolves its queue recipient from its own package
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`skills/objectstack-data/rules/security.md` now states the rule the sharing plugin enforces since ADR-0150 E4: a declared sharing rule's `sharedWith: { type: 'queue', value }` reads the name as its own package's queue, else the one holder in the package's declared `dependencies` closure plus `sys`, else (no package or environment item declares the name) an organization's `sys_queue` row. Three refusal codes are taught, each with an example: `outside-closure` (the only holder is a package the rule's package does not depend on, or an environment-authored item), `ambiguous-in-closure` (two dependencies hold the name) and `ambiguous-in-environment` (the holder the rule reaches, its own package or one dependency, and a non-dependency both hold it). A refused rule grants no one new and is warned as `RESOURCE_CONFLICT`; it loads, so nothing earlier tells the author. `evals/hooks-security-seeds-datasources.json` gains case 18, which requires the queue recipient plus a manifest `dependencies` entry on the queue's package and refuses redeclaring the queue in the rule's package.
11+
12+
The file sits at its token ceiling, so the new bullet (446 bytes) is paid for by these cuts in the same file (459 bytes; the file goes from 15069 to 15056 bytes):
13+
14+
- `(PermissionSetSchema.rowLevelSecurity)` after "permission set / profile" (41 B); the same sentence names `rowLevelSecurity` on a permission set.
15+
- "(the tenant wall still applies)" in the RLS default-deny sentence (32 B); the Layer 0 bullet says the wall is AND-composed ahead of all business RLS.
16+
- The sentence that a legacy SQL-style `=` / `IN (...)` predicate still compiles through a deprecated bridge (98 B). This is not a restatement: the file now teaches canonical CEL only.
17+
- The four "(for `IN`)" notes in the `current_user.*` table (42 B); the predicate list above it spells `field in current_user.ARRAY`.
18+
- The membership-key section intro, shortened to "Declare the set on the roster object, not one policy per record." (80 B); the section heading and the "Choose by" bullet's "a named record → a membership key" carry the rest.
19+
- "(`isDefault` sets)" after the `everyone` baseline in the Positions section (19 B); the `isDefault: true` bullet defines that baseline.
20+
- The admin-only recipe's `tenancy` comment "not a tenant object → Layer 0 contributes nothing" (55 B); the blockquote below it explains the key.
21+
- The blockquote's "it is the half that holds however permissive the grants" (59 B); the `requiredPermissions` paragraph calls it an AND-gate, strictest-wins over field grants.
22+
- "(`@objectstack/plugin-security`)" after `sys_user_permission_set` (33 B); a package pointer an author never writes.
23+
24+
The `(definePermissionSet)` example comment and the field-lock recipe docs link stay.

‎skills/objectstack-data/evals/hooks-security-seeds-datasources.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@
8181
"must_not_contain": ["assigned_to", "beforeInsert"]
8282
}
8383
},
84+
{
85+
"id": 18,
86+
"prompt": "Our package `com.acme.crm` must share every escalated `case` with the members of `support_tier2`, the ownership queue the `com.acme.helpdesk` package ships. `com.acme.crm` declares no dependencies today.",
87+
"expected_output": "A sharing rule in `com.acme.crm` with `sharedWith: { type: 'queue', value: 'support_tier2' }`, and `com.acme.crm`'s manifest declares `dependencies` on `com.acme.helpdesk`: a package's rule reads the queue as its own package's, else the one holder in its declared `dependencies` closure plus `sys`. Without the dependency the only holder sits outside the closure and the rule is refused `outside-closure` (`RESOURCE_CONFLICT`), granting no one. The queue is not redeclared in `com.acme.crm`: a second package holding the name is refused too.",
88+
"files": [],
89+
"assertions": {
90+
"must_contain": ["type: 'queue'", "dependencies", "outside-closure"],
91+
"must_not_contain": ["name: 'support_tier2'"]
92+
}
93+
},
8494
{
8595
"id": 9,
8696
"prompt": "A `vendor` list view of the rows whose `api_key` (a `secret` field) starts with `sk_live`.",

‎skills/objectstack-data/rules/security.md‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const salesUser = definePermissionSet({
3434
## Assigning a permission set to a user
3535

3636
Declaring a set grants nobody anything — an assignment is **data**: one row in
37-
the join object **`sys_user_permission_set`** (`@objectstack/plugin-security`),
37+
the join object **`sys_user_permission_set`**,
3838
carrying `user_id`, `permission_set` (the set's machine **`name`**) and an
3939
optional `organization_id` (`null` = every org context). Optional `valid_from` /
4040
`valid_until` bound a half-open window; `granted_by` is stamped by the gate on
@@ -56,7 +56,7 @@ enforcing code path (explaining another user needs `manage_users`).
5656
## Row-Level Security (RLS)
5757

5858
The **enforced** RLS surface is a list of `rowLevelSecurity` policies on a
59-
**permission set / profile** (`PermissionSetSchema.rowLevelSecurity`), *not* a
59+
**permission set / profile**, *not* a
6060
CEL predicate on the object. Each policy's `using` and/or `check` is a **string**
6161
predicate. `using` admits rows: what a `select` policy lets the
6262
caller read, and the existing rows an `update`/`delete` policy lets it change
@@ -67,7 +67,7 @@ operation: when any applicable policy declares `check`, only those decide
6767
(OR-combined); else each applicable `using` stands in. A non-blank `check` on a
6868
`select`/`delete` policy is refused. Default deny, among the policies that
6969
apply: a row none admits is denied, an unevaluable policy fails closed; when
70-
none applies the policies restrict nothing (the tenant wall still applies) — an
70+
none applies the policies restrict nothing — an
7171
`update`/`delete` target with no write-class `using` is bounded by the caller's
7272
`select` policies.
7373

@@ -94,29 +94,26 @@ Predicates are **canonical CEL** (ADR-0058): `field == current_user.<prop>`,
9494
`field == 'literal'`, `field in current_user.<array>`, comparisons (`>`/`<`/`>=`/`<=`),
9595
`&&`/`||`/`!`, and `== null` checks all lower to a pushdown filter. **No** cross-object
9696
traversal or subqueries — those are a compile error (ADR-0055), never silently dropped.
97-
A legacy SQL-style `=` / `IN (...)` predicate still compiles via a **deprecated**
98-
bridge (warns). The compiler resolves these
97+
The compiler resolves these
9998
`current_user.*` placeholders:
10099

101100
| Placeholder | Resolves to |
102101
|:--|:--|
103102
| `current_user.id` | the caller's user id (ownership) |
104103
| `current_user.email` | the caller's email (ADR-0056) |
105104
| `current_user.organization_id` | the caller's tenant |
106-
| `current_user.org_user_ids` | ids of users in the same org (for `IN`) |
107-
| `current_user.positions` | the caller's positions (for `IN`; ADR-0090 D3) |
108-
| `current_user.queues` | the ownership queues the caller sits in (for `IN`; ADR-0142 D3) |
109-
| `current_user.KEY` | the set an object's `membershipKeys.KEY` declares (for `IN`) |
105+
| `current_user.org_user_ids` | ids of users in the same org |
106+
| `current_user.positions` | the caller's positions (ADR-0090 D3) |
107+
| `current_user.queues` | the ownership queues the caller sits in (ADR-0142 D3) |
108+
| `current_user.KEY` | the set an object's `membershipKeys.KEY` declares |
110109

111110
- Prefer the built-in `member_default` owner scoping (`owner_only_writes` /
112111
`owner_only_deletes`) and the object's `sharingModel` (ADR-0056 D1) over
113112
hand-written policies for the common cases.
114113

115114
## Membership keys — a `current_user.KEY` set the roster object declares
116115

117-
Rows keyed on a **named record** (an account, a supplier):
118-
declare the set on the **roster** object whose rows
119-
define it, not one policy per record.
116+
Declare the set on the **roster** object, not one policy per record.
120117

121118
<!-- os:check -->
122119
```typescript
@@ -169,6 +166,13 @@ rowLevelSecurity: [
169166
one record, once → a sharing rule or a manual share; a team's records → a
170167
sharing rule whose `sharedWith: { type: 'queue', value: '<queue name>' }`
171168
reaches an ownership queue's members (SKILL.md § Ownership queues).
169+
- A package's rule reads `value` as its package's queue, else the one
170+
holder in its declared `dependencies` closure plus `sys`, else (none
171+
declares it) an org's `sys_queue` row. Else it grants no one new, warned
172+
`RESOURCE_CONFLICT`: `outside-closure` (only a non-dependency
173+
or an environment item holds `support`),
174+
`ambiguous-in-closure` (two dependencies do), `ambiguous-in-environment`
175+
(the one it reaches and a non-dependency do).
172176

173177
## Positions grant only what they name; portal users are `external`
174178

@@ -180,7 +184,7 @@ rowLevelSecurity: [
180184
membership tier (closed list `owner`, `admin`, `delegated_admin`, `member`,
181185
`external`, one per member —
182186
https://objectstack.ai/docs/permissions/authentication#membership-tiers-are-a-closed-list).
183-
The `everyone` baseline (`isDefault` sets) does not reach it, it sees no
187+
The `everyone` baseline does not reach it, it sees no
184188
member directory and holds no business unit, and every org-wide default is
185189
owner-only for it: rows reach it **only** through the explicit grants above.
186190

@@ -290,7 +294,7 @@ none — e.g. identity tables a plugin writes via its own adapter
290294
**Recipe — env-global, admin-only object that admins can fully see:**
291295

292296
```typescript
293-
tenancy: { enabled: false }, // not a tenant object → Layer 0 contributes nothing
297+
tenancy: { enabled: false },
294298
requiredPermissions: ['manage_platform_settings'], // capability AND-gate → members get 403
295299
```
296300

@@ -299,8 +303,7 @@ requiredPermissions: ['manage_platform_settings'], // capability AND-gate → me
299303
> wildcard (`'*'`) read grant — the shipped `viewer_readonly`, an app-declared
300304
> default profile, a customer-authored set; not `member_default`, which is
301305
> explicit-allow — reads every row env-wide. `requiredPermissions` alone leaves a
302-
> tenant object whose untagged rows the wall denies to everyone (above); it is
303-
> the half that holds however permissive the grants. Posture model: ADR-0066.
306+
> tenant object whose untagged rows the wall denies to everyone (above). Posture model: ADR-0066.
304307
305308
## Renaming or removing a shipped access item
306309

0 commit comments

Comments
 (0)