pq-secrets: a zero-trust secrets service on top of pq-kms (each request authorized by an Aere Identity presentation signed for that exact request, per-secret policy whose non-admin grants can only narrow, the same refusal for every unauthorized caller, every operation a signed AIP-23 secret-access envelope); identity: a presentation optionally signed for one exact request; proof-kinds: secret-access with requestHash; conformance 240 rules, 626 vectors
This commit is contained in:
1 parent
8c7d72c1a7
commit
ad16b1f69b
97 files changed
+4258
-133
No files matched your search
@@ -20,6 +20,16 @@ const dg = (v) => (v == null ? null : (isDigest(v) ? v.toLowerCase()
|
||||
: (Buffer.isBuffer(v) || v instanceof Uint8Array) ? sha256(Buffer.from(v))
|
||||
: sha256(Buffer.from(typeof v === 'string' ? v : JSON.stringify(v), 'utf8'))));
|
||||
|
||||
// VOCABULARUL unui fel (2026-10-18, B8): `valori: { camp: [predicat, ce spune] }`, judecat de buildProof pe fiecare camp prezent in
|
||||
// declaratie (un camp lipsa il judeca `req`). Un mecanism mic si general; felurile fara `valori` nu se schimba cu nimic.
|
||||
// Operatiile si verdictele unui acces la un secret, intr-un singur loc (cloud-gateway/pq-secrets cere, intr-o proba, ca OPERATII lui sa
|
||||
// fie exact aceasta lista).
|
||||
export const SECRET_ACCESS = Object.freeze({ operations: Object.freeze(['put', 'get', 'metadata', 'rotate', 'revoke-version', 'grant', 'revoke', 'list']), verdicts: Object.freeze(['allowed', 'refused', 'failed']) });
|
||||
const NUME_IN_SERVICIU = /^[a-z0-9][a-z0-9_-]{0,63}$/;
|
||||
const eRegula = (r) => typeof r === 'string' && /^[a-z][a-z0-9-]{0,63}$/.test(r);
|
||||
const eGrant = (g) => typeof g === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,63}$/.test(g);
|
||||
const eIdSauNull = (v) => v === null || (typeof v === 'string' && /^aere-id:[0-9a-f]{40}$/.test(v));
|
||||
|
||||
// schema fiecarui fel: campuri de tip 'digest' (se hashuiesc), 'plain' (raman ca atare), 'bool', 'list'. Toate obligatorii daca in `req`.
|
||||
export const SCHEME = {
|
||||
'data': { digest: { sha256: 'content' }, plain: { name: 'subject' }, req: ['sha256', 'name'] },
|
||||
@@ -45,6 +55,32 @@ export const SCHEME = {
|
||||
'settlement': { digest: { instructionHash: 'instruction' }, hash: ['txHash', 'blockHash'], plain: { chainId: 'chainId', from: 'from', to: 'to', amount: 'amount', asset: 'asset' }, req: ['chainId', 'txHash', 'blockHash', 'amount', 'asset'] },
|
||||
// provenance: din ce a iesit un artefact (parents), prin ce proces, cine l-a produs
|
||||
'provenance': { digest: { subjectHash: 'subject', processHash: 'process' }, list: { parents: 'parentsContent' }, plain: { actor: 'actor' }, req: ['subjectHash', 'parents'] },
|
||||
// 2026-10-18 (roadmap pista B, B8, linia Shield): un acces la un secret (cloud-gateway/pq-secrets): ce serviciu (audienta), ce secret, ce
|
||||
// versiune, ce operatie, verdictul (allowed | refused) cu regulile care au refuzat, grantul care a permis, detinatorul si prezentatorul
|
||||
// (id-uri aere-id, derivate din chei), digestul PREZENTARII (al legaturii semnate: ea numeste prin hash credentialul, dezvaluirile, lantul
|
||||
// de delegare, publicul, nonce-ul si momentul) si al politicii grantului. NICIODATA valoarea secretului, nici un digest al ei (un digest
|
||||
// al unei valori ghicibile nu o ascunde).
|
||||
// 2026-10-18 (revizuirea adversariala B8): `requestHash` (digestul cererii pentru care detinatorul a semnat prezentarea, deja un hash),
|
||||
// `claimedHolder` / `claimedPresenter` (id-urile PRETINSE de o prezentare a carei semnatura nu a fost verificata; `holder` si `presenter`
|
||||
// poarta numai id-uri verificate), `judged` (pe un refuz: fiecare grant judecat, cu regulile pe care a refuzat) si VOCABULARUL valorilor
|
||||
// (`valori`): un plic secret-access cu verdictul "banana" sau operatia "fly" nu se mai poate construi. Campurile noi lipsesc din plicurile
|
||||
// de dinainte, deci acelea raman octet cu octet aceleasi.
|
||||
'secret-access': { digest: { presentationHash: 'presentation', policyHash: 'policy' }, hash: ['requestHash'], plain: { service: 'service', secret: 'secret', version: 'version', operation: 'operation', verdict: 'verdict', rules: 'rules', grant: 'grant', holder: 'holder', presenter: 'presenter', claimedHolder: 'claimedHolder', claimedPresenter: 'claimedPresenter', judged: 'judged' }, req: ['service', 'operation', 'verdict', 'presentationHash'],
|
||||
valori: {
|
||||
service: [(v) => typeof v === 'string' && v.length >= 1 && v.length <= 256 && /^[\x21-\x7e]+$/.test(v), '1 to 256 printable ASCII characters without spaces (the audience of the service)'],
|
||||
secret: [(v) => v === null || v === '*' || (typeof v === 'string' && NUME_IN_SERVICIU.test(v)), 'a secret name (^[a-z0-9][a-z0-9_-]{0,63}$), "*" for list, or null'],
|
||||
version: [(v) => v === null || (Number.isSafeInteger(v) && v >= 1), 'an integer >= 1, or null'],
|
||||
operation: [(v) => SECRET_ACCESS.operations.includes(v), SECRET_ACCESS.operations.join(' | ')],
|
||||
verdict: [(v) => SECRET_ACCESS.verdicts.includes(v), SECRET_ACCESS.verdicts.join(' | ') + ' (failed: allowed and entered, then the change could not be stored)'],
|
||||
rules: [(v) => Array.isArray(v) && v.length <= 128 && v.every(eRegula), 'a list of rule names (^[a-z][a-z0-9-]{0,63}$), at most 128'],
|
||||
grant: [(v) => v === null || eGrant(v), 'a grant id (^[A-Za-z0-9][A-Za-z0-9_.:-]{0,63}$), or null'],
|
||||
holder: [eIdSauNull, 'an aere-id (aere-id: + 40 hex) verified from the presentation, or null'],
|
||||
presenter: [eIdSauNull, 'an aere-id verified from the presentation, or null'],
|
||||
claimedHolder: [eIdSauNull, 'an aere-id the presentation claims and nobody verified, or null'],
|
||||
claimedPresenter: [eIdSauNull, 'an aere-id the presentation claims and nobody verified, or null'],
|
||||
judged: [(v) => Array.isArray(v) && v.length <= 64 && v.every((x) => x && typeof x === 'object' && !Array.isArray(x) && Object.keys(x).sort().join(',') === 'grant,rules' && eGrant(x.grant) && Array.isArray(x.rules) && x.rules.length <= 64 && x.rules.every(eRegula)), 'a list of { grant, rules }, at most 64'],
|
||||
createdAt: [(v) => typeof v === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$/.test(v) && !Number.isNaN(Date.parse(v)), 'an RFC 3339 time'],
|
||||
} },
|
||||
};
|
||||
export const KINDS = Object.keys(SCHEME);
|
||||
|
||||
@@ -81,6 +117,9 @@ export function buildProof(kind, p = {}) {
|
||||
for (const r of s.req) {
|
||||
if (statement[r] === undefined || statement[r] === null) throw new Error('proof-kinds: ' + kind + ' needs the field "' + r + '"');
|
||||
}
|
||||
for (const [camp, [bun, spune]] of Object.entries(s.valori || {})) {
|
||||
if (statement[camp] !== undefined && !bun(statement[camp])) throw new Error('proof-kinds: ' + kind + ' field "' + camp + '" has a value outside its vocabulary (' + spune + ')');
|
||||
}
|
||||
const text = JSON.stringify(statement); // canonic AIP-23
|
||||
return { v: 1, kind: 'aere-proof-of-' + kind + '-attestation', statement, statementHash: sha256(Buffer.from(text, 'utf8')) };
|
||||
}
|
||||
Reference in new issue
Block a user