@conarium-ai/core 0.2.0 → 0.2.2
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 +79 -1
- package/README.md +20 -3
- package/SECURITY.md +15 -0
- package/bin/conarium-init.mjs +11 -2
- package/dist/audit.d.ts.map +1 -1
- package/dist/audit.js +4 -0
- package/dist/audit.js.map +1 -1
- package/dist/governance.d.ts.map +1 -1
- package/dist/governance.js +15 -5
- package/dist/governance.js.map +1 -1
- package/dist/http.d.ts +0 -5
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +32 -9
- package/dist/http.js.map +1 -1
- package/dist/iban.d.ts +56 -0
- package/dist/iban.d.ts.map +1 -0
- package/dist/iban.js +166 -0
- package/dist/iban.js.map +1 -0
- package/dist/llm-gate.d.ts +1 -1
- package/dist/llm-gate.js +1 -1
- package/docs/RECEIPT-SPEC.md +21 -5
- package/examples/demo-bank/README.md +5 -0
- package/examples/per-user-identity/README.md +63 -0
- package/examples/per-user-identity/mint-token.mjs +92 -0
- package/examples/per-user-identity/policy.overlay.json +15 -0
- package/examples/per-user-identity/prove-identity.mjs +138 -0
- package/examples/per-user-identity/rollback.sh +8 -0
- package/package.json +6 -2
- package/test-vectors/keys/vector-key.SECRET-TEST-ONLY.pem +0 -6
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Local proof: same row, two tokens, two receipts.
|
|
4
|
+
* Does not talk to Hetzner. Needs a built dist/ (npm run build).
|
|
5
|
+
*/
|
|
6
|
+
import { createHash, randomBytes } from 'node:crypto'
|
|
7
|
+
import { mkdtempSync, writeFileSync, readFileSync, mkdirSync } from 'node:fs'
|
|
8
|
+
import { join, dirname, resolve } from 'node:path'
|
|
9
|
+
import { tmpdir } from 'node:os'
|
|
10
|
+
import { spawnSync } from 'node:child_process'
|
|
11
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
12
|
+
|
|
13
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
14
|
+
const root = resolve(here, '..', '..')
|
|
15
|
+
const distGov = join(root, 'dist', 'governance.js')
|
|
16
|
+
const distAudit = join(root, 'dist', 'audit.js')
|
|
17
|
+
const distTokens = join(root, 'dist', 'tokens.js')
|
|
18
|
+
const distKeys = join(root, 'dist', 'keys.js')
|
|
19
|
+
const verifyJs = join(root, 'bin', 'conarium-verify.mjs')
|
|
20
|
+
|
|
21
|
+
function fail(msg) {
|
|
22
|
+
console.error(`FAIL ${msg}`)
|
|
23
|
+
process.exit(1)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const { Governance } = await import(pathToFileURL(distGov).href)
|
|
27
|
+
const { Audit } = await import(pathToFileURL(distAudit).href)
|
|
28
|
+
const { loadTokenStore, resolveActor } = await import(pathToFileURL(distTokens).href)
|
|
29
|
+
const { writeKeyPairFiles } = await import(pathToFileURL(distKeys).href)
|
|
30
|
+
|
|
31
|
+
const dir = mkdtempSync(join(tmpdir(), 'cnr-identity-'))
|
|
32
|
+
const tokensFile = join(dir, 'conarium.tokens.json')
|
|
33
|
+
const receiptSink = join(dir, 'receipts.jsonl')
|
|
34
|
+
const auditSink = join(dir, 'audit.jsonl')
|
|
35
|
+
mkdirSync(dir, { recursive: true })
|
|
36
|
+
|
|
37
|
+
const patronRaw = randomBytes(32).toString('base64url')
|
|
38
|
+
const aiRaw = randomBytes(32).toString('base64url')
|
|
39
|
+
writeFileSync(tokensFile, JSON.stringify({
|
|
40
|
+
tokens: [
|
|
41
|
+
{ sha256: createHash('sha256').update(patronRaw).digest('hex'), id: 'emekcan' },
|
|
42
|
+
{ sha256: createHash('sha256').update(aiRaw).digest('hex'), id: 'copilot' },
|
|
43
|
+
],
|
|
44
|
+
}) + '\n')
|
|
45
|
+
|
|
46
|
+
const keyFiles = writeKeyPairFiles(join(dir, 'audit-ed25519'), 'cnr-identity-demo')
|
|
47
|
+
process.env.CONARIUM_AUDIT_SIGNING_KEY = keyFiles.privatePath
|
|
48
|
+
process.env.CONARIUM_AUDIT_TRUST_PUBKEYS = keyFiles.publicPath
|
|
49
|
+
delete process.env.CONARIUM_AUDIT_UNSIGNED
|
|
50
|
+
|
|
51
|
+
const policy = {
|
|
52
|
+
allowTables: ['public.customers'],
|
|
53
|
+
maskColumns: ['*.customer_name', '*.email', '*.phone', '*.tckn', '*.iban'],
|
|
54
|
+
profiles: {
|
|
55
|
+
patron: {
|
|
56
|
+
maskColumns: ['*.email', '*.phone', '*.tckn', '*.iban'],
|
|
57
|
+
maskLabelledNames: false,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
actorProfiles: { emekcan: 'patron' },
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const store = loadTokenStore(tokensFile)
|
|
64
|
+
const patron = resolveActor(patronRaw, store, 'conarium_c2')
|
|
65
|
+
const ai = resolveActor(aiRaw, store, 'conarium_c2')
|
|
66
|
+
if (patron.assurance !== 'per-user-token' || patron.id !== 'emekcan') fail(`patron resolve: ${JSON.stringify(patron)}`)
|
|
67
|
+
if (ai.assurance !== 'per-user-token' || ai.id !== 'copilot') fail(`ai resolve: ${JSON.stringify(ai)}`)
|
|
68
|
+
|
|
69
|
+
const row = { _table: 'public.customers', customer_name: 'Ayşe Yılmaz', email: 'a@b.com', city: 'İzmir' }
|
|
70
|
+
const base = new Governance(policy)
|
|
71
|
+
const asPatron = base.forActor(patron)
|
|
72
|
+
const asAi = base.forActor(ai)
|
|
73
|
+
|
|
74
|
+
const patronOut = asPatron.redact({ rows: [row], rowCount: 1, fields: Object.keys(row) })
|
|
75
|
+
const aiOut = asAi.redact({ rows: [row], rowCount: 1, fields: Object.keys(row) })
|
|
76
|
+
const pName = patronOut.rows[0].customer_name
|
|
77
|
+
const aName = aiOut.rows[0].customer_name
|
|
78
|
+
|
|
79
|
+
console.log(`patron name ${pName}`)
|
|
80
|
+
console.log(`ai name ${aName}`)
|
|
81
|
+
console.log(`patron email ${patronOut.rows[0].email}`)
|
|
82
|
+
console.log(`ai email ${aiOut.rows[0].email}`)
|
|
83
|
+
|
|
84
|
+
if (pName !== 'Ayşe Yılmaz') fail(`patron should see the name, got ${pName}`)
|
|
85
|
+
if (aName !== '[MASKED_PII]') fail(`ai should see [MASKED_PII], got ${aName}`)
|
|
86
|
+
if (patronOut.rows[0].email !== '[MASKED_PII]' || aiOut.rows[0].email !== '[MASKED_PII]') {
|
|
87
|
+
fail('email must stay masked for both (content scanner / remaining maskColumns)')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const audit = new Audit({ sink: auditSink, receiptSink, consumer: 'conarium_c2', failClosed: true })
|
|
91
|
+
audit.log({
|
|
92
|
+
tool: 'query',
|
|
93
|
+
target: 'public.customers',
|
|
94
|
+
denied: false,
|
|
95
|
+
actor: patron.id,
|
|
96
|
+
actorAssurance: patron.assurance,
|
|
97
|
+
policyProfile: asPatron.appliedProfile() || undefined,
|
|
98
|
+
rowsReturned: 1,
|
|
99
|
+
source: 'postgres',
|
|
100
|
+
})
|
|
101
|
+
audit.log({
|
|
102
|
+
tool: 'query',
|
|
103
|
+
target: 'public.customers',
|
|
104
|
+
denied: false,
|
|
105
|
+
actor: ai.id,
|
|
106
|
+
actorAssurance: ai.assurance,
|
|
107
|
+
policyProfile: asAi.appliedProfile() || undefined,
|
|
108
|
+
rowsReturned: 1,
|
|
109
|
+
source: 'postgres',
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const receipts = readFileSync(receiptSink, 'utf8').trim().split('\n').map((l) => JSON.parse(l))
|
|
113
|
+
if (receipts.length !== 2) fail(`expected 2 receipts, got ${receipts.length}`)
|
|
114
|
+
|
|
115
|
+
const [rPatron, rAi] = receipts
|
|
116
|
+
console.log(`patron policy.id ${rPatron.policy.id}`)
|
|
117
|
+
console.log(`patron assurance ${rPatron.actor.assurance} actor.id=${rPatron.actor.id}`)
|
|
118
|
+
console.log(`ai policy.id ${rAi.policy.id}`)
|
|
119
|
+
console.log(`ai assurance ${rAi.actor.assurance} actor.id=${rAi.actor.id}`)
|
|
120
|
+
|
|
121
|
+
if (rPatron.policy.id !== 'conarium.policy/patron') fail(`patron policy.id ${rPatron.policy.id}`)
|
|
122
|
+
if (rAi.policy.id !== 'conarium.policy') fail(`ai (no profile) policy.id ${rAi.policy.id}`)
|
|
123
|
+
if (rPatron.actor.assurance !== 'per-user-token' || rAi.actor.assurance !== 'per-user-token') {
|
|
124
|
+
fail('both receipts must carry per-user-token')
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const v = spawnSync(process.execPath, [verifyJs, receiptSink, '--pubkey', keyFiles.publicPath], {
|
|
128
|
+
encoding: 'utf8',
|
|
129
|
+
env: process.env,
|
|
130
|
+
})
|
|
131
|
+
process.stdout.write(v.stdout || '')
|
|
132
|
+
process.stderr.write(v.stderr || '')
|
|
133
|
+
if (v.status !== 0) fail(`conarium-verify exit ${v.status}`)
|
|
134
|
+
if (!String(v.stdout || v.stderr || '').includes('verified')) fail('verify output missing verified')
|
|
135
|
+
|
|
136
|
+
console.log('PASS same query, two tokens, two receipts, verify EXIT 0')
|
|
137
|
+
console.log(`artefacts in ${dir} (temp; not Hetzner)`)
|
|
138
|
+
process.exit(0)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Restore c2 policy to the backup taken before the identity overlay.
|
|
3
|
+
# Does not touch Hetzner. Run from the directory that holds the config.
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
test -f conarium.config.c2.json.bak || { echo "missing conarium.config.c2.json.bak"; exit 1; }
|
|
6
|
+
cp conarium.config.c2.json.bak conarium.config.c2.json
|
|
7
|
+
unset CONARIUM_TOKENS_FILE || true
|
|
8
|
+
echo "restored conarium.config.c2.json from .bak; CONARIUM_TOKENS_FILE unset"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@conarium-ai/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"//files-artefakt": "examples/ altindaki uretilmis dosyalar (ozel anahtar, makbuz/denetim JSONL) ELENIR. .gitignore npm'i baglamaz: izin listesinde 'examples' oldugu icin demoyu kosturmus bir makinede 'npm publish' _keys/audit-ed25519.pem'i (OZEL ANAHTAR) ve makbuzlari yayinliyordu. test/pack_artefakt.mjs bunu kilitler. Elemeler examples/ ile SINIRLI: test-vectors/ altindaki receipts.jsonl ve .pub.pem YAYINLANMAK ZORUNDA, yoksa ucuncu taraf konformans vektorlerini kosturamaz.",
|
|
5
5
|
"//files": "Pakete NE gireceginin izin listesi. Liste olmadan npm her seyi gonderiyordu: 296 dosya / 1.5 MB — CI workflowlari, gitleaks ayari, 137 KB pazarlama gorseli, sitenin api/chat.js dosyasi. Bir bankanin guvenlik ekibi tarball'i acip bunlari gorur. scripts/ BILEREK var: conarium-reconcile calisirken scripts/pg-snapshot.sql'e atif yapiyor, olmazsa kullanici destek maili yazar.",
|
|
6
6
|
"files": [
|
|
@@ -12,10 +12,14 @@
|
|
|
12
12
|
"examples",
|
|
13
13
|
"!examples/**/_keys",
|
|
14
14
|
"!examples/**/*.jsonl",
|
|
15
|
-
"!examples/**/*.pem",
|
|
16
15
|
"!examples/**/*.keyid",
|
|
16
|
+
"!examples/**/conarium.tokens.json",
|
|
17
17
|
"test-vectors",
|
|
18
|
+
"!**/*.pem",
|
|
19
|
+
"test-vectors/keys/vector-key.pub.pem",
|
|
18
20
|
"deploy",
|
|
21
|
+
"!deploy/hetzner",
|
|
22
|
+
"!deploy/hetzner/**",
|
|
19
23
|
"conarium.config.json",
|
|
20
24
|
"README.md",
|
|
21
25
|
"LICENSE",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
# TEST VECTOR KEY — PUBLISHED ON PURPOSE, NEVER USE FOR ANYTHING REAL.
|
|
2
|
-
# Anyone reading this repository has the private half. It signs nothing
|
|
3
|
-
# but the frozen vectors in this directory.
|
|
4
|
-
-----BEGIN PRIVATE KEY-----
|
|
5
|
-
MC4CAQAwBQYDK2VwBCIEII/aitZbtkTrKP348FUMbsV6glU6gHFUMUIlHJxP3W62
|
|
6
|
-
-----END PRIVATE KEY-----
|