@countinghouse/ch-local 0.0.0-stage → 1.0.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/LICENSE +202 -0
- package/README.md +361 -2
- package/bin/ch-local.js +472 -0
- package/clients/claude-code/.claude-plugin/plugin.json +6 -0
- package/clients/claude-code/.mcp.json +11 -0
- package/clients/claude-code/bin/launch.js +235 -0
- package/clients/claude-code/bin/win-acl.js +420 -0
- package/clients/claude-code/skills/ci-failure-triage/SKILL.md +21 -0
- package/clients/claude-code/skills/countinghouse-module/SKILL.md +177 -0
- package/clients/claude-code/skills/countinghouse-setup/SKILL.md +74 -0
- package/lib/allowlist.js +65 -0
- package/lib/aside.js +16 -0
- package/lib/atomic.js +45 -0
- package/lib/auto-apply.js +245 -0
- package/lib/auto-upgrade.js +98 -0
- package/lib/availability.js +307 -0
- package/lib/ceiling.js +280 -0
- package/lib/clean-text.js +20 -0
- package/lib/cli-change.js +38 -0
- package/lib/client-conditions-fixtures.js +143 -0
- package/lib/client-conditions.js +656 -0
- package/lib/clients.js +179 -0
- package/lib/command-line.js +202 -0
- package/lib/conditions-command.js +116 -0
- package/lib/control.js +134 -0
- package/lib/credential-store.js +414 -0
- package/lib/credentials-command.js +344 -0
- package/lib/daemon-requests.js +137 -0
- package/lib/daemon.js +888 -0
- package/lib/describe-module.js +137 -0
- package/lib/description-check.js +175 -0
- package/lib/failed-json.js +43 -0
- package/lib/gc.js +274 -0
- package/lib/github-token.js +57 -0
- package/lib/handoff-io.js +73 -0
- package/lib/held-back.js +116 -0
- package/lib/hidden-input.js +64 -0
- package/lib/history.js +49 -0
- package/lib/home.js +372 -0
- package/lib/in-place.js +1036 -0
- package/lib/install-plan.js +142 -0
- package/lib/install.js +846 -0
- package/lib/installed-description.js +153 -0
- package/lib/integrity.js +7 -0
- package/lib/lock.js +456 -0
- package/lib/lockfile-rules.js +98 -0
- package/lib/machine.js +20 -0
- package/lib/module-credentials.js +403 -0
- package/lib/module-record.js +298 -0
- package/lib/module-roles.js +44 -0
- package/lib/module-seams.js +26 -0
- package/lib/module-store.js +202 -0
- package/lib/module-values.js +334 -0
- package/lib/names.js +31 -0
- package/lib/next-steps.js +8 -0
- package/lib/node-check.js +56 -0
- package/lib/npm-fetch.js +123 -0
- package/lib/npm-release.js +99 -0
- package/lib/npm-upgrade.js +146 -0
- package/lib/npm.js +41 -0
- package/lib/outside-edits.js +162 -0
- package/lib/own-applied.js +175 -0
- package/lib/own-command.js +380 -0
- package/lib/own-file.js +120 -0
- package/lib/own-record.js +96 -0
- package/lib/own-tree.js +336 -0
- package/lib/pack-table.js +290 -0
- package/lib/packs-command.js +570 -0
- package/lib/packs.js +219 -0
- package/lib/pins.js +64 -0
- package/lib/pipe-probe.js +82 -0
- package/lib/plain-read.js +63 -0
- package/lib/private-file.js +90 -0
- package/lib/private-write.js +33 -0
- package/lib/provenance.js +234 -0
- package/lib/record.js +82 -0
- package/lib/registry.js +22 -0
- package/lib/release-pins.js +350 -0
- package/lib/release-pins.json +4225 -0
- package/lib/release-tags.js +12 -0
- package/lib/release.js +36 -0
- package/lib/restart-command.js +161 -0
- package/lib/rollback.js +227 -0
- package/lib/run-liveness.js +15 -0
- package/lib/runtime-log.js +287 -0
- package/lib/sandbox-support.js +17 -0
- package/lib/semver-order.js +40 -0
- package/lib/session-socket.js +69 -0
- package/lib/session-table.js +238 -0
- package/lib/session.js +281 -0
- package/lib/settings-command.js +82 -0
- package/lib/settings.js +564 -0
- package/lib/shim-binary.js +152 -0
- package/lib/shim-config.js +159 -0
- package/lib/shim-install.js +365 -0
- package/lib/sigstore/README.md +44 -0
- package/lib/sigstore/npm-keys.json +18 -0
- package/lib/sigstore/trusted-root.json +126 -0
- package/lib/snippets.js +76 -0
- package/lib/start.js +721 -0
- package/lib/store-files.js +48 -0
- package/lib/store-paths.js +33 -0
- package/lib/swap-preload.js +38 -0
- package/lib/tar.js +220 -0
- package/lib/uninstall.js +314 -0
- package/lib/unpack.js +41 -0
- package/lib/upgrade-stamp.js +63 -0
- package/lib/upgrade.js +281 -0
- package/lib/watch.js +40 -0
- package/lib/win-acl.js +420 -0
- package/node_modules/@sigstore/bundle/LICENSE +202 -0
- package/node_modules/@sigstore/bundle/README.md +19 -0
- package/node_modules/@sigstore/bundle/dist/build.d.ts +18 -0
- package/node_modules/@sigstore/bundle/dist/build.js +100 -0
- package/node_modules/@sigstore/bundle/dist/bundle.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/bundle.js +24 -0
- package/node_modules/@sigstore/bundle/dist/error.d.ts +4 -0
- package/node_modules/@sigstore/bundle/dist/error.js +25 -0
- package/node_modules/@sigstore/bundle/dist/index.d.ts +8 -0
- package/node_modules/@sigstore/bundle/dist/index.js +43 -0
- package/node_modules/@sigstore/bundle/dist/serialized.d.ts +74 -0
- package/node_modules/@sigstore/bundle/dist/serialized.js +49 -0
- package/node_modules/@sigstore/bundle/dist/utility.d.ts +14 -0
- package/node_modules/@sigstore/bundle/dist/utility.js +2 -0
- package/node_modules/@sigstore/bundle/dist/validate.d.ts +7 -0
- package/node_modules/@sigstore/bundle/dist/validate.js +199 -0
- package/node_modules/@sigstore/bundle/package.json +35 -0
- package/node_modules/@sigstore/core/LICENSE +202 -0
- package/node_modules/@sigstore/core/README.md +10 -0
- package/node_modules/@sigstore/core/dist/asn1/error.d.ts +4 -0
- package/node_modules/@sigstore/core/dist/asn1/error.js +24 -0
- package/node_modules/@sigstore/core/dist/asn1/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/asn1/index.js +20 -0
- package/node_modules/@sigstore/core/dist/asn1/length.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/asn1/length.js +62 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.d.ts +14 -0
- package/node_modules/@sigstore/core/dist/asn1/obj.js +155 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/asn1/parse.js +124 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.d.ts +16 -0
- package/node_modules/@sigstore/core/dist/asn1/tag.js +89 -0
- package/node_modules/@sigstore/core/dist/crypto.d.ts +6 -0
- package/node_modules/@sigstore/core/dist/crypto.js +69 -0
- package/node_modules/@sigstore/core/dist/dsse.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/dsse.js +29 -0
- package/node_modules/@sigstore/core/dist/encoding.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/encoding.js +27 -0
- package/node_modules/@sigstore/core/dist/index.d.ts +9 -0
- package/node_modules/@sigstore/core/dist/index.js +66 -0
- package/node_modules/@sigstore/core/dist/json.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/json.js +60 -0
- package/node_modules/@sigstore/core/dist/oid.d.ts +3 -0
- package/node_modules/@sigstore/core/dist/oid.js +20 -0
- package/node_modules/@sigstore/core/dist/pem.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/pem.js +43 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/rfc3161/error.js +21 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.d.ts +1 -0
- package/node_modules/@sigstore/core/dist/rfc3161/index.js +20 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.d.ts +36 -0
- package/node_modules/@sigstore/core/dist/rfc3161/timestamp.js +212 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.d.ts +12 -0
- package/node_modules/@sigstore/core/dist/rfc3161/tstinfo.js +72 -0
- package/node_modules/@sigstore/core/dist/stream.d.ts +21 -0
- package/node_modules/@sigstore/core/dist/stream.js +117 -0
- package/node_modules/@sigstore/core/dist/x509/cert.d.ts +43 -0
- package/node_modules/@sigstore/core/dist/x509/cert.js +245 -0
- package/node_modules/@sigstore/core/dist/x509/ext.d.ts +41 -0
- package/node_modules/@sigstore/core/dist/x509/ext.js +146 -0
- package/node_modules/@sigstore/core/dist/x509/index.d.ts +2 -0
- package/node_modules/@sigstore/core/dist/x509/index.js +23 -0
- package/node_modules/@sigstore/core/dist/x509/sct.d.ts +25 -0
- package/node_modules/@sigstore/core/dist/x509/sct.js +158 -0
- package/node_modules/@sigstore/core/package.json +31 -0
- package/node_modules/@sigstore/protobuf-specs/LICENSE +202 -0
- package/node_modules/@sigstore/protobuf-specs/README.md +5 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.d.ts +44 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/envelope.js +59 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.d.ts +64 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/events.js +174 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/api/field_behavior.js +141 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.d.ts +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/any.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.d.ts +1309 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/descriptor.js +2191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.d.ts +113 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/google/protobuf/timestamp.js +29 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.d.ts +23 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/dsse.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.d.ts +43 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/entry.js +81 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.d.ts +22 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/hashedrekord.js +56 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.d.ts +35 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/rekor/v2/verifier.js +74 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.d.ts +146 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_bundle.js +103 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.d.ts +304 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_common.js +612 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.d.ts +33 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_monitor.js +55 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.d.ts +144 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_rekor.js +137 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.d.ts +386 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_trustroot.js +284 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.d.ts +191 -0
- package/node_modules/@sigstore/protobuf-specs/dist/__generated__/sigstore_verification.js +281 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/protobuf-specs/dist/index.js +37 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.d.ts +4 -0
- package/node_modules/@sigstore/protobuf-specs/dist/rekor/v2/index.js +35 -0
- package/node_modules/@sigstore/protobuf-specs/package.json +35 -0
- package/node_modules/@sigstore/verify/README.md +9 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.d.ts +12 -0
- package/node_modules/@sigstore/verify/dist/bundle/dsse.js +44 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/bundle/index.js +59 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.d.ts +13 -0
- package/node_modules/@sigstore/verify/dist/bundle/message.js +54 -0
- package/node_modules/@sigstore/verify/dist/error.d.ts +16 -0
- package/node_modules/@sigstore/verify/dist/error.js +34 -0
- package/node_modules/@sigstore/verify/dist/index.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/index.js +28 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.d.ts +21 -0
- package/node_modules/@sigstore/verify/dist/key/certificate.js +216 -0
- package/node_modules/@sigstore/verify/dist/key/index.d.ts +10 -0
- package/node_modules/@sigstore/verify/dist/key/index.js +75 -0
- package/node_modules/@sigstore/verify/dist/key/sct.d.ts +4 -0
- package/node_modules/@sigstore/verify/dist/key/sct.js +78 -0
- package/node_modules/@sigstore/verify/dist/policy.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/policy.js +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.d.ts +50 -0
- package/node_modules/@sigstore/verify/dist/shared.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/timestamp/index.js +24 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/timestamp/tsa.js +63 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.d.ts +11 -0
- package/node_modules/@sigstore/verify/dist/tlog/checkpoint.js +154 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/dsse.js +106 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.d.ts +6 -0
- package/node_modules/@sigstore/verify/dist/tlog/hashedrekord.js +94 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/tlog/index.js +92 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/intoto.js +62 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/merkle.js +104 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.d.ts +3 -0
- package/node_modules/@sigstore/verify/dist/tlog/set.js +60 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.d.ts +8 -0
- package/node_modules/@sigstore/verify/dist/trust/filter.js +23 -0
- package/node_modules/@sigstore/verify/dist/trust/index.d.ts +5 -0
- package/node_modules/@sigstore/verify/dist/trust/index.js +90 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.d.ts +29 -0
- package/node_modules/@sigstore/verify/dist/trust/trust.types.js +2 -0
- package/node_modules/@sigstore/verify/dist/verifier.d.ts +31 -0
- package/node_modules/@sigstore/verify/dist/verifier.js +160 -0
- package/node_modules/@sigstore/verify/package.json +36 -0
- package/package.json +37 -4
package/lib/win-acl.js
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Copied from countinghouse lib/win-acl.js at master c274f2f3 (2026-11-15),
|
|
3
|
+
// with countinghouse #275's fileAcls and privateProblem's directory option,
|
|
4
|
+
// unchanged but for powershellPath, which is exported here, and
|
|
5
|
+
// makePrivateDirs, prefetch, FILE_ACLS_EACH_SCRIPT and runCount, which are
|
|
6
|
+
// ch-local's own (cold-start part 3); keep the two copies in step.
|
|
7
|
+
// (Apache-2.0, the same author.) For the private-file checks the native shim
|
|
8
|
+
// makes (lib/private-file.js): the
|
|
9
|
+
// owner and DACL of a file by well-known SID, read with the PowerShell in the
|
|
10
|
+
// Windows directory, and privateProblem's rule.
|
|
11
|
+
// Windows access control by well-known SID, read and set with the PowerShell
|
|
12
|
+
// in the Windows directory (no localized names, no icacls text). Shared by
|
|
13
|
+
// the operator's ceiling (lib/settings-ceiling.js) and the identity secret
|
|
14
|
+
// (lib/identity.js), where POSIX has mode bits and Windows has none (every
|
|
15
|
+
// file reports 0666 there).
|
|
16
|
+
//
|
|
17
|
+
// PowerShell is started by its absolute path under the Windows directory,
|
|
18
|
+
// never by name (Windows looks in the current directory first, where an
|
|
19
|
+
// agent could have put a powershell.exe), with its working directory there
|
|
20
|
+
// and a minimal environment: no PSModulePath, no profile; the security
|
|
21
|
+
// module is imported from beside that powershell.exe. Every caller fails
|
|
22
|
+
// closed on a throw.
|
|
23
|
+
const fs = require('fs');
|
|
24
|
+
const path = require('path');
|
|
25
|
+
const {execFileSync} = require('child_process');
|
|
26
|
+
|
|
27
|
+
const DRIVE_PATH = /^[A-Za-z]:\\[^"<>|?*\r\n]*$/;
|
|
28
|
+
const SYSTEM = 'S-1-5-18';
|
|
29
|
+
const ADMINISTRATORS = 'S-1-5-32-544';
|
|
30
|
+
|
|
31
|
+
// The process's SystemRoot (the user's own environment: spec #169 section 3),
|
|
32
|
+
// which a caller may check against the Windows known folder.
|
|
33
|
+
function windowsDir() {
|
|
34
|
+
const root = process.env.SystemRoot || process.env.windir || 'C:\\Windows';
|
|
35
|
+
if (!DRIVE_PATH.test(root)) throw new Error(`SystemRoot is not a drive path (${String(root).slice(0, 80)})`);
|
|
36
|
+
return root.replace(/\\+$/, '');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// input: what the script reads from stdin ([Console]::In), never a variable
|
|
40
|
+
// or an argument (a secret is never in another process's environment or
|
|
41
|
+
// command line). Throws; e.code ETIMEDOUT when it took over 10 s.
|
|
42
|
+
// PowerShell in the Windows directory, by its absolute path
|
|
43
|
+
const powershellPath = () => path.win32.join(windowsDir(), 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe');
|
|
44
|
+
|
|
45
|
+
// How many synchronous PowerShell runs this process has made (cold-start
|
|
46
|
+
// part 3's pin: the daemon's first start counts them, on Windows).
|
|
47
|
+
let runs = 0;
|
|
48
|
+
const runCount = () => runs;
|
|
49
|
+
function runPowershell(script, extraEnv = {}, input = '') {
|
|
50
|
+
const root = windowsDir();
|
|
51
|
+
runs++;
|
|
52
|
+
const system32 = path.win32.join(root, 'System32');
|
|
53
|
+
return execFileSync(powershellPath(),
|
|
54
|
+
['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', script],
|
|
55
|
+
{cwd: system32, env: Object.assign({SystemRoot: root, windir: root}, extraEnv), input: input, timeout: 10000, encoding: 'utf8', windowsHide: true});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// runPowershell without blocking: for a script whose answer comes from this
|
|
59
|
+
// same process (the daemon's pipe probe, when a test serves the pipe in
|
|
60
|
+
// process), which a synchronous child would wait on for ever. The same
|
|
61
|
+
// arguments, environment and 10 s bound. -> Promise of stdout; rejects on a
|
|
62
|
+
// non-zero exit, the bound or a failed start.
|
|
63
|
+
function runPowershellAsync(script, extraEnv = {}, input = '') {
|
|
64
|
+
const {spawn} = require('child_process');
|
|
65
|
+
const root = windowsDir();
|
|
66
|
+
const system32 = path.win32.join(root, 'System32');
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
let out = '';
|
|
69
|
+
let settled = false;
|
|
70
|
+
const done = (err) => { if (settled) return; settled = true; clearTimeout(timer); if (err != null) reject(err); else resolve(out); };
|
|
71
|
+
let child;
|
|
72
|
+
try {
|
|
73
|
+
child = spawn(powershellPath(), ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', script],
|
|
74
|
+
{cwd: system32, env: Object.assign({SystemRoot: root, windir: root}, extraEnv), windowsHide: true, stdio: ['pipe', 'pipe', 'ignore']});
|
|
75
|
+
} catch (e) {
|
|
76
|
+
return done(e);
|
|
77
|
+
}
|
|
78
|
+
const timer = setTimeout(() => { try { child.kill(); } catch (e) { /* gone */ } done(new Error('powershell did not answer within 10 s')); }, 10000);
|
|
79
|
+
child.stdout.setEncoding('utf8');
|
|
80
|
+
child.stdout.on('data', (d) => { out += d; });
|
|
81
|
+
child.on('error', done);
|
|
82
|
+
child.on('close', (code) => done(code === 0 ? null : new Error(`powershell exited ${code}`)));
|
|
83
|
+
child.stdin.on('error', () => { /* it ended first: its exit says why */ });
|
|
84
|
+
child.stdin.end(input);
|
|
85
|
+
return undefined;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Pure .NET, and no cmdlet from a module (Get-Acl, ConvertTo-Json,
|
|
90
|
+
// Join-Path, New-Object ...): calling one makes PowerShell look commands up,
|
|
91
|
+
// which without the caller's PSModuleAnalysisCachePath rebuilds its module
|
|
92
|
+
// analysis cache, some 20 s a call on the CI runner, and would load code
|
|
93
|
+
// from whatever module path it has. test/stdio/17 and test/auth/51 check
|
|
94
|
+
// none is named. The JSON is built by hand: a SID, a rights number and
|
|
95
|
+
// Allow or Deny hold no quote.
|
|
96
|
+
const PRELUDE = [
|
|
97
|
+
"$ErrorActionPreference = 'Stop'",
|
|
98
|
+
'$sid = [System.Security.Principal.SecurityIdentifier]',
|
|
99
|
+
'$inheritOnly = [System.Security.AccessControl.PropagationFlags]::InheritOnly'
|
|
100
|
+
];
|
|
101
|
+
// A $p's ACL as JSON: {"owner", "rules": [{sid, rights, type, inheritOnly}]}
|
|
102
|
+
// (inherited rules included: they are evaluated like any other).
|
|
103
|
+
const ACL_FN = [
|
|
104
|
+
'function A($p) {',
|
|
105
|
+
' if ([System.IO.Directory]::Exists($p)) { $a = [System.IO.Directory]::GetAccessControl($p) } else { $a = [System.IO.File]::GetAccessControl($p) }',
|
|
106
|
+
' $r = @()',
|
|
107
|
+
' foreach ($x in $a.GetAccessRules($true, $true, $sid)) {',
|
|
108
|
+
' $io = (($x.PropagationFlags -band $inheritOnly) -ne 0)',
|
|
109
|
+
" $r += ('{\"sid\":\"' + $x.IdentityReference.Value + '\",\"rights\":' + [int64]$x.FileSystemRights + ',\"type\":\"' + [string]$x.AccessControlType + '\",\"inheritOnly\":' + ([string]$io).ToLower() + '}')",
|
|
110
|
+
' }',
|
|
111
|
+
' $o = $a.GetOwner($sid)',
|
|
112
|
+
" $ov = ''",
|
|
113
|
+
' if ($o -ne $null) { $ov = $o.Value }',
|
|
114
|
+
// Only plain allow (A) and deny (D) ACEs are understood: any other type
|
|
115
|
+
// (OA, XA, ZA, XU, the object and callback types) is not, or not wholly,
|
|
116
|
+
// among GetAccessRules' rules. Seen in the SDDL, given as a flag (the SDDL
|
|
117
|
+
// itself, which may quote, is not).
|
|
118
|
+
" $sddl = $a.GetSecurityDescriptorSddlForm([System.Security.AccessControl.AccessControlSections]::Access)",
|
|
119
|
+
' $other = $false',
|
|
120
|
+
" foreach ($t in [regex]::Matches($sddl, '\\(([A-Z]+);')) { if ($t.Groups[1].Value -ne 'A' -and $t.Groups[1].Value -ne 'D') { $other = $true } }",
|
|
121
|
+
" '{\"owner\":\"' + $ov + '\",\"otherAces\":' + ([string]$other).ToLower() + ',\"rules\":[' + ($r -join ',') + ']}'",
|
|
122
|
+
'}'
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
// file -> {user: the current user's SID, owner, rules}; throws on any failure.
|
|
126
|
+
const FILE_ACL_SCRIPT = PRELUDE.concat(ACL_FN, [
|
|
127
|
+
'$u = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value',
|
|
128
|
+
"(A $env:CH_ACL_FILE).Replace('{\"owner\"', '{\"user\":\"' + $u + '\",\"owner\"')"
|
|
129
|
+
]).join('\n');
|
|
130
|
+
function fileAcl(file) {
|
|
131
|
+
// absolute: PowerShell's working directory is System32
|
|
132
|
+
return JSON.parse(runPowershell(FILE_ACL_SCRIPT, {CH_ACL_FILE: path.resolve(file)}));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Several paths' ACLs in one PowerShell run (each run costs 1 to 10 s on a
|
|
136
|
+
// CI runner): files -> [{user, owner, otherAces, rules}], in order. The paths
|
|
137
|
+
// go in one variable, a newline between each (DRIVE_PATH has none, nor does
|
|
138
|
+
// path.resolve give one). Throws on any failure. (As countinghouse's, C2.)
|
|
139
|
+
const FILE_ACLS_SCRIPT = PRELUDE.concat(ACL_FN, [
|
|
140
|
+
'$u = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value',
|
|
141
|
+
'$out = @()',
|
|
142
|
+
"foreach ($f in ($env:CH_ACL_FILES -split \"`n\")) { $out += (A $f).Replace('{\"owner\"', '{\"user\":\"' + $u + '\",\"owner\"') }",
|
|
143
|
+
"'[' + ($out -join ',') + ']'"
|
|
144
|
+
]).join('\n');
|
|
145
|
+
const pathList = (files) => {
|
|
146
|
+
const list = files.map((f) => path.resolve(f));
|
|
147
|
+
if (list.length === 0 || list.some((f) => /[\r\n]/.test(f))) throw new Error('one or more paths, none with a line break');
|
|
148
|
+
return list;
|
|
149
|
+
};
|
|
150
|
+
function fileAcls(files) {
|
|
151
|
+
const list = pathList(files);
|
|
152
|
+
const acls = JSON.parse(runPowershell(FILE_ACLS_SCRIPT, {CH_ACL_FILES: list.join('\n')}));
|
|
153
|
+
if (!Array.isArray(acls) || acls.length !== list.length) throw new Error('fileAcls: not one ACL per path');
|
|
154
|
+
return acls;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Several paths' ACLs in one run, each read in a try of its own: a path whose
|
|
158
|
+
// read fails answers {"failed": true} in its place, never hiding another's.
|
|
159
|
+
const FILE_ACLS_EACH_SCRIPT = PRELUDE.concat(ACL_FN, [
|
|
160
|
+
'$u = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value',
|
|
161
|
+
'$out = @()',
|
|
162
|
+
"foreach ($f in ($env:CH_ACL_FILES -split \"`n\")) { try { $out += (A $f).Replace('{\"owner\"', '{\"user\":\"' + $u + '\",\"owner\"') } catch { $out += '{\"failed\":true}' } }",
|
|
163
|
+
"'[' + ($out -join ',') + ']'"
|
|
164
|
+
]).join('\n');
|
|
165
|
+
|
|
166
|
+
// The ACLs of `paths` read in one PowerShell run, answered one path at a time
|
|
167
|
+
// as fileAcl answers (cold-start part 3: a private read asks its folder's and
|
|
168
|
+
// its file's, a run each). -> fileAcl(p).
|
|
169
|
+
// - Each path is lstat'd first, and only a plain file or directory is sent:
|
|
170
|
+
// no ACL is read through a link found at that lstat (the same gap between
|
|
171
|
+
// an lstat and the read as today's checks, whose own lstat still runs
|
|
172
|
+
// first and refuses a link). A link, or a path that isn't there, is
|
|
173
|
+
// answered by the single read, with today's answer, and so is a path under
|
|
174
|
+
// a listed folder that was left out, a path listed before a folder that
|
|
175
|
+
// holds it, and a path that differs only by case from one listed earlier.
|
|
176
|
+
// - A path whose read failed in the run (or a run that failed, or answered
|
|
177
|
+
// in another shape) is answered by the single read, so its error is
|
|
178
|
+
// exactly today's, and every other path keeps its own. A run that timed
|
|
179
|
+
// out is not followed by more: every sent path answers that timeout, so a
|
|
180
|
+
// refusal comes no later than today's first single read, with its code.
|
|
181
|
+
// A reader serves the one read it was made for and is dropped with it, so a
|
|
182
|
+
// later read reads fresh.
|
|
183
|
+
// run, lstat: a test's; single: the caller's own reader (else fileAcl's export).
|
|
184
|
+
function prefetch(paths, {run = runPowershell, lstat = (p) => fs.lstatSync(p), single = (p) => module.exports.fileAcl(p)} = {}) {
|
|
185
|
+
const known = new Map();
|
|
186
|
+
const plain = [];
|
|
187
|
+
const left = [];
|
|
188
|
+
const under = (r, d) => r.toLowerCase().startsWith(`${d.toLowerCase().replace(/[\\/]+$/, '')}${path.sep}`);
|
|
189
|
+
const all = paths.map((p) => path.resolve(p));
|
|
190
|
+
for (let i = 0; i < all.length; i++) {
|
|
191
|
+
const r = all[i];
|
|
192
|
+
if (plain.includes(r) || left.includes(r)) continue;
|
|
193
|
+
// (a path under a listed folder that was left out, a link or missing, is
|
|
194
|
+
// left out too: its lstat would go through that link; and so is one
|
|
195
|
+
// whose folder is listed after it, or one an earlier listed path spells
|
|
196
|
+
// with other case: a folder is judged before what it holds)
|
|
197
|
+
if (left.some((d) => under(r, d))) { left.push(r); continue; }
|
|
198
|
+
if (all.some((d, j) => (j > i && under(r, d)) || (j < i && d !== r && d.toLowerCase() === r.toLowerCase()))) { left.push(r); continue; }
|
|
199
|
+
let st = null;
|
|
200
|
+
try { st = lstat(r); } catch (e) { st = null; }
|
|
201
|
+
if (st == null || st.isSymbolicLink() || !(st.isFile() || st.isDirectory())) { left.push(r); continue; }
|
|
202
|
+
plain.push(r);
|
|
203
|
+
}
|
|
204
|
+
let timedOut = null;
|
|
205
|
+
if (plain.length > 0) {
|
|
206
|
+
let out = null;
|
|
207
|
+
try { out = JSON.parse(run(FILE_ACLS_EACH_SCRIPT, {CH_ACL_FILES: pathList(plain).join('\n')})); } catch (e) { out = null; if (e != null && e.code === 'ETIMEDOUT') timedOut = e; }
|
|
208
|
+
if (Array.isArray(out) && out.length === plain.length) {
|
|
209
|
+
plain.forEach((p, i) => { if (out[i] != null && typeof out[i] === 'object' && out[i].failed !== true) known.set(p, out[i]); });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return (p) => {
|
|
213
|
+
const r = path.resolve(p);
|
|
214
|
+
if (known.has(r)) return known.get(r);
|
|
215
|
+
if (timedOut != null && plain.includes(r)) throw timedOut;
|
|
216
|
+
return single(p);
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// ch-local's own directories on Windows (the daemon's run directory, C4c):
|
|
221
|
+
// each of `dirs`, in order, created if missing and given a protected DACL
|
|
222
|
+
// (nothing inherited): full control for the current user and SYSTEM, to the
|
|
223
|
+
// directory and everything made in it; then the ACLs of `read`, as
|
|
224
|
+
// fileAcls, in the same run. Only the DACL is written, so no privilege to
|
|
225
|
+
// set an owner is needed. Throws on any failure.
|
|
226
|
+
const PRIVATE_DIRS_SCRIPT = PRELUDE.concat(ACL_FN, [
|
|
227
|
+
'$full = [System.Security.AccessControl.FileSystemRights]::FullControl',
|
|
228
|
+
'$allow = [System.Security.AccessControl.AccessControlType]::Allow',
|
|
229
|
+
"$inherit = [System.Security.AccessControl.InheritanceFlags]'ContainerInherit, ObjectInherit'",
|
|
230
|
+
'$none = [System.Security.AccessControl.PropagationFlags]::None',
|
|
231
|
+
'$me = [System.Security.Principal.WindowsIdentity]::GetCurrent().User',
|
|
232
|
+
`$system = [System.Security.Principal.SecurityIdentifier]::new('${SYSTEM}')`,
|
|
233
|
+
"foreach ($d in ($env:CH_ACL_DIRS -split \"`n\")) {",
|
|
234
|
+
' $a = [System.Security.AccessControl.DirectorySecurity]::new()',
|
|
235
|
+
' $a.SetAccessRuleProtection($true, $false)',
|
|
236
|
+
' $a.AddAccessRule([System.Security.AccessControl.FileSystemAccessRule]::new($me, $full, $inherit, $none, $allow))',
|
|
237
|
+
' $a.AddAccessRule([System.Security.AccessControl.FileSystemAccessRule]::new($system, $full, $inherit, $none, $allow))',
|
|
238
|
+
// (never a missing parent: CreateDirectory makes them, so a home removed
|
|
239
|
+
// meanwhile would be made again -- the reviewer's high on #140, L7)
|
|
240
|
+
' if ([System.IO.Directory]::Exists($d)) { [System.IO.Directory]::SetAccessControl($d, $a) } elseif (-not [System.IO.Directory]::Exists([System.IO.Path]::GetDirectoryName($d))) { throw ("the folder above " + $d + " is not there") } else { [void][System.IO.Directory]::CreateDirectory($d, $a) }',
|
|
241
|
+
'}',
|
|
242
|
+
'$u = $me.Value',
|
|
243
|
+
'$out = @()',
|
|
244
|
+
"foreach ($f in ($env:CH_ACL_FILES -split \"`n\")) { $out += (A $f).Replace('{\"owner\"', '{\"user\":\"' + $u + '\",\"owner\"') }",
|
|
245
|
+
"'[' + ($out -join ',') + ']'"
|
|
246
|
+
]).join('\n');
|
|
247
|
+
// -> the ACLs of `read`, read after `dirs` were made private
|
|
248
|
+
function makePrivateDirs(dirs, read) {
|
|
249
|
+
const d = pathList(dirs);
|
|
250
|
+
const r = pathList(read);
|
|
251
|
+
const acls = JSON.parse(runPowershell(PRIVATE_DIRS_SCRIPT, {CH_ACL_DIRS: d.join('\n'), CH_ACL_FILES: r.join('\n')}));
|
|
252
|
+
if (!Array.isArray(acls) || acls.length !== r.length) throw new Error('makePrivateDirs: not one ACL per path');
|
|
253
|
+
return acls;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Gives file a protected DACL (nothing inherited): full control for the
|
|
257
|
+
// current user and SYSTEM, no one else. Only the DACL is written (a fresh
|
|
258
|
+
// FileSecurity), so no privilege to set an owner is needed. Throws on any
|
|
259
|
+
// failure.
|
|
260
|
+
// Creates file (which must not exist) with data from stdin, its DACL set in
|
|
261
|
+
// the same call that creates it: protected (nothing inherited), full control
|
|
262
|
+
// for the current user and SYSTEM, no one else. There is no instant at which
|
|
263
|
+
// it exists with the directory's inherited DACL, and FileShare.None lets no
|
|
264
|
+
// other handle open while it is written; CreateNew fails on a name that
|
|
265
|
+
// exists (one planted ahead, a link). Throws.
|
|
266
|
+
const CREATE_SCRIPT = [
|
|
267
|
+
"$ErrorActionPreference = 'Stop'",
|
|
268
|
+
'$a = [System.Security.AccessControl.FileSecurity]::new()',
|
|
269
|
+
'$a.SetAccessRuleProtection($true, $false)',
|
|
270
|
+
'$full = [System.Security.AccessControl.FileSystemRights]::FullControl',
|
|
271
|
+
'$allow = [System.Security.AccessControl.AccessControlType]::Allow',
|
|
272
|
+
'$u = [System.Security.Principal.WindowsIdentity]::GetCurrent().User',
|
|
273
|
+
'$a.AddAccessRule([System.Security.AccessControl.FileSystemAccessRule]::new($u, $full, $allow))',
|
|
274
|
+
`$a.AddAccessRule([System.Security.AccessControl.FileSystemAccessRule]::new([System.Security.Principal.SecurityIdentifier]::new('${SYSTEM}'), $full, $allow))`,
|
|
275
|
+
// (the data as base64 of its bytes: console text would be read in the
|
|
276
|
+
// console's code page, and ASCII.GetBytes made every non-ASCII character
|
|
277
|
+
// '?' -- A12)
|
|
278
|
+
'$bytes = [System.Convert]::FromBase64String([Console]::In.ReadToEnd().Trim())',
|
|
279
|
+
'$fs = [System.IO.FileStream]::new($env:CH_ACL_FILE, [System.IO.FileMode]::CreateNew, [System.Security.AccessControl.FileSystemRights]::Write, [System.IO.FileShare]::None, 4096, [System.IO.FileOptions]::None, $a)',
|
|
280
|
+
'try { $fs.Write($bytes, 0, $bytes.Length); $fs.Flush() } finally { $fs.Dispose() }'
|
|
281
|
+
].join('\n');
|
|
282
|
+
// data (a string, as UTF-8, or bytes: a Buffer or any view of an
|
|
283
|
+
// ArrayBuffer) -> what createPrivate's PowerShell reads on stdin: base64 of
|
|
284
|
+
// its bytes. Anything else is refused, never written as its String().
|
|
285
|
+
function createInput(data) {
|
|
286
|
+
if (typeof data === 'string') return Buffer.from(data, 'utf8').toString('base64');
|
|
287
|
+
if (ArrayBuffer.isView(data)) return Buffer.from(data.buffer, data.byteOffset, data.byteLength).toString('base64');
|
|
288
|
+
throw new TypeError('createPrivate: the data is not a string or bytes');
|
|
289
|
+
}
|
|
290
|
+
function createPrivate(file, data) {
|
|
291
|
+
runPowershell(CREATE_SCRIPT, {CH_ACL_FILE: path.resolve(file)}, createInput(data));
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Rights a rule may grant someone other than the file's people without
|
|
295
|
+
// letting them read or change it: Synchronize, ReadPermissions,
|
|
296
|
+
// ReadAttributes.
|
|
297
|
+
const HARMLESS = (0x100000 | 0x20000 | 0x80) >>> 0;
|
|
298
|
+
// CREATOR OWNER only (never CREATOR GROUP, S-1-3-1)
|
|
299
|
+
const CREATORS = new Set(['S-1-3-0']);
|
|
300
|
+
|
|
301
|
+
// A secret's ACL (fileAcl) -> a problem, or null. Owned by the current user,
|
|
302
|
+
// Administrators or SYSTEM; no allow rule grants anyone else more than
|
|
303
|
+
// HARMLESS; anything unrecognised fails closed. directory: the ACL is a
|
|
304
|
+
// directory's, whose inherit-only allow rules are not skipped: they flow into
|
|
305
|
+
// the files made there, so one granting anyone else more than HARMLESS fails.
|
|
306
|
+
// CREATOR OWNER's inherit-only rule is admitted: it grants nothing by
|
|
307
|
+
// itself, only to whoever makes a child there, which no one else can under a
|
|
308
|
+
// private DACL, and Windows profiles carry it. CREATOR GROUP's is not: it
|
|
309
|
+
// becomes a grant to the creator's primary group (None, every local user;
|
|
310
|
+
// or Domain Users).
|
|
311
|
+
function privateProblem(what, acl, {directory = false} = {}) {
|
|
312
|
+
if (acl == null || typeof(acl) !== 'object' || typeof(acl.owner) !== 'string' || typeof(acl.user) !== 'string') return `${what}'s ACL could not be read`;
|
|
313
|
+
if (acl.otherAces !== false) return `${what} has an access rule other than a plain allow or deny, or its rules could not all be read`;
|
|
314
|
+
const own = new Set([acl.user, SYSTEM, ADMINISTRATORS]);
|
|
315
|
+
if (!own.has(acl.owner)) return `${what} is owned by ${acl.owner}, not this user, Administrators or SYSTEM`;
|
|
316
|
+
const rules = Array.isArray(acl.rules) ? acl.rules : (acl.rules != null ? [acl.rules] : []);
|
|
317
|
+
for (const r of rules) {
|
|
318
|
+
if (r == null || typeof(r.sid) !== 'string' || typeof(r.type) !== 'string' || !Number.isFinite(Number(r.rights))) return `${what} has an access rule that could not be read`;
|
|
319
|
+
if (r.type === 'Deny') continue;
|
|
320
|
+
if (r.inheritOnly === true) {
|
|
321
|
+
if (!directory || CREATORS.has(r.sid)) continue;
|
|
322
|
+
if (r.type === 'Allow' && !own.has(r.sid) && ((Number(r.rights) >>> 0) & ~HARMLESS) !== 0) return `${what} has an inherit-only rule for ${r.sid}, which the files made in it would take`;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (r.type !== 'Allow') return `${what} has an access rule of type ${r.type}`;
|
|
326
|
+
if (!own.has(r.sid) && ((Number(r.rights) >>> 0) & ~HARMLESS) !== 0) return `${what} is accessible by ${r.sid}`;
|
|
327
|
+
}
|
|
328
|
+
return null;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// The rights that change a file or folder (or what is in it): write and append data, write extended attributes, delete a child,
|
|
332
|
+
// write attributes, delete, change permissions, take ownership; generic write and generic all. Any other right beyond HARMLESS is
|
|
333
|
+
// a read (read data, read extended attributes, execute).
|
|
334
|
+
const CHANGE_RIGHTS = (0x2 | 0x4 | 0x10 | 0x40 | 0x100 | 0x10000 | 0x40000 | 0x80000 | 0x40000000 | 0x10000000) >>> 0;
|
|
335
|
+
// The other accounts privateProblem would name (allow rules, not inherit-only, granting someone not the user, SYSTEM or
|
|
336
|
+
// Administrators more than HARMLESS), in its order: [{sid, name (names[sid], as principalNames resolves it; '' if not), change}]
|
|
337
|
+
function openPrincipals(acl, names = {}) {
|
|
338
|
+
if (acl == null || typeof(acl) !== 'object' || typeof(acl.user) !== 'string') return [];
|
|
339
|
+
const own = new Set([acl.user, SYSTEM, ADMINISTRATORS]);
|
|
340
|
+
const rules = Array.isArray(acl.rules) ? acl.rules : (acl.rules != null ? [acl.rules] : []);
|
|
341
|
+
const out = [];
|
|
342
|
+
for (const r of rules) {
|
|
343
|
+
if (r == null || typeof(r.sid) !== 'string' || r.type !== 'Allow' || r.inheritOnly === true || own.has(r.sid)) continue;
|
|
344
|
+
const rights = (Number(r.rights) >>> 0);
|
|
345
|
+
if ((rights & ~HARMLESS) === 0) continue;
|
|
346
|
+
const prev = out.find((p) => p.sid === r.sid);
|
|
347
|
+
if (prev != null) { prev.change = prev.change || (rights & CHANGE_RIGHTS) !== 0; continue; }
|
|
348
|
+
out.push({sid: r.sid, name: (names != null && typeof(names[r.sid]) === 'string') ? names[r.sid] : '', change: (rights & CHANGE_RIGHTS) !== 0});
|
|
349
|
+
}
|
|
350
|
+
return out;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// SIDs -> {names: {sid: its name as Windows resolves it ('' when it can't: a capability or workspace SID)}, machine: this machine's
|
|
354
|
+
// name as Windows gives it ([Environment]::MachineName, never the environment's COMPUTERNAME, which a session the shim or Codex
|
|
355
|
+
// starts lacks), localAppData: the user's local application data folder, the known folder (never the environment's)}, in one
|
|
356
|
+
// PowerShell run. For a refusal's words only, so it runs only when one names other accounts, never on the way
|
|
357
|
+
// to a private one (a lookup can reach a domain controller). Every rule is judged by its SID; a SID that is not plainly one is not
|
|
358
|
+
// asked. Each string is written as JSON in ASCII alone (\u escapes), so no console code page changes a localized name. Throws on
|
|
359
|
+
// any failure: the caller then says the SIDs.
|
|
360
|
+
const NAMES_SCRIPT = PRELUDE.concat([
|
|
361
|
+
// (the known folder on its own: a failure there leaves it '', never the names with it)
|
|
362
|
+
"function L() { try { return E ([Environment]::GetFolderPath('LocalApplicationData')) } catch { return '\"\"' } }",
|
|
363
|
+
"function E($t) { $e = ''; foreach ($c in $t.ToCharArray()) { $i = [int]$c; if ($i -lt 32 -or $i -gt 126 -or $i -eq 34 -or $i -eq 92) { $e += '\\u' + $i.ToString('x4') } else { $e += $c } }; return '\"' + $e + '\"' }",
|
|
364
|
+
'$out = @()',
|
|
365
|
+
"foreach ($s in ($env:CH_SIDS -split \"`n\")) {",
|
|
366
|
+
" try { $n = $sid::new($s).Translate([System.Security.Principal.NTAccount]).Value } catch { $n = '' }",
|
|
367
|
+
' $out += (E $n)',
|
|
368
|
+
'}',
|
|
369
|
+
"'{\"machine\":' + (E ([Environment]::MachineName)) + ',\"localAppData\":' + (L) + ',\"names\":[' + ($out -join ',') + ']}'"
|
|
370
|
+
]).join('\n');
|
|
371
|
+
function principalNames(sids) {
|
|
372
|
+
const asked = sids.filter((s) => typeof(s) === 'string' && SID_TEXT.test(s));
|
|
373
|
+
if (asked.length === 0) return {names: {}, machine: null, localAppData: null};
|
|
374
|
+
const got = JSON.parse(runPowershell(NAMES_SCRIPT, {CH_SIDS: asked.join('\n')}));
|
|
375
|
+
if (got == null || !Array.isArray(got.names) || got.names.length !== asked.length) throw new Error('principalNames: not one name per SID');
|
|
376
|
+
const names = {};
|
|
377
|
+
asked.forEach((s, i) => { names[s] = typeof(got.names[i]) === 'string' ? got.names[i] : ''; });
|
|
378
|
+
const given = (v) => (typeof(v) === 'string' && v !== '') ? v : null;
|
|
379
|
+
return {names, machine: given(got.machine), localAppData: given(got.localAppData)};
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Whether anyone but this user, SYSTEM and Administrators holds a right that changes it, or what is made in it: an allow rule,
|
|
383
|
+
// inherit-only ones included (what was made in it took that right), CREATOR OWNER's aside (it grants only to whoever makes a child).
|
|
384
|
+
// A folder someone else could change may already have been changed, so it is moved aside, not repaired (the reviewer's ruling on
|
|
385
|
+
// the Windows home, as for POSIX's group or world write).
|
|
386
|
+
function foreignChange(acl) {
|
|
387
|
+
if (acl == null || typeof(acl) !== 'object' || typeof(acl.user) !== 'string') return false;
|
|
388
|
+
const own = new Set([acl.user, SYSTEM, ADMINISTRATORS]);
|
|
389
|
+
const rules = Array.isArray(acl.rules) ? acl.rules : (acl.rules != null ? [acl.rules] : []);
|
|
390
|
+
return rules.some((r) => r != null && r.type === 'Allow' && typeof(r.sid) === 'string' && !own.has(r.sid) && !CREATORS.has(r.sid) && ((Number(r.rights) >>> 0) & CHANGE_RIGHTS) !== 0);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// The lines that make file private as privateProblem wants it, for Windows PowerShell (each one, on a line of its own): nothing
|
|
394
|
+
// inherited, this user and SYSTEM, each other SID a rule names removed, and the user made the owner. By SID (no names: they are
|
|
395
|
+
// localized, and a user name is never printed). A SID is removed with .NET's PurgeAccessRules, one SID to a line: icacls /remove
|
|
396
|
+
// leaves a SID that names no account (a Codex sandbox capability), and one call with several /remove switches processes nothing,
|
|
397
|
+
// both saying no error (seen on the owner's machine); Get-Acl/Set-Acl need SeSecurityPrivilege (Set-Acl writes the SACL), which a standard user
|
|
398
|
+
// lacks. The Windows legs run the printed lines as printed (test/home-windows-acl.test.js). Single quotes: nothing in a path is
|
|
399
|
+
// expanded. A SID that is not plainly one: no lines.
|
|
400
|
+
// directory: the grants inherit to what is made in it ((OI)(CI)), or
|
|
401
|
+
// /inheritance:r would leave its own files reachable by no one (the
|
|
402
|
+
// reviewer's Fable high on #126, F13)
|
|
403
|
+
const SID_TEXT = /^S-1-[0-9]+(-[0-9]+)+$/;
|
|
404
|
+
// (PowerShell takes U+2018-U+201B as single quotes too: each doubled, as an ASCII one is)
|
|
405
|
+
const psQuote = (s) => `'${String(s).replace(/['\u2018-\u201b]/g, '$&$&')}'`;
|
|
406
|
+
function fixHint(file, acl, {directory = false} = {}) {
|
|
407
|
+
const user = acl != null && typeof(acl.user) === 'string' ? acl.user : null;
|
|
408
|
+
if (user == null || !SID_TEXT.test(user)) return null;
|
|
409
|
+
const rules = Array.isArray(acl.rules) ? acl.rules : (acl.rules != null ? [acl.rules] : []);
|
|
410
|
+
const others = [...new Set(rules.map((r) => r && r.sid).filter((s) => typeof(s) === 'string' && s !== user && s !== SYSTEM))];
|
|
411
|
+
if (others.some((s) => !SID_TEXT.test(s))) return null;
|
|
412
|
+
const f = directory ? '(OI)(CI)F' : 'F';
|
|
413
|
+
const p = psQuote(file);
|
|
414
|
+
// (each grant in single quotes: in PowerShell an unquoted (OI) is a command to run)
|
|
415
|
+
return [`icacls ${p} /inheritance:r /grant:r '*${user}:${f}' '*${SYSTEM}:${f}'`,
|
|
416
|
+
...others.map((s) => ` $i = Get-Item -LiteralPath ${p} -Force; $a = $i.GetAccessControl('Access'); $a.PurgeAccessRules([System.Security.Principal.SecurityIdentifier]'${s}'); $i.SetAccessControl($a)`),
|
|
417
|
+
` icacls ${p} /setowner *${user}`].join('\n');
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
module.exports = {windowsDir, powershellPath, runPowershell, runPowershellAsync, runCount, fileAcl, fileAcls, prefetch, FILE_ACLS_EACH_SCRIPT, makePrivateDirs, createPrivate, createInput, privateProblem, openPrincipals, principalNames, foreignChange, fixHint, PRELUDE, ACL_FN, FILE_ACL_SCRIPT, FILE_ACLS_SCRIPT, PRIVATE_DIRS_SCRIPT, NAMES_SCRIPT, CREATE_SCRIPT, SYSTEM, ADMINISTRATORS, DRIVE_PATH};
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2023 The Sigstore Authors
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @sigstore/bundle · [](https://www.npmjs.com/package/@sigstore/bundle) [](https://github.com/sigstore/sigstore-js/actions/workflows/ci.yml) [](https://github.com/sigstore/sigstore-js/actions/workflows/smoke-test.yml)
|
|
2
|
+
|
|
3
|
+
A JavaScript library for working with the Sigstore bundle format.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- TypeScript types for the different Sigstore bundle versions.
|
|
8
|
+
- Bundle validation functions.
|
|
9
|
+
- Support for serializing/deserializing bundles to/from JSON.
|
|
10
|
+
|
|
11
|
+
## Prerequisites
|
|
12
|
+
|
|
13
|
+
- Node.js version ^20.17.0 || >=22.9.0
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
npm install @sigstore/bundle
|
|
19
|
+
```
|