Repository navigation
Commit 80cdbd4
fix(metadata-protocol, plugin-security): judge a permission set's seal, lock and write intent by (package, name) (#34359)
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9UbbBePzY6g11h3hyWk5ud4vWy)_
Fixes #34226
Clause-②: yes (widening) — a save, a draft save or a draft's publish
that a package addresses to its own permission set N, refused 403
`NOT_OVERRIDABLE` ("provided by a managed package and is sealed") while
a package of another namespace ships N, now lands; the exported
`MetadataAuthoringGateContext` (`@objectstack/metadata-protocol`) and
`PermissionSetLockGateContext` (`@objectstack/plugin-security`) each
gain an optional `packageId`; nothing the save door accepted is refused
Metadata-protocol: none
## 维护者速读
- 改了什么:包 crm 发布了权限集 N 时,另一命名空间的包 hr 现在可以保存、草稿保存并发布它自己的权限集 N,hr 的授权只生效 hr
自己的 N;凡是覆盖 crm 所发布 N 的保存(不指定包、指定 crm、指定 crm 的定制配对包、指定 crm
同命名空间的包)仍按原样封存拒绝。
- 为什么改:ADR-0150 D2 规定权限集按「包 + 名称」区分,但托管封存、plugin-security
的打包权限集锁和存储层写入意图都只看名称,把别的包的同名集当成自己的封存基线,误拒了合法保存。
- 风险与回滚:风险在判断「这次保存是否覆盖某个已发布集」的谓词;它复用安装门与保存门共用的命名空间谓词
`permissionSetHoldersMeet` 与配对判定
`isPairOf`,只在「写入方与每个发布方都不同命名空间、且不是其配对包」时放行。回滚即 revert 本 PR,无数据迁移。
-
先看:`packages/metadata-protocol/src/protocol-packaged-base-refusal.ts`(封存谓词
`isOwnPermissionSetWrite`),`packages/plugins/plugin-security/src/packaged-permission-set-lock-gate.ts`(锁的同一判定),`packages/metadata-protocol/src/protocol-save.ts`
与 `protocol-history-and-publish.ts` 中各一行写入意图。
- 两分钟验证:`pnpm --filter @objectstack/plugin-security exec vitest run
src/packaged-permission-set-lock-gate.test.ts`,预期 37 个全部通过,其中 `[#34226]`
一组覆盖两种注册顺序下的放行、全部封存对照,以及无法回滚的运行时上批量发布被拒后的撤销。
- 需要你做的:评审本次声明的放宽(权限集保存与草稿发布两处门)。
## What changes
A permission set is `(package, name)`, with one set of a name per
namespace (ADR-0150 D2/D9). The managed seal (ADR-0126 / ADR-0131 D6)
keeps protecting a package's own shipped base. Four judges decided "is
this write an override of a shipped set?" by the name alone. All four
now judge the package the write is addressed to, through one verdict:
- **The verdict** (`metadata-protocol`,
`protocol-packaged-base-refusal.ts`): `isOwnPermissionSetWrite(engine,
type, name, packageId)`. It is true only for a `permission` write
addressed to a package P such that, for every package Q that ships the
name, P is not Q's customization pair (`isPairOf`) and P does not meet Q
under `permissionSetHoldersMeet`. The second test covers Q itself, a
co-owner of Q's namespace, a platform namespace, a package with no
namespace, and a name the platform requests by spelling. Every shipper
is judged, never the first found.
- **The save door's seal** (`refusePackagedBaseOverride`): does not seal
such a write. The read-only named-base limb stays ahead of it,
unchanged.
- **The repository's managed seal**: the write intent the save door
(`protocol-save.ts`) and the draft promotion
(`protocol-history-and-publish.ts`) hand the store is `runtime-only` for
such a write, not `override-artifact`. One line each, plus the import.
- **The undo of a refused package publish** (`undoLandedPromotions`,
`protocol-history-and-publish.ts`): on a runtime that cannot roll back,
each undo write judges the package it addresses with the same verdict:
the active-row restore or removal at the package the promotion wrote,
the returned draft at the draft's own binding. Before, the undo of a
package's own set beside another namespace's shipped one was refused by
the store and reported still live, and the draft was not put back.
- **plugin-security's packaged-permission-set lock**
(`packaged-permission-set-lock-gate.ts`): skips the lock only when the
write is addressed to a package that, for every declarer, is not the
declarer's pair and does not meet it. A write naming no package, and a
name no source can classify (fail-closed `unknown`), are judged as
before. Its exported `PermissionSetLockGateContext` gains the same
optional `packageId`.
- **The plumbing**: `MetadataAuthoringGateContext` gains an optional
`packageId`, the package the write is addressed to. The save door passes
`request.packageId` (one line in `protocol-save.ts`). The restore path
passes the row's binding. The private `runAuthoringGate` event type in
`protocol.ts` gains the same optional field (one line).
## FROM → TO
Measured in `packaged-permission-set-lock-gate.test.ts` on this head.
FROM was measured on the same harness with every non-test file of this
diff reverted to `origin/main` (`5a755791a9`). Package `crm` (namespace
`crm`) ships `N`. Every row holds in both registration orders (crm's set
registered before or after the other packages install).
| Write of `N` | FROM (main) | TO (this PR) |
|---|---|---|
| `hr` (namespace `hr`) saves its own `N` | 403 `NOT_OVERRIDABLE`, "…is
provided by a managed package and is sealed…" | saved; `hr`'s grant
confers `hr`'s set, `crm`'s confers `crm`'s |
| `hr` saves its own `N` while `crm` and `fin` both ship `N` | 403
`NOT_OVERRIDABLE` | saved |
| `hr` saves its own `N` as a draft, then publishes it | draft save 403
`NOT_OVERRIDABLE` | draft lands, publish promotes it, `hr`'s grant
confers it |
| save naming no package | 403 `NOT_OVERRIDABLE` (seal) | unchanged |
| save addressed to `crm` | 403 `NOT_OVERRIDABLE` (seal) | unchanged |
| save addressed to `crm`'s customization pair (namespace `crmx`) | 403
`NOT_OVERRIDABLE` (seal) | unchanged |
| save addressed to a co-owner of `crm`'s namespace | 403
`NOT_OVERRIDABLE` (seal) | unchanged |
| `fin` and `crm` ship `N`; save addressed to a co-owner of `crm`'s
namespace | 403 `NOT_OVERRIDABLE` (seal) | unchanged |
| the lock gate, for no package / `crm` / `crm`'s pair / `crm`'s
co-owner | `PackagedPermissionSetLockedError` | unchanged |
| the lock gate, for `hr` | `PackagedPermissionSetLockedError` | passes
|
| publish of a stored draft bound to `crm` or `crm`'s pair | (no such
draft could be stored) | 403 `NOT_OVERRIDABLE` (the store's seal) |
| publish of a stored draft bound to no package or to `crm`'s co-owner |
(no such draft could be stored) | 422 `NAMESPACE_CONFLICT` (the name
rule, judged first) |
## Tests
New pins, as a top-level describe in
`packages/plugins/plugin-security/src/packaged-permission-set-lock-gate.test.ts`:
`[#34226] a permission set is (package, name): the seal and the lock
judge a save by the package it addresses`. The harness is the real
protocol and the real `SchemaRegistry`, both aliased to source. Each
case runs in both registration orders:
- `hr`'s own save lands, and each package's grant confers its own set;
- with two shippers, `hr`'s own save still lands;
- draft save then publish lands;
- CONTROLs at the save door: no package, `crm`, `crm`'s pair (other
namespace), `crm`'s co-owner, and `fin`'s and `crm`'s co-owner. Each is
asserted to be refused by the seal, not the lock;
- CONTROLs at the publish door: a stored draft bound to each of those
addresses, with the code and status asserted;
- the lock gate itself: `hr` passes; no package, `crm`, the pair and the
co-owner are locked;
- the undo of a refused package publish on a runtime that cannot roll
back (`[#32396]` shape, created and edited): `hr`'s own N is reported
`BATCH_ABORTED`, the active rows are as before the publish, and N's
draft is back byte for byte.
The file's engine double now lists a table's own rows by the where's
scalar equalities, answers a version's history row, and applies the
caller's `limit` after its filter (`check:objectql-double-limit`).
Result at `b054ae27`: the full `plugin-security` suite, Test Files 271
passed (271), Tests 6753 passed | 45 skipped, which includes this file
at 37 passed (37); under the verify lock with VERDICT command-exit 0.
<details><summary>FROM reading (H1): the pins on origin/main
source</summary>
Every non-test file of the diff was restored from `5a755791a9` and the
file was run: 16 failed | 17 passed (33). Every TO case and every case
that needs `hr`'s draft failed. `hr`'s save was refused 403
`NOT_OVERRIDABLE`: "Metadata item 'permission/qa_shared_reader' is
provided by a managed package and is sealed against in-place edits.
Clone it under a new name…". The save-door CONTROLs passed on main, so
they hold as before. Afterwards each file's blob equalled HEAD and `git
diff HEAD` was empty.
</details>
<details><summary>Ablations: thirteen legs, each red, each restored
(scripts/ablation-replace.mjs, anchor x1 to x0)</summary>
The seal and lock legs were read from source through the test aliases,
so no dist step applies.
| Leg | Result |
|---|---|
| S1: seal narrowing removed | 14 failed |
| S2: seal pair arm removed | 4 failed (the pair CONTROLs at the save
and publish doors) |
| S3: seal meets arm removed | 8 failed |
| S4: seal judges the first shipper only | 2 failed (the `fin`/`crm`
co-owner CONTROL) |
| I1: save write intent name-wide | 14 failed |
| I2: publish write intent name-wide | 2 failed (draft then publish) |
| P1: the save door hands the gate no package | 14 failed |
| L1: lock narrowing removed | 16 failed |
| L2: lock pair arm removed | 2 failed (the gate case) |
| L3: lock meets arm removed | 2 failed (the gate case) |
| U0: the undo's verdict removed (FROM) | 4 failed (created and edited,
both orders) |
| U1: the undo's active-row intent at no package | 2 failed (edited: the
restore is refused) |
| U2: the undo's returned-draft intent at no package | 2 failed
(created: the draft put is refused) |
The U legs read `metadata-protocol` from source through the test alias,
so no dist step applies; each restore was proved by blob equal to HEAD
and an empty `git diff HEAD`. The final `git diff HEAD` was empty. The
first P1 attempt was refused by the tool, because its replacement was a
substring of the original text; it was re-run with a marked replacement.
</details>
<details><summary>H3 probe (not committed)</summary>
A scratch test called `refusePackagedBaseOverride` for `hr`'s own item
of each package-scoped type while `crm` ships one. The answers are
listed under Acceptance notes.
</details>
## Acceptance notes
- **H1** (both gates key on the name alone): confirmed, and there is a
third judge. After the seal and the lock were narrowed, `hr`'s save was
still refused 403 `NOT_OVERRIDABLE` by the repository's managed seal,
because the save door's write intent was computed from the name-wide
artifact check. The draft promotion computes the same intent. Both are
narrowed here through the same verdict.
- **H2**: confirmed for the four judges above. Every override of `crm`'s
`N` stays sealed, including a save addressed to `crm`'s customization
pair whose namespace differs from `crm`'s.
- **H3** (acceptance item 2), measured: every sealed package-scoped type
shares the name-wide shape. With package `crm` shipping item X and
package `hr` of another namespace, `refusePackagedBaseOverride` refuses
`hr`'s own save of X as sealed for `flow`, `hook`, `job`, `webhook`,
`mapping`, `connector`, `sharing_rule`, `queue`, `assignment_rule`,
`app`, `page`, `dataset`, `analytics_cube`, `picklist`, `book`, `api`,
`tool`, `skill`, `agent`, and so for `permission` before this PR.
`action`'s registration contract refused the bare probe body, but its
seal is the same predicate. `dashboard`, `report` and `email_template`
are not sealed (environment-overlay types). Only `permission` is changed
here: the fix is not the same line for the others, because each type's
identity and override channel differ.
- **Out of scope**, filed:
- #34401: rollback and commit revert of a package's own permission set
beside another namespace's shipped set still hand `restoreWriteFor` the
name-wide intent, so the store refuses the restore
(`protocol-package-commits.ts`, the `revertCommit` restore limb and
`rollbackMetaItemUnaudited`). The `revertCommit` removal limb states the
same intent, but the store admits it (below);
- #34402: the other sealed package-scoped types listed under H3 keep the
name-wide seal.
- **Delete and discard (L1 R1), measured: not refused, no code change.**
`deleteMetaItem` still derives its removal intent from the name-wide
`artifactBacked` (`protocol-diff-delete-load.ts`, lines 642 and 851).
The store admits that removal anyway:
`SysMetadataRepository#assertDeleteAllowed` lets an `override-artifact`
delete through for a `supportsOverlay` type, and `permission` is one
(`supportsOverlay: true`), so `assertAllowed` is never reached. Measured
at this head with a scratch case in the gate file's harness (not
committed), in both registration orders: `hr` deleting its own active
`N` answered `success: true` and removed the row, and `hr` discarding
its own `N` draft answered `success: true` and removed the draft, while
`crm` ships `N`.
- **Overlap**: PR #34238 edits the same `promoteDraftForPublish` host
`Pick` line in `protocol-history-and-publish.ts`. Its head `0ed4158ef6`
added `readItemActiveRows`, and this PR adds `engine`. At that head the
two conflicted textually, and the resolution is the union of both
members. At #34238's current head `db96228e6c` the merge-tree is clean.
If the conflict returns, whichever PR lands second needs one mechanical
merge of `main`.
- The seal's verdict and the lock's relation check are spelled once
each, in their own packages (plugin-security cannot import
`metadata-protocol` at runtime). Both are built only from the shared
predicates `permissionSetHoldersMeet` (`@objectstack/core`) and
`isPairOf` (`@objectstack/metadata-core`), and the pins hold the two in
step at every address.
- `scripts/engine-double-contract.pinned.json`: one count goes 1 → 2 for
the new pinned `findOne` double in the gate's test file, as
`check:engine-double-contract` asks.
## Verification
Head `b054ae27` (unchanged by the L1 R1 round: R1 measured not refused,
see Acceptance notes; nothing in code moved):
- **CI red at `1a2f74f526`, cause**: one compile error in this PR's own
file,
`packages/plugins/plugin-security/src/packaged-permission-set-lock-gate.ts(83,68):
error TS2339: Property 'namespace' does not exist on type '{}'`. The
cast intersected `InstalledPackageSource` with a second `getPackage`
signature, and the first signature (manifest `unknown`) won. The
namespace is now read through the typed `installedManifestsOf` lookup.
Build Core, the three Type Check lanes, Test Core and Live E2E UI all
failed on that line. It is not on `main`: the file is new in this PR.
- **Review S1 / N1 / N2** (contract record 6915371853): S1 is fixed
above (`undoLandedPromotions`), with the pins and the U legs. N1 and N2
are folded into the changeset and the `Clause-②:` line, which now read
the same in both.
- Build closure `pnpm --filter '@objectstack/plugin-security...' build`:
exit 0.
- `typecheck`: `metadata-protocol` and `plugin-security` exit 0 at
`343d5a7f`; `plugin-security` again at `b054ae27`, exit 0 (the last
commit only touched its test file).
- `metadata-protocol` full suite at `343d5a7f` (its source is unchanged
since): Test Files 345 passed | 9 skipped, Tests 22956 passed | 45
skipped.
- `plugin-security` full suite at `b054ae27`: Test Files 271 passed,
Tests 6753 passed | 45 skipped.
- Derived gate sweep at `b054ae27`: `dispatch-gates --ran` printed `85
derived, 83 run, 2 NOT-MEASURED, 0 UNRUN`; every run family exited 0,
including `check:objectql-double-limit`, `check:engine-double-contract`,
`check:query-options-erasure` and `check:type-check-debt`.
`check:dual-build-cjs-loads` and `check:i18n` exit 3 (PREREQUISITE NOT
MET: a full build) and are left to CI.
- Overlap: `git merge-tree --write-tree` of `b054ae27` against
`origin/main` `f84dc192`, #34238 `db96228e6c` and #34324 `e378b62f30`
all exit 0.
- CI at `b054ae27`, read once after the L1 R1 measurement: 55
check-runs, 37 success and 18 skipped, no failure and none pending
(Build Core, TypeScript Type Check, Test Core, Lint & Repo Gates, Live
E2E UI, Dogfood Regression Gate and Check Changeset all success).
- No full dogfood battery is owed: the title has no `!` and there is no
narrowing arm.
---
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01QsR2jUcj2x2Wr4UErwBi12
<!-- signed: repo:objectstack#1 · os-project-manager ·
session_01FEkQ5obaLbqgzRUR9xXfft -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 1089e9e commit 80cdbd4
10 files changed
Lines changed: 390 additions & 18 deletions
File tree
- .changeset
- packages
- metadata-protocol/src
- plugins/plugin-security/src
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
46 | 54 | | |
47 | 55 | | |
48 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
| 180 | + | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | | - | |
| 189 | + | |
190 | 190 | | |
191 | 191 | | |
192 | 192 | | |
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
211 | 213 | | |
212 | 214 | | |
213 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
144 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
145 | 151 | | |
146 | 152 | | |
147 | 153 | | |
| |||
177 | 183 | | |
178 | 184 | | |
179 | 185 | | |
180 | | - | |
| 186 | + | |
181 | 187 | | |
182 | 188 | | |
183 | 189 | | |
| |||
664 | 670 | | |
665 | 671 | | |
666 | 672 | | |
667 | | - | |
| 673 | + | |
668 | 674 | | |
669 | 675 | | |
670 | 676 | | |
| |||
1251 | 1257 | | |
1252 | 1258 | | |
1253 | 1259 | | |
1254 | | - | |
| 1260 | + | |
1255 | 1261 | | |
1256 | 1262 | | |
1257 | 1263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
| |||
151 | 153 | | |
152 | 154 | | |
153 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
154 | 165 | | |
155 | 166 | | |
156 | 167 | | |
| |||
179 | 190 | | |
180 | 191 | | |
181 | 192 | | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
182 | 255 | | |
183 | 256 | | |
184 | 257 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
1824 | 1824 | | |
1825 | 1825 | | |
1826 | 1826 | | |
| 1827 | + | |
1827 | 1828 | | |
1828 | 1829 | | |
1829 | 1830 | | |
| |||
1908 | 1909 | | |
1909 | 1910 | | |
1910 | 1911 | | |
1911 | | - | |
| 1912 | + | |
1912 | 1913 | | |
1913 | 1914 | | |
1914 | 1915 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1755 | 1755 | | |
1756 | 1756 | | |
1757 | 1757 | | |
1758 | | - | |
| 1758 | + | |
1759 | 1759 | | |
1760 | 1760 | | |
1761 | 1761 | | |
| |||
0 commit comments