@vantageos/cloud-identity 0.9.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/README.md +254 -1
  3. package/dist/identity-refusal.d.ts +32 -0
  4. package/dist/identity-refusal.d.ts.map +1 -0
  5. package/dist/identity-refusal.js +28 -0
  6. package/dist/identity-refusal.js.map +1 -0
  7. package/dist/index.d.ts +11 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +10 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/namespace-write.d.ts +20 -0
  12. package/dist/namespace-write.d.ts.map +1 -0
  13. package/dist/namespace-write.js +40 -0
  14. package/dist/namespace-write.js.map +1 -0
  15. package/dist/person-principal.d.ts +7 -0
  16. package/dist/person-principal.d.ts.map +1 -1
  17. package/dist/person-principal.js +7 -0
  18. package/dist/person-principal.js.map +1 -1
  19. package/dist/principal-by-id.d.ts +206 -0
  20. package/dist/principal-by-id.d.ts.map +1 -0
  21. package/dist/principal-by-id.js +334 -0
  22. package/dist/principal-by-id.js.map +1 -0
  23. package/dist/role-policy.d.ts +72 -0
  24. package/dist/role-policy.d.ts.map +1 -0
  25. package/dist/role-policy.js +101 -0
  26. package/dist/role-policy.js.map +1 -0
  27. package/dist/scope-filter.d.ts +26 -0
  28. package/dist/scope-filter.d.ts.map +1 -1
  29. package/dist/scope-filter.js +29 -3
  30. package/dist/scope-filter.js.map +1 -1
  31. package/dist/secret-compare-sync.d.ts +29 -0
  32. package/dist/secret-compare-sync.d.ts.map +1 -0
  33. package/dist/secret-compare-sync.js +64 -0
  34. package/dist/secret-compare-sync.js.map +1 -0
  35. package/dist/tenant-membership.d.ts +85 -0
  36. package/dist/tenant-membership.d.ts.map +1 -0
  37. package/dist/tenant-membership.js +113 -0
  38. package/dist/tenant-membership.js.map +1 -0
  39. package/package.json +25 -1
@@ -1 +1 @@
1
- {"version":3,"file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F;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,SAAS,EAAE,eAAe,CAAC;IAC3B,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,kBAAkB,CAerB;AAMD,KAAK,eAAe,GAAG;IACrB,uEAAuE;IACvE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAChC,oFAAoF;IACpF,WAAW,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,GAAG,SAAS,CAAC;IAClD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,kBAAkB,CAc5E;AAED,+EAA+E;AAC/E,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAG9D"}
@@ -131,6 +131,13 @@ export async function resolvePersonPrincipal(token, deps, door) {
131
131
  * resolved by the consumer): none ->
132
132
  * AGENT_CREDENTIAL_REQUIRED, a
133
133
  * different agent -> AGENT_IDENTITY_MISMATCH.
134
+ *
135
+ * @deprecated Since 0.11.0. Use `resolveActingPrincipal` (and
136
+ * `assertTargetBelongsTo` for the target), which resolve the actor by stored
137
+ * ID. This function takes names (`claimedName`, `agentCredential.agentName`)
138
+ * as identity input, which backend standard R-53 clause 4 makes
139
+ * non-conforming for any new door. Behaviour is unchanged; it will be removed
140
+ * in a major release once consumers have migrated off it.
134
141
  */
135
142
  export function resolvePersonActingName(input) {
136
143
  const { principal, door } = input;
@@ -1 +1 @@
1
- {"version":3,"file":"person-principal.js","sourceRoot":"","sources":["../src/person-principal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA0Cx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AK,CAAC,WAAW,IAAI,EAAE,CAAC;IAC5C,IAAI,IAAI,KAAK,IAAI,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACrE,OAAO;QACL,EAAE,EAAE,KAAK;QACT,OAAO,EAAE,MAAM,CACb,aAAa,EACb,iBAAiB,EACjB,KAAK,CAAC,IAAI,EACV,kCAAkC,EAClC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,IAAI,EAAE,CACzC;KACF,CAAC;AACJ,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,iBAAiB,CAAC,KAAsB;IACtD,MAAM,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,CAAC,CAAC,CAAC,EAAE;QAAE,MAAM,IAAI,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,206 @@
1
+ /**
2
+ * The acting principal by ID, and the target checked by ID.
3
+ *
4
+ * An actor and a target are identified by their stored IDs, never by a name.
5
+ * A name is a display label: it never selects a row and never authorises one.
6
+ *
7
+ * Motivating incident: an agent of organisation A named "eta", calling by name
8
+ * through a service account, completed, updated and deleted the task of
9
+ * organisation B's agent also named "eta" at ten task doors, because every door
10
+ * admitted the caller by comparing names. Two different agents shared a label;
11
+ * nothing compared their IDs.
12
+ *
13
+ * Two functions close that class:
14
+ *
15
+ * - `resolveActingPrincipal(credential, lookups)` turns a VERIFIED credential
16
+ * into `{ principalId, orgId, kind }` read from stored rows, or refuses.
17
+ * - `assertTargetBelongsTo(principal, target, lookups, opts)` admits a target
18
+ * only when its stored organisation ID (and owner ID, where the door is
19
+ * owner-only) equals the principal's resolved IDs.
20
+ *
21
+ * The fleet is the OPERATOR ORGANISATION: the organisation the consumer's
22
+ * `orgKindOf` adapter reports as `"operator"`, read from stored data at run
23
+ * time. No organisation ID is reserved or spelled in this package; an
24
+ * adapter that answers anything else, or nothing, means "not the fleet".
25
+ *
26
+ * RULING 5: membership of the operator org is ORDINARY membership. Its agents
27
+ * and persons resolve as `kind: "agent"` / `"person"` of that org and reach its
28
+ * rows only. Cross-org reach (`kind: "fleet"` + `fleetCrossOrg`) belongs to the
29
+ * operator org's SERVICE ACCOUNT alone; `reserved-fleet-scope` refuses a claim
30
+ * of that scope by any other credential, never plain membership.
31
+ *
32
+ * Pure functions over injected lookups: no database, no framework, no network.
33
+ * The consumer performs each indexed read by ID and passes the function in;
34
+ * every failure (throwing lookup, miss, malformed row, inactive row, wrong
35
+ * organisation) is a typed `IdentityRefusal`, never a default principal.
36
+ *
37
+ * @security This module verifies NOTHING about the credential itself. The IDs
38
+ * in a credential must come from the consumer's verification of what the
39
+ * caller presented (a bearer row, a person's token, the service secret). A
40
+ * client-supplied argument passed as a credential becomes the principal.
41
+ */
42
+ import { z } from "zod";
43
+ import { type IdentityRefusal } from "./identity-refusal.js";
44
+ /**
45
+ * A verified credential, in the package's vocabulary. Every identity field is
46
+ * an ID. The schemas are STRICT: a credential carrying any other key (an
47
+ * `agentName`, a `callerOrchestrator`, a `name`) is refused whole, so a name
48
+ * cannot be smuggled in beside an ID.
49
+ *
50
+ * - `agent`: an agent's own bearer, verified by the consumer (for example by
51
+ * `validatePresentedBearer`): the agent ID and the organisation the bearer
52
+ * row is stamped with.
53
+ * - `person`: a person's token, verified by the consumer: the stored person
54
+ * ID (the verified subject) and the organisation the token is bound to.
55
+ * - `service`: the service account, verified by the consumer. When it acts
56
+ * for an agent it names that agent BY ID (`actingForAgentId`); the agent
57
+ * is resolved within the service account's own organisation.
58
+ */
59
+ export declare const actingCredentialSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
60
+ kind: z.ZodLiteral<"agent">;
61
+ agentId: z.ZodString;
62
+ verifiedOrgId: z.ZodString;
63
+ }, z.core.$strict>, z.ZodObject<{
64
+ kind: z.ZodLiteral<"person">;
65
+ personId: z.ZodString;
66
+ verifiedOrgId: z.ZodString;
67
+ }, z.core.$strict>, z.ZodObject<{
68
+ kind: z.ZodLiteral<"service">;
69
+ serviceAccountId: z.ZodString;
70
+ actingForAgentId: z.ZodOptional<z.ZodString>;
71
+ }, z.core.$strict>], "kind">;
72
+ export type ActingCredential = z.input<typeof actingCredentialSchema>;
73
+ /**
74
+ * Each row repeats its own ID, so a loose lookup (prefix match, wrong index)
75
+ * returning another row cannot become a principal. `active` is REQUIRED and
76
+ * must be `true`: an absent flag grants nothing. Extra fields (a display name)
77
+ * are allowed and ignored.
78
+ */
79
+ export declare const principalRowSchema: z.ZodObject<{
80
+ id: z.ZodString;
81
+ orgId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
82
+ active: z.ZodBoolean;
83
+ }, z.core.$strip>;
84
+ export type PrincipalRow = z.input<typeof principalRowSchema>;
85
+ export declare const organisationRowSchema: z.ZodObject<{
86
+ id: z.ZodString;
87
+ active: z.ZodBoolean;
88
+ }, z.core.$strip>;
89
+ export type OrganisationRow = z.input<typeof organisationRowSchema>;
90
+ /**
91
+ * The kind of a stored organisation, as the consumer's mapping row records it.
92
+ * `"operator"` is the fleet: the operator's own organisation, whose rows are
93
+ * the master scope. Any other answer, `null` included, is not the fleet.
94
+ */
95
+ export type OrgKind = "operator" | "client";
96
+ type Lookup<A extends unknown[], R> = (...args: A) => Promise<R | null | undefined> | R | null | undefined;
97
+ /** Indexed reads BY ID. Only the lookups of the presented path are called. */
98
+ export type PrincipalLookups = {
99
+ agentById?: Lookup<[agentId: string], PrincipalRow>;
100
+ /** A person's row IN one organisation (their membership there). */
101
+ personById?: Lookup<[personId: string, orgId: string], PrincipalRow>;
102
+ serviceAccountById?: Lookup<[serviceAccountId: string], PrincipalRow>;
103
+ /** The organisation row; the operator organisation is checked like any other. */
104
+ organisationById?: Lookup<[orgId: string], OrganisationRow>;
105
+ /**
106
+ * The stored kind of an organisation (for example `orgKind` on its mapping
107
+ * row). Decides, from data, whether an organisation is the operator org,
108
+ * that is the fleet. `null`, a miss, or any value other than exactly
109
+ * `"operator"` is NOT the fleet. A missing or throwing adapter refuses.
110
+ */
111
+ orgKindOf?: Lookup<[orgId: string], OrgKind>;
112
+ };
113
+ /** The one lookup `assertTargetBelongsTo` reads. */
114
+ export type OrgKindLookups = Pick<PrincipalLookups, "orgKindOf">;
115
+ export type ActingPrincipalKind = "agent" | "person" | "service" | "fleet";
116
+ export type ActingPrincipal = {
117
+ /** The stored ID of the actor: agent ID, person ID or service-account ID. */
118
+ principalId: string;
119
+ /** The stored organisation ID. The operator org's ID for `fleet`. */
120
+ orgId: string;
121
+ kind: ActingPrincipalKind;
122
+ /** Set when a service account acts for an agent: the service account's ID. */
123
+ viaServiceAccountId?: string;
124
+ };
125
+ export type ResolveActingPrincipalResult = {
126
+ ok: true;
127
+ principal: ActingPrincipal;
128
+ } | {
129
+ ok: false;
130
+ refusal: IdentityRefusal;
131
+ };
132
+ export type TargetIds = {
133
+ /** The target row's stored organisation ID. Absent: unstamped. */
134
+ orgId?: string | null;
135
+ /** The target row's stored owner ID (agent, person or service account). */
136
+ ownerId?: string | null;
137
+ };
138
+ export type AssertTargetOptions = {
139
+ /** The consumer's name for the door; carried on every refusal. */
140
+ door?: string;
141
+ /** Owner-only door: the target's `ownerId` must equal `principalId`. */
142
+ ownerOnly?: boolean;
143
+ /**
144
+ * A fleet principal may reach a row of a CLIENT organisation only when the
145
+ * door declares it (a master export), and only when `orgKindOf` reports that
146
+ * organisation as `"client"`. Default `false`: refused.
147
+ */
148
+ fleetCrossOrg?: boolean;
149
+ };
150
+ export type AssertTargetResult = {
151
+ ok: true;
152
+ } | {
153
+ ok: false;
154
+ refusal: IdentityRefusal;
155
+ };
156
+ /**
157
+ * Resolves the acting principal from a VERIFIED credential to stored IDs, or
158
+ * refuses. Refusal by default: a credential claiming the fleet kind
159
+ * (`reserved-fleet-scope`), a credential that does not parse (including one
160
+ * carrying any name field), a missing or throwing lookup, a miss, a malformed
161
+ * or inactive row, an unstamped row and an inactive organisation are all
162
+ * refused. Nothing is ever resolved by a name, and nothing falls back to a
163
+ * master principal.
164
+ *
165
+ * - agent: the agent row by `agentId`; its stored org must equal the org
166
+ * the credential was verified for. An agent of the operator org resolves
167
+ * as an ordinary `kind: "agent"` of that org (RULING 5).
168
+ * - person: the person row by (`personId`, `verifiedOrgId`); it must be
169
+ * stamped with that org. A person of the operator org resolves as an
170
+ * ordinary `kind: "person"` of that org (RULING 5).
171
+ * - service: the service-account row by `serviceAccountId`. Alone, it acts
172
+ * as itself (`kind: "service"`, or `kind: "fleet"` when `orgKindOf` reports
173
+ * its stored org as `"operator"`). With `actingForAgentId`, the agent row is read by
174
+ * ID and must be stamped with the service account's own org; the principal
175
+ * is that agent, with `viaServiceAccountId` recording the carrier.
176
+ */
177
+ export declare function resolveActingPrincipal(credential: ActingCredential | null | undefined, lookups: PrincipalLookups, door?: string): Promise<ResolveActingPrincipalResult>;
178
+ /**
179
+ * Admits a target only by comparing its STORED IDs with the principal's
180
+ * resolved IDs, byte for byte. No name field is read; there is none to read.
181
+ *
182
+ * Whether an organisation is the operator org (the fleet) is read from
183
+ * `lookups.orgKindOf`; a missing or throwing adapter refuses.
184
+ *
185
+ * - An absent principal, or one with an empty ID, is refused.
186
+ * - A `kind: "fleet"` principal outside the operator org is refused, and so
187
+ * is a `kind: "service"` principal inside it (the operator org's service
188
+ * account is the fleet). An agent or person of the operator org is an
189
+ * ordinary member of it (RULING 5).
190
+ * - An unstamped target (no `orgId`) is refused to EVERY principal, the
191
+ * fleet principal included. No right is inferred from an absence: a fleet
192
+ * row carries the operator org's ID explicitly, and a row with no
193
+ * organisation is never treated as a master row.
194
+ * - An operator-org row is refused to every client principal.
195
+ * - Otherwise the target's `orgId` must equal the principal's. A fleet
196
+ * principal reaches a client organisation's row only when the door sets
197
+ * `fleetCrossOrg` (a master export) AND `orgKindOf` reports that
198
+ * organisation as `"client"`; an unknown organisation is refused. Any
199
+ * other principal reaching across organisations under `fleetCrossOrg`
200
+ * claims the fleet scope and is refused `reserved-fleet-scope`.
201
+ * - `ownerOnly`: the target's `ownerId` must also equal `principalId`; an
202
+ * absent owner is refused.
203
+ */
204
+ export declare function assertTargetBelongsTo(principal: ActingPrincipal | null | undefined, target: TargetIds | null | undefined, lookups: OrgKindLookups, opts?: AssertTargetOptions): Promise<AssertTargetResult>;
205
+ export {};
206
+ //# sourceMappingURL=principal-by-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"principal-by-id.d.ts","sourceRoot":"","sources":["../src/principal-by-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,eAAe,EAAW,MAAM,uBAAuB,CAAC;AAMtE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,sBAAsB;;;;;;;;;;;;4BAgBjC,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAMtE;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB;;;;iBAI7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D,eAAO,MAAM,qBAAqB;;;iBAGhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAEpE;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE5C,KAAK,MAAM,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,IAAI,CACpC,GAAG,IAAI,EAAE,CAAC,KACP,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAE1D,8EAA8E;AAC9E,MAAM,MAAM,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AA2E;IAC3E,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wEAAwE;IACxE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,CAAC;AA0GxF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,sBAAsB,CAC1C,UAAU,EAAE,gBAAgB,GAAG,IAAI,GAAG,SAAS,EAC/C,OAAO,EAAE,gBAAgB,EACzB,IAAI,SAA2B,GAC9B,OAAO,CAAC,4BAA4B,CAAC,CAsGvC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,qBAAqB,CACzC,SAAS,EAAE,eAAe,GAAG,IAAI,GAAG,SAAS,EAC7C,MAAM,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,EACpC,OAAO,EAAE,cAAc,EACvB,IAAI,GAAE,mBAAwB,GAC7B,OAAO,CAAC,kBAAkB,CAAC,CAiD7B"}
@@ -0,0 +1,334 @@
1
+ /**
2
+ * The acting principal by ID, and the target checked by ID.
3
+ *
4
+ * An actor and a target are identified by their stored IDs, never by a name.
5
+ * A name is a display label: it never selects a row and never authorises one.
6
+ *
7
+ * Motivating incident: an agent of organisation A named "eta", calling by name
8
+ * through a service account, completed, updated and deleted the task of
9
+ * organisation B's agent also named "eta" at ten task doors, because every door
10
+ * admitted the caller by comparing names. Two different agents shared a label;
11
+ * nothing compared their IDs.
12
+ *
13
+ * Two functions close that class:
14
+ *
15
+ * - `resolveActingPrincipal(credential, lookups)` turns a VERIFIED credential
16
+ * into `{ principalId, orgId, kind }` read from stored rows, or refuses.
17
+ * - `assertTargetBelongsTo(principal, target, lookups, opts)` admits a target
18
+ * only when its stored organisation ID (and owner ID, where the door is
19
+ * owner-only) equals the principal's resolved IDs.
20
+ *
21
+ * The fleet is the OPERATOR ORGANISATION: the organisation the consumer's
22
+ * `orgKindOf` adapter reports as `"operator"`, read from stored data at run
23
+ * time. No organisation ID is reserved or spelled in this package; an
24
+ * adapter that answers anything else, or nothing, means "not the fleet".
25
+ *
26
+ * RULING 5: membership of the operator org is ORDINARY membership. Its agents
27
+ * and persons resolve as `kind: "agent"` / `"person"` of that org and reach its
28
+ * rows only. Cross-org reach (`kind: "fleet"` + `fleetCrossOrg`) belongs to the
29
+ * operator org's SERVICE ACCOUNT alone; `reserved-fleet-scope` refuses a claim
30
+ * of that scope by any other credential, never plain membership.
31
+ *
32
+ * Pure functions over injected lookups: no database, no framework, no network.
33
+ * The consumer performs each indexed read by ID and passes the function in;
34
+ * every failure (throwing lookup, miss, malformed row, inactive row, wrong
35
+ * organisation) is a typed `IdentityRefusal`, never a default principal.
36
+ *
37
+ * @security This module verifies NOTHING about the credential itself. The IDs
38
+ * in a credential must come from the consumer's verification of what the
39
+ * caller presented (a bearer row, a person's token, the service secret). A
40
+ * client-supplied argument passed as a credential becomes the principal.
41
+ */
42
+ import { z } from "zod";
43
+ import { refusal } from "./identity-refusal.js";
44
+ // ---------------------------------------------------------------------------
45
+ // The credential: verified IDs only, no name field anywhere
46
+ // ---------------------------------------------------------------------------
47
+ /**
48
+ * A verified credential, in the package's vocabulary. Every identity field is
49
+ * an ID. The schemas are STRICT: a credential carrying any other key (an
50
+ * `agentName`, a `callerOrchestrator`, a `name`) is refused whole, so a name
51
+ * cannot be smuggled in beside an ID.
52
+ *
53
+ * - `agent`: an agent's own bearer, verified by the consumer (for example by
54
+ * `validatePresentedBearer`): the agent ID and the organisation the bearer
55
+ * row is stamped with.
56
+ * - `person`: a person's token, verified by the consumer: the stored person
57
+ * ID (the verified subject) and the organisation the token is bound to.
58
+ * - `service`: the service account, verified by the consumer. When it acts
59
+ * for an agent it names that agent BY ID (`actingForAgentId`); the agent
60
+ * is resolved within the service account's own organisation.
61
+ */
62
+ export const actingCredentialSchema = z.discriminatedUnion("kind", [
63
+ z.strictObject({
64
+ kind: z.literal("agent"),
65
+ agentId: z.string().min(1),
66
+ verifiedOrgId: z.string().min(1),
67
+ }),
68
+ z.strictObject({
69
+ kind: z.literal("person"),
70
+ personId: z.string().min(1),
71
+ verifiedOrgId: z.string().min(1),
72
+ }),
73
+ z.strictObject({
74
+ kind: z.literal("service"),
75
+ serviceAccountId: z.string().min(1),
76
+ actingForAgentId: z.string().min(1).optional(),
77
+ }),
78
+ ]);
79
+ // ---------------------------------------------------------------------------
80
+ // The stored rows the consumer's lookups return
81
+ // ---------------------------------------------------------------------------
82
+ /**
83
+ * Each row repeats its own ID, so a loose lookup (prefix match, wrong index)
84
+ * returning another row cannot become a principal. `active` is REQUIRED and
85
+ * must be `true`: an absent flag grants nothing. Extra fields (a display name)
86
+ * are allowed and ignored.
87
+ */
88
+ export const principalRowSchema = z.object({
89
+ id: z.string().min(1),
90
+ orgId: z.string().min(1).nullish(),
91
+ active: z.boolean(),
92
+ });
93
+ export const organisationRowSchema = z.object({
94
+ id: z.string().min(1),
95
+ active: z.boolean(),
96
+ });
97
+ function nonEmpty(value) {
98
+ return typeof value === "string" && value.length > 0;
99
+ }
100
+ function denied(reason, door, detail) {
101
+ return { ok: false, refusal: refusal("RBAC_DENIED", reason, door, detail) };
102
+ }
103
+ /**
104
+ * Reads one principal row BY ID and checks it: the lookup is supplied and does
105
+ * not throw, the row exists, is well formed, repeats the ID asked for, and is
106
+ * active. The lookup's own error text is never surfaced.
107
+ */
108
+ async function loadPrincipalRow(lookup, args, expectedId, what, door) {
109
+ if (typeof lookup !== "function") {
110
+ return denied("principal-lookup-failed", door, `No lookup was supplied for the ${what}.`);
111
+ }
112
+ let raw;
113
+ try {
114
+ raw = await lookup(...args);
115
+ }
116
+ catch {
117
+ return denied("principal-lookup-failed", door, `The ${what} could not be read, so none is resolved.`);
118
+ }
119
+ if (raw === null || raw === undefined) {
120
+ return denied("principal-not-found", door, `No ${what} has this ID.`);
121
+ }
122
+ const parsed = principalRowSchema.safeParse(raw);
123
+ if (!parsed.success || parsed.data.id !== expectedId) {
124
+ return denied("principal-record-invalid", door, `The ${what} record is not well formed.`);
125
+ }
126
+ if (parsed.data.active !== true) {
127
+ return denied("principal-inactive", door, `The ${what} is not active.`);
128
+ }
129
+ return { ok: true, row: parsed.data };
130
+ }
131
+ /**
132
+ * Reads the stored kind of an organisation. Refusal by default: a missing or
133
+ * throwing adapter refuses; a miss or any answer other than exactly
134
+ * `"operator"` / `"client"` is `null`, which is never the fleet.
135
+ */
136
+ async function loadOrgKind(lookups, orgId, door) {
137
+ const lookup = lookups?.orgKindOf;
138
+ if (typeof lookup !== "function") {
139
+ return denied("principal-lookup-failed", door, "No lookup was supplied for the organisation kind.");
140
+ }
141
+ let raw;
142
+ try {
143
+ raw = await lookup(orgId);
144
+ }
145
+ catch {
146
+ return denied("principal-lookup-failed", door, "The organisation kind could not be read, so none is resolved.");
147
+ }
148
+ return { ok: true, kind: raw === "operator" || raw === "client" ? raw : null };
149
+ }
150
+ /** Every organisation, the operator org included, must exist and be active. */
151
+ async function checkOrganisation(orgId, lookups, door) {
152
+ const lookup = lookups.organisationById;
153
+ if (typeof lookup !== "function") {
154
+ return denied("principal-lookup-failed", door, "No lookup was supplied for the organisation.");
155
+ }
156
+ let raw;
157
+ try {
158
+ raw = await lookup(orgId);
159
+ }
160
+ catch {
161
+ return denied("principal-lookup-failed", door, "The organisation could not be read, so none is resolved.");
162
+ }
163
+ const parsed = organisationRowSchema.safeParse(raw);
164
+ if (!parsed.success || parsed.data.id !== orgId || parsed.data.active !== true) {
165
+ return denied("organisation-not-active", door, "The organisation is not mapped or not active.");
166
+ }
167
+ return null;
168
+ }
169
+ function served(principal) {
170
+ return { ok: true, principal };
171
+ }
172
+ /**
173
+ * Resolves the acting principal from a VERIFIED credential to stored IDs, or
174
+ * refuses. Refusal by default: a credential claiming the fleet kind
175
+ * (`reserved-fleet-scope`), a credential that does not parse (including one
176
+ * carrying any name field), a missing or throwing lookup, a miss, a malformed
177
+ * or inactive row, an unstamped row and an inactive organisation are all
178
+ * refused. Nothing is ever resolved by a name, and nothing falls back to a
179
+ * master principal.
180
+ *
181
+ * - agent: the agent row by `agentId`; its stored org must equal the org
182
+ * the credential was verified for. An agent of the operator org resolves
183
+ * as an ordinary `kind: "agent"` of that org (RULING 5).
184
+ * - person: the person row by (`personId`, `verifiedOrgId`); it must be
185
+ * stamped with that org. A person of the operator org resolves as an
186
+ * ordinary `kind: "person"` of that org (RULING 5).
187
+ * - service: the service-account row by `serviceAccountId`. Alone, it acts
188
+ * as itself (`kind: "service"`, or `kind: "fleet"` when `orgKindOf` reports
189
+ * its stored org as `"operator"`). With `actingForAgentId`, the agent row is read by
190
+ * ID and must be stamped with the service account's own org; the principal
191
+ * is that agent, with `viaServiceAccountId` recording the carrier.
192
+ */
193
+ export async function resolveActingPrincipal(credential, lookups, door = "resolveActingPrincipal") {
194
+ if (credential !== null &&
195
+ typeof credential === "object" &&
196
+ credential.kind === "fleet") {
197
+ return denied("reserved-fleet-scope", door, "The fleet scope is held only by the operator organisation's service account; no credential claims it.");
198
+ }
199
+ const parsed = actingCredentialSchema.safeParse(credential);
200
+ if (!parsed.success) {
201
+ return denied("credential-invalid", door, "The credential does not identify a principal by ID.");
202
+ }
203
+ const cred = parsed.data;
204
+ const look = lookups ?? {};
205
+ if (cred.kind === "agent" || cred.kind === "person") {
206
+ // The org's kind is read so a missing or throwing adapter refuses here as
207
+ // on every path; an operator-org member is NOT refused (RULING 5).
208
+ const credKind = await loadOrgKind(look, cred.verifiedOrgId, door);
209
+ if (!credKind.ok)
210
+ return credKind;
211
+ const loaded = cred.kind === "agent"
212
+ ? await loadPrincipalRow(look.agentById, [cred.agentId], cred.agentId, "agent", door)
213
+ : await loadPrincipalRow(look.personById, [cred.personId, cred.verifiedOrgId], cred.personId, "person", door);
214
+ if (!loaded.ok)
215
+ return loaded;
216
+ const rowOrg = loaded.row.orgId;
217
+ if (!nonEmpty(rowOrg)) {
218
+ return denied("no-verified-organisation", door, `The ${cred.kind} is stamped with no organisation.`);
219
+ }
220
+ if (rowOrg !== cred.verifiedOrgId) {
221
+ return denied("other-organisation", door, `The ${cred.kind} belongs to another organisation than its credential.`);
222
+ }
223
+ const orgRefusal = await checkOrganisation(rowOrg, look, door);
224
+ if (orgRefusal !== null)
225
+ return orgRefusal;
226
+ return served({ principalId: loaded.row.id, orgId: rowOrg, kind: cred.kind });
227
+ }
228
+ // service account
229
+ const svc = await loadPrincipalRow(look.serviceAccountById, [cred.serviceAccountId], cred.serviceAccountId, "service account", door);
230
+ if (!svc.ok)
231
+ return svc;
232
+ const svcOrg = svc.row.orgId;
233
+ if (!nonEmpty(svcOrg)) {
234
+ return denied("no-verified-organisation", door, "The service account is stamped with no organisation.");
235
+ }
236
+ const svcKind = await loadOrgKind(look, svcOrg, door);
237
+ if (!svcKind.ok)
238
+ return svcKind;
239
+ const orgRefusal = await checkOrganisation(svcOrg, look, door);
240
+ if (orgRefusal !== null)
241
+ return orgRefusal;
242
+ if (cred.actingForAgentId === undefined) {
243
+ return served({
244
+ principalId: svc.row.id,
245
+ orgId: svcOrg,
246
+ kind: svcKind.kind === "operator" ? "fleet" : "service",
247
+ });
248
+ }
249
+ const agent = await loadPrincipalRow(look.agentById, [cred.actingForAgentId], cred.actingForAgentId, "agent", door);
250
+ if (!agent.ok)
251
+ return agent;
252
+ if (agent.row.orgId !== svcOrg) {
253
+ return denied("acting-agent-other-organisation", door, "The service account may act only for an agent of its own organisation.");
254
+ }
255
+ return served({
256
+ principalId: agent.row.id,
257
+ orgId: svcOrg,
258
+ kind: "agent",
259
+ viaServiceAccountId: svc.row.id,
260
+ });
261
+ }
262
+ // ---------------------------------------------------------------------------
263
+ // assertTargetBelongsTo
264
+ // ---------------------------------------------------------------------------
265
+ /**
266
+ * Admits a target only by comparing its STORED IDs with the principal's
267
+ * resolved IDs, byte for byte. No name field is read; there is none to read.
268
+ *
269
+ * Whether an organisation is the operator org (the fleet) is read from
270
+ * `lookups.orgKindOf`; a missing or throwing adapter refuses.
271
+ *
272
+ * - An absent principal, or one with an empty ID, is refused.
273
+ * - A `kind: "fleet"` principal outside the operator org is refused, and so
274
+ * is a `kind: "service"` principal inside it (the operator org's service
275
+ * account is the fleet). An agent or person of the operator org is an
276
+ * ordinary member of it (RULING 5).
277
+ * - An unstamped target (no `orgId`) is refused to EVERY principal, the
278
+ * fleet principal included. No right is inferred from an absence: a fleet
279
+ * row carries the operator org's ID explicitly, and a row with no
280
+ * organisation is never treated as a master row.
281
+ * - An operator-org row is refused to every client principal.
282
+ * - Otherwise the target's `orgId` must equal the principal's. A fleet
283
+ * principal reaches a client organisation's row only when the door sets
284
+ * `fleetCrossOrg` (a master export) AND `orgKindOf` reports that
285
+ * organisation as `"client"`; an unknown organisation is refused. Any
286
+ * other principal reaching across organisations under `fleetCrossOrg`
287
+ * claims the fleet scope and is refused `reserved-fleet-scope`.
288
+ * - `ownerOnly`: the target's `ownerId` must also equal `principalId`; an
289
+ * absent owner is refused.
290
+ */
291
+ export async function assertTargetBelongsTo(principal, target, lookups, opts = {}) {
292
+ const door = opts.door ?? "assertTargetBelongsTo";
293
+ if (principal === null ||
294
+ typeof principal !== "object" ||
295
+ !nonEmpty(principal.principalId) ||
296
+ !nonEmpty(principal.orgId)) {
297
+ return denied("credential-invalid", door, "No resolved principal stands behind this call.");
298
+ }
299
+ const principalKind = await loadOrgKind(lookups, principal.orgId, door);
300
+ if (!principalKind.ok)
301
+ return principalKind;
302
+ const inFleet = principalKind.kind === "operator";
303
+ const isFleet = principal.kind === "fleet";
304
+ if ((isFleet && !inFleet) || (inFleet && principal.kind === "service")) {
305
+ return denied("reserved-fleet-scope", door, "The principal does not hold the fleet scope.");
306
+ }
307
+ const targetOrg = target?.orgId;
308
+ if (!nonEmpty(targetOrg)) {
309
+ return denied("target-unstamped", door, "The target carries no organisation, so it is not reachable.");
310
+ }
311
+ if (targetOrg !== principal.orgId) {
312
+ const targetKind = await loadOrgKind(lookups, targetOrg, door);
313
+ if (!targetKind.ok)
314
+ return targetKind;
315
+ if (targetKind.kind === "operator") {
316
+ return denied("reserved-fleet-scope", door, "The target is in the fleet scope.");
317
+ }
318
+ if (!isFleet && opts.fleetCrossOrg === true) {
319
+ return denied("reserved-fleet-scope", door, "Cross-organisation reach is held only by the operator organisation's service account.");
320
+ }
321
+ const masterExport = isFleet && opts.fleetCrossOrg === true && targetKind.kind === "client";
322
+ if (!masterExport) {
323
+ return denied("target-other-organisation", door, "The target belongs to another organisation.");
324
+ }
325
+ }
326
+ if (opts.ownerOnly === true) {
327
+ const owner = target?.ownerId;
328
+ if (!nonEmpty(owner) || owner !== principal.principalId) {
329
+ return denied("target-owner-mismatch", door, "Only the target's owner may act on it.");
330
+ }
331
+ }
332
+ return { ok: true };
333
+ }
334
+ //# sourceMappingURL=principal-by-id.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"principal-by-id.js","sourceRoot":"","sources":["../src/principal-by-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAwB,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEtE,8EAA8E;AAC9E,4DAA4D;AAC5D,8EAA8E;AAE9E;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC,kBAAkB,CAAC,MAAM,EAAE;IACjE,CAAC,CAAC,YAAY,CAAC;QACb,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;QACxB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC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