gcb-host 0.0.0-stage → 0.0.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/CHANGELOG.md +9 -0
- package/bin/gcb.js +5 -0
- package/lib/audit.d.ts +25 -0
- package/lib/audit.d.ts.map +1 -0
- package/lib/audit.js +73 -0
- package/lib/audit.js.map +1 -0
- package/lib/broker.d.ts +61 -0
- package/lib/broker.d.ts.map +1 -0
- package/lib/broker.js +512 -0
- package/lib/broker.js.map +1 -0
- package/lib/commands/authorize.d.ts +38 -0
- package/lib/commands/authorize.d.ts.map +1 -0
- package/lib/commands/authorize.js +134 -0
- package/lib/commands/authorize.js.map +1 -0
- package/lib/commands/compose.d.ts +42 -0
- package/lib/commands/compose.d.ts.map +1 -0
- package/lib/commands/compose.js +208 -0
- package/lib/commands/compose.js.map +1 -0
- package/lib/commands/deployment.d.ts +49 -0
- package/lib/commands/deployment.d.ts.map +1 -0
- package/lib/commands/deployment.js +72 -0
- package/lib/commands/deployment.js.map +1 -0
- package/lib/commands/diagnose.d.ts +4 -0
- package/lib/commands/diagnose.d.ts.map +1 -0
- package/lib/commands/diagnose.js +213 -0
- package/lib/commands/diagnose.js.map +1 -0
- package/lib/commands/host-opener.d.ts +23 -0
- package/lib/commands/host-opener.d.ts.map +1 -0
- package/lib/commands/host-opener.js +244 -0
- package/lib/commands/host-opener.js.map +1 -0
- package/lib/commands/init.d.ts +153 -0
- package/lib/commands/init.d.ts.map +1 -0
- package/lib/commands/init.js +510 -0
- package/lib/commands/init.js.map +1 -0
- package/lib/commands/stage.d.ts +44 -0
- package/lib/commands/stage.d.ts.map +1 -0
- package/lib/commands/stage.js +165 -0
- package/lib/commands/stage.js.map +1 -0
- package/lib/config.d.ts +110 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +408 -0
- package/lib/config.js.map +1 -0
- package/lib/daemon.d.ts +45 -0
- package/lib/daemon.d.ts.map +1 -0
- package/lib/daemon.js +123 -0
- package/lib/daemon.js.map +1 -0
- package/lib/device-flow.d.ts +80 -0
- package/lib/device-flow.d.ts.map +1 -0
- package/lib/device-flow.js +148 -0
- package/lib/device-flow.js.map +1 -0
- package/lib/gh.d.ts +37 -0
- package/lib/gh.d.ts.map +1 -0
- package/lib/gh.js +181 -0
- package/lib/gh.js.map +1 -0
- package/lib/http.d.ts +20 -0
- package/lib/http.d.ts.map +1 -0
- package/lib/http.js +133 -0
- package/lib/http.js.map +1 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +52 -0
- package/lib/index.js.map +1 -0
- package/lib/policy.d.ts +60 -0
- package/lib/policy.d.ts.map +1 -0
- package/lib/policy.js +118 -0
- package/lib/policy.js.map +1 -0
- package/lib/providers/github-app.d.ts +56 -0
- package/lib/providers/github-app.d.ts.map +1 -0
- package/lib/providers/github-app.js +901 -0
- package/lib/providers/github-app.js.map +1 -0
- package/lib/providers/index.d.ts +29 -0
- package/lib/providers/index.d.ts.map +1 -0
- package/lib/providers/index.js +32 -0
- package/lib/providers/index.js.map +1 -0
- package/lib/providers/static.d.ts +18 -0
- package/lib/providers/static.d.ts.map +1 -0
- package/lib/providers/static.js +41 -0
- package/lib/providers/static.js.map +1 -0
- package/lib/proxy.d.ts +23 -0
- package/lib/proxy.d.ts.map +1 -0
- package/lib/proxy.js +57 -0
- package/lib/proxy.js.map +1 -0
- package/package.json +36 -3
- package/README.md +0 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# gcb-host
|
|
2
|
+
|
|
3
|
+
## 0.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#33](https://github.com/code-vaults/git-credential-broker/pull/33) [`4bab834`](https://github.com/code-vaults/git-credential-broker/commit/4bab834c781e6175b6b6e588ad542fa09d532be7) Thanks [@JounQin](https://github.com/JounQin)! - Prepare the first public release of the renamed packages.
|
|
8
|
+
- Updated dependencies [[`4bab834`](https://github.com/code-vaults/git-credential-broker/commit/4bab834c781e6175b6b6e588ad542fa09d532be7)]:
|
|
9
|
+
- gcb-core@0.0.1
|
package/bin/gcb.js
ADDED
package/lib/audit.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AuditSink } from 'gcb-core';
|
|
2
|
+
/** Options for {@link createAudit}. */
|
|
3
|
+
export interface AuditOptions {
|
|
4
|
+
/** Log path; omitted or null means "log nothing to disk". */
|
|
5
|
+
path?: string | null;
|
|
6
|
+
/** Clock, injectable for tests. */
|
|
7
|
+
now?: () => number;
|
|
8
|
+
/** Where write failures are reported. */
|
|
9
|
+
stderr?: NodeJS.WritableStream;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Remove secret-looking fields from one audit record.
|
|
13
|
+
*
|
|
14
|
+
* @param event - the record a caller wants to log.
|
|
15
|
+
* @returns the record with secret-bearing keys replaced by `<redacted>`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function redact(event: Record<string, unknown>): Record<string, unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Create the audit sink.
|
|
20
|
+
*
|
|
21
|
+
* @param options - sink options.
|
|
22
|
+
* @returns the sink; a null path yields a sink that writes nothing.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createAudit(options?: AuditOptions): AuditSink;
|
|
25
|
+
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAY1C,uCAAuC;AACvC,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,mCAAmC;IACnC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;CAChC;AAGD;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAM9E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,OAAO,GAAE,YAAiB,GAAG,SAAS,CAkCjE"}
|
package/lib/audit.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Append-only audit log for credential decisions.
|
|
3
|
+
*
|
|
4
|
+
* The log records *that* a credential was issued and for which repository, never the
|
|
5
|
+
* credential itself: callers pass only a short SHA-256 fingerprint. A defensive redaction
|
|
6
|
+
* pass drops any secret-looking key a future caller might add by accident, and the file is
|
|
7
|
+
* created 0600 so it stays broker-owned.
|
|
8
|
+
*/
|
|
9
|
+
import { chmodSync, closeSync, createWriteStream, mkdirSync, openSync } from 'node:fs';
|
|
10
|
+
import { dirname } from 'node:path';
|
|
11
|
+
/**
|
|
12
|
+
* Keys whose values must never reach the audit log.
|
|
13
|
+
*
|
|
14
|
+
* `token_fingerprint` is deliberately exempt: it is a hash, not a credential, and it is the
|
|
15
|
+
* whole point of the allow records. Without the negative lookahead the `^token` branch would
|
|
16
|
+
* swallow it, and the operator would lose the ability to correlate a grant with a later
|
|
17
|
+
* event — a real bug this pattern previously had.
|
|
18
|
+
*/
|
|
19
|
+
const FORBIDDEN_KEY_RE = /pass(word)?|secret|^token(?!_fingerprint)|token$|credential/i;
|
|
20
|
+
/**
|
|
21
|
+
* Remove secret-looking fields from one audit record.
|
|
22
|
+
*
|
|
23
|
+
* @param event - the record a caller wants to log.
|
|
24
|
+
* @returns the record with secret-bearing keys replaced by `<redacted>`.
|
|
25
|
+
*/
|
|
26
|
+
export function redact(event) {
|
|
27
|
+
const out = {};
|
|
28
|
+
for (const [key, value] of Object.entries(event)) {
|
|
29
|
+
out[key] = FORBIDDEN_KEY_RE.test(key) ? '<redacted>' : value;
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Create the audit sink.
|
|
35
|
+
*
|
|
36
|
+
* @param options - sink options.
|
|
37
|
+
* @returns the sink; a null path yields a sink that writes nothing.
|
|
38
|
+
*/
|
|
39
|
+
export function createAudit(options = {}) {
|
|
40
|
+
const { path = null, now = () => Date.now(), stderr = process.stderr } = options;
|
|
41
|
+
let stream = null;
|
|
42
|
+
if (path) {
|
|
43
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
44
|
+
// Create, restrict, then append through the stream. The mode passed to a create call is
|
|
45
|
+
// advisory on an ACL-based share, which would leave the audit trail writable by other local
|
|
46
|
+
// users — and an audit trail someone else can append to is not an audit trail.
|
|
47
|
+
closeSync(openSync(path, 'a', 0o600));
|
|
48
|
+
chmodSync(path, 0o600);
|
|
49
|
+
stream = createWriteStream(path, { flags: 'a', mode: 0o600 });
|
|
50
|
+
stream.on('error', (error) => {
|
|
51
|
+
stderr.write(`gcb daemon: audit write failed: ${error.message}\n`);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
path,
|
|
56
|
+
record(event) {
|
|
57
|
+
if (!stream)
|
|
58
|
+
return;
|
|
59
|
+
stream.write(`${JSON.stringify({ ts: new Date(now()).toISOString(), ...redact(event) })}\n`);
|
|
60
|
+
},
|
|
61
|
+
close() {
|
|
62
|
+
const target = stream;
|
|
63
|
+
return new Promise((resolve) => {
|
|
64
|
+
if (!target) {
|
|
65
|
+
resolve();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
target.end(resolve);
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=audit.js.map
|
package/lib/audit.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":"AAAA;;;;;;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AE,CAAC,CAAC;QAC9D,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;YAClC,MAAM,CAAC,KAAK,CAAC,mCAAmC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;QACrE,CAAC,CAAC,CAAC;IACL,CAAC;IAED,OAAO;QACL,IAAI;QACJ,MAAM,CAAC,KAA8B;YACnC,IAAI,CAAC,MAAM;gBAAE,OAAO;YACpB,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE,EAAE,GAAG,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;QAC/F,CAAC;QACD,KAAK;YACH,MAAM,MAAM,GAAG,MAAM,CAAC;YACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;oBACZ,OAAO,EAAE,CAAC;oBACV,OAAO;gBACT,CAAC;gBACD,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACtB,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/lib/broker.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { AuditSink, BrokerConfig, Provider, WireResponse } from 'gcb-core';
|
|
2
|
+
/** Reported by the `ping` operation so the container side can prove what it reached. */
|
|
3
|
+
export declare const BROKER_VERSION: string;
|
|
4
|
+
/** Response codes returned to the helper. */
|
|
5
|
+
export declare const CODES: {
|
|
6
|
+
readonly BAD_REQUEST: 'bad-request';
|
|
7
|
+
readonly PROTOCOL_NOT_HTTPS: 'protocol-not-https';
|
|
8
|
+
readonly HOST_NOT_ALLOWED: 'host-not-allowed';
|
|
9
|
+
readonly PATH_REQUIRED: 'path-required';
|
|
10
|
+
readonly REPO_NOT_ALLOWED: 'repo-not-allowed';
|
|
11
|
+
readonly PROVIDER_ERROR: 'provider-error';
|
|
12
|
+
};
|
|
13
|
+
/** Options for {@link createRequestHandler}. */
|
|
14
|
+
export interface RequestHandlerOptions {
|
|
15
|
+
readonly config: BrokerConfig;
|
|
16
|
+
readonly audit: AuditSink;
|
|
17
|
+
readonly providers: ReadonlyMap<string, Provider>;
|
|
18
|
+
/** Host-side diagnostics sink; never seen by the caller. */
|
|
19
|
+
readonly log?: (message: string) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Make the socket path safe to bind.
|
|
23
|
+
*
|
|
24
|
+
* A stale socket left by a crashed broker is removed. Anything else at that path — a
|
|
25
|
+
* symlink, a regular file, a directory — is refused rather than overwritten, because the path
|
|
26
|
+
* may sit in a directory the agent container can write to. The containing directory is checked
|
|
27
|
+
* for the same reason: a symlinked directory would let the container choose where the socket
|
|
28
|
+
* gets bound.
|
|
29
|
+
*
|
|
30
|
+
* @param socketPath - the configured socket path.
|
|
31
|
+
* @throws {Error} when the path exists and is not a stale socket, or the directory is a symlink.
|
|
32
|
+
*/
|
|
33
|
+
export declare function prepareSocketPath(socketPath: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Build the request handler. Kept separate from the server so it can be unit-tested without
|
|
36
|
+
* a socket.
|
|
37
|
+
*
|
|
38
|
+
* @param options - handler options.
|
|
39
|
+
* @returns the handler.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createRequestHandler(options: RequestHandlerOptions): (message: Record<string, unknown>) => Promise<WireResponse>;
|
|
42
|
+
/** Options for {@link startBroker}. */
|
|
43
|
+
export interface StartBrokerOptions {
|
|
44
|
+
readonly config: BrokerConfig;
|
|
45
|
+
readonly audit: AuditSink;
|
|
46
|
+
readonly providers: ReadonlyMap<string, Provider>;
|
|
47
|
+
readonly log?: (message: string) => void;
|
|
48
|
+
}
|
|
49
|
+
/** A running broker. */
|
|
50
|
+
export interface RunningBroker {
|
|
51
|
+
readonly socketPath: string;
|
|
52
|
+
close(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Start the broker.
|
|
56
|
+
*
|
|
57
|
+
* @param options - server options.
|
|
58
|
+
* @returns the running broker.
|
|
59
|
+
*/
|
|
60
|
+
export declare function startBroker(options: StartBrokerOptions): Promise<RunningBroker>;
|
|
61
|
+
//# sourceMappingURL=broker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../src/broker.ts"],"names":[],"mappings":"AAyCA,OAAO,KAAK,EAAgB,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE9F,wFAAwF;AACxF,eAAO,MAAM,cAAc,QAAkB,CAAC;AAS9C,6CAA6C;AAC7C,eAAO,MAAM,KAAK;aAChB,WAAW,EAAE,aAAa;aAC1B,kBAAkB,EAAE,oBAAoB;aACxC,gBAAgB,EAAE,kBAAkB;aACpC,aAAa,EAAE,eAAe;aAC9B,gBAAgB,EAAE,kBAAkB;aACpC,cAAc,EAAE,gBAAgB;CACxB,CAAC;AAUX,gDAAgD;AAChD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAClD,4DAA4D;IAC5D,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC1C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAkC1D;AAGD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,qBAAqB,GAC7B,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,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