@trigguard/cli 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/data/execution-surfaces.json +28 -0
- package/dist/auth.js +20 -0
- package/dist/commands/authorize.d.ts +1 -0
- package/dist/commands/authorize.js +99 -0
- package/dist/commands/chaos.d.ts +1 -0
- package/dist/commands/chaos.js +35 -0
- package/dist/commands/dev.d.ts +1 -0
- package/dist/commands/dev.js +27 -0
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/commands/doctor.js +50 -0
- package/dist/commands/log.d.ts +3 -0
- package/dist/commands/log.js +119 -0
- package/dist/commands/logMonitor.d.ts +1 -0
- package/dist/commands/logMonitor.js +65 -0
- package/dist/commands/login-web.d.ts +1 -0
- package/dist/commands/login-web.js +80 -0
- package/dist/commands/policy-distribution.d.ts +10 -0
- package/dist/commands/policy-distribution.js +108 -0
- package/dist/commands/policy-runtime.d.ts +4 -0
- package/dist/commands/policy-runtime.js +61 -0
- package/dist/commands/policy.d.ts +1 -0
- package/dist/commands/policy.js +123 -0
- package/dist/commands/policyLifecycle.d.ts +13 -0
- package/dist/commands/policyLifecycle.js +601 -0
- package/dist/commands/receiptFetch.d.ts +1 -0
- package/dist/commands/receiptFetch.js +44 -0
- package/dist/commands/receiptProof.d.ts +1 -0
- package/dist/commands/receiptProof.js +43 -0
- package/dist/commands/replay.d.ts +2 -0
- package/dist/commands/replay.js +130 -0
- package/dist/commands/session.d.ts +6 -0
- package/dist/commands/session.js +280 -0
- package/dist/commands/simulate.d.ts +5 -0
- package/dist/commands/simulate.js +89 -0
- package/dist/commands/tg-authorize.d.ts +12 -0
- package/dist/commands/tg-authorize.js +191 -0
- package/dist/commands/tg-init.d.ts +1 -0
- package/dist/commands/tg-init.js +149 -0
- package/dist/commands/tg-setup.d.ts +1 -0
- package/dist/commands/tg-setup.js +43 -0
- package/dist/commands/tg-surfaces.d.ts +7 -0
- package/dist/commands/tg-surfaces.js +50 -0
- package/dist/commands/tg-verify.d.ts +1 -0
- package/dist/commands/tg-verify.js +118 -0
- package/dist/commands/transparency.d.ts +2 -0
- package/dist/commands/transparency.js +65 -0
- package/dist/commands/verify.d.ts +1 -0
- package/dist/commands/verify.js +127 -0
- package/dist/commands/verifyBundle.d.ts +1 -0
- package/dist/commands/verifyBundle.js +109 -0
- package/dist/commands/verifyReceiptCmd.d.ts +1 -0
- package/dist/commands/verifyReceiptCmd.js +49 -0
- package/dist/commands/witness.d.ts +1 -0
- package/dist/commands/witness.js +22 -0
- package/dist/cp/cliDeviceAuth.d.ts +24 -0
- package/dist/cp/cliDeviceAuth.js +68 -0
- package/dist/cp/client.d.ts +19 -0
- package/dist/cp/client.js +73 -0
- package/dist/cp/config.d.ts +8 -0
- package/dist/cp/config.js +113 -0
- package/dist/cp/credentials.d.ts +9 -0
- package/dist/cp/credentials.js +31 -0
- package/dist/cp/provisionCliKey.d.ts +12 -0
- package/dist/cp/provisionCliKey.js +43 -0
- package/dist/cp/types.d.ts +37 -0
- package/dist/cp/types.js +1 -0
- package/dist/stdin.js +9 -0
- package/dist/tg/args.d.ts +3 -0
- package/dist/tg/args.js +28 -0
- package/dist/tg/authorize-format.d.ts +21 -0
- package/dist/tg/authorize-format.js +87 -0
- package/dist/tg/errors.d.ts +6 -0
- package/dist/tg/errors.js +53 -0
- package/dist/tg/gateway.d.ts +2 -0
- package/dist/tg/gateway.js +19 -0
- package/dist/tg/help.d.ts +7 -0
- package/dist/tg/help.js +164 -0
- package/dist/tg/receipt.d.ts +1 -0
- package/dist/tg/receipt.js +13 -0
- package/dist/tg/shellQuote.d.ts +1 -0
- package/dist/tg/shellQuote.js +6 -0
- package/dist/tg.js +92 -0
- package/package.json +50 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { activateBreakGlass, approvePolicyChangeRequest, authorizePolicyActivation, createPolicyChangeRequest, deactivateBreakGlass, finalizePolicyActivationGovernance, isBreakGlassActive, listPendingChanges, loadLocalPolicyState, loadPolicyManifest, rejectPolicyChangeRequest, setChangeWindow, syncPolicyBundle, verifyPolicyManifestSignature, } from "@trigguard/policy-engine";
|
|
3
|
+
function usage() {
|
|
4
|
+
console.error("Usage:\n" +
|
|
5
|
+
" trigguard policy sync <manifest.json> <bundle.json>\n" +
|
|
6
|
+
" trigguard policy state\n" +
|
|
7
|
+
" trigguard policy verify-manifest <manifest.json>\n" +
|
|
8
|
+
" trigguard policy request-change <bundle.json>\n" +
|
|
9
|
+
" trigguard policy approve <changeId> [approver]\n" +
|
|
10
|
+
" trigguard policy reject <changeId> [actor]\n" +
|
|
11
|
+
" trigguard policy set-window <start> <end>\n" +
|
|
12
|
+
" trigguard policy break-glass <reason>\n" +
|
|
13
|
+
" trigguard policy break-glass-end\n" +
|
|
14
|
+
" trigguard policy pending");
|
|
15
|
+
process.exit(1);
|
|
16
|
+
}
|
|
17
|
+
export async function runPolicySync(argv) {
|
|
18
|
+
const manifestPath = argv[0];
|
|
19
|
+
const bundlePath = argv[1];
|
|
20
|
+
if (!manifestPath || !bundlePath)
|
|
21
|
+
usage();
|
|
22
|
+
const manifest = loadPolicyManifest(manifestPath);
|
|
23
|
+
const bundle = JSON.parse(readFileSync(bundlePath, "utf8"));
|
|
24
|
+
const actor = process.env.TRIGGUARD_OPERATOR || process.env.USER || "cli-operator";
|
|
25
|
+
const auth = authorizePolicyActivation(bundle.bundle_hash, actor);
|
|
26
|
+
if (!auth.ok) {
|
|
27
|
+
console.error(`POLICY_GOVERNANCE_VIOLATION: ${auth.detail ?? "policy activation blocked by governance"}`);
|
|
28
|
+
process.exitCode = 2;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const out = syncPolicyBundle(manifest, bundle);
|
|
32
|
+
if (!out.ok) {
|
|
33
|
+
console.error(`Policy sync rejected: ${out.code} ${out.detail ? `(${out.detail})` : ""}`);
|
|
34
|
+
process.exitCode = 2;
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
finalizePolicyActivationGovernance(bundle.bundle_hash, actor, auth);
|
|
38
|
+
console.log(`Policy synced: version=${manifest.version} bundle=${manifest.bundle_hash}`);
|
|
39
|
+
}
|
|
40
|
+
export async function runPolicyState() {
|
|
41
|
+
const s = loadLocalPolicyState();
|
|
42
|
+
if (!s) {
|
|
43
|
+
console.log("No local policy state.");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
console.log(JSON.stringify(s, null, 2));
|
|
47
|
+
}
|
|
48
|
+
export async function runPolicyVerifyManifest(argv) {
|
|
49
|
+
const manifestPath = argv[0];
|
|
50
|
+
if (!manifestPath)
|
|
51
|
+
usage();
|
|
52
|
+
const manifest = loadPolicyManifest(manifestPath);
|
|
53
|
+
const out = verifyPolicyManifestSignature(manifest);
|
|
54
|
+
if (!out.ok) {
|
|
55
|
+
console.error(`Manifest invalid: ${out.detail ?? "signature verification failed"}`);
|
|
56
|
+
process.exitCode = 2;
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
console.log("Manifest signature valid.");
|
|
60
|
+
}
|
|
61
|
+
export async function runPolicyRequestChange(argv) {
|
|
62
|
+
const bundlePath = argv[0];
|
|
63
|
+
const author = argv[1] || process.env.USER || "unknown";
|
|
64
|
+
if (!bundlePath)
|
|
65
|
+
usage();
|
|
66
|
+
const bundle = JSON.parse(readFileSync(bundlePath, "utf8"));
|
|
67
|
+
const req = createPolicyChangeRequest(bundle.bundle_hash, author);
|
|
68
|
+
console.log(JSON.stringify(req, null, 2));
|
|
69
|
+
}
|
|
70
|
+
export async function runPolicyApprove(argv) {
|
|
71
|
+
const changeId = argv[0];
|
|
72
|
+
const approver = argv[1] || process.env.USER || "unknown";
|
|
73
|
+
if (!changeId)
|
|
74
|
+
usage();
|
|
75
|
+
const req = approvePolicyChangeRequest(changeId, approver);
|
|
76
|
+
console.log(JSON.stringify(req, null, 2));
|
|
77
|
+
}
|
|
78
|
+
export async function runPolicyReject(argv) {
|
|
79
|
+
const changeId = argv[0];
|
|
80
|
+
const actor = argv[1] || process.env.USER || "unknown";
|
|
81
|
+
if (!changeId)
|
|
82
|
+
usage();
|
|
83
|
+
const req = rejectPolicyChangeRequest(changeId, actor);
|
|
84
|
+
console.log(JSON.stringify(req, null, 2));
|
|
85
|
+
}
|
|
86
|
+
export async function runPolicySetWindow(argv) {
|
|
87
|
+
const start = argv[0];
|
|
88
|
+
const end = argv[1];
|
|
89
|
+
if (!start || !end)
|
|
90
|
+
usage();
|
|
91
|
+
setChangeWindow(start, end, process.env.USER || "unknown");
|
|
92
|
+
console.log("Policy change window set.");
|
|
93
|
+
}
|
|
94
|
+
export async function runPolicyBreakGlass(argv) {
|
|
95
|
+
const reason = argv.join(" ").trim();
|
|
96
|
+
if (!reason)
|
|
97
|
+
usage();
|
|
98
|
+
const out = activateBreakGlass(reason, process.env.USER || "unknown");
|
|
99
|
+
console.log(JSON.stringify({ break_glass_active: out.active, break_glass_expires: out.expires_at }, null, 2));
|
|
100
|
+
}
|
|
101
|
+
export async function runPolicyBreakGlassEnd() {
|
|
102
|
+
deactivateBreakGlass(process.env.USER || "unknown");
|
|
103
|
+
console.log(JSON.stringify({ break_glass_active: isBreakGlassActive() }, null, 2));
|
|
104
|
+
}
|
|
105
|
+
export async function runPolicyPending() {
|
|
106
|
+
const rows = listPendingChanges();
|
|
107
|
+
console.log(JSON.stringify({ pending_changes: rows }, null, 2));
|
|
108
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { authorizePolicyActivation, finalizePolicyActivationGovernance, getActivePolicyRuntime, listPolicyHistory, loadPolicyManifest, reloadPolicyBundle, rollbackPolicy, } from "@trigguard/policy-engine";
|
|
3
|
+
function usage() {
|
|
4
|
+
console.error("Usage:\n" +
|
|
5
|
+
" trigguard policy reload <manifest.json> <bundle.json>\n" +
|
|
6
|
+
" trigguard policy rollback\n" +
|
|
7
|
+
" trigguard policy history\n" +
|
|
8
|
+
" trigguard policy active");
|
|
9
|
+
process.exit(1);
|
|
10
|
+
}
|
|
11
|
+
export async function runPolicyReload(argv) {
|
|
12
|
+
const manifestPath = argv[0];
|
|
13
|
+
const bundlePath = argv[1];
|
|
14
|
+
if (!manifestPath || !bundlePath)
|
|
15
|
+
usage();
|
|
16
|
+
const manifest = loadPolicyManifest(manifestPath);
|
|
17
|
+
const bundle = JSON.parse(readFileSync(bundlePath, "utf8"));
|
|
18
|
+
const actor = process.env.TRIGGUARD_OPERATOR || process.env.USER || "cli-operator";
|
|
19
|
+
const auth = authorizePolicyActivation(bundle.bundle_hash, actor);
|
|
20
|
+
if (!auth.ok) {
|
|
21
|
+
console.error(`POLICY_GOVERNANCE_VIOLATION: ${auth.detail ?? "policy reload blocked by governance"}`);
|
|
22
|
+
process.exitCode = 2;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const out = await reloadPolicyBundle(manifest, bundle);
|
|
26
|
+
if (!out.ok) {
|
|
27
|
+
const msg = out.detail ? `${out.code} (${out.detail})` : String(out.code);
|
|
28
|
+
console.error(`Policy reload failed: ${msg}`);
|
|
29
|
+
process.exitCode = 2;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
finalizePolicyActivationGovernance(bundle.bundle_hash, actor, auth);
|
|
33
|
+
console.log(`Policy reloaded: version=${manifest.version} bundle=${manifest.bundle_hash}`);
|
|
34
|
+
}
|
|
35
|
+
export async function runPolicyRuntimeRollback() {
|
|
36
|
+
const out = rollbackPolicy();
|
|
37
|
+
if (!out.ok) {
|
|
38
|
+
const msg = out.detail ? `${out.code} (${out.detail})` : String(out.code);
|
|
39
|
+
console.error(`Policy rollback failed: ${msg}`);
|
|
40
|
+
process.exitCode = 2;
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
console.log(`Rolled back to bundle ${out.bundle?.bundle_hash ?? "(unknown)"}`);
|
|
44
|
+
}
|
|
45
|
+
export async function runPolicyHistory() {
|
|
46
|
+
const h = listPolicyHistory();
|
|
47
|
+
console.log(JSON.stringify({ history: h }, null, 2));
|
|
48
|
+
}
|
|
49
|
+
export async function runPolicyActive() {
|
|
50
|
+
const r = getActivePolicyRuntime();
|
|
51
|
+
if (!r) {
|
|
52
|
+
console.log("No active policy runtime (unconfigured or not hydrated).");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
console.log(JSON.stringify({
|
|
56
|
+
bundle_hash: r.bundle_hash,
|
|
57
|
+
version: r.version,
|
|
58
|
+
loaded_at: r.loaded_at,
|
|
59
|
+
policy_bundle: r.policy_bundle,
|
|
60
|
+
}, null, 2));
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runPolicy(argv: string[]): Promise<void>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { runPolicyApprove, runPolicyBreakGlass, runPolicyBreakGlassEnd, runPolicyPending, runPolicyReject, runPolicyRequestChange, runPolicySetWindow, runPolicySync, runPolicyState, runPolicyVerifyManifest, } from "./policy-distribution.js";
|
|
2
|
+
import { runPolicyActive, runPolicyHistory, runPolicyReload, runPolicyRuntimeRollback, } from "./policy-runtime.js";
|
|
3
|
+
import { policyUsage, runPolicyActivate, runPolicyBuild, runPolicyLint, runPolicyPublish, runPolicyStackRollback, runPolicyStage, runPolicyPromote, runPolicyMetrics, runPolicySimulate, runPolicyTest, runPolicyValidate, runPolicyVersionBump, } from "./policyLifecycle.js";
|
|
4
|
+
export async function runPolicy(argv) {
|
|
5
|
+
const cmd = argv[0];
|
|
6
|
+
const rest = argv.slice(1);
|
|
7
|
+
switch (cmd) {
|
|
8
|
+
case "lint":
|
|
9
|
+
if (!rest[0])
|
|
10
|
+
policyUsage();
|
|
11
|
+
await runPolicyLint(rest[0]);
|
|
12
|
+
return;
|
|
13
|
+
case "test":
|
|
14
|
+
if (!rest[0])
|
|
15
|
+
policyUsage();
|
|
16
|
+
await runPolicyTest(rest[0]);
|
|
17
|
+
return;
|
|
18
|
+
case "build":
|
|
19
|
+
if (!rest[0])
|
|
20
|
+
policyUsage();
|
|
21
|
+
await runPolicyBuild(rest[0]);
|
|
22
|
+
return;
|
|
23
|
+
case "simulate":
|
|
24
|
+
await runPolicySimulate(rest);
|
|
25
|
+
return;
|
|
26
|
+
case "publish":
|
|
27
|
+
if (!rest[0])
|
|
28
|
+
policyUsage();
|
|
29
|
+
await runPolicyPublish(rest[0]);
|
|
30
|
+
return;
|
|
31
|
+
case "activate":
|
|
32
|
+
if (!rest[0])
|
|
33
|
+
policyUsage();
|
|
34
|
+
await runPolicyActivate(rest[0]);
|
|
35
|
+
return;
|
|
36
|
+
case "rollback":
|
|
37
|
+
if (rest.length)
|
|
38
|
+
policyUsage();
|
|
39
|
+
await runPolicyRuntimeRollback();
|
|
40
|
+
return;
|
|
41
|
+
case "stack-rollback":
|
|
42
|
+
if (rest.length)
|
|
43
|
+
policyUsage();
|
|
44
|
+
await runPolicyStackRollback();
|
|
45
|
+
return;
|
|
46
|
+
case "reload":
|
|
47
|
+
await runPolicyReload(rest);
|
|
48
|
+
return;
|
|
49
|
+
case "history":
|
|
50
|
+
if (rest.length)
|
|
51
|
+
policyUsage();
|
|
52
|
+
await runPolicyHistory();
|
|
53
|
+
return;
|
|
54
|
+
case "active":
|
|
55
|
+
if (rest.length)
|
|
56
|
+
policyUsage();
|
|
57
|
+
await runPolicyActive();
|
|
58
|
+
return;
|
|
59
|
+
case "stage":
|
|
60
|
+
if (!rest[0])
|
|
61
|
+
policyUsage();
|
|
62
|
+
await runPolicyStage(rest[0]);
|
|
63
|
+
return;
|
|
64
|
+
case "promote":
|
|
65
|
+
if (rest.length)
|
|
66
|
+
policyUsage();
|
|
67
|
+
await runPolicyPromote();
|
|
68
|
+
return;
|
|
69
|
+
case "metrics":
|
|
70
|
+
if (rest.length)
|
|
71
|
+
policyUsage();
|
|
72
|
+
await runPolicyMetrics();
|
|
73
|
+
return;
|
|
74
|
+
case "validate":
|
|
75
|
+
if (!rest[0])
|
|
76
|
+
policyUsage();
|
|
77
|
+
await runPolicyValidate(rest[0]);
|
|
78
|
+
return;
|
|
79
|
+
case "version":
|
|
80
|
+
if (rest[0] !== "bump")
|
|
81
|
+
policyUsage();
|
|
82
|
+
await runPolicyVersionBump(rest.slice(1));
|
|
83
|
+
return;
|
|
84
|
+
case "sync":
|
|
85
|
+
await runPolicySync(rest);
|
|
86
|
+
return;
|
|
87
|
+
case "state":
|
|
88
|
+
if (rest.length)
|
|
89
|
+
policyUsage();
|
|
90
|
+
await runPolicyState();
|
|
91
|
+
return;
|
|
92
|
+
case "verify-manifest":
|
|
93
|
+
await runPolicyVerifyManifest(rest);
|
|
94
|
+
return;
|
|
95
|
+
case "request-change":
|
|
96
|
+
await runPolicyRequestChange(rest);
|
|
97
|
+
return;
|
|
98
|
+
case "approve":
|
|
99
|
+
await runPolicyApprove(rest);
|
|
100
|
+
return;
|
|
101
|
+
case "reject":
|
|
102
|
+
await runPolicyReject(rest);
|
|
103
|
+
return;
|
|
104
|
+
case "set-window":
|
|
105
|
+
await runPolicySetWindow(rest);
|
|
106
|
+
return;
|
|
107
|
+
case "break-glass":
|
|
108
|
+
await runPolicyBreakGlass(rest);
|
|
109
|
+
return;
|
|
110
|
+
case "break-glass-end":
|
|
111
|
+
if (rest.length)
|
|
112
|
+
policyUsage();
|
|
113
|
+
await runPolicyBreakGlassEnd();
|
|
114
|
+
return;
|
|
115
|
+
case "pending":
|
|
116
|
+
if (rest.length)
|
|
117
|
+
policyUsage();
|
|
118
|
+
await runPolicyPending();
|
|
119
|
+
return;
|
|
120
|
+
default:
|
|
121
|
+
policyUsage();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function policyUsage(): never;
|
|
2
|
+
export declare function runPolicyLint(path: string): Promise<void>;
|
|
3
|
+
export declare function runPolicyTest(path: string): Promise<void>;
|
|
4
|
+
export declare function runPolicyBuild(path: string): Promise<void>;
|
|
5
|
+
export declare function runPolicySimulate(rest: string[]): Promise<void>;
|
|
6
|
+
export declare function runPolicyPublish(bundlePath: string): Promise<void>;
|
|
7
|
+
export declare function runPolicyActivate(hashArg: string): Promise<void>;
|
|
8
|
+
export declare function runPolicyStackRollback(): Promise<void>;
|
|
9
|
+
export declare function runPolicyStage(bundleArg: string): Promise<void>;
|
|
10
|
+
export declare function runPolicyPromote(): Promise<void>;
|
|
11
|
+
export declare function runPolicyMetrics(): Promise<void>;
|
|
12
|
+
export declare function runPolicyValidate(bundlePath: string): Promise<void>;
|
|
13
|
+
export declare function runPolicyVersionBump(argv: string[]): Promise<void>;
|