Skip to content

An open-source, self-hosted system for apps built with web technologies.

Replace the System permission with all

zohayrslileh36a0d5c24dbe
diff --git a/scripts/contracts/client-system-access.ts b/scripts/contracts/client-system-access.ts
index 720c9a2..9ed95b2 100644
--- a/scripts/contracts/client-system-access.ts
+++ b/scripts/contracts/client-system-access.ts
@@ -12,8 +12,8 @@ const authManager = {
async grantsPermission(process: string, name: string, values: readonly string[]) {
assert.equal(process, owner.identity)
- assert.equal(name, "system")
- assert.deepEqual(values, ["all"])
+ assert.equal(name, "all")
+ assert.deepEqual(values, [])
return unrestricted
}
diff --git a/scripts/contracts/permissions.ts b/scripts/contracts/permissions.ts
index 0af1e72..f6ab500 100644
--- a/scripts/contracts/permissions.ts
+++ b/scripts/contracts/permissions.ts
@@ -38,6 +38,8 @@ assert(catalog.grants(["read", "write"], ["write"]))
assert(!catalog.grants(false, ["read"]))
assert(!catalog.grants(null, []))
assert(catalog.grants([], []))
+assert(catalog.allows("files", [], null, ["read", "write"]))
+assert(!catalog.allows("files", null, ["read"], ["write"]))
assert.equal(catalog.combine("files", null, false), null)
assert.deepEqual(catalog.combine("files", ["write"], ["read"]), ["read", "write"])
assert.equal(catalog.effective("files", null, false), false)
@@ -64,17 +66,18 @@ assert.throws(() => new PermissionCatalog({
}
}), /invalid default/)
-assert.deepEqual(permissionCatalog.definition("system"), {
- values: ["all"],
- default: ["all"],
- title: "System",
- description: "Access every System capability."
+assert.deepEqual(permissionCatalog.definition("all"), {
+ values: [],
+ default: [],
+ title: "All permissions",
+ description: "Grant every available Client permission."
})
-assert.deepEqual(permissionCatalog.resolve("system", true), ["all"])
-assert.deepEqual(permissionCatalog.declarations({ system: true }), { system: ["all"] })
-assert(permissionCatalog.grants(["all"], ["all"]))
-assert(!permissionCatalog.grants(null, ["all"]))
-assert(permissionCatalog.needReload("system", null, ["all"]))
-assert(permissionCatalog.needReload("system", ["all"], null))
-assert(!permissionCatalog.needReload("system", ["all"], ["all"]))
+assert.deepEqual(permissionCatalog.resolve("all", true), [])
+assert.deepEqual(permissionCatalog.declarations({ all: true }), { all: [] })
+assert(permissionCatalog.grants([], []))
+assert(permissionCatalog.granted([]))
+assert(!permissionCatalog.granted(null))
+assert(permissionCatalog.needReload("all", null, []))
+assert(permissionCatalog.needReload("all", [], null))
+assert(!permissionCatalog.needReload("all", [], []))
assert.throws(() => permissionCatalog.definition("files"), /does not know/)
diff --git a/source/client/view/components/desktop-host/system-access.ts b/source/client/view/components/desktop-host/system-access.ts
index 076f7f6..3ebfc1a 100644
--- a/source/client/view/components/desktop-host/system-access.ts
+++ b/source/client/view/components/desktop-host/system-access.ts
@@ -21,7 +21,7 @@ export default class SystemAccess {
public async all() {
- return await this.authManager.grantsPermission(this.pane, "system", ["all"])
+ return await this.authManager.grantsPermission(this.pane, "all", [])
}
public async program(program: Program) {
diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
index 833d32f..81a318b 100644
--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts
@@ -803,14 +803,14 @@ export default class ProcessManager extends TheLink {
this.hostTraffic,
- permissionCatalog.grants(permissionCatalog.effective(
+ permissionCatalog.granted(permissionCatalog.effective(
- "system",
+ "all",
- program.clientPermissions.system ?? null,
+ program.clientPermissions.all ?? null,
- this.authManager.programManager.permission(program, "system")
- ), ["all"])
+ this.authManager.programManager.permission(program, "all")
+ ))
)
this.processes.set(identity, process)
@@ -1383,7 +1383,18 @@ export default class ProcessManager extends TheLink {
/** Tests one concrete permission against this Process's effective grants. */
public grants(identity: string, name: string, requested: readonly string[]) {
- return permissionCatalog.grants(this.effectivePermission(this.find(identity), name), requested)
+ const process = this.find(identity)
+
+ return permissionCatalog.allows(
+
+ name,
+
+ this.effectivePermission(process, "all"),
+
+ this.effectivePermission(process, name),
+
+ requested
+ )
}
/** Resolves one permission request through declarations, grants, then the owner. */
@@ -1402,6 +1413,11 @@ export default class ProcessManager extends TheLink {
const stored = this.authManager.programManager.permission(process.program, name)
const effective = this.effectivePermission(process, name, stored)
+ if (name !== "all" && permissionCatalog.granted(this.effectivePermission(process, "all"))) {
+
+ return permissionChange([...permissionCatalog.definition(name).values], false)
+ }
+
if (permissionCatalog.grants(effective, requested)) return permissionChange(effective, false)
if (effective === false) return Object.freeze({ permission: false, needReload: false })
@@ -1418,7 +1434,7 @@ export default class ProcessManager extends TheLink {
if (needReload) {
- process.setClientSameOrigin(permissionCatalog.grants(next, ["all"]))
+ process.setClientSameOrigin(permissionCatalog.granted(next))
await this.$outbound.publish("/client-access", process.identity, process.hosted())
}
@@ -1473,7 +1489,7 @@ export default class ProcessManager extends TheLink {
needReload = true
- process.setClientSameOrigin(permissionCatalog.grants(this.effectivePermission(process, "system", permission), ["all"]))
+ if (name === "all") process.setClientSameOrigin(permissionCatalog.granted(this.effectivePermission(process, name, permission)))
await this.$outbound.publish("/client-access", process.identity, process.hosted())
}
diff --git a/source/server/core/permissions.ts b/source/server/core/permissions.ts
index 52fe634..549ee7b 100644
--- a/source/server/core/permissions.ts
+++ b/source/server/core/permissions.ts
@@ -106,6 +106,20 @@ export class PermissionCatalog {
return Array.isArray(grant) && requested.every(value => grant.includes(value))
}
+ /** Whether one value-less or valued permission is present at all. */
+ public granted(permission: PermissionGrant) {
+
+ return Array.isArray(permission)
+ }
+
+ /** Applies the value-less all grant before one permission's own values. */
+ public allows(name: string, all: PermissionGrant, permission: PermissionGrant, requested: readonly string[]) {
+
+ this.definition(name)
+
+ return this.granted(all) || this.grants(permission, requested)
+ }
+
public combine(name: string, ...grants: PermissionGrant[]): Permission {
const present = grants.filter((grant): grant is readonly string[] => Array.isArray(grant))
@@ -172,16 +186,11 @@ function unique(values: string[]) {
/** The complete permission domain recognized by this System release. */
export const permissionCatalog = new PermissionCatalog({
- system: {
- values: ["all"],
- default: ["all"],
- title: "System",
- description: "Access every System capability.",
- requiresReload: (before, permission) => grantsAll(before) !== grantsAll(permission)
+ all: {
+ values: [],
+ default: [],
+ title: "All permissions",
+ description: "Grant every available Client permission.",
+ requiresReload: (before, permission) => Array.isArray(before) !== Array.isArray(permission)
}
})
-
-function grantsAll(permission: Permission) {
-
- return Array.isArray(permission) && permission.includes("all")
-}