@signet-registry/operator 0.0.0-stage → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +29 -0
- package/README.md +191 -2
- package/dist/clients/api.js +251 -0
- package/dist/clients/mcp.js +118 -0
- package/dist/clients/verify.js +106 -0
- package/dist/config/env.js +42 -0
- package/dist/keyless.js +52 -0
- package/dist/main.js +7 -0
- package/dist/operator.js +1613 -0
- package/dist/transparency/sample-graph.js +203 -0
- package/dist/types.js +111 -0
- package/examples/bootstrap/agents/bootstrap-agent.md +5 -0
- package/examples/bootstrap/agents/bootstrap-ops-agent.md +8 -0
- package/examples/bootstrap/bootstrap.manifest.json +107 -0
- package/examples/bootstrap/skills/bootstrap-example.md +8 -0
- package/examples/bootstrap/skills/bootstrap-ops.md +8 -0
- package/examples/demo/agents/registry-agent.md +34 -0
- package/examples/demo/demo.manifest.json +90 -0
- package/examples/demo/skills/registry-mcp.md +74 -0
- package/examples/demo/skills/tame-llama.md +37 -0
- package/examples/signet-demo/agents/signet-demo-agent.md +39 -0
- package/examples/signet-demo/agents/signet-security-agent.md +36 -0
- package/examples/signet-demo/signet-demo.manifest.json +219 -0
- package/examples/signet-demo/skills/access-review.md +40 -0
- package/examples/signet-demo/skills/certification-workflow.md +39 -0
- package/examples/signet-demo/skills/governance-audit.md +39 -0
- package/examples/signet-demo/skills/graph-explorer.md +38 -0
- package/examples/signet-demo/skills/mcp-onboarding.md +39 -0
- package/examples/signet-demo/skills/policy-authoring.md +39 -0
- package/examples/signet-demo/skills/provenance-audit.md +39 -0
- package/examples/signet-demo/skills/registry-search.md +38 -0
- package/examples/signet-demo/skills/secrets-hygiene.md +39 -0
- package/examples/signet-demo/skills/skill-authoring.md +40 -0
- package/examples/transparency/README.md +39 -0
- package/examples/transparency/sample-graph.spec.json +16 -0
- package/package.json +58 -4
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createHash, createPublicKey, verify as verifySignature } from 'node:crypto';
|
|
2
|
+
export function sha256Hex(input) {
|
|
3
|
+
return createHash('sha256').update(input).digest('hex');
|
|
4
|
+
}
|
|
5
|
+
function parseSignatureBytes(signature) {
|
|
6
|
+
if (signature.startsWith('base64:')) {
|
|
7
|
+
return Buffer.from(signature.slice('base64:'.length), 'base64');
|
|
8
|
+
}
|
|
9
|
+
if (signature.startsWith('hex:')) {
|
|
10
|
+
return Buffer.from(signature.slice('hex:'.length), 'hex');
|
|
11
|
+
}
|
|
12
|
+
throw new Error('Signature must use a supported encoding prefix such as base64: or hex:.');
|
|
13
|
+
}
|
|
14
|
+
// Mirrors the algorithms accepted by the registry core so operator verification
|
|
15
|
+
// reproduces the server verdict locally.
|
|
16
|
+
export function verifyDetachedSignature(input) {
|
|
17
|
+
try {
|
|
18
|
+
const key = createPublicKey(input.publicKeyPem);
|
|
19
|
+
const signatureBytes = parseSignatureBytes(input.signature);
|
|
20
|
+
const message = typeof input.message === 'string' ? Buffer.from(input.message, 'utf8') : input.message;
|
|
21
|
+
switch (input.algorithm) {
|
|
22
|
+
case 'ed25519':
|
|
23
|
+
case 'ed448':
|
|
24
|
+
return verifySignature(null, message, key, signatureBytes);
|
|
25
|
+
case 'rsa-sha256':
|
|
26
|
+
case 'ecdsa-p256-sha256':
|
|
27
|
+
case 'ecdsa-sha256':
|
|
28
|
+
return verifySignature('sha256', message, key, signatureBytes);
|
|
29
|
+
case 'ecdsa-p384-sha384':
|
|
30
|
+
case 'ecdsa-sha384':
|
|
31
|
+
return verifySignature('sha384', message, key, signatureBytes);
|
|
32
|
+
default:
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Mirrors the registry's verdict logic for detached provenance signatures.
|
|
42
|
+
* Fetch the canonical N-Quads artifact the signature binds
|
|
43
|
+
* (`provenance_sha256`, via \`GET /v1/artifacts/{sha256}\`), pass those bytes
|
|
44
|
+
* here, and pass the current export digest as \`currentProvenanceSha256\` to
|
|
45
|
+
* distinguish \`valid\` from \`stale\` after the provenance has grown.
|
|
46
|
+
*/
|
|
47
|
+
export function verifyProvenanceSignature(input) {
|
|
48
|
+
const bytes = typeof input.canonicalRdfBytes === 'string'
|
|
49
|
+
? Buffer.from(input.canonicalRdfBytes, 'utf8')
|
|
50
|
+
: input.canonicalRdfBytes;
|
|
51
|
+
const digest_matches = sha256Hex(bytes) === input.signature.provenance_sha256;
|
|
52
|
+
const publicKeyPem = input.resolvePublicKey(input.signature.key_ref);
|
|
53
|
+
const signature_valid = digest_matches && publicKeyPem !== undefined
|
|
54
|
+
? verifyDetachedSignature({
|
|
55
|
+
algorithm: input.signature.algorithm,
|
|
56
|
+
publicKeyPem,
|
|
57
|
+
message: bytes,
|
|
58
|
+
signature: input.signature.signature,
|
|
59
|
+
})
|
|
60
|
+
: false;
|
|
61
|
+
const verdict = !digest_matches || !signature_valid
|
|
62
|
+
? 'invalid'
|
|
63
|
+
: input.currentProvenanceSha256 !== undefined &&
|
|
64
|
+
input.signature.provenance_sha256 !== input.currentProvenanceSha256
|
|
65
|
+
? 'stale'
|
|
66
|
+
: 'valid';
|
|
67
|
+
return {
|
|
68
|
+
key_ref: input.signature.key_ref,
|
|
69
|
+
algorithm: input.signature.algorithm,
|
|
70
|
+
digest_matches,
|
|
71
|
+
signature_valid,
|
|
72
|
+
verdict,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function verifyEnvelopeSignatures(input) {
|
|
76
|
+
const canonical_json_sha256_matches = sha256Hex(Buffer.from(input.envelope.canonical_json, 'utf8')) === input.envelope.canonical_json_sha256;
|
|
77
|
+
const signatures = input.envelope.detached_signatures.map((signature) => {
|
|
78
|
+
const signedPayload = signature.signed_payload ?? 'canonical_json';
|
|
79
|
+
const expectedDigest = signedPayload === 'canonical_rdf' ? input.envelope.canonical_rdf_sha256 : input.envelope.canonical_json_sha256;
|
|
80
|
+
const digest_matches = expectedDigest !== undefined && signature.envelope_sha256 === expectedDigest;
|
|
81
|
+
const message = signedPayload === 'canonical_rdf'
|
|
82
|
+
? input.canonicalRdfBytes
|
|
83
|
+
: Buffer.from(input.envelope.canonical_json, 'utf8');
|
|
84
|
+
const publicKeyPem = message ? input.resolvePublicKey(signature.key_ref) : undefined;
|
|
85
|
+
const signature_valid = digest_matches && publicKeyPem !== undefined && message !== undefined
|
|
86
|
+
? verifyDetachedSignature({
|
|
87
|
+
algorithm: signature.algorithm,
|
|
88
|
+
publicKeyPem,
|
|
89
|
+
message,
|
|
90
|
+
signature: signature.signature,
|
|
91
|
+
})
|
|
92
|
+
: false;
|
|
93
|
+
return {
|
|
94
|
+
key_ref: signature.key_ref,
|
|
95
|
+
algorithm: signature.algorithm,
|
|
96
|
+
signed_payload: signedPayload,
|
|
97
|
+
digest_matches,
|
|
98
|
+
signature_valid,
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
canonical_json_sha256_matches,
|
|
103
|
+
signatures,
|
|
104
|
+
all_signatures_valid: signatures.every((signature) => signature.signature_valid),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
function defaultRepoRoot() {
|
|
5
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
return path.resolve(here, '..', '..', '..', '..');
|
|
7
|
+
}
|
|
8
|
+
function defaultApiEnvFile() {
|
|
9
|
+
return path.join(defaultRepoRoot(), 'service', 'api', 'infra', '.env');
|
|
10
|
+
}
|
|
11
|
+
function defaultWebappEnvFile() {
|
|
12
|
+
return path.join(defaultRepoRoot(), 'service', 'webapp', 'knowledge-manager', 'infra', '.env');
|
|
13
|
+
}
|
|
14
|
+
function defaultMcpEnvFile() {
|
|
15
|
+
return path.join(defaultRepoRoot(), 'service', 'mcp', 'infra', '.env');
|
|
16
|
+
}
|
|
17
|
+
const EnvSchema = z.object({
|
|
18
|
+
API_ORIGIN: z.string().url().default('http://localhost:3100'),
|
|
19
|
+
MCP_ORIGIN: z.string().url().default('http://localhost:3000'),
|
|
20
|
+
WEBAPP_ORIGIN: z.string().url().default('http://localhost:3200'),
|
|
21
|
+
REPO_ROOT: z.string().default(defaultRepoRoot()),
|
|
22
|
+
API_ENV_FILE: z.string().default(defaultApiEnvFile()),
|
|
23
|
+
WEBAPP_ENV_FILE: z.string().default(defaultWebappEnvFile()),
|
|
24
|
+
MCP_ENV_FILE: z.string().default(defaultMcpEnvFile()),
|
|
25
|
+
// Cloudflare Access service-token headers for the deployed tunnels
|
|
26
|
+
// (machine clients outside the edge access layer). Both must be set to take effect.
|
|
27
|
+
SIGNET_CF_ACCESS_CLIENT_ID: z.string().optional(),
|
|
28
|
+
SIGNET_CF_ACCESS_CLIENT_SECRET: z.string().optional(),
|
|
29
|
+
});
|
|
30
|
+
export function loadEnv(input = process.env) {
|
|
31
|
+
return EnvSchema.parse(input);
|
|
32
|
+
}
|
|
33
|
+
/** Cloudflare Access headers for machine clients, when configured. */
|
|
34
|
+
export function cfAccessHeaders(env) {
|
|
35
|
+
if (env.SIGNET_CF_ACCESS_CLIENT_ID && env.SIGNET_CF_ACCESS_CLIENT_SECRET) {
|
|
36
|
+
return {
|
|
37
|
+
'CF-Access-Client-Id': env.SIGNET_CF_ACCESS_CLIENT_ID,
|
|
38
|
+
'CF-Access-Client-Secret': env.SIGNET_CF_ACCESS_CLIENT_SECRET,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {};
|
|
42
|
+
}
|
package/dist/keyless.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { bundleToJSON } from '@sigstore/bundle';
|
|
2
|
+
import { X509Certificate } from '@sigstore/core';
|
|
3
|
+
import { CIContextProvider, FulcioSigner, MessageSignatureBundleBuilder, RekorWitness } from '@sigstore/sign';
|
|
4
|
+
const OIDC_ISSUER_OID_V1 = '1.3.6.1.4.1.57264.1.1';
|
|
5
|
+
const OIDC_ISSUER_OID_V2 = '1.3.6.1.4.1.57264.1.8';
|
|
6
|
+
function oidcIssuerFromCertificate(cert) {
|
|
7
|
+
const v2 = cert.extension(OIDC_ISSUER_OID_V2);
|
|
8
|
+
if (v2) {
|
|
9
|
+
const value = v2.valueObj?.subs?.[0]?.value;
|
|
10
|
+
if (value)
|
|
11
|
+
return value.toString('ascii');
|
|
12
|
+
}
|
|
13
|
+
const v1 = cert.extension(OIDC_ISSUER_OID_V1);
|
|
14
|
+
return v1 ? v1.value.toString('ascii') : undefined;
|
|
15
|
+
}
|
|
16
|
+
function readBundleIdentity(bundle) {
|
|
17
|
+
const material = bundle['verificationMaterial'];
|
|
18
|
+
const chain = material?.['x509CertificateChain'];
|
|
19
|
+
const certificate = material?.['certificate'] ?? chain?.certificates?.[0];
|
|
20
|
+
const rawBytes = certificate?.['rawBytes'];
|
|
21
|
+
if (typeof rawBytes !== 'string') {
|
|
22
|
+
throw new Error('Fulcio bundle does not carry a signing certificate.');
|
|
23
|
+
}
|
|
24
|
+
const cert = X509Certificate.parse(Buffer.from(rawBytes, 'base64'));
|
|
25
|
+
const identity = cert.subjectAltName;
|
|
26
|
+
const issuer = oidcIssuerFromCertificate(cert);
|
|
27
|
+
if (!identity || !issuer) {
|
|
28
|
+
throw new Error('Signing certificate is missing its subject alternative name or OIDC issuer.');
|
|
29
|
+
}
|
|
30
|
+
return { identity, issuer };
|
|
31
|
+
}
|
|
32
|
+
// Keyless (sigstore) signing for CI: the OIDC identity (ambient in GitHub
|
|
33
|
+
// Actions via CIContextProvider, or an explicit token) is exchanged at Fulcio
|
|
34
|
+
// for a short-lived certificate, the payload bytes are signed with an
|
|
35
|
+
// ephemeral P-256 key, and the sigstore bundle is assembled (serialized JSON,
|
|
36
|
+
// the shape the registry verifies). Rekor upload is optional.
|
|
37
|
+
export async function buildKeylessBundle(input) {
|
|
38
|
+
const identityProvider = input.oidcToken
|
|
39
|
+
? { getToken: async () => input.oidcToken }
|
|
40
|
+
: new CIContextProvider();
|
|
41
|
+
const signer = new FulcioSigner({
|
|
42
|
+
identityProvider,
|
|
43
|
+
...(input.fulcioBaseURL ? { fulcioBaseURL: input.fulcioBaseURL } : {}),
|
|
44
|
+
});
|
|
45
|
+
const builder = new MessageSignatureBundleBuilder({
|
|
46
|
+
signer,
|
|
47
|
+
witnesses: input.rekorBaseURL ? [new RekorWitness({ rekorBaseURL: input.rekorBaseURL })] : [],
|
|
48
|
+
});
|
|
49
|
+
const bundle = await builder.create({ data: input.data });
|
|
50
|
+
const serialized = bundleToJSON(bundle);
|
|
51
|
+
return { bundle: serialized, ...readBundleIdentity(serialized) };
|
|
52
|
+
}
|