@openinc/parse-server-opendash 4.15.1 → 4.16.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.
|
@@ -38,7 +38,8 @@ export declare namespace Permissions {
|
|
|
38
38
|
metaadmin = "meta:can-see-admin",
|
|
39
39
|
chatadmin = "chat:can-see-admin",
|
|
40
40
|
changelog = "changelog:can-see-app",
|
|
41
|
-
changelog_restore = "changelog:can-restore-deleted"
|
|
41
|
+
changelog_restore = "changelog:can-restore-deleted",
|
|
42
|
+
tenant_admin = "opendash:can-admin-tenants"
|
|
42
43
|
}
|
|
43
44
|
enum GTFS {
|
|
44
45
|
global = "gtfs:can-access-global"
|
|
@@ -84,6 +84,12 @@ var Permissions;
|
|
|
84
84
|
// Restoring a deleted object writes with the master key, so it is kept
|
|
85
85
|
// separate from merely reading the changelog.
|
|
86
86
|
CORE["changelog_restore"] = "changelog:can-restore-deleted";
|
|
87
|
+
// Cross-tenant administration: `defaultHandler` honours a submitted
|
|
88
|
+
// `tenant` only for a holder, and the frontend offers the tenant field to
|
|
89
|
+
// them alone. Registered so od-admin holds it without manual setup — and
|
|
90
|
+
// *only* od-admin: the `Permission` beforeSave hook keeps the tenant roles
|
|
91
|
+
// off it, which every other registered permission is granted to.
|
|
92
|
+
CORE["tenant_admin"] = "opendash:can-admin-tenants";
|
|
87
93
|
})(CORE = Permissions.CORE || (Permissions.CORE = {}));
|
|
88
94
|
let GTFS;
|
|
89
95
|
(function (GTFS) {
|
package/dist/hooks/Permission.js
CHANGED
|
@@ -13,10 +13,45 @@ const masterKeyPermission = [
|
|
|
13
13
|
"opendash:source:write-tag-ignore-tenant-prefix",
|
|
14
14
|
"opendash:source:write-tag-group",
|
|
15
15
|
];
|
|
16
|
+
/**
|
|
17
|
+
* Permissions no tenant role may hold, whichever tenant the object is filed
|
|
18
|
+
* under.
|
|
19
|
+
*
|
|
20
|
+
* A permission is held by whoever can *read* its object (`hasPermission`), and
|
|
21
|
+
* `defaultAclHandler` grants `od-tenant-admin-<tenant>` read and write on every
|
|
22
|
+
* object with a tenant — on purpose for ordinary permissions, which a tenant
|
|
23
|
+
* admin holds and hands on within their tenant. For a cross-tenant permission
|
|
24
|
+
* that default is an escalation: `opendash:can-admin-tenants` is registered for
|
|
25
|
+
* every tenant on startup, so it would make every tenant's admin a cross-tenant
|
|
26
|
+
* one. Granting it to anyone beyond od-admin stays possible, with the master
|
|
27
|
+
* key, through a user or a role of its own in the ACL.
|
|
28
|
+
*/
|
|
29
|
+
const crossTenantPermission = ["opendash:can-admin-tenants"];
|
|
30
|
+
/**
|
|
31
|
+
* Take back the read/write `defaultAclHandler` gave the object's tenant roles.
|
|
32
|
+
* Runs on every save, master key included, so re-saving an object written
|
|
33
|
+
* before this existed is enough to repair it.
|
|
34
|
+
*/
|
|
35
|
+
function revokeTenantRoles(object) {
|
|
36
|
+
const tenantId = object.get("tenant")?.id;
|
|
37
|
+
const acl = object.getACL();
|
|
38
|
+
if (!tenantId || !acl)
|
|
39
|
+
return;
|
|
40
|
+
for (const role of [
|
|
41
|
+
`od-tenant-admin-${tenantId}`,
|
|
42
|
+
`od-tenant-user-${tenantId}`,
|
|
43
|
+
]) {
|
|
44
|
+
acl.setRoleReadAccess(role, false);
|
|
45
|
+
acl.setRoleWriteAccess(role, false);
|
|
46
|
+
}
|
|
47
|
+
object.setACL(acl);
|
|
48
|
+
}
|
|
16
49
|
async function init() {
|
|
17
50
|
(0, index_js_1.beforeSaveHook)(index_js_2.Permission, async (request) => {
|
|
18
51
|
const { object, original, user } = request;
|
|
19
|
-
if ((masterKeyPermission.includes(object.get("key")) ||
|
|
52
|
+
if ((masterKeyPermission.includes(object.get("key")) ||
|
|
53
|
+
(object.get("key") && object.get("key").startsWith("master:"))) &&
|
|
54
|
+
!request.master) {
|
|
20
55
|
throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, `User is not allowed to create or update permission with key '${object.get("key")}' without master key`);
|
|
21
56
|
}
|
|
22
57
|
await (0, index_js_1.defaultHandler)(request);
|
|
@@ -24,6 +59,9 @@ async function init() {
|
|
|
24
59
|
allowCustomACL: true,
|
|
25
60
|
denyTenantUserRead: true,
|
|
26
61
|
});
|
|
62
|
+
if (crossTenantPermission.includes(object.get("key"))) {
|
|
63
|
+
revokeTenantRoles(object);
|
|
64
|
+
}
|
|
27
65
|
});
|
|
28
66
|
(0, index_js_1.afterSaveHook)(index_js_2.Permission, async ({ object, original, user }) => {
|
|
29
67
|
// TODO
|