@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
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// This platform's native shim, for the client's config entry (countinghouse's
|
|
3
|
+
// shared-runtime design, #236, section 10).
|
|
4
|
+
//
|
|
5
|
+
// Only a source checkout (dev and tests: npm-shim/ beside this lib/, which no
|
|
6
|
+
// published ch-local ships) looks for a shim beyond the one install placed,
|
|
7
|
+
// and only at fixed paths inside the checkout. Everything else -- an
|
|
8
|
+
// installed ch-local (<home>/app/node_modules/@countinghouse/ch-local/lib,
|
|
9
|
+
// or the same under <home>/previous/app after a rollback), and anything whose place can't be told -- uses only the binary
|
|
10
|
+
// install verified and put at <home>/shim (lib/shim-install.js). Nothing is
|
|
11
|
+
// ever looked up by package name: Node's lookup walks every parent
|
|
12
|
+
// directory's node_modules and the global folders ($NODE_PATH,
|
|
13
|
+
// ~/.node_modules), so a ch-shim found that way was never verified, and a
|
|
14
|
+
// client config would run it in every session. A shim there that fails a
|
|
15
|
+
// check below, or none there, runs the per-session mode, said.
|
|
16
|
+
const fs = require('fs');
|
|
17
|
+
const path = require('path');
|
|
18
|
+
|
|
19
|
+
const exeOf = (platform) => (platform === 'win32' ? 'ch-shim.exe' : 'ch-shim');
|
|
20
|
+
const real = (p) => { try { return fs.realpathSync.native(p); } catch (e) { return null; } };
|
|
21
|
+
// as lib/start.js and the shim compare directories: case-insensitive where
|
|
22
|
+
// the file system usually is
|
|
23
|
+
const samePath = (a, b, platform) => (platform === 'win32' || platform === 'darwin' ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
24
|
+
|
|
25
|
+
// whether this code is the home's installed ch-local, by realpath: its lib/
|
|
26
|
+
// under <home>/app or <home>/previous/app, where install puts the package
|
|
27
|
+
// (lib/install.js: <app>/node_modules/<its name>); a home or app that isn't
|
|
28
|
+
// there is not
|
|
29
|
+
const SELF = require('../package.json').name;
|
|
30
|
+
function runsFromHome(home, {platform = process.platform, libDir = __dirname} = {}) {
|
|
31
|
+
if (home == null) return false;
|
|
32
|
+
const me = real(libDir);
|
|
33
|
+
if (me == null) return false;
|
|
34
|
+
const where = require('./home').layout({COUNTINGHOUSE_HOME: home});
|
|
35
|
+
return [where.app, where.previousApp].some((app) => {
|
|
36
|
+
const lib = real(path.join(app, 'node_modules', ...SELF.split('/'), 'lib'));
|
|
37
|
+
return lib != null && samePath(lib, me, platform);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// whether this code is a source checkout: its own npm-shim/ beside lib/
|
|
42
|
+
function isCheckout(libDir = __dirname) {
|
|
43
|
+
return fs.existsSync(path.join(libDir, '..', 'npm-shim', 'ch-shim', 'index.js'));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// a checkout's own built shim, at fixed paths inside it: cargo's build in
|
|
47
|
+
// shim/target/release, or this platform's package in the checkout's own
|
|
48
|
+
// node_modules. No lookup by name, so nothing outside the checkout.
|
|
49
|
+
function defaultLocate({libDir = __dirname, platform = process.platform, arch = process.arch} = {}) {
|
|
50
|
+
if (!isCheckout(libDir)) return {status: 'unsupported'};
|
|
51
|
+
const root = path.join(libDir, '..');
|
|
52
|
+
const target = require(path.join(root, 'npm-shim', 'targets.js')).find((t) => t.os === platform && t.cpu === arch);
|
|
53
|
+
if (target == null) return {status: 'unsupported'};
|
|
54
|
+
const name = `@countinghouse/ch-shim-${target.key}`;
|
|
55
|
+
for (const file of [path.join(root, 'shim', 'target', 'release', exeOf(platform)), path.join(root, 'node_modules', '@countinghouse', `ch-shim-${target.key}`, 'bin', exeOf(platform))]) {
|
|
56
|
+
if (fs.existsSync(file)) return {status: 'found', path: file};
|
|
57
|
+
}
|
|
58
|
+
return {status: 'missing', package: name};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// whether this release (its own lib/release-pins.json, part of the verified
|
|
62
|
+
// app) pins a shim for this platform. One that can't be read or parsed counts
|
|
63
|
+
// as pinned: the note then says reinstall, which repairs it.
|
|
64
|
+
function pinnedHere(platform = process.platform, arch = process.arch, libDir = __dirname) {
|
|
65
|
+
let parsed;
|
|
66
|
+
try {
|
|
67
|
+
parsed = require('./release-pins').parseReleasePins(fs.readFileSync(path.join(libDir, 'release-pins.json')));
|
|
68
|
+
} catch (e) {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
if (parsed.problem != null) return true;
|
|
72
|
+
const name = parsed.pins.shim.packages[`${platform}-${arch}`];
|
|
73
|
+
return name != null && Object.prototype.hasOwnProperty.call(parsed.pins.pins, name);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// The binary install puts beside the app (<home>/shim/ch-shim, by its pin
|
|
77
|
+
// and verified; the install step is on top of the auto-upgrade build) wins
|
|
78
|
+
// over any other lookup, once it and the directories above it are this
|
|
79
|
+
// user's alone: a client config names that file, and whoever can replace it,
|
|
80
|
+
// or anything in its directory, runs as this user in every session.
|
|
81
|
+
// - <home>: lib/home.js homeOwnershipProblem (a directory; on POSIX this
|
|
82
|
+
// user's, not group- or world-writable).
|
|
83
|
+
// - <home>/shim: lib/private-file.js's rule for a private directory, the one
|
|
84
|
+
// the native shim applies (POSIX: not a link, this user's (effective uid),
|
|
85
|
+
// mode 0700 exactly; Windows: not a link or junction, owner and DACL by
|
|
86
|
+
// privateProblem).
|
|
87
|
+
// - ch-shim: a regular file, not a link; on POSIX owned by this user, no
|
|
88
|
+
// group or other write, no setuid or setgid, executable by its owner; on
|
|
89
|
+
// Windows owner and DACL by privateProblem (an unreadable DACL fails
|
|
90
|
+
// closed).
|
|
91
|
+
// Which release it is stays install's to keep right (it replaces it with the
|
|
92
|
+
// app). (home, {platform, geteuid, acl}) -> {file} | {problem} | null (no
|
|
93
|
+
// file there).
|
|
94
|
+
function installed(home, {platform = process.platform, geteuid = process.geteuid, acl} = {}) {
|
|
95
|
+
if (home == null) return null;
|
|
96
|
+
const {checkDirPosix, checkPathWindows} = require('./private-file');
|
|
97
|
+
const dir = path.join(home, 'shim');
|
|
98
|
+
const file = path.join(dir, exeOf(platform));
|
|
99
|
+
let fst;
|
|
100
|
+
try {
|
|
101
|
+
fst = fs.lstatSync(file);
|
|
102
|
+
} catch (e) {
|
|
103
|
+
// only an absent file is "none there"; anything else is said
|
|
104
|
+
if (e.code === 'ENOENT') return null;
|
|
105
|
+
return {problem: `${file} could not be read (${e.code || e.message})`};
|
|
106
|
+
}
|
|
107
|
+
const me = platform === 'win32' || typeof geteuid !== 'function' ? null : geteuid();
|
|
108
|
+
try {
|
|
109
|
+
const owned = require('./home').homeOwnershipProblem(fs.realpathSync(home), platform, {fileAcl: acl != null ? acl.fileAcl : undefined});
|
|
110
|
+
if (owned != null) return {problem: `${home}: ${owned}`};
|
|
111
|
+
if (platform === 'win32') {
|
|
112
|
+
checkPathWindows(dir, true, acl);
|
|
113
|
+
checkPathWindows(file, false, acl);
|
|
114
|
+
return {file};
|
|
115
|
+
}
|
|
116
|
+
checkDirPosix(dir, me);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return {problem: e.code === 'NOT_PRIVATE' ? e.message : `${dir} could not be checked (${e.code || e.message})`};
|
|
119
|
+
}
|
|
120
|
+
const m = fst.mode & 0o7777;
|
|
121
|
+
if (fst.isSymbolicLink() || !fst.isFile()) return {problem: `${file}: it is not a regular file (or is a link)`};
|
|
122
|
+
if (me != null && fst.uid !== me) return {problem: `${file}: it is owned by uid ${fst.uid}, not this user`};
|
|
123
|
+
if ((m & 0o022) !== 0) return {problem: `${file}: it is writable by group or others (mode ${m.toString(8).padStart(4, '0')})`};
|
|
124
|
+
if ((m & 0o6000) !== 0) return {problem: `${file}: it is setuid or setgid (mode ${m.toString(8).padStart(4, '0')})`};
|
|
125
|
+
if ((m & 0o100) === 0) return {problem: `${file}: it is not executable by its owner`};
|
|
126
|
+
return {file};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// {home?, locate?, platform?, geteuid?, acl?} -> {shim: absolute path | null,
|
|
130
|
+
// note: a line for the user | null}. An installed shim that fails the checks
|
|
131
|
+
// above is not used, and the note says why. Only a source checkout that is
|
|
132
|
+
// not a home's app asks locate (its own, or a test's).
|
|
133
|
+
function shimFor({home = null, locate = defaultLocate, platform = process.platform, geteuid, acl, arch = process.arch, libDir = __dirname} = {}) {
|
|
134
|
+
const here = installed(home, {platform, geteuid, acl});
|
|
135
|
+
if (here != null && here.file != null) return {shim: here.file, note: null};
|
|
136
|
+
const passed = here != null ? `ch-local: the installed shim is not used: ${here.problem}; reinstall ch-local to put it right.\n` : '';
|
|
137
|
+
if (!isCheckout(libDir) || runsFromHome(home, {platform, libDir})) {
|
|
138
|
+
if (passed !== '') return {shim: null, note: `${passed}ch-local: until then each session runs its own runtime.\n`};
|
|
139
|
+
if (pinnedHere(platform, arch, libDir)) {
|
|
140
|
+
return {shim: null, note: `ch-local: the shared runtime's shim for this platform is not installed${home != null ? ` (${path.join(home, 'shim', exeOf(platform))})` : ''}; reinstall ch-local. Until then each session runs its own runtime.\n`};
|
|
141
|
+
}
|
|
142
|
+
return {shim: null, note: 'ch-local: this release installs no shared-runtime shim for this platform, so it runs one runtime per session.\n'};
|
|
143
|
+
}
|
|
144
|
+
const r = locate();
|
|
145
|
+
if (r != null && r.status === 'found') return {shim: r.path, note: passed === '' ? null : passed};
|
|
146
|
+
if (r != null && r.status === 'missing') {
|
|
147
|
+
return {shim: null, note: `${passed}ch-local: the shared runtime's shim for this platform (${r.package}) is not installed or holds no binary; reinstall ch-local. Until then each session runs its own runtime.\n`};
|
|
148
|
+
}
|
|
149
|
+
return {shim: null, note: `${passed}ch-local: there is no shared-runtime shim for this platform, so it runs one runtime per session.\n`};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
module.exports = {shimFor, installedShim: installed, exeOf, defaultLocate, runsFromHome, isCheckout};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// <home>/shim.json (countinghouse's shared-runtime design, #236, section 6,
|
|
3
|
+
// "The shim's home and shim.json"): what the native shim runs, from paths
|
|
4
|
+
// ch-local resolves at install. The shim spawns `<node> <chLocal> daemon` and
|
|
5
|
+
// `<node> <chLocal> conditions --for <pid> --home <home>` from it, and gives the daemon a
|
|
6
|
+
// cleared environment holding exactly `env`.
|
|
7
|
+
//
|
|
8
|
+
// {"node": <absolute>, "chLocal": <absolute: <home>/bin/ch-local.js>,
|
|
9
|
+
// "env": {PATH, HOME | USERPROFILE, LANG?, TMPDIR? (POSIX) |
|
|
10
|
+
// SystemRoot, TEMP, TMP, APPDATA, LOCALAPPDATA (Windows)}}
|
|
11
|
+
//
|
|
12
|
+
// 0600, written through a temporary file created exclusively and renamed into
|
|
13
|
+
// place, so a symlink at the path is replaced, never written through. The
|
|
14
|
+
// shim refuses any other key (naming it), a relative path or a non-string
|
|
15
|
+
// value; shimJsonProblem applies the same rule here.
|
|
16
|
+
const fs = require('node:fs');
|
|
17
|
+
const path = require('node:path');
|
|
18
|
+
const {isFullPath} = require('./home');
|
|
19
|
+
|
|
20
|
+
const POSIX_KEYS = ['PATH', 'HOME', 'LANG', 'TMPDIR'];
|
|
21
|
+
const WINDOWS_KEYS = ['PATH', 'USERPROFILE', 'LANG', 'SystemRoot', 'TEMP', 'TMP', 'APPDATA', 'LOCALAPPDATA'];
|
|
22
|
+
|
|
23
|
+
// a variable of env by name, case-insensitively on Windows (Path, PATH)
|
|
24
|
+
function pick(env, name, platform) {
|
|
25
|
+
if (platform !== 'win32') return env[name];
|
|
26
|
+
const k = Object.keys(env).find((n) => n.toUpperCase() === name.toUpperCase());
|
|
27
|
+
return k != null ? env[k] : undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// the body install writes: node (io.node), chLocal (the installed launcher)
|
|
31
|
+
// and the allowlisted variables present at install
|
|
32
|
+
function shimJsonFor({node, home, env = process.env, platform = process.platform}) {
|
|
33
|
+
// joined by that platform's rules, as the shim there reads it
|
|
34
|
+
const join = platform === 'win32' ? path.win32.join : path.posix.join;
|
|
35
|
+
return {node, chLocal: join(home, 'bin', 'ch-local.js'), env: allowedEnv(env, platform)};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// env's variables on shim.json's allowlist for `platform`, and no others: the
|
|
39
|
+
// daemon's environment, and its runtime's, however the daemon was started
|
|
40
|
+
function allowedEnv(env, platform = process.platform) {
|
|
41
|
+
const keys = platform === 'win32' ? WINDOWS_KEYS : POSIX_KEYS;
|
|
42
|
+
const out = {};
|
|
43
|
+
for (const k of keys) {
|
|
44
|
+
const v = pick(env, k, platform);
|
|
45
|
+
if (typeof v === 'string' && v !== '') out[k] = v;
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// A per-session runtime's environment (#413 section 6.9; the Reviewer's
|
|
51
|
+
// high review of L5a, 1): an allowlist, never the client's whole
|
|
52
|
+
// environment, so no credential a client sets reaches the runtime or a
|
|
53
|
+
// worker. The daemon's keys (above), plus the locale and time zone, the
|
|
54
|
+
// extra CA bundle a corporate network needs (a path), the acceptance switch
|
|
55
|
+
// (honoured only with an acceptance run's origin map), and on Windows what a
|
|
56
|
+
// process needs to run a .cmd. No test switch: a client's environment never
|
|
57
|
+
// turns on the runtime's test-only delays. No proxy variable: countinghouse
|
|
58
|
+
// makes no call through an HTTP proxy (its lockdown sets proxy: null on a
|
|
59
|
+
// module's request; its remote client has its own agent), so a proxy here
|
|
60
|
+
// would only be readable by a module that declares it. Start adds the
|
|
61
|
+
// credential slots after this.
|
|
62
|
+
const LOCALE = /^(LC_[A-Z]+|LANGUAGE|TZ)$/;
|
|
63
|
+
const RUNTIME_EXTRA = ['NODE_EXTRA_CA_CERTS', 'COUNTINGHOUSE_ACCEPTANCE'];
|
|
64
|
+
// what a Windows process needs to run a .cmd (npm, git) and find its
|
|
65
|
+
// system directories: no secret among them
|
|
66
|
+
const WINDOWS_EXTRA = ['PATHEXT', 'ComSpec', 'SystemDrive', 'WINDIR', 'PROGRAMDATA', 'ProgramFiles'];
|
|
67
|
+
function runtimeEnv(env, platform = process.platform) {
|
|
68
|
+
const out = allowedEnv(env, platform);
|
|
69
|
+
if (platform === 'win32') for (const k of WINDOWS_EXTRA) { const v = pick(env || {}, k, platform); if (typeof v === 'string' && v !== '') out[k] = v; }
|
|
70
|
+
// by any case on win32, as the whole allowlist is there (the Reviewer's
|
|
71
|
+
// round 3, 8); on POSIX by their own names
|
|
72
|
+
const win = platform === 'win32';
|
|
73
|
+
for (const [k, v] of Object.entries(env || {})) {
|
|
74
|
+
if (typeof v !== 'string' || v === '' || k in out) continue;
|
|
75
|
+
const name = win ? k.toUpperCase() : k;
|
|
76
|
+
if (LOCALE.test(name) || RUNTIME_EXTRA.includes(name)) out[k] = v;
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// -> null, or what the shim would refuse on `platform`: paths absolute for
|
|
82
|
+
// that platform, its own allowlist only, and never a .cmd or .bat node (run
|
|
83
|
+
// through cmd.exe, with its parsing), as the shim's config.rs refuses
|
|
84
|
+
function shimJsonProblem(body, platform = process.platform) {
|
|
85
|
+
if (body == null || typeof body !== 'object' || Array.isArray(body)) return 'shim.json is not an object';
|
|
86
|
+
for (const k of ['node', 'chLocal']) {
|
|
87
|
+
if (typeof body[k] !== 'string' || !isFullPath(body[k], platform)) return `${k} is not an absolute path`;
|
|
88
|
+
}
|
|
89
|
+
if (/\.(cmd|bat)$/i.test(body.node)) return 'node is a .cmd or .bat script, not a program';
|
|
90
|
+
if (body.env == null || typeof body.env !== 'object' || Array.isArray(body.env)) return 'env is not an object';
|
|
91
|
+
const allowed = new Set(platform === 'win32' ? WINDOWS_KEYS : POSIX_KEYS);
|
|
92
|
+
for (const [k, v] of Object.entries(body.env)) {
|
|
93
|
+
if (!allowed.has(k)) return `env names ${k}, which the daemon may not be given`;
|
|
94
|
+
if (typeof v !== 'string') return `env's ${k} is not a string`;
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Whether the shim could start what <home>/shim.json names, now: this user's
|
|
100
|
+
// own file (lib/own-file.js), valid (shimJsonProblem), its node runnable
|
|
101
|
+
// and its chLocal readable. shim.json names the Node install ran under, and a
|
|
102
|
+
// Node upgrade that moves it (brew, nvm) leaves the shim starting nothing
|
|
103
|
+
// (A3, the final pass). access: fs.accessSync (a test's own); fileAcl: the
|
|
104
|
+
// session's ACL reader (Windows). -> null, or
|
|
105
|
+
// {which: 'shim.json' | 'node' | 'chLocal', code}: which, and the errno, for
|
|
106
|
+
// a line that names no path
|
|
107
|
+
function shimJsonRunProblem(home, {platform = process.platform, access = fs.accessSync, fileAcl = null} = {}) {
|
|
108
|
+
let bytes;
|
|
109
|
+
try {
|
|
110
|
+
bytes = require('./own-file').readOwnFile(path.join(home, 'shim.json'), {max: 64 * 1024, platform, fileAcl});
|
|
111
|
+
} catch (e) {
|
|
112
|
+
// (a check that couldn't be made is said as such, never as a bad file:
|
|
113
|
+
// the medium on A3, 3)
|
|
114
|
+
return {which: 'shim.json', code: e.code || 'unreadable'};
|
|
115
|
+
}
|
|
116
|
+
if (bytes == null) return {which: 'shim.json', code: 'missing'};
|
|
117
|
+
let body;
|
|
118
|
+
try { body = JSON.parse(bytes.toString('utf8')); } catch (e) { return {which: 'shim.json', code: 'invalid'}; }
|
|
119
|
+
if (shimJsonProblem(body, platform) != null) return {which: 'shim.json', code: 'invalid'};
|
|
120
|
+
// (a regular file each, and runnable or readable: access alone passes a
|
|
121
|
+
// directory, and X_OK is an existence check on Windows -- the medium, 4)
|
|
122
|
+
for (const [which, mode] of [['node', fs.constants.X_OK], ['chLocal', fs.constants.R_OK]]) {
|
|
123
|
+
try {
|
|
124
|
+
if (!fs.statSync(body[which]).isFile()) return {which, code: 'not a file'};
|
|
125
|
+
access(body[which], mode);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
return {which, code: e.code || 'refused'};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// writes <home>/shim.json -> the body written
|
|
134
|
+
function writeShimJson(home, args) {
|
|
135
|
+
const body = shimJsonFor({...args, home});
|
|
136
|
+
const problem = shimJsonProblem(body, args.platform || process.platform);
|
|
137
|
+
if (problem != null) throw new Error(`shim.json would be refused: ${problem}`);
|
|
138
|
+
const file = path.join(home, 'shim.json');
|
|
139
|
+
const temp = path.join(home, `.shim.json.${process.pid}.${Date.now()}.tmp`);
|
|
140
|
+
const fd = fs.openSync(temp, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | (fs.constants.O_NOFOLLOW || 0), 0o600);
|
|
141
|
+
let placed = false;
|
|
142
|
+
try {
|
|
143
|
+
try {
|
|
144
|
+
// 0600 whatever the umask (one of 0277 would leave 0400, which the
|
|
145
|
+
// shim refuses)
|
|
146
|
+
if (process.platform !== 'win32') fs.fchmodSync(fd, 0o600);
|
|
147
|
+
fs.writeSync(fd, `${JSON.stringify(body, null, 2)}\n`);
|
|
148
|
+
} finally {
|
|
149
|
+
fs.closeSync(fd);
|
|
150
|
+
}
|
|
151
|
+
fs.renameSync(temp, file);
|
|
152
|
+
placed = true;
|
|
153
|
+
} finally {
|
|
154
|
+
if (!placed) { try { fs.unlinkSync(temp); } catch (e) { /* gone */ } }
|
|
155
|
+
}
|
|
156
|
+
return body;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
module.exports = {shimJsonFor, shimJsonProblem, writeShimJson, POSIX_KEYS, WINDOWS_KEYS, allowedEnv, runtimeEnv, shimJsonRunProblem};
|