@eum-agent/authorization-policy 1.1.0 → 1.2.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/index.js +40 -6
- package/package.json +3 -3
- package/ui/ui.js +34 -2
package/dist/index.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
+
import { dirname } from "node:path";
|
|
1
2
|
import { randomUUID } from "node:crypto";
|
|
2
3
|
import { existsSync } from "node:fs";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { z } from "zod";
|
|
5
6
|
//#region src/schema.ts
|
|
6
|
-
/** Default policy owned by the authorization extension. */
|
|
7
|
-
/** Missing owner settings use Ask; unknown values are refused. */
|
|
8
7
|
const ApprovalPolicy = z.enum([
|
|
9
8
|
"ask",
|
|
10
9
|
"deny",
|
|
11
10
|
"allow"
|
|
12
11
|
]);
|
|
13
|
-
/** Complete persisted authorization settings. */
|
|
14
12
|
const AuthorizationSettings = z.object({ policy: ApprovalPolicy }).strict();
|
|
15
13
|
//#endregion
|
|
16
14
|
//#region src/index.ts
|
|
17
|
-
/** Owns the default authorization policy and its settings methods. */
|
|
18
15
|
const plugin = {
|
|
19
16
|
name: "@eum-agent/authorization-policy",
|
|
20
|
-
requires: [
|
|
17
|
+
requires: [
|
|
18
|
+
"approval-mechanism",
|
|
19
|
+
"configuration-transactions",
|
|
20
|
+
"restricted-execution"
|
|
21
|
+
],
|
|
21
22
|
provides: ["authorization-strategy", "authorization-settings-participant"],
|
|
22
23
|
apply(ctx) {
|
|
23
24
|
const storage = ctx.storage.open();
|
|
@@ -45,6 +46,11 @@ const plugin = {
|
|
|
45
46
|
return `strategy:${epoch}:${id ?? "decision"}`;
|
|
46
47
|
},
|
|
47
48
|
decide(authority, request, approval) {
|
|
49
|
+
if (restrictions?.effective(authority.sessionId)) return {
|
|
50
|
+
kind: "result",
|
|
51
|
+
result: { kind: "unavailable" },
|
|
52
|
+
source: "policy-deny"
|
|
53
|
+
};
|
|
48
54
|
const policy = read().policy;
|
|
49
55
|
if (policy === "deny") return {
|
|
50
56
|
kind: "result",
|
|
@@ -60,6 +66,11 @@ const plugin = {
|
|
|
60
66
|
},
|
|
61
67
|
ask(authority, request) {
|
|
62
68
|
ctx.signal.throwIfAborted();
|
|
69
|
+
if (restrictions?.effective(authority.sessionId)) return {
|
|
70
|
+
kind: "result",
|
|
71
|
+
result: { kind: "unavailable" },
|
|
72
|
+
source: "policy-deny"
|
|
73
|
+
};
|
|
63
74
|
const id = strategy.askQuestionId(request.id);
|
|
64
75
|
if (authority.answer && !authority.answer.answers.some((answer) => answer.questionId === id)) return {
|
|
65
76
|
kind: "result",
|
|
@@ -73,6 +84,26 @@ const plugin = {
|
|
|
73
84
|
}
|
|
74
85
|
};
|
|
75
86
|
ctx.services.provide("authorization-strategy", strategy);
|
|
87
|
+
const restrictions = ctx.services.get("restricted-execution");
|
|
88
|
+
if (restrictions) ctx.onDispose(restrictions.registerAdapter({
|
|
89
|
+
capability: "authorization",
|
|
90
|
+
role: "authorization",
|
|
91
|
+
confirm: () => ({ digest: "non-interactive-existing-permissions" }),
|
|
92
|
+
bind() {
|
|
93
|
+
const at = revision;
|
|
94
|
+
return {
|
|
95
|
+
snapshot: {
|
|
96
|
+
policy: read().policy,
|
|
97
|
+
interactive: false,
|
|
98
|
+
revision: at
|
|
99
|
+
},
|
|
100
|
+
assertCurrent() {
|
|
101
|
+
ctx.signal.throwIfAborted();
|
|
102
|
+
if (revision !== at) throw new Error("restriction_stale: authorization policy changed");
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}));
|
|
76
107
|
const participant = {
|
|
77
108
|
connectionIdentity: storage.connectionIdentity,
|
|
78
109
|
prepare(value) {
|
|
@@ -119,7 +150,10 @@ const plugin = {
|
|
|
119
150
|
}
|
|
120
151
|
});
|
|
121
152
|
const module = fileURLToPath(new URL("../ui/ui.js", import.meta.url));
|
|
122
|
-
if (existsSync(module)) ctx.client.
|
|
153
|
+
if (existsSync(module)) ctx.client.registerPackageFiles({
|
|
154
|
+
root: dirname(module),
|
|
155
|
+
entry: "ui.js"
|
|
156
|
+
});
|
|
123
157
|
}
|
|
124
158
|
};
|
|
125
159
|
//#endregion
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"en-US": "Authorization Policy",
|
|
5
5
|
"zh-CN": "授权策略"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.2.0",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"description": "Default authorization policy and resource permission settings",
|
|
10
10
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"i18next": "^26.4.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@eum-agent/plugin": "1.
|
|
25
|
+
"@eum-agent/plugin": "1.2.0",
|
|
26
26
|
"@types/react": "^19.2.18",
|
|
27
27
|
"@types/react-dom": "^19.2.5",
|
|
28
28
|
"react": "^19.2.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {},
|
|
45
45
|
"foundationDependencies": {
|
|
46
|
-
"@eum-agent/storage-sqlite": "1.
|
|
46
|
+
"@eum-agent/storage-sqlite": "1.2.0"
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
package/ui/ui.js
CHANGED
|
@@ -187,16 +187,48 @@ function local(record) {
|
|
|
187
187
|
/** Existing processes keep their initial profile; file holders can be explicitly stopped. */
|
|
188
188
|
function FileHolders({ record }) {
|
|
189
189
|
const { t } = useTranslation$1();
|
|
190
|
-
const
|
|
190
|
+
const source = useBrowserService("processes");
|
|
191
|
+
const processes = source?.getState().processes ?? [];
|
|
191
192
|
const client = useGateway();
|
|
192
193
|
const stopping = useGatewayAction();
|
|
194
|
+
const [processError, setProcessError] = useState();
|
|
195
|
+
const [processRead, refreshProcessRead] = useState(0);
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
if (record.kind !== "file" || !source) return;
|
|
198
|
+
let current = true;
|
|
199
|
+
setProcessError(void 0);
|
|
200
|
+
source.getState().load(client, () => current).catch((error) => {
|
|
201
|
+
if (current) setProcessError(error instanceof Error ? error.message : String(error));
|
|
202
|
+
});
|
|
203
|
+
return () => {
|
|
204
|
+
current = false;
|
|
205
|
+
};
|
|
206
|
+
}, [
|
|
207
|
+
client,
|
|
208
|
+
source,
|
|
209
|
+
record.kind,
|
|
210
|
+
processRead
|
|
211
|
+
]);
|
|
193
212
|
if (record.kind !== "file") return null;
|
|
213
|
+
const failure = processError ? /* @__PURE__ */ jsxs("span", {
|
|
214
|
+
className: "text-xs text-destructive",
|
|
215
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
216
|
+
role: "alert",
|
|
217
|
+
children: processError
|
|
218
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
219
|
+
size: "sm",
|
|
220
|
+
variant: "text",
|
|
221
|
+
onClick: () => refreshProcessRead((before) => before + 1),
|
|
222
|
+
children: t("common.retry")
|
|
223
|
+
})]
|
|
224
|
+
}) : null;
|
|
194
225
|
const holders = processes.filter((process) => process.state !== "ended" && process.held.some((held) => held.path === record.target.path && held.access === record.target.operation));
|
|
195
|
-
if (!holders.length) return
|
|
226
|
+
if (!holders.length) return failure;
|
|
196
227
|
return /* @__PURE__ */ jsxs("span", {
|
|
197
228
|
"data-slot": "grant-holders",
|
|
198
229
|
className: "flex flex-wrap items-center gap-2 text-xs text-warning",
|
|
199
230
|
children: [
|
|
231
|
+
failure,
|
|
200
232
|
t("access.stillHeld", { count: holders.length }),
|
|
201
233
|
/* @__PURE__ */ jsx(Button, {
|
|
202
234
|
variant: "ghost",
|