An open-source, self-hosted system for apps built with web technologies.
Consolidate permissions under Programs
zohayrslileh273855cf449b
diff --git a/scripts/contracts/process-lifecycle.ts b/scripts/contracts/process-lifecycle.tsindex 905c9a6..8d761f3 100644--- a/scripts/contracts/process-lifecycle.ts+++ b/scripts/contracts/process-lifecycle.ts@@ -51,36 +51,6 @@ async function register(manager: ProcessManager, identity: string) {return await manager.register(identity, null, program(identity), {}, launch, null, false, null, null)}-// A Process permission handle represents only its temporary assignment layer.-// Coverage within that layer includes its own `all`, but never consults the-// Program's persistent or declared values.-{- const manager = processManager()- const process = await register(manager, "temporary-permissions")-- assert.equal(manager.processPermission(process, "network"), null)- assert.deepEqual(manager.processPermissions(process), {})- assert.equal(manager.processAllows(process, "network", ["https://api.example.com"]), false)- assert.equal(manager.grants(process.identity, "network", ["https://api.example.com"]), false)-- await manager.setProcessPermission(process, "network", ["https://api.example.com/v1/**"])-- assert.deepEqual(manager.processPermission(process, "network"), ["https://api.example.com/v1/**"])- assert(manager.processAllows(process, "network", ["https://api.example.com/v1/users"]))- assert(!manager.processAllows(process, "network", ["https://other.example.com/users"]))- assert(manager.grants(process.identity, "network", ["https://api.example.com/v1/users"]))-- await manager.setProcessPermission(process, "all", true)-- assert(manager.processAllows(process, "appearance"))- assert(manager.grants(process.identity, "appearance", []))-- await manager.deleteProcessPermission(process, "network")- await manager.deleteProcessPermission(process, "all")-- assert.deepEqual(manager.processPermissions(process), {})-}-// Parentage retains the exact Process entity after it exits. Absence and// ended lineage therefore remain distinct states at every System boundary.{diff --git a/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/client/core/link-manager/auth-manager/process-manager/process-manager.tsindex aab9cb3..d4b244a 100644--- a/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts+++ b/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts@@ -5,7 +5,7 @@ import { Publish, Subscribe } from "@the-link/core/decorators"import { TheLink } from "@the-link/core"import AuthManager from "../auth-manager"import Process from "./process"-import { type ClientLaunch, type PermissionInput, type PermissionName, type ServerLaunch } from "@phreshos/core"+import { type ClientLaunch, type ServerLaunch } from "@phreshos/core"import { type TrafficKind } from "@server/core/link-manager/auth-manager/process-manager/process-traffic"import { type ServiceKey, type WindowLayer } from "@phreshos/core"import { type ServiceScope } from "@server/core/link-manager/auth-manager/process-manager/endpoint-services"@@ -192,16 +192,6 @@ export default class ProcessManager extends TheLink {await this.$outbound.publish("/endpoint/stop", identity, which)}- public async permissions<Name extends PermissionName>(- subject: unknown,- operation: "all" | "get" | "allows" | "set" | "delete",- name?: Name,- value?: PermissionInput<Name>- ) {-- return await this.$outbound.publishFirst("/permissions", subject, operation, name, value)- }-/** Announces a locally changed counterpart to desktop representations. */public async changed() {diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.tsindex 3e5858e..505d193 100644--- a/source/client/view/components/desktop-host/host.ts+++ b/source/client/view/components/desktop-host/host.ts@@ -633,44 +633,6 @@ export default function host(authManager: AuthManager, pane: string, desktop: ()return []}- if (word === "process-permissions") {-- await access.requireAll()-- const operation = args[1]-- if (operation !== "all" && operation !== "get" && operation !== "allows" && operation !== "set" && operation !== "delete") throw new Error(`The System does not know the Process permission operation "${String(operation)}"`)-- const target = address(holdProcess(args[0]))-- if (operation === "all") return [await processManager.permissions(target, operation)]-- const permission = parsePermissionName(args[2])-- if (operation === "allows") return [await processManager.permissions(- target,- operation,- permission,- args[3] as PermissionRequest<typeof permission>- )]-- if (operation === "set") {-- await processManager.permissions(- target,- operation,- permission,- args[3] as Exclude<PermissionInput<typeof permission>, null>- )-- return []- }-- await processManager.permissions(target, operation, permission)-- return []- }-if (word === "startup") {const program = await permittedProgram(args[0])diff --git a/source/client/view/structure/desktop/taskbar/system/system-dialogs.tsx b/source/client/view/structure/desktop/taskbar/system/system-dialogs.tsxindex 29ffbf9..0678c3e 100644--- a/source/client/view/structure/desktop/taskbar/system/system-dialogs.tsx+++ b/source/client/view/structure/desktop/taskbar/system/system-dialogs.tsx@@ -115,9 +115,7 @@ function PermissionRequest({ dialog, description, decide }: PermissionRequestPro<TaskbarButton small autoFocus disabled={decision.isPending} onClick={() => decision.safeExecute(null)}>Later</TaskbarButton>- <TaskbarButton small disabled={decision.isPending} onClick={() => decision.safeExecute("process")}>Allow for this Process</TaskbarButton>-- <TaskbarButton small disabled={decision.isPending} onClick={() => decision.safeExecute("always")}>Always allow</TaskbarButton>+ <TaskbarButton small disabled={decision.isPending} onClick={() => decision.safeExecute(true)}>Allow for this Program</TaskbarButton></div>diff --git a/source/server/core/dialog-manager.ts b/source/server/core/dialog-manager.tsindex 2d63b06..1cbe896 100644--- a/source/server/core/dialog-manager.ts+++ b/source/server/core/dialog-manager.ts@@ -181,7 +181,7 @@ export interface PermissionDialog {readonly process: Readonly<{ identity: string, name: string | null }>}-export type PermissionChoice = "process" | "always" | false | null+export type PermissionChoice = true | false | nullexport type SystemDialog = ServerCrashDialog | PermissionDialog@@ -196,7 +196,7 @@ interface PendingPermission {function isPermissionChoice(value: unknown): value is PermissionChoice {- return value === "process" || value === "always" || value === false || value === null+ return value === true || value === false || value === null}export type DialogManagerSnapshot = ReturnType<DialogManager["toJSON"]>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.tsindex 98fc5bd..464f9c2 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@@ -27,7 +27,6 @@ import {type PermissionName,type PermissionRequest,type PermissionValue,- type Permissions,type ServerLaunch,type ServiceKey,type WindowGeometry,@@ -1527,110 +1526,12 @@ export default class ProcessManager extends TheLink {return this.authManager.programManager.permission(this.find(identity).program, name)}- /** Reads one assignment from this Process's temporary layer only. */- public processPermission<Name extends PermissionName>(process: Process, name: Name): Permission<Name> {-- return clonePermission((process.permissions.get(name) ?? null) as Permission<Name>)- }-- /** Returns an independent snapshot of this Process's temporary layer. */- public processPermissions(process: Process): Permissions {-- return clonePermissions(Object.fromEntries(process.permissions) as Permissions)- }-- /** Tests one request against this Process's temporary layer only. */- public processAllows<Name extends PermissionName>(- process: Process,- name: Name,- input: PermissionRequest<Name> = true- ) {-- const requested = permissionCatalog.resolve(name, input)-- if (!Array.isArray(requested)) throw new Error("A permission check must be true or a list of values")-- return permissionCatalog.allows(- name,- this.processPermission(process, "all"),- this.processPermission(process, name),- requested- )- }-- /** Replaces one assignment in this Process's temporary layer. */- public async setProcessPermission<Name extends PermissionName>(- process: Process,- name: Name,- input: Exclude<PermissionInput<Name>, null>- ) {-- const before = this.processPermission(process, name)- const permission = permissionCatalog.resolve(name, input)-- if (permission === null) throw new Error("A temporary Process permission cannot be null")-- if (permissionCatalog.changed(before, permission)) process.permissions.set(name, permission)-- await this.processPermissionChanged(process, name, before, permission)- }-- /** Removes one assignment from this Process's temporary layer. */- public async deleteProcessPermission<Name extends PermissionName>(process: Process, name: Name) {-- const before = this.processPermission(process, name)-- process.permissions.delete(name)-- await this.processPermissionChanged(process, name, before, null)- }-- @Connect("/permissions")- protected async permissionOperations(subject: unknown, operation: unknown, name?: unknown, value?: unknown) {-- const process = this.system.holdProcess(subject)-- if (operation === "all") return this.processPermissions(process)- if (operation === "get") return this.processPermission(process, parsePermissionName(name))- if (operation === "allows") {-- const permission = parsePermissionName(name)-- return this.processAllows(process, permission, value as PermissionRequest<typeof permission>)- }- if (operation === "set") {-- const permission = parsePermissionName(name)-- await this.setProcessPermission(process, permission, value as Exclude<PermissionInput<typeof permission>, null>)-- return- }- if (operation === "delete") {-- await this.deleteProcessPermission(process, parsePermissionName(name))-- return- }-- throw new Error(`The System does not know the Process permission operation "${String(operation)}"`)- }-- /** Tests one concrete permission against this Process's effective grants. */+ /** Tests one concrete permission for the Program executing this Process. */public grants<Name extends PermissionName>(identity: string, name: Name, requested: readonly PermissionValue<Name>[]) {const process = this.find(identity)- return permissionCatalog.allows(-- name,-- this.effectivePermission(process, "all"),-- this.effectivePermission(process, name),-- requested- )+ return this.authManager.programManager.grantsPermission(process.program, name, requested)}/** Tests one native Storage target against this Process's effective grants. */@@ -1638,12 +1539,7 @@ export default class ProcessManager extends TheLink {const process = this.find(identity)- return permissionCatalog.allowsStorage(- this.effectivePermission(process, "all"),- this.effectivePermission(process, "storage"),- path,- operation- )+ return this.authManager.programManager.grantsStorage(process.program, path, operation)}/** Resolves one permission request through declarations, grants, then the owner. */@@ -1663,11 +1559,10 @@ export default class ProcessManager extends TheLink {if (!Array.isArray(requested)) throw new Error("A permission request must be true or a list of values")const declared = process.program.clientPermissions[name] ?? null- const temporary = process.permissions.get(name) ?? nullconst stored = this.authManager.programManager.permission(process.program, name)- const effective = this.effectivePermission(process, name, stored)+ const effective = this.authManager.programManager.effectivePermission(process.program, name, stored)- if (name !== "all" && permissionCatalog.granted(this.effectivePermission(process, "all"))) {+ if (name !== "all" && permissionCatalog.granted(this.authManager.programManager.effectivePermission(process.program, "all"))) {return permissionChange([...permissionCatalog.definition(name).default], false)}@@ -1677,22 +1572,10 @@ export default class ProcessManager extends TheLink {const choice = await this.authManager.dialogManager.requestPermission(process, request, name, requested)- if (choice === "process") {-- const permission = permissionCatalog.merge(name, temporary, requested)- const next = permissionCatalog.effective(name, declared, permission, stored)-- const needReload = permissionCatalog.needReload(name, effective, next)-- await this.setProcessPermission(process, name, permission)-- return permissionChange(next, needReload)- }-- if (choice === "always") {+ if (choice === true) {const permission = permissionCatalog.merge(name, stored, requested)- const next = permissionCatalog.effective(name, declared, temporary, permission)+ const next = permissionCatalog.effective(name, declared, permission)await this.authManager.programManager.setPermission(process.program, name, permission)@@ -1702,20 +1585,6 @@ export default class ProcessManager extends TheLink {return Object.freeze({ permission: choice, needReload: false })}- private effectivePermission<Name extends PermissionName>(- process: Process,- name: Name,- stored = this.authManager.programManager.permission(process.program, name)- ) {-- return permissionCatalog.effective(- name,- process.program.clientPermissions[name] ?? null,- process.permissions.get(name) ?? null,- stored- )- }-/** Publishes the Client access shape changed by one stored grant. */public async storedPermissionChanged<Name extends PermissionName>(program: Program,@@ -1729,48 +1598,23 @@ export default class ProcessManager extends TheLink {if (process.program !== program || !process.client) continueconst declared = program.clientPermissions[name] ?? null- const temporary = process.permissions.get(name) ?? nullconst changed = permissionCatalog.needReload(name,- permissionCatalog.effective(name, declared, temporary, before),+ permissionCatalog.effective(name, declared, before),- permissionCatalog.effective(name, declared, temporary, permission)+ permissionCatalog.effective(name, declared, permission))if (!changed) continue- if (name === "all") process.setClientSameOrigin(permissionCatalog.granted(this.effectivePermission(process, name, permission)))+ if (name === "all") process.setClientSameOrigin(permissionCatalog.granted(this.authManager.programManager.effectivePermission(program, name, permission)))await this.$outbound.publish("/client-access", process.identity, process.hosted())}}- private async processPermissionChanged<Name extends PermissionName>(- process: Process,- name: Name,- before: Permission<Name>,- permission: Permission<Name>- ) {-- if (!process.client) return-- const declared = process.program.clientPermissions[name] ?? null- const stored = this.authManager.programManager.permission(process.program, name)- const changed = permissionCatalog.needReload(- name,- permissionCatalog.effective(name, declared, before, stored),- permissionCatalog.effective(name, declared, permission, stored)- )-- if (!changed) return-- if (name === "all") process.setClientSameOrigin(permissionCatalog.granted(this.effectivePermission(process, name)))-- await this.$outbound.publish("/client-access", process.identity, process.hosted())- }-public cancelPermission(identity: string, request: string) {const process = this.processes.get(identity)@@ -1849,37 +1693,6 @@ export default class ProcessManager extends TheLink {throw new Error(`The System does not know the Program permission operation "${String(operation)}"`)}- if (word === "process-permissions") {-- const target = this.system.holdProcess(rest[0], process)- const operation = rest[1]-- if (operation === "all") return [this.processPermissions(target)]- if (operation === "get") return [this.processPermission(target, parsePermissionName(rest[2]))]- if (operation === "allows") {-- const permission = parsePermissionName(rest[2])-- return [this.processAllows(target, permission, rest[3] as PermissionRequest<typeof permission>)]- }- if (operation === "set") {-- const permission = parsePermissionName(rest[2])-- await this.setProcessPermission(target, permission, rest[3] as Exclude<PermissionInput<typeof permission>, null>)-- return []- }- if (operation === "delete") {-- await this.deleteProcessPermission(target, parsePermissionName(rest[2]))-- return []- }-- throw new Error(`The System does not know the Process permission operation "${String(operation)}"`)- }-if (word === "program-agent") {const program = this.system.holdProgram(rest[0], process.program)@@ -2962,16 +2775,6 @@ function permissionChange<Name extends PermissionName>(permission: Permission<Na})}-function clonePermission<Name extends PermissionName>(permission: Permission<Name>): Permission<Name> {-- return Array.isArray(permission) ? [...permission] : permission-}--function clonePermissions(permissions: Permissions): Permissions {-- return Object.fromEntries(Object.entries(permissions).map(([name, permission]) => [name, clonePermission(permission)]))-}-// Where an answer goes, read out of the question itself.//// A question is named by its asker before it leaves — which half ofdiff --git a/source/server/core/link-manager/auth-manager/process-manager/process.ts b/source/server/core/link-manager/auth-manager/process-manager/process.tsindex 1582459..05f8dbd 100644--- a/source/server/core/link-manager/auth-manager/process-manager/process.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/process.ts@@ -8,7 +8,6 @@ import { randomUUID } from "node:crypto"import { type Layer } from "@phreshos/core"import { Tunnel } from "@the-link/core"import type { ServerRuntime } from "@server/core/server-runtime"-import type { Permission, PermissionName } from "@phreshos/core"/*** One live execution of a Program.@@ -71,9 +70,6 @@ export default class Process {// either life.public readonly parent: Process | null- /** User grants retained only for this Process lifetime. */- public readonly permissions = new Map<PermissionName, Exclude<Permission, null>>()-private readonly hostTraffic: HostTrafficprivate clientSameOrigin: booleandiff --git a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/server/core/link-manager/auth-manager/program-manager/program-manager.tsindex 23e1a84..e793534 100644--- a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts+++ b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts@@ -27,6 +27,7 @@ import {type PermissionInput,type PermissionName,type PermissionRequest,+ type PermissionValue,type Permissions} from "@phreshos/core"@@ -169,7 +170,7 @@ export default class ProgramManager extends TheLink {return clonePermissions(readPermissions(program))}- /** Tests one requested value against this Program's persistent layer only. */+ /** Tests one requested value against this Program's stored permissions. */public allowsPermission<Name extends PermissionName>(program: Program,name: Name,@@ -190,6 +191,42 @@ export default class ProgramManager extends TheLink {)}+ /** Resolves one permission from this Program's declaration and stored value. */+ public effectivePermission<Name extends PermissionName>(+ program: Program,+ name: Name,+ stored = this.permission(program, name)+ ) {++ return permissionCatalog.effective(name, program.clientPermissions[name] ?? null, stored)+ }++ /** Tests one request against this Program's complete effective authority. */+ public grantsPermission<Name extends PermissionName>(+ program: Program,+ name: Name,+ requested: readonly PermissionValue<Name>[]+ ) {++ return permissionCatalog.allows(+ name,+ this.effectivePermission(program, "all"),+ this.effectivePermission(program, name),+ requested+ )+ }++ /** Tests one native Storage operation against this Program's authority. */+ public grantsStorage(program: Program, path: string, operation?: "read" | "write" | "delete") {++ return permissionCatalog.allowsStorage(+ this.effectivePermission(program, "all"),+ this.effectivePermission(program, "storage"),+ path,+ operation+ )+ }+/** Stores one canonical user grant and propagates its effective access change. */public async setPermission<Name extends PermissionName>(program: Program,