@clagentic/console 1.10.0-beta.3 → 1.10.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/lib/build-sha.json +2 -2
- package/lib/build-update-offer.js +29 -0
- package/lib/daemon.js +5 -9
- package/lib/grant-keys.js +24 -137
- package/lib/identity/config.js +118 -0
- package/lib/identity/contract.js +61 -0
- package/lib/identity/delivery.js +224 -0
- package/lib/identity/holder.js +87 -0
- package/lib/identity/index.js +229 -0
- package/lib/identity/jose.js +13 -0
- package/lib/identity/origin.js +28 -0
- package/lib/identity/owner.js +30 -0
- package/lib/identity/providers/gatekeeper.js +91 -0
- package/lib/identity/providers/jwks-self.js +85 -0
- package/lib/identity/providers/module.js +98 -0
- package/lib/identity/providers/signing-key.js +118 -0
- package/lib/identity/record.js +23 -0
- package/lib/identity/unavailable.js +29 -0
- package/lib/project-notifications.js +2 -3
- package/lib/prompt-kinds/permission.js +0 -18
- package/lib/prompt-registry.js +5 -13
- package/lib/public/css/notifications-center.css +2 -8
- package/lib/public/css/rewind.css +0 -1
- package/lib/public/modules/app-notifications.js +4 -7
- package/lib/public/modules/build-notice-gate.js +73 -0
- package/lib/public/modules/diagnostics.js +43 -1
- package/lib/public/modules/prompt-banner.js +0 -12
- package/lib/public/modules/prompt-kinds/permission-choices.js +1 -6
- package/lib/public/modules/prompt-kinds/permission.js +0 -15
- package/lib/sdk-bridge.js +82 -3
- package/lib/sessions.js +7 -0
- package/lib/turn-initiator.js +29 -14
- package/lib/utils.js +4 -7
- package/lib/ws-schema.js +3 -3
- package/lib/yoke/adapters/claude-worker.js +5 -5
- package/lib/yoke/adapters/claude.js +5 -5
- package/package.json +3 -1
- package/scripts/vendor-identity-vectors.js +52 -0
package/lib/build-sha.json
CHANGED
|
@@ -131,7 +131,36 @@ function summarizeOffer(a) {
|
|
|
131
131
|
: 'Running build ' + short(a.loadedBuildSha) + '; installed build ' + short(a.installedBuildSha) + '.';
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
var DEFAULT_NOTICE_COOLDOWN_MS = 60 * 60 * 1000;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* How long a client keeps a closed build-update notice quiet. `raw` is the
|
|
138
|
+
* CLAGENTIC_CONSOLE_BUILD_NOTICE_COOLDOWN_MS value; unset, empty or invalid
|
|
139
|
+
* (not a non-negative number) falls back to the default. 0 disables the quiet period.
|
|
140
|
+
*/
|
|
141
|
+
function noticeCooldownFrom(raw) {
|
|
142
|
+
if (raw === undefined || raw === null || raw === '') return DEFAULT_NOTICE_COOLDOWN_MS;
|
|
143
|
+
var n = Number(raw);
|
|
144
|
+
return isFinite(n) && n >= 0 ? n : DEFAULT_NOTICE_COOLDOWN_MS;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** The standing diagnostic every client is sent for a stale build. */
|
|
148
|
+
function composeNotice(assessment, changes, cooldownMs) {
|
|
149
|
+
return {
|
|
150
|
+
type: 'diagnostic',
|
|
151
|
+
severity: 'warning',
|
|
152
|
+
source: 'build-update',
|
|
153
|
+
message: summarizeOffer(assessment) + ' Restart to apply it when it suits you; nothing restarts on its own.',
|
|
154
|
+
buildUpdate: buildOffer({ assessment: assessment, changes: changes }),
|
|
155
|
+
actionable: { label: 'Restart to apply update', action: 'restart_for_build_update' },
|
|
156
|
+
noticeCooldownMs: cooldownMs,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
134
160
|
module.exports = {
|
|
161
|
+
DEFAULT_NOTICE_COOLDOWN_MS: DEFAULT_NOTICE_COOLDOWN_MS,
|
|
162
|
+
noticeCooldownFrom: noticeCooldownFrom,
|
|
163
|
+
composeNotice: composeNotice,
|
|
135
164
|
collectInterruptions: collectInterruptions,
|
|
136
165
|
coveredBy: coveredBy,
|
|
137
166
|
describeInterruptions: describeInterruptions,
|
package/lib/daemon.js
CHANGED
|
@@ -47,7 +47,7 @@ var { dropSkillsCache } = require("./server-skills");
|
|
|
47
47
|
var { waitForIdleThenAct } = require("./build-update-check");
|
|
48
48
|
var { createBuildMonitor } = require("./build-monitor");
|
|
49
49
|
var { createBuildUpdateRestart } = require("./build-update-restart");
|
|
50
|
-
var {
|
|
50
|
+
var { composeNotice, noticeCooldownFrom } = require("./build-update-offer");
|
|
51
51
|
var { createStandingOffer } = require("./build-update-standing");
|
|
52
52
|
var { listBuildChanges, resolveHistoryRepo } = require("./build-changes");
|
|
53
53
|
var { RESTART_EXIT_CODE, isSupervised, unsupervisedEnv } = require("./supervisor");
|
|
@@ -1397,6 +1397,9 @@ function liveProjectsForOffer() {
|
|
|
1397
1397
|
var BUILD_CHECK_MS = Number(readConsoleEnv("CLAGENTIC_CONSOLE_BUILD_CHECK_MS")) || 60 * 1000;
|
|
1398
1398
|
// A failed change-list read is retried no more often than the journal reminder.
|
|
1399
1399
|
var BUILD_REMINDER_EVERY = 30;
|
|
1400
|
+
// How long a closed build-update notice stays quiet in a client before the same
|
|
1401
|
+
// notice may show again; the client applies it (lib/public/modules/build-notice-gate.js).
|
|
1402
|
+
var BUILD_NOTICE_COOLDOWN_MS = noticeCooldownFrom(readConsoleEnv("CLAGENTIC_CONSOLE_BUILD_NOTICE_COOLDOWN_MS"));
|
|
1400
1403
|
|
|
1401
1404
|
// The offer clients hold is reconciled against the monitor's confirmed stale
|
|
1402
1405
|
// assessment after every poll (lib/build-update-standing.js): it is shown,
|
|
@@ -1408,14 +1411,7 @@ var buildStandingOffer = createStandingOffer({
|
|
|
1408
1411
|
retryAfterMs: BUILD_CHECK_MS * BUILD_REMINDER_EVERY,
|
|
1409
1412
|
broadcast: function (message) { relay.broadcastAll(message); },
|
|
1410
1413
|
compose: function (a, changes) {
|
|
1411
|
-
return
|
|
1412
|
-
type: "diagnostic",
|
|
1413
|
-
severity: "warning",
|
|
1414
|
-
source: "build-update",
|
|
1415
|
-
message: summarizeOffer(a) + " Restart to apply it when it suits you; nothing restarts on its own.",
|
|
1416
|
-
buildUpdate: buildOffer({ assessment: a, changes: changes }),
|
|
1417
|
-
actionable: { label: "Restart to apply update", action: "restart_for_build_update" },
|
|
1418
|
-
};
|
|
1414
|
+
return composeNotice(a, changes, BUILD_NOTICE_COOLDOWN_MS);
|
|
1419
1415
|
},
|
|
1420
1416
|
log: function (line) { console.log("[daemon] " + line); },
|
|
1421
1417
|
});
|
package/lib/grant-keys.js
CHANGED
|
@@ -3,100 +3,41 @@
|
|
|
3
3
|
// What an "Allow for Session" answer grants, and how a later tool call is
|
|
4
4
|
// matched against it. One function builds the key for a call; the same key is
|
|
5
5
|
// what is stored when the operator grants it and what a later call is looked
|
|
6
|
-
// up by
|
|
6
|
+
// up by.
|
|
7
7
|
//
|
|
8
8
|
// Key shapes (stored as keys of session.allowedTools, persisted in the session
|
|
9
9
|
// meta record, always with the value true):
|
|
10
|
-
// <Tool>
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
// shape for a tool that has a narrower one.
|
|
14
|
-
// Bash=<command> exactly this command line and nothing wider. A line
|
|
15
|
-
// too long to keep has no key. Bash:<anything> (the
|
|
16
|
-
// retired prefix shape) is dropped on load.
|
|
17
|
-
// Skill:<name> one skill.
|
|
18
|
-
// <other tool> tool name (MCP tools already carry server and tool).
|
|
10
|
+
// <Tool> the whole tool: every later call of it in the session skips
|
|
11
|
+
// the prompt. This holds for file tools and Bash alike.
|
|
12
|
+
// Skill:<name> one skill (the Skill tool is one name over many skills).
|
|
19
13
|
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
23
|
-
//
|
|
24
|
-
// A call with no usable key (a file-tool call, a command too long to persist)
|
|
25
|
-
// has key null: it can be allowed once, never for the session.
|
|
26
|
-
|
|
27
|
-
// The session meta record is read back from a 4 KiB chunk, so a grant map that
|
|
28
|
-
// grew without bound would make the whole session unloadable after a restart.
|
|
29
|
-
var MAX_KEY_LENGTH = 160;
|
|
30
|
-
var MAX_GRANTS = 16;
|
|
31
|
-
var MAX_GRANT_BYTES = 1600;
|
|
32
|
-
|
|
33
|
-
// Binding a file grant to the filesystem (lexical paths, then realpaths) left
|
|
34
|
-
// a new hole at every review, so file tools never produce a session grant: no
|
|
35
|
-
// key, no stored value, no filesystem read.
|
|
36
|
-
var FILE_TOOLS = Object.create(null);
|
|
37
|
-
FILE_TOOLS.Write = true;
|
|
38
|
-
FILE_TOOLS.Edit = true;
|
|
39
|
-
FILE_TOOLS.MultiEdit = true;
|
|
40
|
-
FILE_TOOLS.NotebookEdit = true;
|
|
41
|
-
|
|
42
|
-
function isFileTool(toolName) {
|
|
43
|
-
return FILE_TOOLS[toolName] === true;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// The one table of tools that have scoped keys, or (file tools) none. A
|
|
47
|
-
// bare-name key for any of them is the legacy whole-tool grant that older
|
|
48
|
-
// sessions persisted; isGranted honours it for every tool listed here, so
|
|
49
|
-
// changing a tool's keys cannot silently drop its persisted grants.
|
|
50
|
-
var SCOPED_TOOLS = Object.create(null);
|
|
51
|
-
SCOPED_TOOLS.Bash = true;
|
|
52
|
-
SCOPED_TOOLS.Skill = true;
|
|
53
|
-
Object.keys(FILE_TOOLS).forEach(function (t) { SCOPED_TOOLS[t] = true; });
|
|
14
|
+
// Bash=<command> keys were written by builds that scoped a Bash grant to one
|
|
15
|
+
// command line. No call produces one now, so they are dropped on load rather
|
|
16
|
+
// than left as grants nothing can match.
|
|
54
17
|
|
|
55
|
-
|
|
56
|
-
return SCOPED_TOOLS[toolName] === true;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Deriving a prefix from the command text (lexical rules over a shell grammar)
|
|
60
|
-
// missed shell semantics at two successive reviews, so a Bash grant is the
|
|
61
|
-
// exact line and nothing wider. The command is used byte for byte: any
|
|
62
|
-
// transform (trim, whitespace collapse, normalization) would let two different
|
|
63
|
-
// command strings, which bash runs differently, share one key.
|
|
64
|
-
function bashKey(input) {
|
|
65
|
-
var command = input && typeof input.command === "string" ? input.command : "";
|
|
66
|
-
if (command === "") return null;
|
|
67
|
-
return command.length + 5 <= MAX_KEY_LENGTH ? "Bash=" + command : null;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Key shapes older sessions persisted that no call produces any more: a file
|
|
71
|
-
// tool key (Write:<path> in any form) and a Bash prefix key (Bash:<command>).
|
|
72
|
-
// They are dropped on load, never honoured.
|
|
73
|
-
function isRetiredKey(key) {
|
|
74
|
-
var m = /^([^:=]+)([:=])/.exec(key);
|
|
75
|
-
if (m === null) return false;
|
|
76
|
-
return isFileTool(m[1]) || (m[1] === "Bash" && m[2] === ":");
|
|
77
|
-
}
|
|
18
|
+
var SCOPED_BASH_KEY = /^Bash=/;
|
|
78
19
|
|
|
79
20
|
/**
|
|
80
21
|
* Whether a persisted value is one a grant under this key can hold: true, and
|
|
81
|
-
*
|
|
22
|
+
* not the retired exact-command Bash key.
|
|
82
23
|
*/
|
|
83
24
|
function isGrantValue(key, value) {
|
|
84
|
-
return value === true && !
|
|
25
|
+
return value === true && !SCOPED_BASH_KEY.test(key);
|
|
85
26
|
}
|
|
86
27
|
|
|
87
28
|
/**
|
|
88
|
-
* The key a call is granted and matched by
|
|
89
|
-
*
|
|
29
|
+
* The key a call is granted and matched by.
|
|
30
|
+
*
|
|
31
|
+
* Most tools are discriminated by bare tool name alone: MCP tools already fold
|
|
32
|
+
* server and tool into the name. The Claude `Skill` tool is the exception:
|
|
33
|
+
* every skill arrives as toolName "Skill" with a different `input.skill`, so a
|
|
34
|
+
* bare "Skill" key would authorize every skill. Falls back to the bare name
|
|
35
|
+
* when the call names no skill.
|
|
90
36
|
* @param {string} toolName
|
|
91
37
|
* @param {?object} input
|
|
92
|
-
* @returns {
|
|
38
|
+
* @returns {string}
|
|
93
39
|
*/
|
|
94
40
|
function permissionGrantKey(toolName, input) {
|
|
95
|
-
if (toolName === "Bash") return bashKey(input);
|
|
96
|
-
if (isFileTool(toolName)) return null;
|
|
97
|
-
// The Skill tool is one name over many skills; a bare "Skill" key would
|
|
98
|
-
// authorize every one of them. Falls back to the bare name only when the
|
|
99
|
-
// call names no skill.
|
|
100
41
|
if (toolName === "Skill" && input && typeof input.skill === "string" && input.skill) {
|
|
101
42
|
return "Skill:" + input.skill;
|
|
102
43
|
}
|
|
@@ -109,71 +50,17 @@ function permissionGrantKey(toolName, input) {
|
|
|
109
50
|
* @returns {{key: string, tool: string, wholeTool: boolean, text: string}}
|
|
110
51
|
*/
|
|
111
52
|
function describeGrantKey(key) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
key: key, tool: key, wholeTool: true,
|
|
116
|
-
text: "Every " + key + " call, whatever it does (whole-tool grant)",
|
|
117
|
-
};
|
|
53
|
+
if (key.indexOf("Skill:") === 0) {
|
|
54
|
+
return { key: key, tool: "Skill", wholeTool: false, text: "Skill " + key.slice(6) };
|
|
118
55
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
text = "Bash: exactly this command: " + value;
|
|
124
|
-
} else if (tool === "Skill") {
|
|
125
|
-
text = "Skill " + value;
|
|
126
|
-
} else {
|
|
127
|
-
text = key;
|
|
128
|
-
}
|
|
129
|
-
return { key: key, tool: tool, wholeTool: false, text: text };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* The sentence the card and banner show before the click, or null when the
|
|
134
|
-
* call cannot be granted for the session.
|
|
135
|
-
* @returns {?string}
|
|
136
|
-
*/
|
|
137
|
-
function grantScopeText(toolName, input) {
|
|
138
|
-
var key = permissionGrantKey(toolName, input);
|
|
139
|
-
if (key === null) return null;
|
|
140
|
-
var d = describeGrantKey(key);
|
|
141
|
-
if (d.wholeTool) return "Allow every " + toolName + " call in this session";
|
|
142
|
-
if (d.tool === "Bash") {
|
|
143
|
-
return "Allow only this exact command in this session";
|
|
144
|
-
}
|
|
145
|
-
if (d.tool === "Skill") return "Allow the " + key.slice(6) + " skill in this session";
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/** Whether a call is covered by a grant in the session's map. */
|
|
150
|
-
function isGranted(allowedTools, toolName, input) {
|
|
151
|
-
if (!allowedTools) return false;
|
|
152
|
-
var own = function (k) { return Object.prototype.hasOwnProperty.call(allowedTools, k); };
|
|
153
|
-
var key = permissionGrantKey(toolName, input);
|
|
154
|
-
if (key !== null && own(key) && isGrantValue(key, allowedTools[key])) return true;
|
|
155
|
-
// A whole-tool grant from before grants were scoped.
|
|
156
|
-
return hasNarrowKey(toolName) && own(toolName) && allowedTools[toolName] === true;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/** Whether one more grant fits in the persisted record. */
|
|
160
|
-
function fitsBudget(allowedTools, key) {
|
|
161
|
-
var keys = Object.keys(allowedTools || {});
|
|
162
|
-
if (keys.indexOf(key) !== -1) return true;
|
|
163
|
-
if (keys.length >= MAX_GRANTS) return false;
|
|
164
|
-
var size = function (k) { return Buffer.byteLength(k) + 8; };
|
|
165
|
-
var bytes = keys.reduce(function (n, k) { return n + size(k); }, 0);
|
|
166
|
-
return bytes + size(key) <= MAX_GRANT_BYTES;
|
|
56
|
+
return {
|
|
57
|
+
key: key, tool: key, wholeTool: true,
|
|
58
|
+
text: "Every " + key + " call, whatever it does (whole-tool grant)",
|
|
59
|
+
};
|
|
167
60
|
}
|
|
168
61
|
|
|
169
62
|
module.exports = {
|
|
170
63
|
permissionGrantKey: permissionGrantKey,
|
|
171
64
|
describeGrantKey: describeGrantKey,
|
|
172
|
-
grantScopeText: grantScopeText,
|
|
173
|
-
isGranted: isGranted,
|
|
174
|
-
isFileTool: isFileTool,
|
|
175
65
|
isGrantValue: isGrantValue,
|
|
176
|
-
fitsBudget: fitsBudget,
|
|
177
|
-
MAX_KEY_LENGTH: MAX_KEY_LENGTH,
|
|
178
|
-
MAX_GRANTS: MAX_GRANTS,
|
|
179
66
|
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Reads the `identity` block of the console configuration (daemon.json).
|
|
4
|
+
//
|
|
5
|
+
// identity.provider "none" (default) | "gatekeeper" | "jwks-self" | "module"
|
|
6
|
+
// identity.spawn_root where session delivery directories are created
|
|
7
|
+
//
|
|
8
|
+
// gatekeeper: identity.gatekeeper.socket issuer socket (absolute path)
|
|
9
|
+
// identity.gatekeeper.binary client executable, default "gatekeeper"
|
|
10
|
+
// identity.gatekeeper.timeout_ms bound on one request
|
|
11
|
+
// jwks-self: identity.signing_key private key (PEM, PKCS#8 Ed25519)
|
|
12
|
+
// identity.jwks_path where the public key set is published
|
|
13
|
+
// identity.issuer `iss` of the assertions, default file URL of jwks_path
|
|
14
|
+
// identity.roles role ceiling the assertions carry, default none
|
|
15
|
+
// identity.ttl_seconds assertion lifetime, default 3600, at most 43200
|
|
16
|
+
// module: identity.provider_module absolute path of a user-supplied provider
|
|
17
|
+
//
|
|
18
|
+
// An absent block, or provider "none", is the default: the console does nothing
|
|
19
|
+
// identity-related. A block that cannot be understood is reported as provider
|
|
20
|
+
// "invalid" so every session says so instead of silently running unattested.
|
|
21
|
+
|
|
22
|
+
var path = require("path");
|
|
23
|
+
var url = require("url");
|
|
24
|
+
var contract = require("./contract");
|
|
25
|
+
|
|
26
|
+
var DEFAULT_TTL_SECONDS = 3600;
|
|
27
|
+
var DEFAULT_GATEKEEPER_BINARY = "gatekeeper";
|
|
28
|
+
var DEFAULT_TIMEOUT_MS = 8000;
|
|
29
|
+
|
|
30
|
+
function none() {
|
|
31
|
+
return { provider: "none" };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function invalid(reason) {
|
|
35
|
+
return { provider: "invalid", reason: reason };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function isAbsolutePath(value) {
|
|
39
|
+
return typeof value === "string" && value !== "" && path.isAbsolute(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function isObject(value) {
|
|
43
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function commonFields(raw, configDir) {
|
|
47
|
+
var spawnRoot = raw.spawn_root === undefined ? path.join(configDir, "identity", "spawn") : raw.spawn_root;
|
|
48
|
+
if (!isAbsolutePath(spawnRoot)) return { error: "identity.spawn_root must be an absolute path" };
|
|
49
|
+
return { spawnRoot: spawnRoot };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function gatekeeperConfig(raw, common) {
|
|
53
|
+
var gk = raw.gatekeeper;
|
|
54
|
+
if (!isObject(gk) || !isAbsolutePath(gk.socket)) {
|
|
55
|
+
return invalid("identity.gatekeeper.socket must be an absolute path");
|
|
56
|
+
}
|
|
57
|
+
var binary = gk.binary === undefined ? DEFAULT_GATEKEEPER_BINARY : gk.binary;
|
|
58
|
+
if (typeof binary !== "string" || binary === "") return invalid("identity.gatekeeper.binary must be a string");
|
|
59
|
+
var timeout = gk.timeout_ms === undefined ? DEFAULT_TIMEOUT_MS : gk.timeout_ms;
|
|
60
|
+
if (!Number.isInteger(timeout) || timeout <= 0) return invalid("identity.gatekeeper.timeout_ms must be a positive integer");
|
|
61
|
+
return { provider: "gatekeeper", spawnRoot: common.spawnRoot, socket: gk.socket, binary: binary, timeoutMs: timeout };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function jwksSelfConfig(raw, common, configDir) {
|
|
65
|
+
var signingKey = raw.signing_key === undefined ? path.join(configDir, "identity", "signing-key.pem") : raw.signing_key;
|
|
66
|
+
var jwksPath = raw.jwks_path === undefined ? path.join(configDir, "identity", "jwks.json") : raw.jwks_path;
|
|
67
|
+
if (!isAbsolutePath(signingKey)) return invalid("identity.signing_key must be an absolute path");
|
|
68
|
+
if (!isAbsolutePath(jwksPath)) return invalid("identity.jwks_path must be an absolute path");
|
|
69
|
+
var issuer = raw.issuer === undefined ? url.pathToFileURL(jwksPath).href : raw.issuer;
|
|
70
|
+
if (typeof issuer !== "string" || issuer === "") return invalid("identity.issuer must be a string");
|
|
71
|
+
var roles = raw.roles === undefined ? [] : raw.roles;
|
|
72
|
+
if (!Array.isArray(roles) || roles.some(function (r) { return !contract.matches(contract.ROLE_PATTERN, r); }) || new Set(roles).size !== roles.length) {
|
|
73
|
+
return invalid("identity.roles must be a list of distinct role names");
|
|
74
|
+
}
|
|
75
|
+
var ttl = raw.ttl_seconds === undefined ? DEFAULT_TTL_SECONDS : raw.ttl_seconds;
|
|
76
|
+
if (!Number.isInteger(ttl) || ttl <= 0 || ttl > contract.MAX_LIFETIME_SECONDS) {
|
|
77
|
+
return invalid("identity.ttl_seconds must be between 1 and " + contract.MAX_LIFETIME_SECONDS);
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
provider: "jwks-self",
|
|
81
|
+
spawnRoot: common.spawnRoot,
|
|
82
|
+
signingKey: signingKey,
|
|
83
|
+
// Only the default key is created when it is missing: a key path someone
|
|
84
|
+
// named is never replaced by a freshly generated one.
|
|
85
|
+
generateKey: raw.signing_key === undefined,
|
|
86
|
+
jwksPath: jwksPath,
|
|
87
|
+
issuer: issuer,
|
|
88
|
+
roles: roles.slice(),
|
|
89
|
+
ttlSeconds: ttl,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function resolveConfig(raw, configDir) {
|
|
94
|
+
if (raw === undefined || raw === null) return none();
|
|
95
|
+
if (!isObject(raw)) return invalid("identity must be an object");
|
|
96
|
+
var name = raw.provider;
|
|
97
|
+
if (name === undefined) name = raw.provider_module === undefined ? "none" : "module";
|
|
98
|
+
if (name === "none") return none();
|
|
99
|
+
if (typeof name !== "string") return invalid("identity.provider must be a string");
|
|
100
|
+
if (raw.provider_module !== undefined && name !== "module") {
|
|
101
|
+
return invalid("identity.provider_module cannot be combined with identity.provider " + name);
|
|
102
|
+
}
|
|
103
|
+
var common = commonFields(raw, configDir);
|
|
104
|
+
if (common.error) return invalid(common.error);
|
|
105
|
+
switch (name) {
|
|
106
|
+
case contract.PROVIDERS.GATEKEEPER:
|
|
107
|
+
return gatekeeperConfig(raw, common);
|
|
108
|
+
case contract.PROVIDERS.JWKS_SELF:
|
|
109
|
+
return jwksSelfConfig(raw, common, configDir);
|
|
110
|
+
case "module":
|
|
111
|
+
if (!isAbsolutePath(raw.provider_module)) return invalid("identity.provider_module must be an absolute path");
|
|
112
|
+
return { provider: "module", spawnRoot: common.spawnRoot, modulePath: raw.provider_module };
|
|
113
|
+
default:
|
|
114
|
+
return invalid("identity.provider " + JSON.stringify(name.slice(0, 40)) + " is not one the console knows");
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
module.exports = { resolveConfig: resolveConfig };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Constants of the published Identity Assertion contract (version 1.0.0). The
|
|
4
|
+
// console implements the contract from its text, a JWS library and the vendored
|
|
5
|
+
// conformance vectors; it shares no code with any issuer.
|
|
6
|
+
|
|
7
|
+
var CONTRACT_VERSION = "1.0.0";
|
|
8
|
+
var CONTRACT_MAJOR = 1;
|
|
9
|
+
|
|
10
|
+
// What the console delivers a session's assertion through.
|
|
11
|
+
var IDENTITY_DIR_ENV = "CLAGENTIC_IDENTITY_DIR";
|
|
12
|
+
var IDENTITY_FILE = "identity.jwt";
|
|
13
|
+
var IDENTITY_TMP_DIR = "tmp";
|
|
14
|
+
|
|
15
|
+
var MAX_LIFETIME_SECONDS = 43200;
|
|
16
|
+
var MAX_FILE_BYTES = 16384;
|
|
17
|
+
var MAX_JWKS_BYTES = 65536;
|
|
18
|
+
|
|
19
|
+
var ALGORITHMS = Object.freeze(["EdDSA", "ES256"]);
|
|
20
|
+
var GRADES = Object.freeze(["workload", "harness"]);
|
|
21
|
+
var ORIGINS = Object.freeze(["human", "scheduled", "loop", "trigger", "agent"]);
|
|
22
|
+
|
|
23
|
+
var ACTOR_PATTERN = /^(agent|runtime):[A-Za-z0-9._-]{1,128}$/;
|
|
24
|
+
var SUBJECT_PATTERN = /^(human|agent|runtime):[A-Za-z0-9._-]{1,128}$/;
|
|
25
|
+
var ROLE_PATTERN = /^[a-z][a-z0-9_-]{0,63}$/;
|
|
26
|
+
var NAME_PATTERN = /^[A-Za-z0-9._-]{1,128}$/;
|
|
27
|
+
|
|
28
|
+
// RegExp.prototype.test coerces its argument to a string, so null, true or 5
|
|
29
|
+
// would pass for the names "null", "true" and "5". Every check of a name against
|
|
30
|
+
// one of the patterns above goes through here instead.
|
|
31
|
+
function matches(pattern, value) {
|
|
32
|
+
return typeof value === "string" && pattern.test(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The names providers record on a session. "declared" is the record of a
|
|
36
|
+
// session that has no assertion: the console says what it did, nothing is signed.
|
|
37
|
+
var PROVIDERS = Object.freeze({
|
|
38
|
+
GATEKEEPER: "gatekeeper",
|
|
39
|
+
JWKS_SELF: "jwks-self",
|
|
40
|
+
DECLARED: "declared",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
module.exports = {
|
|
44
|
+
CONTRACT_VERSION: CONTRACT_VERSION,
|
|
45
|
+
CONTRACT_MAJOR: CONTRACT_MAJOR,
|
|
46
|
+
IDENTITY_DIR_ENV: IDENTITY_DIR_ENV,
|
|
47
|
+
IDENTITY_FILE: IDENTITY_FILE,
|
|
48
|
+
IDENTITY_TMP_DIR: IDENTITY_TMP_DIR,
|
|
49
|
+
MAX_LIFETIME_SECONDS: MAX_LIFETIME_SECONDS,
|
|
50
|
+
MAX_FILE_BYTES: MAX_FILE_BYTES,
|
|
51
|
+
MAX_JWKS_BYTES: MAX_JWKS_BYTES,
|
|
52
|
+
ALGORITHMS: ALGORITHMS,
|
|
53
|
+
GRADES: GRADES,
|
|
54
|
+
ORIGINS: ORIGINS,
|
|
55
|
+
ACTOR_PATTERN: ACTOR_PATTERN,
|
|
56
|
+
SUBJECT_PATTERN: SUBJECT_PATTERN,
|
|
57
|
+
ROLE_PATTERN: ROLE_PATTERN,
|
|
58
|
+
NAME_PATTERN: NAME_PATTERN,
|
|
59
|
+
matches: matches,
|
|
60
|
+
PROVIDERS: PROVIDERS,
|
|
61
|
+
};
|