Skip to content

Commit 6b1ef34

Browse files
committed
fix(spec): the effective-access origins cover every resolver channel, and the contract states order, positions and the unknown-user departure from explain
Contract review fixes on the describeEffectiveAccess declaration: - a fourth origin kind, derived, with a closed source: platform_admin_config (OS_PLATFORM_OWNER_EMAIL confers admin_full_access with no grant row or position) and ai_access (sys_user.ai_access confers ai_seat), so every name the resolver confers has an origin; - external_default for an external member carries both its position (org_external's static binding) and its default origin; - positions and the permission-set order are the resolver's, spelled out; - the gate sentence names where it departs from explain's 404 for an unknown id. The exhaustive-switch pin covers the new kind and both sources, and plugin-security's registered-member pin lists the optional member. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FEkQ5odNVgHTd2MQbQCp5t
1 parent 80410d2 commit 6b1ef34

3 files changed

Lines changed: 102 additions & 31 deletions

File tree

‎packages/plugins/plugin-security/src/registered-security-service-members.pin.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const DECLARED_MEMBERS = {
7676
checkControlledByParentWrite: 'optional',
7777
explain: 'required',
7878
describeDelegableScope: 'required',
79+
describeEffectiveAccess: 'optional',
7980
listAudienceBindingSuggestions: 'required',
8081
confirmAudienceBindingSuggestion: 'required',
8182
dismissAudienceBindingSuggestion: 'required',

‎packages/spec/src/contracts/security-service.test.ts‎

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -815,28 +815,36 @@ describe('Security Service Contract', () => {
815815
const answer: EffectiveAccess = {
816816
userId: 'u2',
817817
organizationId: 'org_1',
818-
positions: ['sales_rep'],
818+
positions: ['org_member', 'sales_rep', 'everyone'],
819+
// The resolver's order: grant rows, position-bound sets, derived names, the human baseline.
819820
permissionSets: [
820-
{ name: 'member_default', origins: [{ kind: 'default' }] },
821821
{ name: 'sales_user', origins: [{ kind: 'direct' }, { kind: 'position', position: 'sales_rep' }] },
822+
{ name: 'ai_seat', origins: [{ kind: 'derived', source: 'ai_access' }] },
823+
{ name: 'member_default', origins: [{ kind: 'default' }] },
822824
],
823825
};
824826
const withIt = makeService({ describeEffectiveAccess: async () => answer });
825827
await expect(withIt.describeEffectiveAccess?.('u2', { userId: 'u1' })).resolves.toEqual(answer);
826828
});
827829

828-
it('EffectiveAccess: three closed origins, a position origin names its position, no organization is null (compile-time)', () => {
830+
it('EffectiveAccess: four closed origins, a position names its position, a derived origin its closed source (compile-time)', () => {
829831
const everyOrigin: EffectivePermissionSetOrigin[] = [
830-
{ kind: 'default' },
831-
{ kind: 'position', position: 'sales_rep' },
832832
{ kind: 'direct' },
833+
{ kind: 'position', position: 'sales_rep' },
834+
{ kind: 'default' },
835+
{ kind: 'derived', source: 'platform_admin_config' },
836+
{ kind: 'derived', source: 'ai_access' },
833837
];
834-
expect(everyOrigin).toHaveLength(3);
838+
expect(everyOrigin).toHaveLength(5);
835839
// @ts-expect-error a `position` origin must name the position
836840
const positionWithoutName: EffectivePermissionSetOrigin = { kind: 'position' };
837-
// @ts-expect-error the vocabulary is closed: a set reaches a user by default, position or direct grant
841+
// @ts-expect-error the vocabulary is closed: direct, position, default or derived
838842
const notAnOrigin: EffectivePermissionSetOrigin = { kind: 'inherited' };
839-
expect([positionWithoutName, notAnOrigin]).toHaveLength(2);
843+
// @ts-expect-error a `derived` origin must name the standing that confers it
844+
const derivedWithoutSource: EffectivePermissionSetOrigin = { kind: 'derived' };
845+
// @ts-expect-error the derived sources are closed: the configured platform administrators or `sys_user.ai_access`
846+
const notASource: EffectivePermissionSetOrigin = { kind: 'derived', source: 'api_key_scope' };
847+
expect([positionWithoutName, notAnOrigin, derivedWithoutSource, notASource]).toHaveLength(4);
840848

841849
expectTypeOf<EffectivePermissionSet>().toEqualTypeOf<{
842850
name: string;
@@ -852,23 +860,43 @@ describe('Security Service Contract', () => {
852860
(userId: string, callerContext?: SecurityContext) => Promise<EffectiveAccess>
853861
>();
854862

855-
// An exhaustive consumer: a fourth origin added to the union would stop
856-
// this switch compiling at the `never` line.
863+
// An exhaustive consumer: a fifth origin kind, or a third derived source,
864+
// added to the union would stop this switch compiling at a `never` line.
865+
const sourceLabel = (source: Extract<EffectivePermissionSetOrigin, { kind: 'derived' }>['source']): string => {
866+
switch (source) {
867+
case 'platform_admin_config':
868+
return 'configured platform administrator';
869+
case 'ai_access':
870+
return 'AI seat';
871+
default: {
872+
const unhandled: never = source;
873+
return unhandled;
874+
}
875+
}
876+
};
857877
const label = (o: EffectivePermissionSetOrigin): string => {
858878
switch (o.kind) {
859-
case 'default':
860-
return 'default';
861-
case 'position':
862-
return `position:${o.position}`;
863879
case 'direct':
864880
return 'direct';
881+
case 'position':
882+
return `position:${o.position}`;
883+
case 'default':
884+
return 'default';
885+
case 'derived':
886+
return `derived:${sourceLabel(o.source)}`;
865887
default: {
866888
const unhandled: never = o;
867889
return unhandled;
868890
}
869891
}
870892
};
871-
expect(everyOrigin.map(label)).toEqual(['default', 'position:sales_rep', 'direct']);
893+
expect(everyOrigin.map(label)).toEqual([
894+
'direct',
895+
'position:sales_rep',
896+
'default',
897+
'derived:configured platform administrator',
898+
'derived:AI seat',
899+
]);
872900
});
873901

874902
it('reopenAudienceBindingSuggestion is OPTIONAL — absence leaves every dismissal standing (compile-time)', async () => {

‎packages/spec/src/contracts/security-service.ts‎

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,32 +153,54 @@ export interface PositionGrantSummary {
153153
}
154154

155155
/**
156-
* How a permission set reaches a user, in {@link EffectivePermissionSet}:
156+
* How a permission set reaches a user, in {@link EffectivePermissionSet}. One
157+
* kind per channel through which the resolver enforcement uses
158+
* (`resolveUserAuthzGrants` in `@objectstack/core`, joined with the security
159+
* service's human baseline) names a set for a user:
157160
*
161+
* - `direct` — one of the user's own `sys_user_permission_set` grant rows
162+
* names it.
163+
* - `position` — the definition of a position the user holds names it in
164+
* `permissionSets` (ADR-0131 D3/D4); `position` is that position's name. A
165+
* built-in identity position's static binding is such a definition too: an
166+
* external member's `external_default` is reported with
167+
* `{ kind: 'position', position: 'org_external' }`. `everyone` is never
168+
* reported here: its bindings are `default`.
158169
* - `default` — a default binding: the set is bound to the `everyone`
159170
* audience anchor (the deployment baseline, an app's `isDefault` set, an
160171
* accepted package default; ADR-0090 D5), or it is the human baseline the
161-
* resolution adds for every authenticated member (`external_default` for an
162-
* external member).
163-
* - `position` — the definition of a position the user holds names it in
164-
* `permissionSets` (ADR-0131 D3/D4); `position` is that position's name.
165-
* `everyone` is never reported here: its bindings are `default`.
166-
* - `direct` — one of the user's own `sys_user_permission_set` grant rows
167-
* names it.
172+
* security service adds for every authenticated member (`external_default`
173+
* for an external member, so that set carries both its `position` and its
174+
* `default` origin).
175+
* - `derived` — the resolver confers the name from the user's standing, with
176+
* no grant row and no position definition naming it. `source` says which
177+
* standing, and the vocabulary is closed:
178+
* - `platform_admin_config` — the user's own stored email matches the
179+
* deployment's configured platform administrators
180+
* (`OS_PLATFORM_OWNER_EMAIL`), which confers `admin_full_access` and
181+
* platform-admin standing (on a walled tenancy posture, the only anchor
182+
* of that standing);
183+
* - `ai_access` — the user's `sys_user.ai_access` flag is set, which
184+
* confers the `ai_seat` capability name.
185+
*
186+
* Only the user's own resolution is described: the sets an API key's scopes,
187+
* an agent's ceiling or the anonymous `guest` anchor confer belong to a
188+
* credential or principal kind, not to the user, and are not origins.
168189
*/
169190
export type EffectivePermissionSetOrigin =
170-
| { kind: 'default' }
191+
| { kind: 'direct' }
171192
| { kind: 'position'; position: string }
172-
| { kind: 'direct' };
193+
| { kind: 'default' }
194+
| { kind: 'derived'; source: 'platform_admin_config' | 'ai_access' };
173195

174196
/** One permission set in {@link EffectiveAccess}. */
175197
export interface EffectivePermissionSet {
176198
/** The permission set's machine name. */
177199
name: string;
178200
/**
179201
* Every way the set reaches the user, at least one. A set reached two ways
180-
* is listed once, with both origins (a direct grant and a position, or two
181-
* positions).
202+
* is listed once, with both origins (a direct grant and a position, two
203+
* positions, or a grant row and the configured platform administrator).
182204
*/
183205
origins: EffectivePermissionSetOrigin[];
184206
}
@@ -192,9 +214,26 @@ export interface EffectiveAccess {
192214
* vetted for the described user as `explain` vets it. `null` with none.
193215
*/
194216
organizationId: string | null;
195-
/** The positions the user holds there, in force (the resolver's `positions`). */
217+
/**
218+
* The positions the user holds there, in force, exactly as the resolver
219+
* lists them: the derived `platform_admin` first where it is held, then the
220+
* positions projected from the user's membership (`org_owner`, `org_admin`,
221+
* `org_member`, `org_external`) and the user's own position rows, then the
222+
* `everyone` audience anchor for every member who is not external. A position
223+
* the activation ledger switched off is not listed. `everyone` and
224+
* `platform_admin` are listed although neither is ever an origin
225+
* (`everyone`'s bindings are `default`; `platform_admin` names no set).
226+
*/
196227
positions: string[];
197-
/** The permission sets in force for the user there, in resolution order. */
228+
/**
229+
* The permission sets in force for the user there, each once, in the
230+
* resolver's order: the sets of the user's grant rows in grant order, then
231+
* the position-bound sets in the order the held positions name them, then
232+
* the `derived` names (`admin_full_access` from the configured platform
233+
* administrators, then `ai_seat`), then the human baseline sets the
234+
* security service adds. A set already listed keeps its first place and
235+
* gains the later origin.
236+
*/
198237
permissionSets: EffectivePermissionSet[];
199238
}
200239

@@ -1249,8 +1288,11 @@ export interface ISecurityService {
12491288
* Gated as `explain` is: describing someone else requires `manage_users`,
12501289
* organization administration of an organization that user is a member of,
12511290
* or a delegated `adminScope` covering that user. A user who does not exist
1252-
* is refused exactly as one the caller may not manage, so the answer says
1253-
* nothing about which ids exist.
1291+
* is refused exactly as one the caller may not manage, for every caller, so
1292+
* the answer says nothing about which ids exist. This is where it departs
1293+
* from `explain`, which answers an admitted caller `404` for an id with no
1294+
* user row: an implementation sharing explain's gate must not carry that
1295+
* `404` over.
12541296
*
12551297
* **OPTIONAL, and absence is a defined state.** A security service that
12561298
* predates it omits it; callers feature-detect

0 commit comments

Comments
 (0)