@dads-framework/postgres-access 0.2.0 → 0.4.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/BENCHMARK.md +94 -8
- package/README.md +157 -101
- package/dist/compile-access-policy.d.ts +2 -1
- package/dist/compile-access-policy.d.ts.map +1 -1
- package/dist/compile-access-policy.js +9 -4
- package/dist/compile-access-policy.js.map +1 -1
- package/dist/drizzle-executor.d.ts +2 -2
- package/dist/drizzle-executor.d.ts.map +1 -1
- package/dist/drizzle-executor.js.map +1 -1
- package/dist/drizzle-structural.d.ts +23 -0
- package/dist/drizzle-structural.d.ts.map +1 -0
- package/dist/drizzle-structural.js +22 -0
- package/dist/drizzle-structural.js.map +1 -0
- package/dist/drizzle.d.ts +4 -0
- package/dist/drizzle.d.ts.map +1 -0
- package/dist/drizzle.js +4 -0
- package/dist/drizzle.js.map +1 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/lookup-primary-pool.d.ts +2 -3
- package/dist/lookup-primary-pool.d.ts.map +1 -1
- package/dist/lookup-primary-pool.js +1 -1
- package/dist/lookup-primary-pool.js.map +1 -1
- package/dist/lookup-revision-query.d.ts.map +1 -1
- package/dist/lookup-revision-query.js +1 -2
- package/dist/lookup-revision-query.js.map +1 -1
- package/dist/lower-permissions.d.ts.map +1 -1
- package/dist/lower-permissions.js +38 -15
- package/dist/lower-permissions.js.map +1 -1
- package/dist/pg-transaction-lifecycle.d.ts +9 -0
- package/dist/pg-transaction-lifecycle.d.ts.map +1 -0
- package/dist/pg-transaction-lifecycle.js +26 -0
- package/dist/pg-transaction-lifecycle.js.map +1 -0
- package/dist/policy/column-relations.d.ts +34 -0
- package/dist/policy/column-relations.d.ts.map +1 -0
- package/dist/policy/column-relations.js +127 -0
- package/dist/policy/column-relations.js.map +1 -0
- package/dist/policy/compile-filter.d.ts +53 -0
- package/dist/policy/compile-filter.d.ts.map +1 -0
- package/dist/policy/compile-filter.js +133 -0
- package/dist/policy/compile-filter.js.map +1 -0
- package/dist/policy/compile-forward-policy.d.ts +20 -0
- package/dist/policy/compile-forward-policy.d.ts.map +1 -0
- package/dist/policy/compile-forward-policy.js +128 -0
- package/dist/policy/compile-forward-policy.js.map +1 -0
- package/dist/policy/compile-linear-batch.d.ts +1 -0
- package/dist/policy/compile-linear-batch.d.ts.map +1 -1
- package/dist/policy/compile-linear-batch.js +3 -6
- package/dist/policy/compile-linear-batch.js.map +1 -1
- package/dist/policy/compile-linear-check.d.ts.map +1 -1
- package/dist/policy/compile-linear-check.js +53 -18
- package/dist/policy/compile-linear-check.js.map +1 -1
- package/dist/policy/compile-postgres-policy.d.ts +9 -4
- package/dist/policy/compile-postgres-policy.d.ts.map +1 -1
- package/dist/policy/compile-postgres-policy.js +89 -118
- package/dist/policy/compile-postgres-policy.js.map +1 -1
- package/dist/policy/compile-recursive-policy.d.ts +53 -0
- package/dist/policy/compile-recursive-policy.d.ts.map +1 -0
- package/dist/policy/compile-recursive-policy.js +231 -0
- package/dist/policy/compile-recursive-policy.js.map +1 -0
- package/dist/policy/compile-recursive-subjects.d.ts +27 -0
- package/dist/policy/compile-recursive-subjects.d.ts.map +1 -0
- package/dist/policy/compile-recursive-subjects.js +180 -0
- package/dist/policy/compile-recursive-subjects.js.map +1 -0
- package/dist/policy/compile-reverse-policy.d.ts +12 -2
- package/dist/policy/compile-reverse-policy.d.ts.map +1 -1
- package/dist/policy/compile-reverse-policy.js +164 -39
- package/dist/policy/compile-reverse-policy.js.map +1 -1
- package/dist/policy/compile-shared-point-check.d.ts.map +1 -1
- package/dist/policy/compile-shared-point-check.js +166 -16
- package/dist/policy/compile-shared-point-check.js.map +1 -1
- package/dist/policy/compile-subject-lookup.d.ts +8 -0
- package/dist/policy/compile-subject-lookup.d.ts.map +1 -0
- package/dist/policy/compile-subject-lookup.js +253 -0
- package/dist/policy/compile-subject-lookup.js.map +1 -0
- package/dist/policy/permission-cycles.d.ts +27 -0
- package/dist/policy/permission-cycles.d.ts.map +1 -0
- package/dist/policy/permission-cycles.js +179 -0
- package/dist/policy/permission-cycles.js.map +1 -0
- package/dist/policy/policy-model.d.ts +24 -0
- package/dist/policy/policy-model.d.ts.map +1 -1
- package/dist/policy/policy-sql.d.ts +39 -5
- package/dist/policy/policy-sql.d.ts.map +1 -1
- package/dist/policy/policy-sql.js +184 -15
- package/dist/policy/policy-sql.js.map +1 -1
- package/dist/policy/resolve-filter.d.ts +25 -0
- package/dist/policy/resolve-filter.d.ts.map +1 -0
- package/dist/policy/resolve-filter.js +143 -0
- package/dist/policy/resolve-filter.js.map +1 -0
- package/dist/policy/run-filter.d.ts +6 -0
- package/dist/policy/run-filter.d.ts.map +1 -0
- package/dist/policy/run-filter.js +36 -0
- package/dist/policy/run-filter.js.map +1 -0
- package/dist/policy/tarjan-scc.d.ts +3 -0
- package/dist/policy/tarjan-scc.d.ts.map +1 -0
- package/dist/policy/tarjan-scc.js +58 -0
- package/dist/policy/tarjan-scc.js.map +1 -0
- package/dist/postgres-access.tsbuildinfo +1 -1
- package/dist/postgres-authorization.d.ts +21 -17
- package/dist/postgres-authorization.d.ts.map +1 -1
- package/dist/postgres-authorization.js +52 -35
- package/dist/postgres-authorization.js.map +1 -1
- package/dist/postgres-options.d.ts +25 -0
- package/dist/postgres-options.d.ts.map +1 -0
- package/dist/postgres-options.js +34 -0
- package/dist/postgres-options.js.map +1 -0
- package/dist/postgres-response.d.ts +5 -0
- package/dist/postgres-response.d.ts.map +1 -1
- package/dist/postgres-response.js +38 -0
- package/dist/postgres-response.js.map +1 -1
- package/dist/postgres-serialization-conflict.d.ts.map +1 -1
- package/dist/postgres-serialization-conflict.js.map +1 -1
- package/dist/postgres-tuples.d.ts.map +1 -1
- package/dist/postgres-tuples.js +68 -23
- package/dist/postgres-tuples.js.map +1 -1
- package/dist/postgres-types.d.ts +11 -0
- package/dist/postgres-types.d.ts.map +1 -1
- package/dist/postgres-types.js.map +1 -1
- package/dist/prepared-check-executor.d.ts.map +1 -1
- package/dist/prepared-check-executor.js.map +1 -1
- package/dist/protected-authorization-scope.d.ts +6 -8
- package/dist/protected-authorization-scope.d.ts.map +1 -1
- package/dist/protected-authorization-scope.js +13 -8
- package/dist/protected-authorization-scope.js.map +1 -1
- package/dist/relationship-schema.d.ts +9 -0
- package/dist/relationship-schema.d.ts.map +1 -1
- package/dist/relationship-schema.js +22 -2
- package/dist/relationship-schema.js.map +1 -1
- package/dist/revisioned-lookup.d.ts.map +1 -1
- package/dist/revisioned-lookup.js +3 -8
- package/dist/revisioned-lookup.js.map +1 -1
- package/dist/testing.d.ts +20 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +86 -0
- package/dist/testing.js.map +1 -0
- package/dist/transactional-access-changes.d.ts +3 -3
- package/dist/transactional-access-changes.d.ts.map +1 -1
- package/dist/transactional-access-changes.js +6 -4
- package/dist/transactional-access-changes.js.map +1 -1
- package/dist/with-protected-drizzle-transaction.d.ts +18 -0
- package/dist/with-protected-drizzle-transaction.d.ts.map +1 -0
- package/dist/with-protected-drizzle-transaction.js +52 -0
- package/dist/with-protected-drizzle-transaction.js.map +1 -0
- package/dist/with-protected-pg-transaction.d.ts +29 -0
- package/dist/with-protected-pg-transaction.d.ts.map +1 -0
- package/dist/with-protected-pg-transaction.js +84 -0
- package/dist/with-protected-pg-transaction.js.map +1 -0
- package/dist/with-protected-postgres-transaction.d.ts +6 -21
- package/dist/with-protected-postgres-transaction.d.ts.map +1 -1
- package/dist/with-protected-postgres-transaction.js +4 -45
- package/dist/with-protected-postgres-transaction.js.map +1 -1
- package/dist/with-read-snapshot.d.ts +21 -0
- package/dist/with-read-snapshot.d.ts.map +1 -0
- package/dist/with-read-snapshot.js +46 -0
- package/dist/with-read-snapshot.js.map +1 -0
- package/package.json +26 -4
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {} from "./policy-model.js";
|
|
2
1
|
import { readLinearPath } from "./compile-linear-check.js";
|
|
3
2
|
import { compileLinearBatchBranch } from "./compile-linear-batch.js";
|
|
4
3
|
import { compileSharedPointCheck } from "./compile-shared-point-check.js";
|
|
5
4
|
import { compileReversePermission } from "./compile-reverse-policy.js";
|
|
6
|
-
import {
|
|
5
|
+
import { analyzePermissionCycles } from "./permission-cycles.js";
|
|
6
|
+
import { compileForwardPermission, countRecursiveClauses, createForwardContext, } from "./compile-forward-policy.js";
|
|
7
|
+
import { permissionIdentity, QueryBuilder, splitIdentity, subjectReachability } from "./policy-sql.js";
|
|
7
8
|
/** Fixed outer binding used only by named integration adapters. */
|
|
8
9
|
export const POSTGRES_AUTHORIZATION_CANDIDATE_BINDING = Object.freeze({
|
|
9
10
|
tableAlias: "dad_authorization_candidate",
|
|
@@ -12,56 +13,105 @@ export const POSTGRES_AUTHORIZATION_CANDIDATE_BINDING = Object.freeze({
|
|
|
12
13
|
/** Compiles one permission decision into a parameterized Postgres Boolean query. */
|
|
13
14
|
export function compilePostgresCheck(model, namespace, request) {
|
|
14
15
|
const builder = new QueryBuilder();
|
|
15
|
-
const
|
|
16
|
-
const expression = compilePermission(model, builder, namespaceSql, {
|
|
16
|
+
const context = createForwardContext(model, builder, namespace, {
|
|
17
17
|
type: builder.value(request.subject.type),
|
|
18
18
|
id: builder.value(request.subject.id),
|
|
19
19
|
entity: request.subject.type,
|
|
20
|
-
}
|
|
20
|
+
});
|
|
21
|
+
const resource = {
|
|
21
22
|
type: builder.value(request.resource.type),
|
|
22
23
|
id: builder.value(request.resource.id),
|
|
23
24
|
entity: request.resource.type,
|
|
24
|
-
}
|
|
25
|
-
|
|
25
|
+
};
|
|
26
|
+
const expression = compileForwardPermission(context, resource, request.permission);
|
|
27
|
+
if (Buffer.byteLength(expression) > 16 * 1024 || countRecursiveClauses(expression) > 6)
|
|
26
28
|
return compileSharedPointCheck(model, namespace, request);
|
|
27
29
|
return Object.freeze({
|
|
28
30
|
kind: "check",
|
|
29
31
|
text: `SELECT (${expression}) AS allowed`,
|
|
30
32
|
values: builder.values,
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
canPrepare: builder.
|
|
33
|
+
// Prepare bounded ordinary and recursive single-check plans so PostgreSQL
|
|
34
|
+
// reuses compiled execution plans across repeated checks.
|
|
35
|
+
canPrepare: builder.hasRecursive
|
|
36
|
+
? builder.values.length <= 24 && builder.throughCount <= 2
|
|
37
|
+
: builder.values.length <= 9 && builder.throughCount <= 2,
|
|
34
38
|
});
|
|
35
39
|
}
|
|
36
40
|
/** One ordinal input relation and one SQL statement preserve input ordering and duplicates. */
|
|
37
41
|
export function compilePostgresCheckMany(model, namespace, requests) {
|
|
38
42
|
const builder = new QueryBuilder();
|
|
39
43
|
const namespaceSql = builder.value(namespace);
|
|
40
|
-
const
|
|
44
|
+
const cycles = analyzePermissionCycles(model);
|
|
45
|
+
const ordinals = requests.map((_, ordinal) => ordinal);
|
|
46
|
+
const subjectKinds = requests.map((request) => request.subject.type);
|
|
47
|
+
const subjectIds = requests.map((request) => request.subject.id);
|
|
48
|
+
const resourceKinds = requests.map((request) => request.resource.type);
|
|
49
|
+
const resourceIds = requests.map((request) => request.resource.id);
|
|
50
|
+
const permissions = requests.map((request) => request.permission);
|
|
51
|
+
const inputRows = `SELECT * FROM unnest(${builder.value(ordinals)}::integer[], ${builder.value(subjectKinds)}::text[], ${builder.value(subjectIds)}::text[], ${builder.value(resourceKinds)}::text[], ${builder.value(resourceIds)}::text[], ${builder.value(permissions)}::text[])`;
|
|
41
52
|
const shared = [];
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
resourceType,
|
|
50
|
-
permission,
|
|
51
|
-
index: shared.length,
|
|
52
|
-
});
|
|
53
|
-
shared.push(branch.hits);
|
|
54
|
-
return branch.decision;
|
|
55
|
-
}
|
|
56
|
-
const expression = compilePermission(model, builder, namespaceSql, { type: "i.subject_kind", id: "i.subject_id", entity: resourceType }, { type: "i.resource_kind", id: "i.resource_id", entity: resourceType }, permission, new Set());
|
|
57
|
-
return `WHEN i.resource_kind = ${builder.value(resourceType)} AND i.permission = ${builder.value(permission)} THEN (${expression})`;
|
|
58
|
-
});
|
|
53
|
+
const joins = [];
|
|
54
|
+
const identities = [
|
|
55
|
+
...new Set(requests.map((request) => permissionIdentity(request.resource.type, request.permission))),
|
|
56
|
+
];
|
|
57
|
+
const branches = identities.map((identity) => compileBatchBranch(model, cycles, builder, namespaceSql, identity, shared, joins));
|
|
58
|
+
const joinSql = joins.length === 0 ? "" : ` ${joins.join(" ")}`;
|
|
59
|
+
const text = `WITH input(ordinal, subject_kind, subject_id, resource_kind, resource_id, permission) AS (${inputRows})${shared.map((query) => `, ${query}`).join("")} SELECT i.ordinal AS ordinal, CASE ${branches.join(" ")} ELSE false END AS allowed FROM input i${joinSql} ORDER BY i.ordinal`;
|
|
59
60
|
return Object.freeze({
|
|
60
61
|
kind: "check-many",
|
|
61
|
-
text
|
|
62
|
+
text,
|
|
62
63
|
values: builder.values,
|
|
64
|
+
canPrepare: identities.length <= 4 && Buffer.byteLength(text) <= 8 * 1024,
|
|
63
65
|
});
|
|
64
66
|
}
|
|
67
|
+
function shouldUseSharedBatchBranch(model, cycles, namespaceSql, resourceType, permission) {
|
|
68
|
+
if (readLinearPath(model, resourceType, permission) !== undefined) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
const probeBuilder = new QueryBuilder();
|
|
72
|
+
const probeContext = {
|
|
73
|
+
model,
|
|
74
|
+
cycles,
|
|
75
|
+
builder: probeBuilder,
|
|
76
|
+
namespace: namespaceSql,
|
|
77
|
+
subject: {
|
|
78
|
+
type: "i.subject_kind",
|
|
79
|
+
id: "i.subject_id",
|
|
80
|
+
entity: resourceType,
|
|
81
|
+
},
|
|
82
|
+
active: new Set(),
|
|
83
|
+
};
|
|
84
|
+
const probeSql = compileForwardPermission(probeContext, { type: "i.resource_kind", id: "i.resource_id", entity: resourceType }, permission);
|
|
85
|
+
return Buffer.byteLength(probeSql) > 16 * 1024 || countRecursiveClauses(probeSql) > 6;
|
|
86
|
+
}
|
|
87
|
+
function compileBatchBranch(model, cycles, builder, namespaceSql, identity, shared, joins) {
|
|
88
|
+
const [resourceType, permission] = splitIdentity(identity);
|
|
89
|
+
if (shouldUseSharedBatchBranch(model, cycles, namespaceSql, resourceType, permission)) {
|
|
90
|
+
const branch = compileLinearBatchBranch(model, builder, {
|
|
91
|
+
namespace: namespaceSql,
|
|
92
|
+
resourceType,
|
|
93
|
+
permission,
|
|
94
|
+
index: shared.length,
|
|
95
|
+
});
|
|
96
|
+
shared.push(branch.hits);
|
|
97
|
+
joins.push(branch.join);
|
|
98
|
+
return branch.decision;
|
|
99
|
+
}
|
|
100
|
+
const context = {
|
|
101
|
+
model,
|
|
102
|
+
cycles,
|
|
103
|
+
builder,
|
|
104
|
+
namespace: namespaceSql,
|
|
105
|
+
subject: {
|
|
106
|
+
type: "i.subject_kind",
|
|
107
|
+
id: "i.subject_id",
|
|
108
|
+
entity: resourceType,
|
|
109
|
+
},
|
|
110
|
+
active: new Set(),
|
|
111
|
+
};
|
|
112
|
+
const expression = compileForwardPermission(context, { type: "i.resource_kind", id: "i.resource_id", entity: resourceType }, permission);
|
|
113
|
+
return `WHEN i.resource_kind = ${builder.value(resourceType)} AND i.permission = ${builder.value(permission)} THEN (${expression})`;
|
|
114
|
+
}
|
|
65
115
|
/**
|
|
66
116
|
* Computes allowed IDs actor-first from the reverse subject index. It never
|
|
67
117
|
* enumerates every resource of a kind in application memory or SQL.
|
|
@@ -79,7 +129,7 @@ export function compilePostgresLookup(model, namespace, request) {
|
|
|
79
129
|
// Flattening the LATERAL probe can scan the namespace once per iteration.
|
|
80
130
|
return Object.freeze({
|
|
81
131
|
kind: "lookup",
|
|
82
|
-
text: `WITH RECURSIVE ${subjectReachability(namespaceSql, subject.type, subject.id)} SELECT DISTINCT allowed_resource.resource_id FROM (${allowedResourceIds}) allowed_resource ORDER BY allowed_resource.resource_id`,
|
|
132
|
+
text: `WITH RECURSIVE ${subjectReachability(namespaceSql, subject.type, subject.id, model.columnRelations, builder)} SELECT DISTINCT allowed_resource.resource_id FROM (${allowedResourceIds}) allowed_resource ORDER BY allowed_resource.resource_id`,
|
|
83
133
|
values: builder.values,
|
|
84
134
|
});
|
|
85
135
|
}
|
|
@@ -87,103 +137,24 @@ export function compilePostgresLookup(model, namespace, request) {
|
|
|
87
137
|
* Compiles one descriptor's permission against the fixed integration candidate
|
|
88
138
|
* binding. The caller supplies neither SQL text nor an identifier.
|
|
89
139
|
*/
|
|
90
|
-
export function compilePostgresCandidatePredicate(model, namespace, request) {
|
|
91
|
-
const builder = new QueryBuilder();
|
|
92
|
-
const
|
|
93
|
-
const expression = compilePermission(model, builder, namespaceSql, {
|
|
140
|
+
export function compilePostgresCandidatePredicate(model, namespace, request, options) {
|
|
141
|
+
const builder = new QueryBuilder(options?.paramOffset ?? 1);
|
|
142
|
+
const context = createForwardContext(model, builder, namespace, {
|
|
94
143
|
type: builder.value(request.subject.type),
|
|
95
144
|
id: builder.value(request.subject.id),
|
|
96
145
|
entity: request.subject.type,
|
|
97
|
-
}
|
|
146
|
+
});
|
|
147
|
+
const idColumn = options?.idColumn ??
|
|
148
|
+
`${POSTGRES_AUTHORIZATION_CANDIDATE_BINDING.tableAlias}.${POSTGRES_AUTHORIZATION_CANDIDATE_BINDING.resourceIdColumn}`;
|
|
149
|
+
const expression = compileForwardPermission(context, {
|
|
98
150
|
type: builder.value(request.resourceType),
|
|
99
|
-
id:
|
|
151
|
+
id: idColumn,
|
|
100
152
|
entity: request.resourceType,
|
|
101
|
-
}, request.permission
|
|
153
|
+
}, request.permission);
|
|
102
154
|
return Object.freeze({
|
|
103
155
|
kind: "candidate-predicate",
|
|
104
156
|
text: `(${expression})`,
|
|
105
157
|
values: builder.values,
|
|
106
158
|
});
|
|
107
159
|
}
|
|
108
|
-
function compilePermission(model, builder, namespace, subject, resource, permissionName, active) {
|
|
109
|
-
const definition = model.permissions.find((candidate) => candidate.wireName === permissionName &&
|
|
110
|
-
candidate.entity === resource.entity);
|
|
111
|
-
if (!definition)
|
|
112
|
-
throw new Error(`Postgres policy cannot find permission ${permissionName}.`);
|
|
113
|
-
const identity = `${resource.entity}\u0000${permissionName}`;
|
|
114
|
-
if (active.has(identity))
|
|
115
|
-
throw new Error("Postgres SQL compilation does not yet support a cycle through permissions. Subject-set cycles are supported by recursive relation SQL; rewrite this permission-through cycle or add a dedicated recursive permission compiler.");
|
|
116
|
-
active.add(identity);
|
|
117
|
-
try {
|
|
118
|
-
return compileExpression(model, builder, namespace, subject, resource, definition.expression, active);
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
active.delete(identity);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function compileExpression(model, builder, namespace, subject, resource, expression, active) {
|
|
125
|
-
if (expression.kind === "relation")
|
|
126
|
-
return compileRelationMembership(builder, namespace, subject, resource, expression.relation);
|
|
127
|
-
if (expression.kind === "through") {
|
|
128
|
-
const relationSql = builder.value(expression.relation);
|
|
129
|
-
const throughAlias = builder.throughAlias();
|
|
130
|
-
const related = {
|
|
131
|
-
type: `${throughAlias}.subject_kind`,
|
|
132
|
-
id: `${throughAlias}.subject_id`,
|
|
133
|
-
entity: relatedEntity(model, resource.entity, expression.relation),
|
|
134
|
-
};
|
|
135
|
-
const child = compilePermissionForRelated(model, builder, namespace, subject, related, expression.permission, active);
|
|
136
|
-
// OFFSET 0 keeps each arrow a correlated subplan. Pulling arrows up
|
|
137
|
-
// into semijoins can repeatedly execute the nested membership query.
|
|
138
|
-
return `EXISTS (SELECT 1 FROM ${TUPLES} ${throughAlias} WHERE ${throughAlias}.namespace = ${namespace} AND ${throughAlias}.resource_kind = ${resource.type} AND ${throughAlias}.resource_id = ${resource.id} AND ${throughAlias}.relation = ${relationSql} AND ${throughAlias}.subject_is_wildcard = false AND ${throughAlias}.subject_relation = '' AND (${child}) OFFSET 0)`;
|
|
139
|
-
}
|
|
140
|
-
if (expression.kind === "exclude")
|
|
141
|
-
return `((${compileExpression(model, builder, namespace, subject, resource, expression.include, active)}) AND NOT (${compileExpression(model, builder, namespace, subject, resource, expression.exclude, active)}))`;
|
|
142
|
-
const joiner = expression.kind === "any-of" ? " OR " : " AND ";
|
|
143
|
-
return `(${expression.expressions.map((child) => `(${compileExpression(model, builder, namespace, subject, resource, child, active)})`).join(joiner)})`;
|
|
144
|
-
}
|
|
145
|
-
function compilePermissionForRelated(model, builder, namespace, subject, resource, permission, active) {
|
|
146
|
-
const definition = model.permissions.find((candidate) => candidate.wireName === permission && candidate.entity === resource.entity);
|
|
147
|
-
if (!definition)
|
|
148
|
-
throw new Error("Postgres policy is missing a through permission.");
|
|
149
|
-
return compilePermission(model, builder, namespace, subject, resource, permission, active);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* The recursive UNION deduplicates usersets, including cycles and diamonds.
|
|
153
|
-
* Keep each hop correlated so stale statistics cannot select a repeated
|
|
154
|
-
* namespace scan in place of a tuple key lookup.
|
|
155
|
-
*/
|
|
156
|
-
function compileRelationMembership(builder, namespace, subject, resource, relation) {
|
|
157
|
-
const relationSql = builder.value(relation);
|
|
158
|
-
return `EXISTS (WITH RECURSIVE requested(resource_kind, resource_id, relation) AS (
|
|
159
|
-
VALUES (${resource.type}, ${resource.id}, ${relationSql})
|
|
160
|
-
UNION
|
|
161
|
-
SELECT child.subject_kind, child.subject_id, child.subject_relation
|
|
162
|
-
FROM requested requested_relation
|
|
163
|
-
CROSS JOIN LATERAL (
|
|
164
|
-
SELECT tuple.subject_kind, tuple.subject_id, tuple.subject_relation
|
|
165
|
-
FROM ${TUPLES} tuple
|
|
166
|
-
WHERE tuple.namespace = ${namespace}
|
|
167
|
-
AND tuple.resource_kind = requested_relation.resource_kind
|
|
168
|
-
AND tuple.resource_id = requested_relation.resource_id
|
|
169
|
-
AND tuple.relation = requested_relation.relation
|
|
170
|
-
AND tuple.subject_is_wildcard = false
|
|
171
|
-
AND tuple.subject_relation <> ''
|
|
172
|
-
OFFSET 0
|
|
173
|
-
) child
|
|
174
|
-
)
|
|
175
|
-
SELECT 1
|
|
176
|
-
FROM ${TUPLES} tuple
|
|
177
|
-
JOIN requested requested_relation
|
|
178
|
-
ON requested_relation.resource_kind = tuple.resource_kind
|
|
179
|
-
AND requested_relation.resource_id = tuple.resource_id
|
|
180
|
-
AND requested_relation.relation = tuple.relation
|
|
181
|
-
WHERE tuple.namespace = ${namespace}
|
|
182
|
-
AND ((tuple.subject_is_wildcard = false AND tuple.subject_relation = '' AND tuple.subject_kind = ${subject.type} AND tuple.subject_id = ${subject.id}) OR (tuple.subject_is_wildcard = true AND tuple.subject_kind = ${subject.type}))
|
|
183
|
-
LIMIT 1)`;
|
|
184
|
-
}
|
|
185
|
-
function splitIdentity(value) {
|
|
186
|
-
const index = value.indexOf("\u0000");
|
|
187
|
-
return [value.slice(0, index), value.slice(index + 1)];
|
|
188
|
-
}
|
|
189
160
|
//# sourceMappingURL=compile-postgres-policy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile-postgres-policy.js","sourceRoot":"","sources":["../../src/policy/compile-postgres-policy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile-postgres-policy.js","sourceRoot":"","sources":["../../src/policy/compile-postgres-policy.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAA4B,MAAM,wBAAwB,CAAC;AAC3F,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,oBAAoB,GAGrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,YAAY,E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wBAAwB,CACzC,OAAO,EACP;QACE,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC;QACzC,EAAE,EAAE,QAAQ;QACZ,MAAM,EAAE,OAAO,CAAC,YAAY;KAC7B,EACD,OAAO,CAAC,UAAU,CACnB,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,qBAAqB;QAC3B,IAAI,EAAE,IAAI,UAAU,GAAG;QACvB,MAAM,EAAE,OAAO,CAAC,MAAM;KACvB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { AuthorizationModelDefinition, CompiledPermissionExpression } from "./policy-model.js";
|
|
2
|
+
import type { RecursiveSccPlan } from "./permission-cycles.js";
|
|
3
|
+
import { type QueryBuilder } from "./policy-sql.js";
|
|
4
|
+
export type RecursiveResourceRef = {
|
|
5
|
+
readonly type: string;
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly entity: string;
|
|
8
|
+
};
|
|
9
|
+
type CompileForwardExpression = (resource: RecursiveResourceRef, expression: CompiledPermissionExpression) => string;
|
|
10
|
+
type CompileReverseExpression = (entity: string, expression: CompiledPermissionExpression) => string;
|
|
11
|
+
export type RecursiveForwardInput = {
|
|
12
|
+
readonly model: AuthorizationModelDefinition;
|
|
13
|
+
readonly builder: QueryBuilder;
|
|
14
|
+
readonly namespace: string;
|
|
15
|
+
readonly resource: RecursiveResourceRef;
|
|
16
|
+
readonly entryEntity: string;
|
|
17
|
+
readonly entryPermission: string;
|
|
18
|
+
readonly scc: RecursiveSccPlan;
|
|
19
|
+
readonly compileExpression: CompileForwardExpression;
|
|
20
|
+
};
|
|
21
|
+
export type RecursiveReverseInput = {
|
|
22
|
+
readonly model: AuthorizationModelDefinition;
|
|
23
|
+
readonly builder: QueryBuilder;
|
|
24
|
+
readonly namespace: string;
|
|
25
|
+
readonly entryEntity: string;
|
|
26
|
+
readonly entryPermission: string;
|
|
27
|
+
readonly scc: RecursiveSccPlan;
|
|
28
|
+
readonly compileExpression: CompileReverseExpression;
|
|
29
|
+
};
|
|
30
|
+
export type RecursiveSharedInput = {
|
|
31
|
+
readonly model: AuthorizationModelDefinition;
|
|
32
|
+
readonly builder: QueryBuilder;
|
|
33
|
+
readonly namespace: string;
|
|
34
|
+
readonly cteName: string;
|
|
35
|
+
readonly scc: RecursiveSccPlan;
|
|
36
|
+
readonly baseAliases: ReadonlyMap<string, string>;
|
|
37
|
+
readonly guardAliases: ReadonlyMap<CompiledPermissionExpression, string>;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Compiles a monotonic permission SCC into a top-down recursive EXISTS check.
|
|
41
|
+
* SQL UNION deduplicates `(resource_kind, resource_id, permission_name)` so
|
|
42
|
+
* cyclic tuple graphs terminate safely.
|
|
43
|
+
*/
|
|
44
|
+
export declare function compileRecursiveForwardCheck(input: RecursiveForwardInput): string;
|
|
45
|
+
/**
|
|
46
|
+
* Compiles a monotonic permission SCC into an actor-first bottom-up recursive
|
|
47
|
+
* query returning allowed `resource_id` values for `(entryEntity, entryPermission)`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function compileRecursiveReverseLookup(input: RecursiveReverseInput): string;
|
|
50
|
+
/** Compiles the recursive CTE body for a shared point-check plan. */
|
|
51
|
+
export declare function compileRecursiveSharedBody(input: RecursiveSharedInput): string;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=compile-recursive-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-recursive-policy.d.ts","sourceRoot":"","sources":["../../src/policy/compile-recursive-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAC;AACpG,OAAO,KAAK,EAAoC,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAEjG,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC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Q,CAAC,OAAO,EAAE,YAAY,CAAC;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClD,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,4BAA4B,EAAE,MAAM,CAAC,CAAC;CAC1E,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,qBAAqB,GAAG,MAAM,CAyBjF;AA0DD;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,qBAAqB,GAAG,MAAM,CA0BlF;AAsDD,qEAAqE;AACrE,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,oBAAoB,GAAG,MAAM,CAoB9E"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { findColumnRelation } from "./column-relations.js";
|
|
2
|
+
import { notExpired, TUPLES } from "./policy-sql.js";
|
|
3
|
+
/**
|
|
4
|
+
* Compiles a monotonic permission SCC into a top-down recursive EXISTS check.
|
|
5
|
+
* SQL UNION deduplicates `(resource_kind, resource_id, permission_name)` so
|
|
6
|
+
* cyclic tuple graphs terminate safely.
|
|
7
|
+
*/
|
|
8
|
+
export function compileRecursiveForwardCheck(input) {
|
|
9
|
+
const { builder, scc } = input;
|
|
10
|
+
builder.markRecursive();
|
|
11
|
+
const walkAlias = builder.cteAlias("rec_walk");
|
|
12
|
+
const entryEntitySql = builder.value(input.entryEntity);
|
|
13
|
+
const entryPermSql = builder.value(input.entryPermission);
|
|
14
|
+
const edgeSelects = scc.edges.map((edge) => compileForwardEdge(input, edge, "current_node"));
|
|
15
|
+
const baseBranches = scc.nodes
|
|
16
|
+
.filter((node) => node.base !== undefined)
|
|
17
|
+
.map((node) => compileForwardBaseBranch(input, node));
|
|
18
|
+
return `EXISTS (WITH RECURSIVE ${walkAlias}(resource_kind, resource_id, permission_name) AS (
|
|
19
|
+
SELECT ${entryEntitySql}::text, (${input.resource.id})::text, ${entryPermSql}::text
|
|
20
|
+
WHERE (${input.resource.type})::text = ${entryEntitySql}::text
|
|
21
|
+
UNION
|
|
22
|
+
SELECT next_node.resource_kind, next_node.resource_id, next_node.permission_name
|
|
23
|
+
FROM ${walkAlias} current_node
|
|
24
|
+
CROSS JOIN LATERAL (
|
|
25
|
+
${edgeSelects.join(" UNION ALL ")}
|
|
26
|
+
OFFSET 0
|
|
27
|
+
) next_node
|
|
28
|
+
)
|
|
29
|
+
SELECT 1
|
|
30
|
+
FROM ${walkAlias} reached
|
|
31
|
+
WHERE (${baseBranches.join(" OR ")})
|
|
32
|
+
LIMIT 1)`;
|
|
33
|
+
}
|
|
34
|
+
function compileForwardEdge(input, edge, nodeAlias) {
|
|
35
|
+
const { builder, namespace } = input;
|
|
36
|
+
const tupleAlias = builder.throughAlias();
|
|
37
|
+
const fromEntity = builder.value(edge.fromEntity);
|
|
38
|
+
const fromPerm = builder.value(edge.fromPermission);
|
|
39
|
+
const toEntity = builder.value(edge.toEntity);
|
|
40
|
+
const toPerm = builder.value(edge.toPermission);
|
|
41
|
+
const guardSql = compileForwardGuards(input, edge, nodeAlias);
|
|
42
|
+
const columnRel = findColumnRelation(input.model, edge.fromEntity, edge.relation);
|
|
43
|
+
if (columnRel !== undefined && columnRel.targetEntity === edge.toEntity) {
|
|
44
|
+
return `SELECT ${toEntity}::text AS resource_kind, ${tupleAlias}.${columnRel.targetIdColumn} AS resource_id, ${toPerm}::text AS permission_name
|
|
45
|
+
FROM ${columnRel.table} ${tupleAlias}
|
|
46
|
+
WHERE ${nodeAlias}.resource_kind = ${fromEntity}
|
|
47
|
+
AND ${nodeAlias}.permission_name = ${fromPerm}
|
|
48
|
+
AND ${tupleAlias}.${columnRel.idColumn} = ${nodeAlias}.resource_id
|
|
49
|
+
AND ${tupleAlias}.${columnRel.targetIdColumn} IS NOT NULL${guardSql}`;
|
|
50
|
+
}
|
|
51
|
+
const relation = builder.value(edge.relation);
|
|
52
|
+
return `SELECT ${tupleAlias}.subject_kind AS resource_kind, ${tupleAlias}.subject_id AS resource_id, ${toPerm}::text AS permission_name
|
|
53
|
+
FROM ${TUPLES} ${tupleAlias}
|
|
54
|
+
WHERE ${nodeAlias}.resource_kind = ${fromEntity}
|
|
55
|
+
AND ${nodeAlias}.permission_name = ${fromPerm}
|
|
56
|
+
AND ${tupleAlias}.namespace = ${namespace}
|
|
57
|
+
AND ${tupleAlias}.resource_kind = ${nodeAlias}.resource_kind
|
|
58
|
+
AND ${tupleAlias}.resource_id = ${nodeAlias}.resource_id
|
|
59
|
+
AND ${tupleAlias}.relation = ${relation}
|
|
60
|
+
AND ${tupleAlias}.subject_kind = ${toEntity}
|
|
61
|
+
AND ${tupleAlias}.subject_is_wildcard = false
|
|
62
|
+
AND ${tupleAlias}.subject_relation = ''
|
|
63
|
+
AND ${notExpired(tupleAlias)}${guardSql}`;
|
|
64
|
+
}
|
|
65
|
+
function compileForwardGuards(input, edge, nodeAlias) {
|
|
66
|
+
if (edge.guards.length === 0)
|
|
67
|
+
return "";
|
|
68
|
+
const ref = {
|
|
69
|
+
type: `${nodeAlias}.resource_kind`,
|
|
70
|
+
id: `${nodeAlias}.resource_id`,
|
|
71
|
+
entity: edge.fromEntity,
|
|
72
|
+
};
|
|
73
|
+
const checks = edge.guards.map((guard) => `(${input.compileExpression(ref, guard)})`);
|
|
74
|
+
return ` AND ${checks.join(" AND ")}`;
|
|
75
|
+
}
|
|
76
|
+
function compileForwardBaseBranch(input, node) {
|
|
77
|
+
if (node.base === undefined)
|
|
78
|
+
return "false";
|
|
79
|
+
const entitySql = input.builder.value(node.entity);
|
|
80
|
+
const permSql = input.builder.value(node.permission);
|
|
81
|
+
const ref = {
|
|
82
|
+
type: "reached.resource_kind",
|
|
83
|
+
id: "reached.resource_id",
|
|
84
|
+
entity: node.entity,
|
|
85
|
+
};
|
|
86
|
+
const expr = input.compileExpression(ref, node.base);
|
|
87
|
+
return `(reached.resource_kind = ${entitySql} AND reached.permission_name = ${permSql} AND (${expr}))`;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Compiles a monotonic permission SCC into an actor-first bottom-up recursive
|
|
91
|
+
* query returning allowed `resource_id` values for `(entryEntity, entryPermission)`.
|
|
92
|
+
*/
|
|
93
|
+
export function compileRecursiveReverseLookup(input) {
|
|
94
|
+
const { builder, scc } = input;
|
|
95
|
+
builder.markRecursive();
|
|
96
|
+
const allowedAlias = builder.cteAlias("rec_allowed");
|
|
97
|
+
const baseAnchors = scc.nodes
|
|
98
|
+
.filter((node) => node.base !== undefined)
|
|
99
|
+
.map((node) => compileReverseBaseAnchor(input, node));
|
|
100
|
+
const edgeSelects = scc.edges.map((edge) => compileReverseEdge(input, edge));
|
|
101
|
+
const entryEntitySql = builder.value(input.entryEntity);
|
|
102
|
+
const entryPermSql = builder.value(input.entryPermission);
|
|
103
|
+
return `SELECT DISTINCT reached.resource_id
|
|
104
|
+
FROM (
|
|
105
|
+
WITH RECURSIVE ${allowedAlias}(resource_kind, resource_id, permission_name) AS (
|
|
106
|
+
${baseAnchors.join(" UNION ")}
|
|
107
|
+
UNION
|
|
108
|
+
SELECT child.resource_kind, child.resource_id, child.permission_name
|
|
109
|
+
FROM ${allowedAlias} parent_node
|
|
110
|
+
CROSS JOIN LATERAL (
|
|
111
|
+
${edgeSelects.join(" UNION ALL ")}
|
|
112
|
+
OFFSET 0
|
|
113
|
+
) child
|
|
114
|
+
)
|
|
115
|
+
SELECT resource_id
|
|
116
|
+
FROM ${allowedAlias}
|
|
117
|
+
WHERE resource_kind = ${entryEntitySql} AND permission_name = ${entryPermSql}
|
|
118
|
+
) reached`;
|
|
119
|
+
}
|
|
120
|
+
function compileReverseBaseAnchor(input, node) {
|
|
121
|
+
if (node.base === undefined) {
|
|
122
|
+
return "SELECT ''::text, ''::text, ''::text WHERE false";
|
|
123
|
+
}
|
|
124
|
+
const entitySql = input.builder.value(node.entity);
|
|
125
|
+
const permSql = input.builder.value(node.permission);
|
|
126
|
+
const baseQuery = input.compileExpression(node.entity, node.base);
|
|
127
|
+
return `SELECT ${entitySql}::text AS resource_kind, base_row.resource_id, ${permSql}::text AS permission_name
|
|
128
|
+
FROM (${baseQuery}) base_row`;
|
|
129
|
+
}
|
|
130
|
+
function compileReverseEdge(input, edge) {
|
|
131
|
+
const { builder, namespace } = input;
|
|
132
|
+
const tupleAlias = builder.throughAlias();
|
|
133
|
+
const fromEntity = builder.value(edge.fromEntity);
|
|
134
|
+
const fromPerm = builder.value(edge.fromPermission);
|
|
135
|
+
const toEntity = builder.value(edge.toEntity);
|
|
136
|
+
const toPerm = builder.value(edge.toPermission);
|
|
137
|
+
const columnRel = findColumnRelation(input.model, edge.fromEntity, edge.relation);
|
|
138
|
+
if (columnRel !== undefined && columnRel.targetEntity === edge.toEntity) {
|
|
139
|
+
const guardSql = compileReverseGuards(input, edge, `${tupleAlias}.${columnRel.idColumn}`);
|
|
140
|
+
return `SELECT ${fromEntity}::text AS resource_kind, ${tupleAlias}.${columnRel.idColumn} AS resource_id, ${fromPerm}::text AS permission_name
|
|
141
|
+
FROM ${columnRel.table} ${tupleAlias}
|
|
142
|
+
WHERE parent_node.resource_kind = ${toEntity}
|
|
143
|
+
AND parent_node.permission_name = ${toPerm}
|
|
144
|
+
AND ${tupleAlias}.${columnRel.targetIdColumn} = parent_node.resource_id${guardSql}`;
|
|
145
|
+
}
|
|
146
|
+
const relation = builder.value(edge.relation);
|
|
147
|
+
const guardSql = compileReverseGuards(input, edge, `${tupleAlias}.resource_id`);
|
|
148
|
+
return `SELECT ${tupleAlias}.resource_kind, ${tupleAlias}.resource_id, ${fromPerm}::text AS permission_name
|
|
149
|
+
FROM ${TUPLES} ${tupleAlias}
|
|
150
|
+
WHERE parent_node.resource_kind = ${toEntity}
|
|
151
|
+
AND parent_node.permission_name = ${toPerm}
|
|
152
|
+
AND ${tupleAlias}.namespace = ${namespace}
|
|
153
|
+
AND ${tupleAlias}.resource_kind = ${fromEntity}
|
|
154
|
+
AND ${tupleAlias}.relation = ${relation}
|
|
155
|
+
AND ${tupleAlias}.subject_kind = parent_node.resource_kind
|
|
156
|
+
AND ${tupleAlias}.subject_id = parent_node.resource_id
|
|
157
|
+
AND ${tupleAlias}.subject_is_wildcard = false
|
|
158
|
+
AND ${tupleAlias}.subject_relation = ''
|
|
159
|
+
AND ${notExpired(tupleAlias)}${guardSql}`;
|
|
160
|
+
}
|
|
161
|
+
function compileReverseGuards(input, edge, idExpr) {
|
|
162
|
+
if (edge.guards.length === 0)
|
|
163
|
+
return "";
|
|
164
|
+
const checks = edge.guards.map((guard) => {
|
|
165
|
+
const query = input.compileExpression(edge.fromEntity, guard);
|
|
166
|
+
return `EXISTS (SELECT 1 FROM (${query}) guard_row WHERE guard_row.resource_id = ${idExpr})`;
|
|
167
|
+
});
|
|
168
|
+
return ` AND ${checks.join(" AND ")}`;
|
|
169
|
+
}
|
|
170
|
+
/** Compiles the recursive CTE body for a shared point-check plan. */
|
|
171
|
+
export function compileRecursiveSharedBody(input) {
|
|
172
|
+
const { builder, cteName, scc, baseAliases } = input;
|
|
173
|
+
builder.markRecursive();
|
|
174
|
+
const anchors = scc.nodes
|
|
175
|
+
.filter((node) => baseAliases.has(node.identity))
|
|
176
|
+
.map((node) => {
|
|
177
|
+
const alias = baseAliases.get(node.identity) ?? "";
|
|
178
|
+
const entitySql = builder.value(node.entity);
|
|
179
|
+
const permSql = builder.value(node.permission);
|
|
180
|
+
return `SELECT resource_kind, resource_id, ${permSql}::text AS permission_name FROM ${alias} WHERE resource_kind = ${entitySql}`;
|
|
181
|
+
});
|
|
182
|
+
const edges = scc.edges.map((edge) => compileSharedEdge(input, edge));
|
|
183
|
+
return `${anchors.join(" UNION ")}
|
|
184
|
+
UNION
|
|
185
|
+
SELECT child.resource_kind, child.resource_id, child.permission_name
|
|
186
|
+
FROM ${cteName} parent_node
|
|
187
|
+
CROSS JOIN LATERAL (
|
|
188
|
+
${edges.join(" UNION ALL ")}
|
|
189
|
+
OFFSET 0
|
|
190
|
+
) child`;
|
|
191
|
+
}
|
|
192
|
+
function compileSharedEdge(input, edge) {
|
|
193
|
+
const { builder, namespace, guardAliases } = input;
|
|
194
|
+
const tupleAlias = builder.throughAlias();
|
|
195
|
+
const fromEntity = builder.value(edge.fromEntity);
|
|
196
|
+
const fromPerm = builder.value(edge.fromPermission);
|
|
197
|
+
const toEntity = builder.value(edge.toEntity);
|
|
198
|
+
const toPerm = builder.value(edge.toPermission);
|
|
199
|
+
const columnRel = findColumnRelation(input.model, edge.fromEntity, edge.relation);
|
|
200
|
+
if (columnRel !== undefined && columnRel.targetEntity === edge.toEntity) {
|
|
201
|
+
const colGuards = edge.guards.map((guard) => {
|
|
202
|
+
const alias = guardAliases.get(guard) ?? "";
|
|
203
|
+
return `EXISTS (SELECT 1 FROM ${alias} guard_row WHERE guard_row.resource_kind = ${fromEntity} AND guard_row.resource_id = ${tupleAlias}.${columnRel.idColumn})`;
|
|
204
|
+
});
|
|
205
|
+
const guardSql = colGuards.length > 0 ? ` AND ${colGuards.join(" AND ")}` : "";
|
|
206
|
+
return `SELECT ${fromEntity}::text AS resource_kind, ${tupleAlias}.${columnRel.idColumn} AS resource_id, ${fromPerm}::text AS permission_name
|
|
207
|
+
FROM ${columnRel.table} ${tupleAlias}
|
|
208
|
+
WHERE parent_node.resource_kind = ${toEntity}
|
|
209
|
+
AND parent_node.permission_name = ${toPerm}
|
|
210
|
+
AND ${tupleAlias}.${columnRel.targetIdColumn} = parent_node.resource_id${guardSql}`;
|
|
211
|
+
}
|
|
212
|
+
const relation = builder.value(edge.relation);
|
|
213
|
+
const guardChecks = edge.guards.map((guard) => {
|
|
214
|
+
const alias = guardAliases.get(guard) ?? "";
|
|
215
|
+
return `EXISTS (SELECT 1 FROM ${alias} guard_row WHERE guard_row.resource_kind = ${tupleAlias}.resource_kind AND guard_row.resource_id = ${tupleAlias}.resource_id)`;
|
|
216
|
+
});
|
|
217
|
+
const guardSql = guardChecks.length > 0 ? ` AND ${guardChecks.join(" AND ")}` : "";
|
|
218
|
+
return `SELECT ${tupleAlias}.resource_kind, ${tupleAlias}.resource_id, ${fromPerm}::text AS permission_name
|
|
219
|
+
FROM ${TUPLES} ${tupleAlias}
|
|
220
|
+
WHERE parent_node.resource_kind = ${toEntity}
|
|
221
|
+
AND parent_node.permission_name = ${toPerm}
|
|
222
|
+
AND ${tupleAlias}.namespace = ${namespace}
|
|
223
|
+
AND ${tupleAlias}.resource_kind = ${fromEntity}
|
|
224
|
+
AND ${tupleAlias}.relation = ${relation}
|
|
225
|
+
AND ${tupleAlias}.subject_kind = parent_node.resource_kind
|
|
226
|
+
AND ${tupleAlias}.subject_id = parent_node.resource_id
|
|
227
|
+
AND ${tupleAlias}.subject_is_wildcard = false
|
|
228
|
+
AND ${tupleAlias}.subject_relation = ''
|
|
229
|
+
AND ${notExpired(tupleAlias)}${guardSql}`;
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=compile-recursive-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-recursive-policy.js","sourceRoot":"","sources":["../../src/policy/compile-recursive-policy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,EAAqB,MAAM,iBAAiB,CAAC;AA2CxE;;;;GAIG;AACH,MAAM,UAAU,4BAA4B,CAAC,KAA4B;IACvE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC;IAC/B,OAAO,CAAC,aAAa,EAAE,CAAC;IACxB,MAAM,SAAS,GAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACxD,MAAM,YA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