@astram/guard 0.36.0 → 0.37.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.
- package/dist/authz/list-scope-sql.d.ts +21 -0
- package/dist/authz/list-scope-sql.d.ts.map +1 -1
- package/dist/authz/list-scope-sql.js +45 -2
- package/dist/authz/mariadb-list-scope-adapter.d.ts.map +1 -1
- package/dist/authz/mariadb-list-scope-adapter.js +10 -25
- package/dist/authz/mariadb-policy-store.d.ts +7 -4
- package/dist/authz/mariadb-policy-store.d.ts.map +1 -1
- package/dist/authz/mariadb-policy-store.js +51 -9
- package/dist/authz/mariadb-record-rule-adapter.d.ts +19 -1
- package/dist/authz/mariadb-record-rule-adapter.d.ts.map +1 -1
- package/dist/authz/mariadb-record-rule-adapter.js +65 -14
- package/dist/authz/rule-subject.d.ts +32 -0
- package/dist/authz/rule-subject.d.ts.map +1 -0
- package/dist/authz/rule-subject.js +71 -0
- package/dist/authz/viewer-departments.d.ts +14 -0
- package/dist/authz/viewer-departments.d.ts.map +1 -0
- package/dist/authz/viewer-departments.js +61 -0
- package/dist/authz/wire-record-authorization.d.ts.map +1 -1
- package/dist/authz/wire-record-authorization.js +25 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -4
- package/migrations/1710000000141-AddRecordRuleSubjectRoles.cjs +95 -0
- package/package.json +5 -5
|
@@ -77,6 +77,7 @@
|
|
|
77
77
|
*/
|
|
78
78
|
import type { ListScopeSpec, ScopeCondition } from '@astram/core';
|
|
79
79
|
import { type ObjectType } from '@astram/engine';
|
|
80
|
+
import { AuthorizationUnavailableError } from '@astram/core';
|
|
80
81
|
/** The translated fragment: a boolean WHERE expression + its ordered bind params. */
|
|
81
82
|
export interface TranslatedListScope {
|
|
82
83
|
/** A SQL boolean expression carrying ONLY `?` placeholders + backtick columns. */
|
|
@@ -93,7 +94,27 @@ export interface TranslatedListScope {
|
|
|
93
94
|
export interface ListScopePrincipal {
|
|
94
95
|
readonly principalId: string;
|
|
95
96
|
readonly principalTenantId: string;
|
|
97
|
+
/**
|
|
98
|
+
* The viewer's department codes for `in_my_departments` / `not_in_my_departments`
|
|
99
|
+
* (department-scoped policies, spec §5 D): the codes of the viewer's in-effect postings in
|
|
100
|
+
* `principalTenantId`. `null` / absent = NOT LOADED: the wiring loads the set whenever a
|
|
101
|
+
* group uses a department operator, so a department operator meeting an unloaded set is a
|
|
102
|
+
* programming error and the translator THROWS {@link UnloadedDepartmentSetError} (fail
|
|
103
|
+
* closed, never `TRUE`). The owning-tenant (cross-tenant) deny branch is always translated
|
|
104
|
+
* with an EMPTY set (D3), whatever this holds.
|
|
105
|
+
*/
|
|
106
|
+
readonly departmentCodes?: readonly string[] | null | undefined;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Thrown when a department operator is translated without a loaded viewer department set (a
|
|
110
|
+
* wiring error). It IS an {@link AuthorizationUnavailableError} (branded), so the read fails
|
|
111
|
+
* 503 like any other unanswerable access decision (spec §13), never an unbounded list.
|
|
112
|
+
*/
|
|
113
|
+
export declare class UnloadedDepartmentSetError extends AuthorizationUnavailableError {
|
|
114
|
+
constructor(typeKey: string);
|
|
96
115
|
}
|
|
116
|
+
/** Whether any condition of any group uses a department operator (the wiring's load trigger). */
|
|
117
|
+
export declare function groupsUseDepartmentOperator(groups: readonly (readonly ScopeCondition[])[]): boolean;
|
|
97
118
|
/** Error thrown when a scope condition references a field the type does not register. */
|
|
98
119
|
export declare class UnknownScopeFieldError extends Error {
|
|
99
120
|
constructor(typeKey: string, field: string);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-scope-sql.d.ts","sourceRoot":"","sources":["../../src/authz/list-scope-sql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAEH,OAAO,KAAK,EACV,aAAa,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,EAAE,aAAa,EACnB,GAAG,EAAE,UAAU,EACf,SAAS,EAAE,kBAAkB,EAC7B,IAAI,EAAE;IACJ;;;;;;OAMG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,MAAM,CAAC;IACrB;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,SAAS,CAAC,SAAS,cAAc,EAAE,CAAC,EAAE,CAAC;CAC3D,GACA,mBAAmB,CAgKrB"}
|
|
@@ -77,10 +77,34 @@
|
|
|
77
77
|
* PURE — no DB, no I/O. `translateListScope(spec, reg, principal) → { sql, params }`.
|
|
78
78
|
*/
|
|
79
79
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
80
|
-
exports.UnknownScopeFieldError = void 0;
|
|
80
|
+
exports.UnknownScopeFieldError = exports.UnloadedDepartmentSetError = void 0;
|
|
81
|
+
exports.groupsUseDepartmentOperator = groupsUseDepartmentOperator;
|
|
81
82
|
exports.translateListScope = translateListScope;
|
|
82
83
|
const engine_1 = require("@astram/engine");
|
|
83
84
|
const core_1 = require("@astram/core");
|
|
85
|
+
/**
|
|
86
|
+
* Thrown when a department operator is translated without a loaded viewer department set (a
|
|
87
|
+
* wiring error). It IS an {@link AuthorizationUnavailableError} (branded), so the read fails
|
|
88
|
+
* 503 like any other unanswerable access decision (spec §13), never an unbounded list.
|
|
89
|
+
*/
|
|
90
|
+
class UnloadedDepartmentSetError extends core_1.AuthorizationUnavailableError {
|
|
91
|
+
constructor(typeKey) {
|
|
92
|
+
super(`list-scope: a department operator on type '${typeKey}' met an unloaded viewer ` +
|
|
93
|
+
`department set (wiring error); the read fails closed.`);
|
|
94
|
+
this.name = 'UnloadedDepartmentSetError';
|
|
95
|
+
Object.setPrototypeOf(this, UnloadedDepartmentSetError.prototype);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.UnloadedDepartmentSetError = UnloadedDepartmentSetError;
|
|
99
|
+
/** The department operators (department-scoped policies). */
|
|
100
|
+
const DEPARTMENT_OPERATORS = new Set([
|
|
101
|
+
'in_my_departments',
|
|
102
|
+
'not_in_my_departments',
|
|
103
|
+
]);
|
|
104
|
+
/** Whether any condition of any group uses a department operator (the wiring's load trigger). */
|
|
105
|
+
function groupsUseDepartmentOperator(groups) {
|
|
106
|
+
return groups.some((g) => g.some((c) => DEPARTMENT_OPERATORS.has(c.operator)));
|
|
107
|
+
}
|
|
84
108
|
/** Error thrown when a scope condition references a field the type does not register. */
|
|
85
109
|
class UnknownScopeFieldError extends Error {
|
|
86
110
|
constructor(typeKey, field) {
|
|
@@ -183,6 +207,23 @@ function translateCondition(cond, reg, principal, p) {
|
|
|
183
207
|
case 'is_not_owner':
|
|
184
208
|
// Same guards, mirrored for the negative ownership operator.
|
|
185
209
|
return `(${col} IS NOT NULL AND ${col} <> '' AND ${col} <> ${p.bind(principal.principalId)})`;
|
|
210
|
+
case 'in_my_departments':
|
|
211
|
+
case 'not_in_my_departments': {
|
|
212
|
+
// Department-scoped policies (spec §5 D, D5). Mirrors `conditionHolds`: in = a non-empty
|
|
213
|
+
// value that equals (byte for byte — `CAST(… AS BINARY)`, so no case- or pad-insensitive
|
|
214
|
+
// collation can widen the list past decide()'s `===`) one of the viewer's codes; not_in =
|
|
215
|
+
// its null-safe negation. Every code is a bound `?`; none reaches the SQL text.
|
|
216
|
+
const codes = principal.departmentCodes;
|
|
217
|
+
if (codes === null || codes === undefined)
|
|
218
|
+
throw new UnloadedDepartmentSetError(reg.typeKey);
|
|
219
|
+
const negate = op === 'not_in_my_departments';
|
|
220
|
+
if (codes.length === 0)
|
|
221
|
+
return negate ? 'TRUE' : 'FALSE';
|
|
222
|
+
const placeholders = codes.map((c) => `CAST(${p.bind(c)} AS BINARY)`).join(', ');
|
|
223
|
+
return negate
|
|
224
|
+
? `(${col} IS NULL OR ${col} = '' OR CAST(${col} AS BINARY) NOT IN (${placeholders}))`
|
|
225
|
+
: `(${col} IS NOT NULL AND ${col} <> '' AND CAST(${col} AS BINARY) IN (${placeholders}))`;
|
|
226
|
+
}
|
|
186
227
|
default:
|
|
187
228
|
// Unknown operator → a condition that never matches (fail-closed; never widen).
|
|
188
229
|
return 'FALSE';
|
|
@@ -352,7 +393,9 @@ function translateListScope(spec, reg, principal, opts) {
|
|
|
352
393
|
if (!rootUnbounded) {
|
|
353
394
|
const crossTenant = translateCrossTenant(spec, reg, schema, nowMs, p);
|
|
354
395
|
if (crossTenant !== null) {
|
|
355
|
-
|
|
396
|
+
// D3: a record reached only by a cross-tenant grant is judged with an EMPTY viewer
|
|
397
|
+
// department set (decide() does the same for a resource outside the subtree).
|
|
398
|
+
const owningDeny = translateGroups(opts.owningTenantDeny ?? [], reg, { ...principal, departmentCodes: [] }, p);
|
|
356
399
|
const crossBranch = owningDeny !== null ? `( ${crossTenant} ) AND NOT ( ${owningDeny} )` : crossTenant;
|
|
357
400
|
result = `( ${sameTenantBranch} OR ${crossBranch} )`;
|
|
358
401
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mariadb-list-scope-adapter.d.ts","sourceRoot":"","sources":["../../src/authz/mariadb-list-scope-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAGjB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"mariadb-list-scope-adapter.d.ts","sourceRoot":"","sources":["../../src/authz/mariadb-list-scope-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,oBAAoB,EACpB,gBAAgB,EAGjB,MAAM,cAAc,CAAC;AAKtB,iFAAiF;AACjF,eAAO,MAAM,sBAAsB,eAAmC,CAAC;AAEvE,oFAAoF;AACpF,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnE;AAsBD;;;GAGG;AACH,qBAAa,uBAAwB,YAAW,aAAa;IAC3D,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAqB;IACxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,EAAE,EAAE,kBAAkB,EAAE,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;IAO5D,oBAAoB,CACxB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,oBAAoB,CAAC;CA8EjC"}
|
|
@@ -44,31 +44,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
44
44
|
exports.MariaDbListScopeAdapter = exports.SHIELD_LIST_SCOPE_PORT = void 0;
|
|
45
45
|
const core_1 = require("@astram/core");
|
|
46
46
|
const framework_schema_names_js_1 = require("../config/framework-schema-names.js");
|
|
47
|
+
const rule_subject_js_1 = require("./rule-subject.js");
|
|
47
48
|
/** The DI token the adapter is bound under (parity with the rule-port token). */
|
|
48
49
|
exports.SHIELD_LIST_SCOPE_PORT = Symbol('SHIELD_LIST_SCOPE_PORT');
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* A group's subject is consistent across its rows (the store writes one subject per policy),
|
|
57
|
-
* so it is read from the group's HEAD row (like the effect). A group that FAILS the subject
|
|
58
|
-
* match contributes to NEITHER allow NOR deny — it is simply not this principal's rule (a
|
|
59
|
-
* role-subjected DENY not aimed at the principal must NOT over-restrict them, the symmetric
|
|
60
|
-
* divergence — so BOTH sides are filtered identically).
|
|
61
|
-
*/
|
|
62
|
-
function subjectMatches(head, subject) {
|
|
63
|
-
const kind = head.rpr_subject_kind;
|
|
64
|
-
if (kind === 'everyone')
|
|
65
|
-
return true;
|
|
66
|
-
if (kind === 'role') {
|
|
67
|
-
return head.rpr_subject_value !== null && subject.roleIds.includes(head.rpr_subject_value);
|
|
68
|
-
}
|
|
69
|
-
// Unknown subject kind → does NOT match (fail-closed).
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
50
|
+
// Subject matching is the ONE shared helper (`rule-subject.ts`) the per-record rule adapter
|
|
51
|
+
// also uses (department-scoped policies D4), so list and decide() agree on who a rule
|
|
52
|
+
// applies to. A group that FAILS the subject match contributes to NEITHER allow NOR deny —
|
|
53
|
+
// it is simply not this principal's rule (a role-subjected DENY not aimed at the principal
|
|
54
|
+
// must NOT over-restrict them — so BOTH sides are filtered identically). Like `evaluate`,
|
|
55
|
+
// every row of the group must subject-match (the store writes one subject per policy, so
|
|
56
|
+
// this equals the head-row check on well-formed data and stays identical on malformed data).
|
|
72
57
|
/**
|
|
73
58
|
* The concrete list-scope adapter. Reads the ADMIN rules for `(tenant, type_key, action|*)`
|
|
74
59
|
* and projects them into allow/deny {@link ScopeCondition} AND-groups for the translator.
|
|
@@ -93,7 +78,7 @@ class MariaDbListScopeAdapter {
|
|
|
93
78
|
: `rpr_tenant_uuid IS NULL`;
|
|
94
79
|
let rows;
|
|
95
80
|
try {
|
|
96
|
-
rows = (await this.db.query(`SELECT rpr_policy_uuid, rpr_effect, rpr_subject_kind, rpr_subject_value, rpr_field, rpr_operator, rpr_value
|
|
81
|
+
rows = (await this.db.query(`SELECT rpr_policy_uuid, rpr_effect, rpr_subject_kind, rpr_subject_value, rpr_subject_role_uuids, rpr_field, rpr_operator, rpr_value
|
|
97
82
|
FROM \`${this.schema}\`.\`record_permission_rule\`
|
|
98
83
|
WHERE rpr_type_key = ?
|
|
99
84
|
AND ${tenantClause}
|
|
@@ -132,7 +117,7 @@ class MariaDbListScopeAdapter {
|
|
|
132
117
|
// A group whose subject does NOT match this principal contributes to NEITHER allow NOR
|
|
133
118
|
// deny (it is not this principal's rule). Applied identically to allow AND deny so a
|
|
134
119
|
// role-subjected deny not aimed at the principal cannot over-restrict them.
|
|
135
|
-
if (!subjectMatches(
|
|
120
|
+
if (!groupRows.every((row) => (0, rule_subject_js_1.subjectMatches)(row, subject.roleIds)))
|
|
136
121
|
continue;
|
|
137
122
|
// A NULL-field row contributes NO condition (unconditional). A group of only such
|
|
138
123
|
// rows → an EMPTY condition list, which the translator renders as `(TRUE)` — a
|
|
@@ -28,10 +28,13 @@
|
|
|
28
28
|
* • `rpr_type_key` — the policy's `typeKey` (same on every row).
|
|
29
29
|
* • `rpr_action` — the policy's `action` (same on every row).
|
|
30
30
|
* • `rpr_effect` — the policy's `effect` ('allow' | 'deny'; same every row).
|
|
31
|
-
* • `rpr_subject_kind` —
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* • `rpr_subject_value`— always NULL (
|
|
31
|
+
* • `rpr_subject_kind` — the policy's subject kind (department-scoped policies, D4):
|
|
32
|
+
* `'everyone'` (absent subject — the pre-existing mapping),
|
|
33
|
+
* `'roles'` or `'except_roles'`. Same on every row.
|
|
34
|
+
* • `rpr_subject_value`— always NULL (the legacy single-`role` kind is read, never written).
|
|
35
|
+
* • `rpr_subject_role_uuids` — NULL for `everyone`; else the JSON array of the subject's
|
|
36
|
+
* role ids, sorted and distinct (guard migration 141). Same on
|
|
37
|
+
* every row.
|
|
35
38
|
* • `rpr_field` — the condition's `field` (NULL for a 0-condition policy).
|
|
36
39
|
* • `rpr_operator` — the condition's operator, persisted with core's CANONICAL
|
|
37
40
|
* name (`eq`, `ne`, `is_owner`, …). The read adapter
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mariadb-policy-store.d.ts","sourceRoot":"","sources":["../../src/authz/mariadb-policy-store.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mariadb-policy-store.d.ts","sourceRoot":"","sources":["../../src/authz/mariadb-policy-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;AAGH,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACN,WAAW,EAGZ,MAAM,cAAc,CAAC;AAItB,sFAAsF;AACtF,eAAO,MAAM,mBAAmB,eAAgC,CAAC;AAEjE,kFAAkF;AAClF,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnE;AAkED;;;;GAIG;AACH,qBAAa,kBAAmB,YAAW,WAAW;IACpD,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAgB;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,EAAE,EAAE,aAAa,EAAE,IAAI,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAO;IAO7D;;;;;OAKG;IACG,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC;IAiDzE;;;;OAIG;IACG,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC;IAmDjF;;;;OAIG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQnD;;;;;;;;;;OAUG;IACG,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CASjF"}
|
|
@@ -29,10 +29,13 @@
|
|
|
29
29
|
* • `rpr_type_key` — the policy's `typeKey` (same on every row).
|
|
30
30
|
* • `rpr_action` — the policy's `action` (same on every row).
|
|
31
31
|
* • `rpr_effect` — the policy's `effect` ('allow' | 'deny'; same every row).
|
|
32
|
-
* • `rpr_subject_kind` —
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* • `rpr_subject_value`— always NULL (
|
|
32
|
+
* • `rpr_subject_kind` — the policy's subject kind (department-scoped policies, D4):
|
|
33
|
+
* `'everyone'` (absent subject — the pre-existing mapping),
|
|
34
|
+
* `'roles'` or `'except_roles'`. Same on every row.
|
|
35
|
+
* • `rpr_subject_value`— always NULL (the legacy single-`role` kind is read, never written).
|
|
36
|
+
* • `rpr_subject_role_uuids` — NULL for `everyone`; else the JSON array of the subject's
|
|
37
|
+
* role ids, sorted and distinct (guard migration 141). Same on
|
|
38
|
+
* every row.
|
|
36
39
|
* • `rpr_field` — the condition's `field` (NULL for a 0-condition policy).
|
|
37
40
|
* • `rpr_operator` — the condition's operator, persisted with core's CANONICAL
|
|
38
41
|
* name (`eq`, `ne`, `is_owner`, …). The read adapter
|
|
@@ -70,6 +73,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
70
73
|
exports.MariaDbPolicyStore = exports.SHIELD_POLICY_STORE = void 0;
|
|
71
74
|
const node_crypto_1 = require("node:crypto");
|
|
72
75
|
const framework_schema_names_js_1 = require("../config/framework-schema-names.js");
|
|
76
|
+
const rule_subject_js_1 = require("./rule-subject.js");
|
|
73
77
|
/** The DI token the policy store is bound under (parity with the rule-port token). */
|
|
74
78
|
exports.SHIELD_POLICY_STORE = Symbol('SHIELD_POLICY_STORE');
|
|
75
79
|
/**
|
|
@@ -82,7 +86,39 @@ const OPERAND_LESS_OPERATORS = new Set([
|
|
|
82
86
|
'is_not_null',
|
|
83
87
|
'is_owner',
|
|
84
88
|
'is_not_owner',
|
|
89
|
+
'in_my_departments',
|
|
90
|
+
'not_in_my_departments',
|
|
85
91
|
]);
|
|
92
|
+
/** The `(rpr_subject_kind, rpr_subject_role_uuids)` pair written on every row of a policy. */
|
|
93
|
+
function subjectColumns(subject) {
|
|
94
|
+
if (subject === undefined || subject.kind === 'everyone')
|
|
95
|
+
return ['everyone', null];
|
|
96
|
+
const ids = [...new Set(subject.roleIds)].sort();
|
|
97
|
+
return [subject.kind, JSON.stringify(ids)];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Rebuild a policy's subject from its group's first row. A legacy `role` row reads as
|
|
101
|
+
* `{ kind: 'roles', roleIds: [value] }`. A row whose subject the enforcement helper would never
|
|
102
|
+
* match (unknown kind, malformed / empty JSON) reads as `{ kind: 'roles', roleIds: [] }` — "applies
|
|
103
|
+
* to nobody", which is what enforcement does with it — so the admin still sees (and can delete)
|
|
104
|
+
* the rule. A row with no subject columns at all (pre-subject reader) reads as `everyone`.
|
|
105
|
+
*/
|
|
106
|
+
function subjectOf(row) {
|
|
107
|
+
const kind = row.rpr_subject_kind;
|
|
108
|
+
if (kind === undefined || kind === 'everyone')
|
|
109
|
+
return { kind: 'everyone' };
|
|
110
|
+
if (kind === 'role') {
|
|
111
|
+
return typeof row.rpr_subject_value === 'string' && row.rpr_subject_value !== ''
|
|
112
|
+
? { kind: 'roles', roleIds: [row.rpr_subject_value] }
|
|
113
|
+
: { kind: 'roles', roleIds: [] };
|
|
114
|
+
}
|
|
115
|
+
if (kind === 'roles' || kind === 'except_roles') {
|
|
116
|
+
const ids = (0, rule_subject_js_1.parseSubjectRoleIds)(row.rpr_subject_role_uuids);
|
|
117
|
+
if (ids !== null)
|
|
118
|
+
return { kind, roleIds: [...ids] };
|
|
119
|
+
}
|
|
120
|
+
return { kind: 'roles', roleIds: [] };
|
|
121
|
+
}
|
|
86
122
|
/** Serialize a condition operand to the VARCHAR form the enforcement adapter reads. */
|
|
87
123
|
function serializeValue(condition) {
|
|
88
124
|
if (OPERAND_LESS_OPERATORS.has(condition.operator))
|
|
@@ -124,22 +160,26 @@ class MariaDbPolicyStore {
|
|
|
124
160
|
operator: c.operator, // canonical core name (eq/ne/is_owner/…)
|
|
125
161
|
value: serializeValue(c),
|
|
126
162
|
}));
|
|
163
|
+
// ONE subject for the whole policy, written onto every row (D4).
|
|
164
|
+
const [subjectKind, subjectRoleUuids] = subjectColumns(policy.subject);
|
|
127
165
|
for (const row of rows) {
|
|
128
166
|
await this.db.query(`INSERT INTO \`${this.schema}\`.\`record_permission_rule\`
|
|
129
167
|
(rpr_uuid, rpr_policy_uuid, rpr_tenant_uuid, rpr_type_key, rpr_action,
|
|
130
|
-
rpr_effect, rpr_subject_kind, rpr_subject_value, rpr_field, rpr_operator, rpr_value
|
|
131
|
-
|
|
168
|
+
rpr_effect, rpr_subject_kind, rpr_subject_value, rpr_field, rpr_operator, rpr_value,
|
|
169
|
+
rpr_subject_role_uuids)
|
|
170
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [
|
|
132
171
|
(0, node_crypto_1.randomUUID)(), // rpr_uuid — a fresh per-row id
|
|
133
172
|
policyUuid, // rpr_policy_uuid — the SHARED group id
|
|
134
173
|
tenantId, // rpr_tenant_uuid
|
|
135
174
|
policy.typeKey, // rpr_type_key
|
|
136
175
|
policy.action, // rpr_action
|
|
137
176
|
policy.effect, // rpr_effect
|
|
138
|
-
|
|
139
|
-
null, // rpr_subject_value
|
|
177
|
+
subjectKind, // rpr_subject_kind — everyone | roles | except_roles
|
|
178
|
+
null, // rpr_subject_value (legacy single-role kind is never written)
|
|
140
179
|
row.field, // rpr_field
|
|
141
180
|
row.operator, // rpr_operator
|
|
142
181
|
row.value, // rpr_value
|
|
182
|
+
subjectRoleUuids, // rpr_subject_role_uuids — JSON array, or NULL for everyone
|
|
143
183
|
]);
|
|
144
184
|
}
|
|
145
185
|
return { policyId: policyUuid, tenantId, policy };
|
|
@@ -150,7 +190,8 @@ class MariaDbPolicyStore {
|
|
|
150
190
|
* (its conditions = its rows, in row order). Returns `[]` when none exist (NORMAL).
|
|
151
191
|
*/
|
|
152
192
|
async listPolicies(typeKey, tenantId) {
|
|
153
|
-
const rows = (await this.db.query(`SELECT rpr_policy_uuid, rpr_action, rpr_effect,
|
|
193
|
+
const rows = (await this.db.query(`SELECT rpr_policy_uuid, rpr_action, rpr_effect, rpr_subject_kind, rpr_subject_value,
|
|
194
|
+
rpr_subject_role_uuids, rpr_field, rpr_operator, rpr_value
|
|
154
195
|
FROM \`${this.schema}\`.\`record_permission_rule\`
|
|
155
196
|
WHERE rpr_type_key = ?
|
|
156
197
|
AND rpr_tenant_uuid = ?
|
|
@@ -191,6 +232,7 @@ class MariaDbPolicyStore {
|
|
|
191
232
|
action: first.rpr_action ?? '',
|
|
192
233
|
effect: first.rpr_effect === 'deny' ? 'deny' : 'allow',
|
|
193
234
|
conditions,
|
|
235
|
+
subject: subjectOf(first),
|
|
194
236
|
},
|
|
195
237
|
});
|
|
196
238
|
}
|
|
@@ -38,7 +38,9 @@
|
|
|
38
38
|
* 14-operator {@link import('@astram/core').PolicyOperator} model (unified with
|
|
39
39
|
* the guided policy builder, Task 0.2): `eq/ne` (dual-accept legacy
|
|
40
40
|
* `equals`/`not_equals`), `in/not_in`, `gt/lt/gte/lte`, `contains/not_contains`,
|
|
41
|
-
* `is_null/is_not_null`, `is_owner/is_not_owner
|
|
41
|
+
* `is_null/is_not_null`, `is_owner/is_not_owner`, plus the principal-relative
|
|
42
|
+
* `in_my_departments/not_in_my_departments` (department-scoped policies: the viewer's
|
|
43
|
+
* department codes, read lazily once per evaluate). An unknown operator makes the
|
|
42
44
|
* rule NOT match (fail-closed, never a spurious allow) — see `conditionHolds`
|
|
43
45
|
* below for the exact per-operator semantics and the documented edge-case choices.
|
|
44
46
|
*/
|
|
@@ -56,9 +58,25 @@ export interface RuleQueryable {
|
|
|
56
58
|
export declare class MariaDbRecordPermissionRuleAdapter implements RecordPermissionRulePort {
|
|
57
59
|
private readonly db;
|
|
58
60
|
private readonly schema;
|
|
61
|
+
private readonly appSchema;
|
|
62
|
+
private readonly now;
|
|
59
63
|
constructor(db: RuleQueryable, opts?: {
|
|
60
64
|
schema?: string;
|
|
65
|
+
/**
|
|
66
|
+
* The org (`<app>`) database the viewer-department reader joins (memberships, postings,
|
|
67
|
+
* departments). Checked; absent ⇒ resolved from `SHIELD_DB_NAMESPACE` here, once.
|
|
68
|
+
*/
|
|
69
|
+
appSchema?: string;
|
|
70
|
+
/** Clock for the posting in-effect window (epoch ms). */
|
|
71
|
+
now?: () => number;
|
|
61
72
|
});
|
|
73
|
+
/**
|
|
74
|
+
* The viewer department set `D` for this evaluation (spec §5 C, D3):
|
|
75
|
+
* - root and a record reached outside the principal's subtree (cross-tenant grant) ⇒ empty;
|
|
76
|
+
* - otherwise the codes of the principal's in-effect postings in `principal.tenantId`.
|
|
77
|
+
* A reader failure throws {@link AuthorizationUnavailableError} (fail closed).
|
|
78
|
+
*/
|
|
79
|
+
private departmentsFor;
|
|
62
80
|
evaluate(input: RulePermitInput): Promise<RulePermit>;
|
|
63
81
|
}
|
|
64
82
|
//# sourceMappingURL=mariadb-record-rule-adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mariadb-record-rule-adapter.d.ts","sourceRoot":"","sources":["../../src/authz/mariadb-record-rule-adapter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mariadb-record-rule-adapter.d.ts","sourceRoot":"","sources":["../../src/authz/mariadb-record-rule-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAU1F,qFAAqF;AACrF,eAAO,MAAM,uBAAuB,eAAoC,CAAC;AAEzE,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnE;AAmMD;;;GAGG;AACH,qBAAa,kCAAmC,YAAW,wBAAwB;IACjF,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAgB;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;gBAGjC,EAAE,EAAE,aAAa,EACjB,IAAI,GAAE;QACJ,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB;;;WAGG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,yDAAyD;QACzD,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;KACf;IAaR;;;;;OAKG;YACW,cAAc;IAoBtB,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;CAmF5D"}
|
|
@@ -39,7 +39,9 @@
|
|
|
39
39
|
* 14-operator {@link import('@astram/core').PolicyOperator} model (unified with
|
|
40
40
|
* the guided policy builder, Task 0.2): `eq/ne` (dual-accept legacy
|
|
41
41
|
* `equals`/`not_equals`), `in/not_in`, `gt/lt/gte/lte`, `contains/not_contains`,
|
|
42
|
-
* `is_null/is_not_null`, `is_owner/is_not_owner
|
|
42
|
+
* `is_null/is_not_null`, `is_owner/is_not_owner`, plus the principal-relative
|
|
43
|
+
* `in_my_departments/not_in_my_departments` (department-scoped policies: the viewer's
|
|
44
|
+
* department codes, read lazily once per evaluate). An unknown operator makes the
|
|
43
45
|
* rule NOT match (fail-closed, never a spurious allow) — see `conditionHolds`
|
|
44
46
|
* below for the exact per-operator semantics and the documented edge-case choices.
|
|
45
47
|
*/
|
|
@@ -47,18 +49,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
47
49
|
exports.MariaDbRecordPermissionRuleAdapter = exports.SHIELD_RECORD_RULE_PORT = void 0;
|
|
48
50
|
const core_1 = require("@astram/core");
|
|
49
51
|
const framework_schema_names_js_1 = require("../config/framework-schema-names.js");
|
|
52
|
+
const rule_subject_js_1 = require("./rule-subject.js");
|
|
53
|
+
const viewer_departments_js_1 = require("./viewer-departments.js");
|
|
50
54
|
/** The DI token the adapter is bound under (parity with the session store token). */
|
|
51
55
|
exports.SHIELD_RECORD_RULE_PORT = Symbol('SHIELD_RECORD_RULE_PORT');
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
/** The department operators (department-scoped policies, spec §5 C). */
|
|
57
|
+
const DEPARTMENT_OPERATORS = new Set([
|
|
58
|
+
'in_my_departments',
|
|
59
|
+
'not_in_my_departments',
|
|
60
|
+
]);
|
|
61
|
+
/**
|
|
62
|
+
* `in_my_departments`: the attribute is a non-empty string AND is (exactly, `===`) one of the
|
|
63
|
+
* viewer's department codes `D`. `not_in_my_departments` is its plain negation, so it holds on
|
|
64
|
+
* an absent / null / empty attribute and on every row when `D` is empty (deny-only, D2).
|
|
65
|
+
*/
|
|
66
|
+
function inDepartments(actual, departments) {
|
|
67
|
+
return typeof actual === 'string' && actual !== '' && departments.includes(actual);
|
|
62
68
|
}
|
|
63
69
|
/** Resolve a rule value token against the request (e.g. `$actor.id`) or use the literal. */
|
|
64
70
|
function resolveValue(raw, input) {
|
|
@@ -140,7 +146,7 @@ function orderedCompare(actual, expected) {
|
|
|
140
146
|
* → does NOT hold for either (fail-closed — no owner to compare, and an
|
|
141
147
|
* empty attribute must never "match" an empty `principal.id`).
|
|
142
148
|
*/
|
|
143
|
-
function conditionHolds(row, input) {
|
|
149
|
+
function conditionHolds(row, input, departments) {
|
|
144
150
|
if (row.rpr_field === null)
|
|
145
151
|
return true; // unconditional
|
|
146
152
|
const actual = fieldValue(row.rpr_field, input);
|
|
@@ -208,6 +214,15 @@ function conditionHolds(row, input) {
|
|
|
208
214
|
// absent OR empty-string → does NOT hold (fail-closed; same hardening,
|
|
209
215
|
// mirrored for the negative ownership operator).
|
|
210
216
|
return isPresent(actual) && actual !== '' && actual !== input.principal.id;
|
|
217
|
+
case 'in_my_departments':
|
|
218
|
+
// `departments` is loaded by `evaluate` before any group with a department operator is
|
|
219
|
+
// evaluated; `null` here would be a wiring bug → the condition does not hold (and for
|
|
220
|
+
// the negative operator see below).
|
|
221
|
+
return departments !== null && inDepartments(actual, departments);
|
|
222
|
+
case 'not_in_my_departments':
|
|
223
|
+
// NOT `in_my_departments` (deny-only, D2). An unloaded set (`null`, a wiring bug) is
|
|
224
|
+
// treated as the empty set: the condition holds, so a deny applies (fail closed).
|
|
225
|
+
return departments === null || !inDepartments(actual, departments);
|
|
211
226
|
default:
|
|
212
227
|
return false; // unknown operator → fail-closed (rule does not apply)
|
|
213
228
|
}
|
|
@@ -219,11 +234,36 @@ function conditionHolds(row, input) {
|
|
|
219
234
|
class MariaDbRecordPermissionRuleAdapter {
|
|
220
235
|
db;
|
|
221
236
|
schema;
|
|
237
|
+
appSchema;
|
|
238
|
+
now;
|
|
222
239
|
constructor(db, opts = {}) {
|
|
223
240
|
this.db = db;
|
|
224
241
|
// The `record_permission_rule` database: `opts.schema` (checked), else the resolved authz
|
|
225
242
|
// name (configurable-framework-db), fixed at construction.
|
|
226
243
|
this.schema = (0, framework_schema_names_js_1.authzSchemaAtConstruction)(opts.schema);
|
|
244
|
+
this.appSchema =
|
|
245
|
+
opts.appSchema !== undefined
|
|
246
|
+
? (0, core_1.assertSchemaName)(opts.appSchema, 'opts.appSchema')
|
|
247
|
+
: (0, core_1.resolveFrameworkSchemas)(process.env).app;
|
|
248
|
+
this.now = opts.now ?? Date.now;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* The viewer department set `D` for this evaluation (spec §5 C, D3):
|
|
252
|
+
* - root and a record reached outside the principal's subtree (cross-tenant grant) ⇒ empty;
|
|
253
|
+
* - otherwise the codes of the principal's in-effect postings in `principal.tenantId`.
|
|
254
|
+
* A reader failure throws {@link AuthorizationUnavailableError} (fail closed).
|
|
255
|
+
*/
|
|
256
|
+
async departmentsFor(input) {
|
|
257
|
+
const { principal, resource } = input;
|
|
258
|
+
if (principal.isRoot)
|
|
259
|
+
return [];
|
|
260
|
+
const recordTenant = resource.tenantId;
|
|
261
|
+
if (recordTenant !== undefined &&
|
|
262
|
+
recordTenant !== null &&
|
|
263
|
+
!principal.scopeSubtreeNodeIds.includes(recordTenant)) {
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
return (0, viewer_departments_js_1.readViewerDepartmentCodes)(this.db, this.appSchema, principal.id, principal.tenantId, this.now());
|
|
227
267
|
}
|
|
228
268
|
async evaluate(input) {
|
|
229
269
|
// tenant scoping: match rows for the resource's tenant OR the global/system baseline
|
|
@@ -231,7 +271,7 @@ class MariaDbRecordPermissionRuleAdapter {
|
|
|
231
271
|
const tenantId = input.resource.tenantId ?? input.principal.tenantId;
|
|
232
272
|
let rows;
|
|
233
273
|
try {
|
|
234
|
-
rows = (await this.db.query(`SELECT rpr_policy_uuid, rpr_effect, rpr_subject_kind, rpr_subject_value, rpr_field, rpr_operator, rpr_value
|
|
274
|
+
rows = (await this.db.query(`SELECT rpr_policy_uuid, rpr_effect, rpr_subject_kind, rpr_subject_value, rpr_subject_role_uuids, rpr_field, rpr_operator, rpr_value
|
|
235
275
|
FROM \`${this.schema}\`.\`record_permission_rule\`
|
|
236
276
|
WHERE rpr_type_key = ?
|
|
237
277
|
AND (rpr_tenant_uuid = ? OR rpr_tenant_uuid IS NULL)
|
|
@@ -266,6 +306,10 @@ class MariaDbRecordPermissionRuleAdapter {
|
|
|
266
306
|
}
|
|
267
307
|
let allow = false;
|
|
268
308
|
let explicitDeny = false;
|
|
309
|
+
// The viewer department set, read LAZILY: at most once per evaluate, and only when a
|
|
310
|
+
// subject-matching group uses a department operator (a request without such a policy
|
|
311
|
+
// pays no extra query — spec §5 B, §12 case 11).
|
|
312
|
+
let departments = null;
|
|
269
313
|
for (const groupRows of groups.values()) {
|
|
270
314
|
const head = groupRows[0];
|
|
271
315
|
if (head === undefined)
|
|
@@ -274,7 +318,14 @@ class MariaDbRecordPermissionRuleAdapter {
|
|
|
274
318
|
// Its effect is consistent across rows (the store writes one effect per policy);
|
|
275
319
|
// we take the group's effect from its first row and ignore any anomalous mix
|
|
276
320
|
// fail-closed (a non-'allow'/'deny' effect contributes nothing).
|
|
277
|
-
|
|
321
|
+
if (!groupRows.every((row) => (0, rule_subject_js_1.subjectMatches)(row, input.principal.roleIds)))
|
|
322
|
+
continue;
|
|
323
|
+
if (departments === null &&
|
|
324
|
+
groupRows.some((row) => row.rpr_field !== null && DEPARTMENT_OPERATORS.has(row.rpr_operator ?? ''))) {
|
|
325
|
+
departments = await this.departmentsFor(input); // throws on outage (fail closed)
|
|
326
|
+
}
|
|
327
|
+
const set = departments;
|
|
328
|
+
const applies = groupRows.every((row) => conditionHolds(row, input, set));
|
|
278
329
|
if (!applies)
|
|
279
330
|
continue;
|
|
280
331
|
const effect = head.rpr_effect;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One subject matcher for `record_permission_rule` rows, shared by the single-record adapter
|
|
3
|
+
* (`decide()` / get) and the list-scope adapter (list / aggregate) so the two paths can never
|
|
4
|
+
* disagree on who a rule applies to (department-scoped policies, spec §5 C/D, D4; Shield #8).
|
|
5
|
+
*
|
|
6
|
+
* Kinds (fixed list, spec §10):
|
|
7
|
+
* - `everyone` — every principal (the pre-existing default);
|
|
8
|
+
* - `role` — LEGACY single-role row: `rpr_subject_value` is one role uuid;
|
|
9
|
+
* - `roles` — the principal holds at least one role of `rpr_subject_role_uuids`;
|
|
10
|
+
* - `except_roles` — the principal holds none of them.
|
|
11
|
+
*
|
|
12
|
+
* FAIL CLOSED (Shield #1): an unknown kind, or a `roles` / `except_roles` row whose JSON is
|
|
13
|
+
* malformed, empty, not an array or holds a non-string / empty entry, never matches. For an
|
|
14
|
+
* `except_roles` deny this loses the deny for that group; that is reachable only by a direct DB
|
|
15
|
+
* write (the store never writes it) and is pinned by a unit test (spec §13).
|
|
16
|
+
*/
|
|
17
|
+
/** The subject columns of a rule row. The JSON column may arrive as a string or parsed. */
|
|
18
|
+
export interface RuleSubjectColumns {
|
|
19
|
+
readonly rpr_subject_kind: string;
|
|
20
|
+
readonly rpr_subject_value: string | null;
|
|
21
|
+
readonly rpr_subject_role_uuids?: unknown;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The role ids of a `roles` / `except_roles` row, or `null` when the stored value is not a
|
|
25
|
+
* non-empty array of non-empty strings. The `mariadb` driver returns a JSON column either as
|
|
26
|
+
* its text or as the parsed value (depending on server type info / `autoJsonMap`), so both are
|
|
27
|
+
* accepted.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseSubjectRoleIds(raw: unknown): readonly string[] | null;
|
|
30
|
+
/** Whether the rule's subject applies to a principal holding `roleIds`. */
|
|
31
|
+
export declare function subjectMatches(row: RuleSubjectColumns, roleIds: readonly string[]): boolean;
|
|
32
|
+
//# sourceMappingURL=rule-subject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-subject.d.ts","sourceRoot":"","sources":["../../src/authz/rule-subject.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,2FAA2F;AAC3F,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAC3C;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,GAAG,IAAI,CAoB1E;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAiB3F"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* One subject matcher for `record_permission_rule` rows, shared by the single-record adapter
|
|
4
|
+
* (`decide()` / get) and the list-scope adapter (list / aggregate) so the two paths can never
|
|
5
|
+
* disagree on who a rule applies to (department-scoped policies, spec §5 C/D, D4; Shield #8).
|
|
6
|
+
*
|
|
7
|
+
* Kinds (fixed list, spec §10):
|
|
8
|
+
* - `everyone` — every principal (the pre-existing default);
|
|
9
|
+
* - `role` — LEGACY single-role row: `rpr_subject_value` is one role uuid;
|
|
10
|
+
* - `roles` — the principal holds at least one role of `rpr_subject_role_uuids`;
|
|
11
|
+
* - `except_roles` — the principal holds none of them.
|
|
12
|
+
*
|
|
13
|
+
* FAIL CLOSED (Shield #1): an unknown kind, or a `roles` / `except_roles` row whose JSON is
|
|
14
|
+
* malformed, empty, not an array or holds a non-string / empty entry, never matches. For an
|
|
15
|
+
* `except_roles` deny this loses the deny for that group; that is reachable only by a direct DB
|
|
16
|
+
* write (the store never writes it) and is pinned by a unit test (spec §13).
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.parseSubjectRoleIds = parseSubjectRoleIds;
|
|
20
|
+
exports.subjectMatches = subjectMatches;
|
|
21
|
+
/**
|
|
22
|
+
* The role ids of a `roles` / `except_roles` row, or `null` when the stored value is not a
|
|
23
|
+
* non-empty array of non-empty strings. The `mariadb` driver returns a JSON column either as
|
|
24
|
+
* its text or as the parsed value (depending on server type info / `autoJsonMap`), so both are
|
|
25
|
+
* accepted.
|
|
26
|
+
*/
|
|
27
|
+
function parseSubjectRoleIds(raw) {
|
|
28
|
+
let value = raw;
|
|
29
|
+
if (typeof value === 'string') {
|
|
30
|
+
try {
|
|
31
|
+
value = JSON.parse(value);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (value instanceof Uint8Array) {
|
|
38
|
+
try {
|
|
39
|
+
value = JSON.parse(Buffer.from(value).toString('utf8'));
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
if (!Array.isArray(value) || value.length === 0)
|
|
46
|
+
return null;
|
|
47
|
+
for (const id of value) {
|
|
48
|
+
if (typeof id !== 'string' || id.length === 0)
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
/** Whether the rule's subject applies to a principal holding `roleIds`. */
|
|
54
|
+
function subjectMatches(row, roleIds) {
|
|
55
|
+
switch (row.rpr_subject_kind) {
|
|
56
|
+
case 'everyone':
|
|
57
|
+
return true;
|
|
58
|
+
case 'role':
|
|
59
|
+
return row.rpr_subject_value !== null && roleIds.includes(row.rpr_subject_value);
|
|
60
|
+
case 'roles': {
|
|
61
|
+
const listed = parseSubjectRoleIds(row.rpr_subject_role_uuids);
|
|
62
|
+
return listed !== null && listed.some((id) => roleIds.includes(id));
|
|
63
|
+
}
|
|
64
|
+
case 'except_roles': {
|
|
65
|
+
const listed = parseSubjectRoleIds(row.rpr_subject_role_uuids);
|
|
66
|
+
return listed !== null && !listed.some((id) => roleIds.includes(id));
|
|
67
|
+
}
|
|
68
|
+
default:
|
|
69
|
+
return false; // unknown subject kind → does NOT match (fail-closed)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Department code shape (spec §10): 1–32 of `A–Z`, `0–9`, `_`, case-sensitive. */
|
|
2
|
+
export declare const DEPARTMENT_CODE_PATTERN: RegExp;
|
|
3
|
+
/** The minimal query surface (a `mariadb` Pool or connection satisfies it). */
|
|
4
|
+
export interface DepartmentQueryable {
|
|
5
|
+
query(sql: string, params?: readonly unknown[]): Promise<unknown>;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Read the viewer's department codes. `appSchema` is the org (`<app>`) database name, already
|
|
9
|
+
* checked at construction by the caller (`schemaNamesAtConstruction`); it is the only text
|
|
10
|
+
* interpolated into the SQL.
|
|
11
|
+
* @throws AuthorizationUnavailableError when the read fails.
|
|
12
|
+
*/
|
|
13
|
+
export declare function readViewerDepartmentCodes(q: DepartmentQueryable, appSchema: string, userUuid: string, companyUuid: string, nowMs: number): Promise<readonly string[]>;
|
|
14
|
+
//# sourceMappingURL=viewer-departments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viewer-departments.d.ts","sourceRoot":"","sources":["../../src/authz/viewer-departments.ts"],"names":[],"mappings":"AAmBA,mFAAmF;AACnF,eAAO,MAAM,uBAAuB,QAAsB,CAAC;AAE3D,+EAA+E;AAC/E,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACnE;AAMD;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC7C,CAAC,EAAE,mBAAmB,EACtB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC,CAiC5B"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEPARTMENT_CODE_PATTERN = void 0;
|
|
4
|
+
exports.readViewerDepartmentCodes = readViewerDepartmentCodes;
|
|
5
|
+
/**
|
|
6
|
+
* The viewer's department CODES for the principal-relative department operators
|
|
7
|
+
* (`in_my_departments` / `not_in_my_departments`; department-scoped policies, spec §5 B, D1, D3).
|
|
8
|
+
*
|
|
9
|
+
* The set is the distinct non-NULL `d_code` of the departments on the user's IN-EFFECT postings
|
|
10
|
+
* of their ACTIVE membership in `companyUuid` (the principal's active company), with the user
|
|
11
|
+
* `active` — the same membership/posting predicate as `readRoleIdsForTenant` in
|
|
12
|
+
* `identity/permission-facts.adapter.ts`, so roles and departments come from the same postings.
|
|
13
|
+
*
|
|
14
|
+
* ── Read lazily, at gate 6 (which already reads MariaDB), and only when a subject-matching rule
|
|
15
|
+
* group uses a department operator; the session hot path is untouched (Shield #12).
|
|
16
|
+
* ── FAIL CLOSED: a query failure THROWS {@link AuthorizationUnavailableError} (503), never an
|
|
17
|
+
* empty set that could read as "no departments" and never a widened list. A department
|
|
18
|
+
* without a code contributes nothing; only codes matching {@link DEPARTMENT_CODE_PATTERN}
|
|
19
|
+
* are returned (defence against a direct DB write). Every value is bound (`?`).
|
|
20
|
+
* ── Root and non-user principals (service accounts) have no membership: the set is empty.
|
|
21
|
+
*/
|
|
22
|
+
const core_1 = require("@astram/core");
|
|
23
|
+
/** Department code shape (spec §10): 1–32 of `A–Z`, `0–9`, `_`, case-sensitive. */
|
|
24
|
+
exports.DEPARTMENT_CODE_PATTERN = /^[A-Z0-9_]{1,32}$/;
|
|
25
|
+
/**
|
|
26
|
+
* Read the viewer's department codes. `appSchema` is the org (`<app>`) database name, already
|
|
27
|
+
* checked at construction by the caller (`schemaNamesAtConstruction`); it is the only text
|
|
28
|
+
* interpolated into the SQL.
|
|
29
|
+
* @throws AuthorizationUnavailableError when the read fails.
|
|
30
|
+
*/
|
|
31
|
+
async function readViewerDepartmentCodes(q, appSchema, userUuid, companyUuid, nowMs) {
|
|
32
|
+
let rows;
|
|
33
|
+
try {
|
|
34
|
+
rows = (await q.query(`SELECT DISTINCT d.d_code AS d_code
|
|
35
|
+
FROM \`${appSchema}\`.\`company_membership\` cm
|
|
36
|
+
JOIN \`${appSchema}\`.\`users\` u ON u.u_uuid = cm.cm_user_uuid AND u.u_status = 'active'
|
|
37
|
+
JOIN \`${appSchema}\`.\`membership_posting\` mp ON mp.mp_membership_uuid = cm.cm_uuid
|
|
38
|
+
JOIN \`${appSchema}\`.\`departments\` d ON d.d_uuid = mp.mp_department_uuid
|
|
39
|
+
JOIN \`${appSchema}\`.\`company_departments\` cd
|
|
40
|
+
ON cd.cd_department_uuid = d.d_uuid AND cd.cd_company_uuid = cm.cm_company_uuid
|
|
41
|
+
WHERE cm.cm_user_uuid = ? AND cm.cm_company_uuid = ? AND cm.cm_is_active = 1
|
|
42
|
+
AND mp.mp_department_uuid IS NOT NULL
|
|
43
|
+
AND d.d_code IS NOT NULL
|
|
44
|
+
AND (mp.mp_effective_from_ms IS NULL OR mp.mp_effective_from_ms <= ?)
|
|
45
|
+
AND (mp.mp_effective_until_ms IS NULL OR mp.mp_effective_until_ms > ?)`, [userUuid, companyUuid, nowMs, nowMs]));
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
// No department code or user id in the message (spec §11 rule 9).
|
|
49
|
+
throw new core_1.AuthorizationUnavailableError(`department store unavailable: ${err.message}`);
|
|
50
|
+
}
|
|
51
|
+
if (!Array.isArray(rows)) {
|
|
52
|
+
throw new core_1.AuthorizationUnavailableError('department store returned an unexpected result');
|
|
53
|
+
}
|
|
54
|
+
const codes = new Set();
|
|
55
|
+
for (const row of rows) {
|
|
56
|
+
const code = row?.d_code;
|
|
57
|
+
if (typeof code === 'string' && exports.DEPARTMENT_CODE_PATTERN.test(code))
|
|
58
|
+
codes.add(code);
|
|
59
|
+
}
|
|
60
|
+
return [...codes];
|
|
61
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire-record-authorization.d.ts","sourceRoot":"","sources":["../../src/authz/wire-record-authorization.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,OAAO,KAAK,EACV,iBAAiB,EAEjB,cAAc,EAEd,mBAAmB,EACnB,SAAS,EAET,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAMtB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAC7E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGjD,OAAO,EAEL,KAAK,aAAa,EACnB,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"wire-record-authorization.d.ts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AM,EAAE,yBAAyB,EACjC,OAAO,GAAE,+BAAoC,GAC5C,iBAAiB,CAoCnB;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GAAG,CACxB,GAAG,EAAE,UAAU,EACf,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,MAAM,KACX,OAAO,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC,CAAC;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,yBAAyB,GAAG,WAAW,CAmH/E"}
|
|
@@ -12,6 +12,7 @@ const mariadb_cross_tenant_grant_adapter_js_1 = require("./mariadb-cross-tenant-
|
|
|
12
12
|
const mariadb_list_scope_adapter_js_1 = require("./mariadb-list-scope-adapter.js");
|
|
13
13
|
const operation_marker_check_js_1 = require("./operation-marker-check.js");
|
|
14
14
|
const list_scope_sql_js_1 = require("./list-scope-sql.js");
|
|
15
|
+
const viewer_departments_js_1 = require("./viewer-departments.js");
|
|
15
16
|
const session_facts_als_js_1 = require("../request-auth/session-facts-als.js");
|
|
16
17
|
const framework_schema_names_js_1 = require("../config/framework-schema-names.js");
|
|
17
18
|
const manifest_operation_authority_adapter_js_1 = require("./manifest-operation-authority-adapter.js");
|
|
@@ -19,6 +20,10 @@ const manifest_operation_authority_adapter_js_1 = require("./manifest-operation-
|
|
|
19
20
|
function authzSchemaOf(inputs) {
|
|
20
21
|
return (0, framework_schema_names_js_1.schemaNamesAtConstruction)(inputs.schemas).authz;
|
|
21
22
|
}
|
|
23
|
+
/** The org (`<app>`) database the viewer-department reader joins: `inputs.schemas`, else now. */
|
|
24
|
+
function appSchemaOf(inputs) {
|
|
25
|
+
return (0, framework_schema_names_js_1.schemaNamesAtConstruction)(inputs.schemas).app;
|
|
26
|
+
}
|
|
22
27
|
/**
|
|
23
28
|
* Construct the four framework-owned record-tier adapters over the supplied pool +
|
|
24
29
|
* manifest, and return the fully-wired core {@link DecisionAuthority}. Behavior-identical
|
|
@@ -74,6 +79,7 @@ function buildRecordAuthorization(inputs, options = {}) {
|
|
|
74
79
|
? withRedisPermissionVersion(inputs.permissionFacts, options.versionCache)
|
|
75
80
|
: inputs.permissionFacts;
|
|
76
81
|
const schema = authzSchemaOf(inputs);
|
|
82
|
+
const appSchema = appSchemaOf(inputs);
|
|
77
83
|
// Delegation / trusted-operation authority over the DECLARED manifest (no DB). Empty ⇒
|
|
78
84
|
// pass-through. The app supplies the entries; the framework owns the adapter. The marker check
|
|
79
85
|
// also uses it (plan D-5): a principal bound to an undeclared step is denied outright.
|
|
@@ -89,7 +95,9 @@ function buildRecordAuthorization(inputs, options = {}) {
|
|
|
89
95
|
// ── The FOUR framework-owned record-tier adapters — constructed HERE, and ONLY here.
|
|
90
96
|
// Record-permit ADMIN rules over `shield_authz.record_permission_rule` (widen the
|
|
91
97
|
// core-owned owner baseline, deny-wins). Empty table ⇒ owner-only (NOT a lockout).
|
|
92
|
-
|
|
98
|
+
// The department operators read the viewer's department codes from `<app>` on the same
|
|
99
|
+
// pool, lazily (department-scoped policies, spec §5 C).
|
|
100
|
+
recordRule: new mariadb_record_rule_adapter_js_1.MariaDbRecordPermissionRuleAdapter(inputs.pool, { schema, appSchema }),
|
|
93
101
|
// Per-record SHARE source over `shield_authz.record_share` (widening permit, union
|
|
94
102
|
// with baseline under deny-wins). No share ⇒ false (baseline still governs).
|
|
95
103
|
recordShare: new mariadb_record_share_adapter_js_1.MariaDbRecordShareAdapter(inputs.pool, { schema }),
|
|
@@ -120,6 +128,7 @@ function buildRecordAuthorization(inputs, options = {}) {
|
|
|
120
128
|
function buildListScopeFn(inputs) {
|
|
121
129
|
// The authz database, resolved ONCE here (build time) and captured by the per-request fn.
|
|
122
130
|
const schema = authzSchemaOf(inputs);
|
|
131
|
+
const appSchema = appSchemaOf(inputs);
|
|
123
132
|
// Framework-constructed over `inputs.pool` — UN-overridable (not a field of the inputs).
|
|
124
133
|
const listScopePort = new mariadb_list_scope_adapter_js_1.MariaDbListScopeAdapter(inputs.pool, { schema });
|
|
125
134
|
// The cross-tenant grant adapter — reused HERE to resolve the OWNING tenants a grantee
|
|
@@ -183,9 +192,23 @@ function buildListScopeFn(inputs) {
|
|
|
183
192
|
owningTenantDeny = owningPolicy.deny; // ONLY the deny — the GRANT is the permit source
|
|
184
193
|
}
|
|
185
194
|
}
|
|
195
|
+
// ── Viewer department codes (department-scoped policies, spec §5 D, D3) ───────────────
|
|
196
|
+
// Loaded ONLY when a group the translator will see uses a department operator (no extra
|
|
197
|
+
// query otherwise). Same-tenant set: the actor's in-effect postings in `actor.tenantId`,
|
|
198
|
+
// exactly the set decide() reads for a record in the actor's subtree. Root has no
|
|
199
|
+
// membership (empty set, as decide()). The owning-tenant deny branch (`owningTenantDeny`)
|
|
200
|
+
// is always translated with an EMPTY set by the translator itself, so it needs no read.
|
|
201
|
+
// A reader outage throws (fail closed).
|
|
202
|
+
let departmentCodes = null;
|
|
203
|
+
if ((0, list_scope_sql_js_1.groupsUseDepartmentOperator)(spec.policyAllow) ||
|
|
204
|
+
(0, list_scope_sql_js_1.groupsUseDepartmentOperator)(spec.policyDeny)) {
|
|
205
|
+
departmentCodes = actor.isRoot
|
|
206
|
+
? []
|
|
207
|
+
: await (0, viewer_departments_js_1.readViewerDepartmentCodes)(inputs.pool, appSchema, actor.id, actor.tenantId, Date.now());
|
|
208
|
+
}
|
|
186
209
|
// Translate the abstract spec → SAFE parameterized WHERE fragment. An unknown-field
|
|
187
210
|
// rejection here also PROPAGATES (fail-closed).
|
|
188
|
-
const translated = (0, list_scope_sql_js_1.translateListScope)(spec, reg, { principalId: actor.id, principalTenantId: actor.tenantId }, { owningTenantDeny, schema });
|
|
211
|
+
const translated = (0, list_scope_sql_js_1.translateListScope)(spec, reg, { principalId: actor.id, principalTenantId: actor.tenantId, departmentCodes }, { owningTenantDeny, schema });
|
|
189
212
|
return { sql: translated.sql, params: translated.params };
|
|
190
213
|
};
|
|
191
214
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -59,7 +59,8 @@ export { MariaDbSessionRecordStore, SHIELD_SESSION_RECORD_STORE, RedisHotSession
|
|
|
59
59
|
export { MariaDbRecordPermissionRuleAdapter, SHIELD_RECORD_RULE_PORT, type RuleQueryable, } from './authz/mariadb-record-rule-adapter.js';
|
|
60
60
|
export { MariaDbPolicyStore, SHIELD_POLICY_STORE, type RuleQueryable as PolicyStoreQueryable, } from './authz/mariadb-policy-store.js';
|
|
61
61
|
export { MariaDbListScopeAdapter, SHIELD_LIST_SCOPE_PORT, type ListScopeQueryable, } from './authz/mariadb-list-scope-adapter.js';
|
|
62
|
-
export { translateListScope, UnknownScopeFieldError, type TranslatedListScope, type ListScopePrincipal, } from './authz/list-scope-sql.js';
|
|
62
|
+
export { translateListScope, UnknownScopeFieldError, UnloadedDepartmentSetError, type TranslatedListScope, type ListScopePrincipal, } from './authz/list-scope-sql.js';
|
|
63
|
+
export { readViewerDepartmentCodes, DEPARTMENT_CODE_PATTERN, type DepartmentQueryable, } from './authz/viewer-departments.js';
|
|
63
64
|
export { MariaDbRecordShareAdapter, SHIELD_RECORD_SHARE_PORT, type ShareQueryable, } from './authz/mariadb-record-share-adapter.js';
|
|
64
65
|
export { RecordShareWriter, SHIELD_RECORD_SHARE_WRITER, SHARE_MANAGED_BY_LINKED_RECORD, ShareNotPermittedError, ShareStoreUnavailableError, type RecordShareRow, type ShareInput, type ShareGranteeKind, type ShareTypeInfo, type ShareTypeResolver, type ShareAuditEvent, type ShareAuditSink, } from './authz/record-share-writer.js';
|
|
65
66
|
export { makeShareDeleteCascade, type RecordDeletedHook, type ShareQueryFn, } from './authz/record-share-cascade.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,kBAAkB,EAAE,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K,SAAS,EACd,KAAK,UAAU,GAChB,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.isLockedHash = exports.lockedPasswordHash = exports.SHIELD_PASSWORD_HASHER = exports.argon2idHasherProvider = exports.Argon2idPasswordHasher = exports.stubDecisionAuthority = exports.GlobalEnforcementGuard = exports.currentRequestPrincipal = exports.NO_SESSION_FACTS = exports.SHIELD_SESSION_FACTS_ALS = exports.MariaDbApiKeyStore = exports.isApiKey = exports.extractBearerToken = exports.principalFromClaims = exports.resolveRequestAuth = exports.resolveRequestPrincipal = exports.SessionTokenBinder = exports.SHIELD_SERVICE_AUTHENTICATOR = exports.SHIELD_SESSION_TOKEN_BINDER = exports.CatalogGatabilityError = exports.CatalogReconciler = exports.OperationInventoryScanner = exports.uuidArrayField = exports.optionalUuidField = exports.uuidField = exports.UuidPipe = exports.normalizeClassification = exports.DEFAULT_CLASSIFIED_ACTION = exports.CLASSIFICATION_METADATA = exports.Classified = exports.Public = exports.SHIELD_RECORD_AUTHORIZATION = exports.SHIELD_DECISION_AUTHORITY = exports.ShieldModule = exports.actionsOf = exports.actionsFor = exports.agentClientDataAckKey = exports.agentClientDataTombstoneKey = exports.agentTenantModeKey = exports.AGENT_BOOTSTRAP_TENANT_MODES = exports.AGENT_TENANT_MODES = exports.AGENT_ACTIONS = exports.SERVICE_ACCOUNT_ACTIONS = exports.RECORD_SHARE_ACTIONS = exports.CROSS_TENANT_GRANT_ACTIONS = exports.IDENTITY_ACTIONS = exports.MODULE_KEY = exports.permissionTextByKey = exports.buildIdentityModuleRegistry = exports.guardMigrationsDir = void 0;
|
|
20
20
|
exports.SystemClock = exports.Sha256RefreshTokenHasher = exports.CryptoTokenGenerator = exports.RedisRecentRotationStore = exports.SHIELD_HOT_SESSION_STORE = exports.RedisHotSessionStore = exports.SHIELD_SESSION_RECORD_STORE = exports.MariaDbSessionRecordStore = exports.DEFAULT_OBJECT_STORAGE_MAX_BYTES = exports.loadObjectStorageConfig = exports.FileShareError = exports.FILE_SHARE_ERROR_CODES = exports.SHIELD_FILE_SHARE = exports.SHIELD_AGENT_CLIENT_DATA_DISCLOSURE = exports.SHIELD_AGENT_CLIENT_DATA_PROFILES = exports.SHIELD_AGENT_TASK_CALLS = exports.SHIELD_PROPOSAL_READER = exports.SHIELD_PROPOSAL_PORT = exports.SHIELD_AGENT_FILE_READER = exports.SHIELD_FILE_INGEST = exports.SHIELD_OBJECT_STORE = exports.isDeniedAppContentType = exports.MAX_APP_FILE_PROFILES = exports.APP_CONTENT_TYPE_DENY_LIST = exports.FILE_INTAKE_DEFAULT_MAX_BYTES = exports.FILE_INTAKE_REQUEST_KEY = exports.FileIntake = exports.ObjectStoreBootCheck = exports.SHIELD_NOTIFICATIONS = exports.loadNotificationConfig = exports.NotificationUnavailableError = exports.NotificationValidationError = exports.NotificationKindError = exports.NOTIFICATION_BULK_ACTIONS = exports.NOTIFICATION_STATUSES = exports.NOTIFICATION_SEVERITIES = exports.NOTIFICATION_CATEGORIES = exports.NotificationService = exports.loadAuditSealConfig = exports.NodeSha256Hash = exports.NodeSha256Digest = exports.S3ObjectStore = exports.wasResolvedFromSecretRef = exports.assertNoUnresolvedSecretRefs = exports.createSecretsProviderFromEnv = exports.resolveBootSecrets = exports.EncryptedFileSecretsProvider = exports.LocalKekCrypto = exports.resolveAuthLinkBaseUrls = exports.CredentialExistsError = void 0;
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
23
|
-
exports.
|
|
21
|
+
exports.frameworkDatabasesLogLine = exports.assertPoolBudget = exports.BootSequence = exports.buildListScopeFn = exports.MariaDbSessionRestrictionStore = exports.SHIELD_SESSION_RESTRICTIONS = exports.SHIELD_PERMISSION_VERSION_CACHE = exports.DEFAULT_PERMISSION_VERSION_TTL_MS = exports.PERMISSION_VERSION_KEY_PREFIX = exports.RedisPermissionVersionCache = exports.withRedisPermissionVersion = exports.buildRecordAuthorization = exports.SHIELD_OPERATION_AUTHORITY_PORT = exports.ManifestOperationAuthorityAdapter = exports.GrantStoreUnavailableError = exports.InvalidGrantError = exports.GrantNotPermittedError = exports.SHIELD_CROSS_TENANT_GRANT_WRITER = exports.CrossTenantGrantWriter = exports.SHIELD_CROSS_TENANT_GRANT_PORT = exports.MariaDbCrossTenantGrantAdapter = exports.makeShareDeleteCascade = exports.ShareStoreUnavailableError = exports.ShareNotPermittedError = exports.SHARE_MANAGED_BY_LINKED_RECORD = exports.SHIELD_RECORD_SHARE_WRITER = exports.RecordShareWriter = exports.SHIELD_RECORD_SHARE_PORT = exports.MariaDbRecordShareAdapter = exports.DEPARTMENT_CODE_PATTERN = exports.readViewerDepartmentCodes = exports.UnloadedDepartmentSetError = exports.UnknownScopeFieldError = exports.translateListScope = exports.SHIELD_LIST_SCOPE_PORT = exports.MariaDbListScopeAdapter = exports.SHIELD_POLICY_STORE = exports.MariaDbPolicyStore = exports.SHIELD_RECORD_RULE_PORT = exports.MariaDbRecordPermissionRuleAdapter = exports.accessBindingTtlMs = exports.ROTATE_GRACE_MS = exports.SHIELD_SESSION_LIFETIMES = exports.HotRevokingSessionRecordStore = exports.SHIELD_CLOCK = exports.SHIELD_REFRESH_HASHER = exports.SHIELD_TOKEN_GENERATOR = exports.systemClockProvider = exports.refreshHasherProvider = exports.cryptoTokenGeneratorProvider = void 0;
|
|
22
|
+
exports.SHIELD_AUDIT_SINK = exports.SHIELD_SESSION_SWEEPER = exports.SHIELD_PROFILE_WRITER = exports.SHIELD_RECOVERY_CODE_STORE = exports.SHIELD_MESSAGE_DISPATCHER = exports.SHIELD_EMAIL_SENDER = exports.SHIELD_EMAIL_CHANGE_TOKEN_STORE = exports.SHIELD_RESET_TOKEN_STORE = exports.SHIELD_CREDENTIAL_WRITER = exports.SHIELD_SESSION_AUTHORITY = exports.SHIELD_AUTHENTICATOR = exports.SHIELD_PROFILE_RESOLVER = exports.SHIELD_CREDENTIAL_RESOLVER = exports.SHIELD_REDIS = exports.withoutStatementTimeout = exports.mariadbPoolTuningOptions = exports.mariadbSslOption = exports.reservedOperationPrincipal = exports.RESERVED_OPERATION_PRINCIPALS = exports.assertNoReservedRootId = exports.ORG_BOOTSTRAP_PRINCIPAL_ID = exports.rootIdsFromEnv = exports.loadPoolTuning = exports.loadDbTlsConfig = exports.isDevOrTestNodeEnv = exports.DEFAULT_LOGIN_IP_LIMIT = exports.loadRefreshReplayWindowMs = exports.loadLoginIpLimit = exports.DEFAULT_REDIS_URL = exports.DEFAULT_DB_CONFIG = exports.assertRefreshHmacKey = exports.loadRefreshHmacKey = exports.loadSessionLifetimes = exports.loadRedisConfig = exports.loadDbConfig = exports.SCHEMA_SVC_POOL_HARD_CAP = exports.DEFAULT_POOL_BUDGET = exports.evaluatePoolBudget = exports.loadPoolBudget = exports.loadAppConfig = exports.frameworkSchemasOf = exports.FRAMEWORK_SCHEMAS = exports.APP_CONFIG = exports.resolveMigrationLedgerCheck = exports.resolveMigrationLedger = exports.frameworkMigrationIds = exports.assertFrameworkMigrationsApplied = exports.SHIELD_MIGRATION_LEDGER_REGISTRY = exports.MigrationLedgerRegistry = exports.FrameworkMigrationLedgerCheck = void 0;
|
|
23
|
+
exports.buildClosureRows = exports.ConfirmEmailController = exports.AccountController = exports.generateRecoveryCodes = exports.buildOtpauthUri = exports.generateTotpSecret = exports.SHIELD_LOGIN_TOTP_VERIFIER = exports.SHIELD_MFA_STEP_UP = exports.SHIELD_MFA_LIMITER = exports.challengeMatches = exports.credentialFingerprint = exports.CredentialMfaStepUp = exports.RedisPendingMfaStore = exports.PendingMfaStore = exports.AuthController = exports.SHIELD_SCOPE_SUBTREE_RESOLVER = exports.SHIELD_SESSION_FACTS_PROJECTOR = exports.ProfileNameTakenError = exports.maskPhone = exports.MAX_MESSAGE_SEND_TIMEOUT_MS = exports.DEFAULT_MESSAGE_SEND_TIMEOUT_MS = exports.EMAIL_PROVIDER_VALUES = exports.loadMessageConfig = exports.MariaDbEmailAddressChanger = exports.maskEmail = exports.isEmailShaped = exports.canonicalEmail = exports.hmacSha1 = exports.resolveTotpVerifier = exports.makeDefaultTotpVerifier = exports.AuthModule = exports.SHIELD_CAPTCHA_GATE = exports.RECAPTCHA_SITEVERIFY_URL = exports.RecaptchaVerifier = exports.TURNSTILE_SITEVERIFY_URL = exports.TurnstileVerifier = exports.MAX_CAPTCHA_TIMEOUT_MS = exports.DEFAULT_CAPTCHA_TIMEOUT_MS = exports.DEFAULT_CAPTCHA_MIN_SCORE = exports.DEFAULT_CAPTCHA_THRESHOLD = exports.CAPTCHA_FAIL_MODES = exports.CAPTCHA_MODES = exports.CAPTCHA_ENDPOINTS = exports.loadCaptchaConfig = exports.SHIELD_SIGN_IN_WITH = exports.DEFAULT_SIGN_IN_WITH = exports.resolveSignInWith = exports.MariaDbCredentialResolver = exports.SHIELD_TOTP_VERIFIER_OVERRIDE = exports.SHIELD_MFA_DEVICE_STORE = void 0;
|
|
24
|
+
exports.ScopeUnknownParentError = exports.ScopeDepthError = exports.ScopeCycleError = void 0;
|
|
24
25
|
// Framework authz migrations (shield_authz DDL — permission / role_permission /
|
|
25
26
|
// authz_permission_version). Absolute path a consumer's `@astram/migrate` setup merges in.
|
|
26
27
|
var migrations_dir_js_1 = require("./migrations-dir.js");
|
|
@@ -258,7 +259,8 @@ Object.defineProperty(exports, "SHIELD_RECORD_RULE_PORT", { enumerable: true, ge
|
|
|
258
259
|
// `PolicyStore` (core admin port) over the SAME `record_permission_rule` table the
|
|
259
260
|
// rule adapter enforces — author-what-enforces. Persists a `GuidedPolicy`'s N
|
|
260
261
|
// AND-composed conditions as N rows sharing one `rpr_policy_uuid` group id (the read
|
|
261
|
-
// adapter AND-groups by it). `everyone`
|
|
262
|
+
// adapter AND-groups by it). Policy subject (`everyone` default, `roles`, `except_roles`) on
|
|
263
|
+
// every row; canonical operator
|
|
262
264
|
// names; parameterized SQL; no hard-coded UUIDs. NOT wired into buildRecordAuthorization
|
|
263
265
|
// here — the admin authoring surface (Phase 5) consumes it.
|
|
264
266
|
var mariadb_policy_store_js_1 = require("./authz/mariadb-policy-store.js");
|
|
@@ -278,6 +280,13 @@ Object.defineProperty(exports, "SHIELD_LIST_SCOPE_PORT", { enumerable: true, get
|
|
|
278
280
|
var list_scope_sql_js_1 = require("./authz/list-scope-sql.js");
|
|
279
281
|
Object.defineProperty(exports, "translateListScope", { enumerable: true, get: function () { return list_scope_sql_js_1.translateListScope; } });
|
|
280
282
|
Object.defineProperty(exports, "UnknownScopeFieldError", { enumerable: true, get: function () { return list_scope_sql_js_1.UnknownScopeFieldError; } });
|
|
283
|
+
Object.defineProperty(exports, "UnloadedDepartmentSetError", { enumerable: true, get: function () { return list_scope_sql_js_1.UnloadedDepartmentSetError; } });
|
|
284
|
+
// The viewer department-code reader behind `in_my_departments` / `not_in_my_departments`
|
|
285
|
+
// (department-scoped policies): codes of the viewer's in-effect postings in their active
|
|
286
|
+
// company; outage ⇒ AuthorizationUnavailableError.
|
|
287
|
+
var viewer_departments_js_1 = require("./authz/viewer-departments.js");
|
|
288
|
+
Object.defineProperty(exports, "readViewerDepartmentCodes", { enumerable: true, get: function () { return viewer_departments_js_1.readViewerDepartmentCodes; } });
|
|
289
|
+
Object.defineProperty(exports, "DEPARTMENT_CODE_PATTERN", { enumerable: true, get: function () { return viewer_departments_js_1.DEPARTMENT_CODE_PATTERN; } });
|
|
281
290
|
// The per-record SHARE adapter (ADR-0003 / design §6): the concrete `RecordSharePort` over
|
|
282
291
|
// the `record_share` table. Answers `hasShare` (user- OR role-granted shares, exact-or-`*`
|
|
283
292
|
// action). No share ⇒ false; store outage ⇒ AuthorizationUnavailableError. Injected into
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework authz migration — policy subject role sets on `<authz>.record_permission_rule`
|
|
3
|
+
* (department-scoped policies; spec `docs/features/department-scoped-policies/SPEC.md` v2 §4; id 141
|
|
4
|
+
* per `docs/migrations/RESERVATIONS.md`).
|
|
5
|
+
*
|
|
6
|
+
* Adds `rpr_subject_role_uuids JSON NULL` after `rpr_subject_value`: a JSON array of 1–16 distinct
|
|
7
|
+
* role uuids when `rpr_subject_kind` is `roles` or `except_roles`, NULL otherwise. Every row of one
|
|
8
|
+
* policy (`rpr_policy_uuid` group) carries the same kind and array. `rpr_subject_kind VARCHAR(16)`
|
|
9
|
+
* already fits the new kinds; no other DDL. No data change: existing rows keep NULL (their kinds
|
|
10
|
+
* `everyone` / legacy `role` do not read the column). No ids hard-coded.
|
|
11
|
+
*
|
|
12
|
+
* Idempotent: the column is added only when `information_schema.COLUMNS` shows it absent; a re-run
|
|
13
|
+
* issues no DDL.
|
|
14
|
+
*
|
|
15
|
+
* `down` refuses (throws a fixed message, changes nothing) while any row has kind `roles` or
|
|
16
|
+
* `except_roles`: without the column those rows would never match, so an `except_roles` deny would
|
|
17
|
+
* silently stop applying. Otherwise it drops the column, only when present. It never deletes rules.
|
|
18
|
+
*
|
|
19
|
+
* Database name from `ctx.schemas` (`frameworkSchemasForMigration(...).authz`), so the four-database,
|
|
20
|
+
* namespace and single layouts all work. Sorts after `...009` (creates `record_permission_rule`) and
|
|
21
|
+
* above every published id (132).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const { frameworkSchemasForMigration } = require('@astram/core');
|
|
25
|
+
|
|
26
|
+
const MIGRATION = '1710000000141-AddRecordRuleSubjectRoles';
|
|
27
|
+
const TABLE = 'record_permission_rule';
|
|
28
|
+
const COLUMN = 'rpr_subject_role_uuids';
|
|
29
|
+
|
|
30
|
+
const DOWN_REFUSED =
|
|
31
|
+
`${MIGRATION}: refusing to roll back: record_permission_rule holds policies with a role subject ` +
|
|
32
|
+
"(rpr_subject_kind 'roles' or 'except_roles'). Delete or re-author them first; nothing was changed.";
|
|
33
|
+
|
|
34
|
+
async function exists(query, sql, params) {
|
|
35
|
+
const rows = await query(sql, params);
|
|
36
|
+
return Array.isArray(rows) && rows.length > 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const tableExists = (query, schema) =>
|
|
40
|
+
exists(
|
|
41
|
+
query,
|
|
42
|
+
`SELECT 1 AS n FROM information_schema.TABLES
|
|
43
|
+
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? LIMIT 1`,
|
|
44
|
+
[schema, TABLE],
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const columnExists = (query, schema) =>
|
|
48
|
+
exists(
|
|
49
|
+
query,
|
|
50
|
+
`SELECT 1 AS n FROM information_schema.COLUMNS
|
|
51
|
+
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND COLUMN_NAME = ? LIMIT 1`,
|
|
52
|
+
[schema, TABLE, COLUMN],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const tbl = (schema) => `\`${schema}\`.\`${TABLE}\``;
|
|
56
|
+
|
|
57
|
+
async function up(ctx) {
|
|
58
|
+
const { query } = ctx;
|
|
59
|
+
const AUTHZ = frameworkSchemasForMigration(ctx, process.env).authz;
|
|
60
|
+
|
|
61
|
+
if (!(await tableExists(query, AUTHZ))) {
|
|
62
|
+
throw new Error(
|
|
63
|
+
`${MIGRATION}: ${AUTHZ}.${TABLE} does not exist; run 1710000000009-CreateRecordPermissionRule first.`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!(await columnExists(query, AUTHZ))) {
|
|
68
|
+
await query(
|
|
69
|
+
`ALTER TABLE ${tbl(AUTHZ)} ADD COLUMN IF NOT EXISTS ${COLUMN} JSON NULL AFTER rpr_subject_value`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function down(ctx) {
|
|
75
|
+
const { query } = ctx;
|
|
76
|
+
const AUTHZ = frameworkSchemasForMigration(ctx, process.env).authz;
|
|
77
|
+
|
|
78
|
+
if (!(await tableExists(query, AUTHZ))) return;
|
|
79
|
+
if (!(await columnExists(query, AUTHZ))) return;
|
|
80
|
+
|
|
81
|
+
// Refuse before any change while a role-subject policy exists (never drop a live deny).
|
|
82
|
+
if (
|
|
83
|
+
await exists(
|
|
84
|
+
query,
|
|
85
|
+
`SELECT 1 AS n FROM ${tbl(AUTHZ)} WHERE rpr_subject_kind IN (?, ?) LIMIT 1`,
|
|
86
|
+
['roles', 'except_roles'],
|
|
87
|
+
)
|
|
88
|
+
) {
|
|
89
|
+
throw new Error(DOWN_REFUSED);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
await query(`ALTER TABLE ${tbl(AUTHZ)} DROP COLUMN IF EXISTS ${COLUMN}`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = { up, down };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astram/guard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.37.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Astram framework — the enforcement guard + real-world adapters (the 'hands'). One global deny-by-default gate every request passes through (ADR-0002), classification decorators, boot-pool assertion (ADR-0018), the forRoot() registration seam, and the DB/Redis/crypto adapters that connect the sealed core to a real backend. Depends on @astram/core (ADR-0003, ADR-0023).",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"argon2": "^0.41.1",
|
|
37
37
|
"ioredis": "^5.4.1",
|
|
38
38
|
"mariadb": "^3.5.4",
|
|
39
|
-
"@astram/
|
|
40
|
-
"@astram/
|
|
39
|
+
"@astram/engine": "0.22.1",
|
|
40
|
+
"@astram/core": "1.21.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@nestjs/common": "^11",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@nestjs/platform-express": "^11",
|
|
46
46
|
"reflect-metadata": "^0.2",
|
|
47
47
|
"rxjs": "^7",
|
|
48
|
-
"@astram/messaging": "^0.1.
|
|
48
|
+
"@astram/messaging": "^0.1.28"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"@astram/messaging": {
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"typescript": "^5.7.0",
|
|
69
69
|
"unplugin-swc": "^1.5.1",
|
|
70
70
|
"vitest": "^2.1.8",
|
|
71
|
-
"@astram/messaging": "0.1.
|
|
71
|
+
"@astram/messaging": "0.1.28"
|
|
72
72
|
},
|
|
73
73
|
"repository": {
|
|
74
74
|
"type": "git",
|