@xkwdstore/agent 2.1.2 → 2.1.4
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/README.md +4 -4
- package/package.json +1 -1
- package/scripts/install-machine-agent.ps1 +41 -7
- package/src/cli.js +1 -1
- package/src/profilePath.js +86 -14
package/README.md
CHANGED
|
@@ -4,9 +4,9 @@ Terminal-only, cryptographically authenticated CLI for XKWDStore browser automat
|
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
> **@xkwdstore/agent 2.1.
|
|
7
|
+
> **@xkwdstore/agent 2.1.4 is the last version published on npm.**
|
|
8
8
|
>
|
|
9
|
-
> The current source version is **2.1.
|
|
9
|
+
> The current source version is **2.1.4** (machine-wide hardening). It is
|
|
10
10
|
> NOT claimed to be published unless the release workflow has published it — see
|
|
11
11
|
> `reports/` for the authoritative publication state.
|
|
12
12
|
|
|
@@ -29,7 +29,7 @@ curl -L -o "%TEMP%\xkwdstore-install.ps1" https://raw.githubusercontent.com/Essa
|
|
|
29
29
|
The generated launcher runs the pinned command:
|
|
30
30
|
|
|
31
31
|
```powershell
|
|
32
|
-
npx --yes @xkwdstore/agent@2.1.
|
|
32
|
+
npx --yes @xkwdstore/agent@2.1.4 start
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
Automated installer tests use `-NoLaunch` or a mocked `npx` command so the
|
|
@@ -203,7 +203,7 @@ The agent does NOT update itself. To use a newer version, change the version
|
|
|
203
203
|
number in the command. The pinned command for this release is:
|
|
204
204
|
|
|
205
205
|
```powershell
|
|
206
|
-
npx --yes @xkwdstore/agent@2.1.
|
|
206
|
+
npx --yes @xkwdstore/agent@2.1.4 start
|
|
207
207
|
```
|
|
208
208
|
|
|
209
209
|
> 2.1.0 is the current local agent version (machine-wide hardening).
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# XKWDStore Agent
|
|
1
|
+
# XKWDStore Agent - Machine-Wide Silent Startup (version from -AgentVersion)
|
|
2
2
|
#
|
|
3
3
|
# Installs / removes the machine-wide BROKER + per-session interactive WORKER
|
|
4
4
|
# startup. This script MUST run elevated (it creates a Windows service and writes
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
# -NoLaunch (test) validate + write files, never start a process
|
|
36
36
|
|
|
37
37
|
param(
|
|
38
|
-
[string]$AgentVersion = '2.1.
|
|
38
|
+
[string]$AgentVersion = '2.1.4',
|
|
39
39
|
[string]$Server = 'https://x.kwdstore.com',
|
|
40
40
|
[string]$ServiceAccount = 'LocalSystem',
|
|
41
41
|
[string]$AgentRoot,
|
|
@@ -69,10 +69,10 @@ function Get-NodePath {
|
|
|
69
69
|
return $cmd.Source
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
#
|
|
72
|
+
# -- install -----------------------------------------------------------------
|
|
73
73
|
if (-not $Uninstall) {
|
|
74
74
|
Write-Host ''
|
|
75
|
-
Write-Host
|
|
75
|
+
Write-Host " XKWDStore Agent $AgentVersion - machine-wide silent startup" -ForegroundColor Cyan
|
|
76
76
|
Write-Host ' ==================================================' -ForegroundColor Cyan
|
|
77
77
|
Assert-Elevated
|
|
78
78
|
$node = Get-NodePath
|
|
@@ -106,6 +106,40 @@ if (-not $Uninstall) {
|
|
|
106
106
|
Write-Warn2 "agent src not found next to the installer; using the repo path in the service wrapper"
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
# 1a-bis. Provision the RUNTIME DEPENDENCIES into the install dir.
|
|
110
|
+
# The block above copies a `node_modules` only if one sits next to the
|
|
111
|
+
# installer. A normal `npm install @xkwdstore/agent` hoists the agent's
|
|
112
|
+
# dependencies to the CALLER's node_modules, so the package directory ships
|
|
113
|
+
# none. Copying only what happens to be there therefore produced an install
|
|
114
|
+
# with no dependencies at all, and the broker died on its first bare
|
|
115
|
+
# `require('playwright-core')` - a MODULE_NOT_FOUND crash-loop masked by the
|
|
116
|
+
# service restarting it. The installer must guarantee the dependency tree
|
|
117
|
+
# exists, not hope it was shipped alongside.
|
|
118
|
+
$agentPkgJson = Join-Path $AgentInstallDir 'package.json'
|
|
119
|
+
if (Test-Path -LiteralPath $agentPkgJson) {
|
|
120
|
+
$depProbe = Join-Path $AgentInstallDir 'node_modules\playwright-core'
|
|
121
|
+
if (-not (Test-Path -LiteralPath $depProbe)) {
|
|
122
|
+
$agentLockJson = Join-Path $AgentInstallDir 'package-lock.json'
|
|
123
|
+
Write-Step 'provisioning agent runtime dependencies (npm)'
|
|
124
|
+
Push-Location $AgentInstallDir
|
|
125
|
+
try {
|
|
126
|
+
if (Test-Path -LiteralPath $agentLockJson) {
|
|
127
|
+
& npm ci --omit=dev --no-audit --no-fund *> $null
|
|
128
|
+
} else {
|
|
129
|
+
& npm install --omit=dev --no-audit --no-fund *> $null
|
|
130
|
+
}
|
|
131
|
+
} finally { Pop-Location }
|
|
132
|
+
if (-not (Test-Path -LiteralPath $depProbe)) {
|
|
133
|
+
Write-Host ' X agent runtime dependencies could not be provisioned.' -ForegroundColor Red
|
|
134
|
+
Write-Host ' The agent needs npm + network access on this machine.' -ForegroundColor Red
|
|
135
|
+
exit 1
|
|
136
|
+
}
|
|
137
|
+
Write-Ok 'agent runtime dependencies provisioned'
|
|
138
|
+
} else {
|
|
139
|
+
Write-Ok 'agent runtime dependencies already present'
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
109
143
|
# 1b. place the worker-entry launcher where the logon task expects it AND the
|
|
110
144
|
# installer-managed scripts next to the installed program files.
|
|
111
145
|
$workerEntrySrc = Join-Path $PSScriptRoot 'worker-entry.js'
|
|
@@ -266,7 +300,7 @@ try {
|
|
|
266
300
|
$staleCmd = Join-Path $MachineRoot 'launcher\broker-service.cmd'
|
|
267
301
|
if (Test-Path -LiteralPath $staleCmd) { Remove-Item $staleCmd -Force -ErrorAction SilentlyContinue }
|
|
268
302
|
|
|
269
|
-
# 4. per-session worker fallback (logon task)
|
|
303
|
+
# 4. per-session worker fallback (logon task) - only used if session spawning is unavailable
|
|
270
304
|
$taskName = 'XKWDStoreAgentWorker'
|
|
271
305
|
try {
|
|
272
306
|
$action = New-ScheduledTaskAction -Execute $node -Argument "`"$workerEntryDst`""
|
|
@@ -325,9 +359,9 @@ try {
|
|
|
325
359
|
exit 0
|
|
326
360
|
}
|
|
327
361
|
|
|
328
|
-
#
|
|
362
|
+
# -- uninstall ---------------------------------------------------------------
|
|
329
363
|
Write-Host ''
|
|
330
|
-
Write-Host
|
|
364
|
+
Write-Host " XKWDStore Agent $AgentVersion - uninstall" -ForegroundColor Cyan
|
|
331
365
|
Assert-Elevated
|
|
332
366
|
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
|
333
367
|
if ($svc) {
|
package/src/cli.js
CHANGED
|
@@ -24,7 +24,7 @@ const crypto = require('crypto');
|
|
|
24
24
|
const os = require('os');
|
|
25
25
|
const path = require('path');
|
|
26
26
|
|
|
27
|
-
const CLI_VERSION = '2.1.
|
|
27
|
+
const CLI_VERSION = '2.1.4';
|
|
28
28
|
const PROTOCOL_VERSION = 2;
|
|
29
29
|
|
|
30
30
|
// ── Command parsing ──────────────────────────────────────────────────────────
|
package/src/profilePath.js
CHANGED
|
@@ -207,9 +207,9 @@ function _fsyncPath(p, kind) {
|
|
|
207
207
|
*
|
|
208
208
|
* On POSIX, chmod the path to `mode` (best-effort in dev, fail-closed in prod).
|
|
209
209
|
*/
|
|
210
|
-
function _applyPerms(target, mode) {
|
|
210
|
+
function _applyPerms(target, mode, opts = {}) {
|
|
211
211
|
if (IS_WIN) {
|
|
212
|
-
_applyWindowsAcl(target);
|
|
212
|
+
_applyWindowsAcl(target, opts);
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
215
215
|
try {
|
|
@@ -225,19 +225,72 @@ function _applyPerms(target, mode) {
|
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Windows SID of the user logged in on the ACTIVE CONSOLE session — the user
|
|
230
|
+
* whose session the browser worker (and therefore Chromium) runs in.
|
|
231
|
+
*
|
|
232
|
+
* Chromium is launched by the per-session worker, which the Session-0 broker
|
|
233
|
+
* starts with CreateProcessAsUser(WTSQueryUserToken(activeSession)). Chromium
|
|
234
|
+
* therefore writes its profile — and its ProcessSingleton lock — as THAT user,
|
|
235
|
+
* not as the broker (SYSTEM) that creates the directory. A profile DACL that
|
|
236
|
+
* grants only the broker's own SID + Administrators + SYSTEM leaves Chromium
|
|
237
|
+
* unable to create the lock, and every launch fails with
|
|
238
|
+
* "Failed to create a ProcessSingleton for your profile directory".
|
|
239
|
+
*
|
|
240
|
+
* Returns null when there is no active console session (headless CI / no logged
|
|
241
|
+
* in user) or the SID cannot be resolved; callers then add no extra ACE.
|
|
242
|
+
*/
|
|
243
|
+
function _activeConsoleUserSid() {
|
|
244
|
+
if (!IS_WIN) return null;
|
|
245
|
+
const script = [
|
|
246
|
+
"$ErrorActionPreference='Stop'",
|
|
247
|
+
"$u = (Get-CimInstance Win32_ComputerSystem).UserName",
|
|
248
|
+
"if (-not $u) { '' } else {",
|
|
249
|
+
" (New-Object System.Security.Principal.NTAccount($u)).Translate([System.Security.Principal.SecurityIdentifier]).Value",
|
|
250
|
+
"}",
|
|
251
|
+
].join('; ');
|
|
252
|
+
try {
|
|
253
|
+
const r = spawnSync('powershell', ['-NoProfile', '-NonInteractive', '-Command', script], {
|
|
254
|
+
windowsHide: true, encoding: 'utf8', timeout: 10000,
|
|
255
|
+
});
|
|
256
|
+
const sid = (r.stdout || '').trim();
|
|
257
|
+
return /^S-\d-[\d-]+$/.test(sid) ? sid : null;
|
|
258
|
+
} catch { return null; }
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function _applyWindowsAcl(target, opts = {}) {
|
|
229
262
|
const { enforce } = _windowsAclPolicy();
|
|
230
263
|
if (!enforce) return;
|
|
231
264
|
|
|
265
|
+
// Extra SIDs that must ALSO be granted — notably the interactive session user
|
|
266
|
+
// who runs Chromium. Only well-formed SIDs are accepted.
|
|
267
|
+
const extraSids = (Array.isArray(opts.extraSids) ? opts.extraSids : [])
|
|
268
|
+
.filter((s) => typeof s === 'string' && /^S-\d-[\d-]+$/.test(s));
|
|
269
|
+
|
|
232
270
|
// Resolve the current user's SID structurally (not by localized username).
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
271
|
+
// `opts.ownerSid` is a TEST-ONLY injection so a regression test can prove what
|
|
272
|
+
// happens when the ACL is applied by a DIFFERENT principal (the Session-0
|
|
273
|
+
// broker running as SYSTEM) than the user who later runs Chromium.
|
|
274
|
+
let ownerSid = typeof opts.ownerSid === 'string' && /^S-\d-[\d-]+$/.test(opts.ownerSid)
|
|
275
|
+
? opts.ownerSid
|
|
276
|
+
: null;
|
|
277
|
+
if (!ownerSid) {
|
|
278
|
+
const ownerSidResult = spawnSync('powershell', [
|
|
279
|
+
'-NoProfile', '-NonInteractive', '-Command',
|
|
280
|
+
'[System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value',
|
|
281
|
+
], { windowsHide: true, encoding: 'utf8' });
|
|
282
|
+
if (ownerSidResult.status !== 0 || !ownerSidResult.stdout.trim()) {
|
|
283
|
+
throw new ProfileIdentityError('cannot resolve current user SID for ACL verification', 'PROFILE_ACL_NO_USER');
|
|
284
|
+
}
|
|
285
|
+
ownerSid = ownerSidResult.stdout.trim();
|
|
239
286
|
}
|
|
240
|
-
|
|
287
|
+
|
|
288
|
+
// PowerShell array literals: the extra (interactive-session) SIDs, and the
|
|
289
|
+
// full ALLOWLIST used by the verification step below.
|
|
290
|
+
const extraSidArray = extraSids.map((s) => `'${s}'`).join(', ');
|
|
291
|
+
const allowedSidArray = [ownerSid, 'S-1-5-32-544', 'S-1-5-18', ...extraSids]
|
|
292
|
+
.map((s) => `'${s}'`)
|
|
293
|
+
.join(', ');
|
|
241
294
|
|
|
242
295
|
let isDir = false;
|
|
243
296
|
try { isDir = fs.statSync(target).isDirectory(); } catch { /* treat as file */ }
|
|
@@ -289,6 +342,18 @@ function _applyWindowsAcl(target) {
|
|
|
289
342
|
[System.Security.AccessControl.AccessControlType]::Allow)
|
|
290
343
|
$acl.AddAccessRule($systemRule)
|
|
291
344
|
|
|
345
|
+
# Interactive session user(s): Chromium runs AS THIS USER (the worker is
|
|
346
|
+
# started with CreateProcessAsUser(WTSQueryUserToken(activeSession))), so the
|
|
347
|
+
# profile MUST be writable by them or Chrome cannot create its singleton lock.
|
|
348
|
+
foreach ($extraSid in @(${extraSidArray})) {
|
|
349
|
+
if (-not $extraSid) { continue }
|
|
350
|
+
$extraRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
|
|
351
|
+
(New-Object System.Security.Principal.SecurityIdentifier($extraSid)),
|
|
352
|
+
$colRights, $inhFlags, $propFlags,
|
|
353
|
+
[System.Security.AccessControl.AccessControlType]::Allow)
|
|
354
|
+
$acl.AddAccessRule($extraRule)
|
|
355
|
+
}
|
|
356
|
+
|
|
292
357
|
# Apply the fresh DACL (instance method — works in PS 5.1+ without extra assemblies)
|
|
293
358
|
(Get-Item -LiteralPath $path).SetAccessControl($acl)
|
|
294
359
|
`;
|
|
@@ -320,9 +385,7 @@ function _applyWindowsAcl(target) {
|
|
|
320
385
|
$acl = $item.GetAccessControl()
|
|
321
386
|
$allRules = $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])
|
|
322
387
|
$allowed = @(
|
|
323
|
-
|
|
324
|
-
'S-1-5-32-544',
|
|
325
|
-
'S-1-5-18'
|
|
388
|
+
${allowedSidArray}
|
|
326
389
|
)
|
|
327
390
|
$leaked = @()
|
|
328
391
|
$ownerHasAccess = $false
|
|
@@ -684,7 +747,12 @@ function writeIdentityMarker(dir, tuple, options = {}) {
|
|
|
684
747
|
};
|
|
685
748
|
// 0o700: only the owning user may traverse/read the profile dir.
|
|
686
749
|
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
687
|
-
|
|
750
|
+
// The browser profile is written by Chromium running AS THE INTERACTIVE
|
|
751
|
+
// SESSION USER (the worker is launched with CreateProcessAsUser on that
|
|
752
|
+
// session's token), so that user must be granted access in addition to the
|
|
753
|
+
// broker's own identity, Administrators and SYSTEM. Without it Chromium
|
|
754
|
+
// cannot create its ProcessSingleton lock and every launch fails.
|
|
755
|
+
_applyPerms(dir, 0o700, { extraSids: [_activeConsoleUserSid()] });
|
|
688
756
|
const tmp = path.join(dir, '.' + IDENTITY_FILE + '.tmp.' + crypto.randomBytes(6).toString('hex'));
|
|
689
757
|
let renamed = false;
|
|
690
758
|
try {
|
|
@@ -1114,4 +1182,8 @@ module.exports = {
|
|
|
1114
1182
|
quarantineDir,
|
|
1115
1183
|
// Phase 10: exported for ACL-policy config unit tests.
|
|
1116
1184
|
windowsAclPolicy: _windowsAclPolicy,
|
|
1185
|
+
// Exported for the interactive-session ACL regression tests: the profile DACL
|
|
1186
|
+
// must grant the user who runs Chromium, not only the process that created it.
|
|
1187
|
+
_applyWindowsAcl,
|
|
1188
|
+
_activeConsoleUserSid,
|
|
1117
1189
|
};
|