mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 01:14:47 +00:00
Add the LogicSRC OpenCreds specification
Leaving a password manager means writing every secret you own to disk in the clear, and losing whatever the spreadsheet had no column for. A CSV is plaintext by construction, lossy by omission, and carries no integrity: nothing in it says which rows were meant to be there, so a truncated import looks exactly like a complete one. The same gap showed up inside LogicSRC. `logicsrc credentials` moves .env secrets and SSH keys through end-to-end-encrypted team vaults, but it can only model a key/value pair. A card, a passport, a login with a TOTP seed, or an OAuth account with a refresh token are all things people already keep in a vault, and none of them are a key/value pair. OpenCreds defines three things: the item, the vault, and the database. - Six item types (login, card, identity, note, key, account) as one record with a type and a named field group, so everything the user typed lives in a single encrypted blob. Codes 1-4 match MarkSyncr's deployed vault and are not renumbered; compatibility is cheaper than elegance. - AES-256-GCM over that record with the item id bound as AAD. Without it, anyone with storage write access could move a low-value login's ciphertext into a high-value row and watch what the user does next. - A key hierarchy where the user key is random, not derived, so a password change re-wraps 32 bytes rather than re-encrypting a vault. The auth hash comes out of a different HKDF label than the wrap key, which is what lets it reach a server at all. - A portable .opencreds file, encrypted by default, whose header is the AAD over the payload -- so the manifest is authenticated by the same tag as the data and a truncated import fails rather than reporting success. The plaintext form exists because people move to products that read nothing else; it is opt-in, confirmed, 0600, and labelled "protected": false in its own header. Namespaces are carried as data, not fixed by the spec: labels are compiled into every ciphertext a vault has written, so editing one does not migrate a vault, it makes it undecryptable. MarkSyncr's deployed vault is conformant by declaring `marksyncr`. Ships: prd/0004, nine spec pages under docs/opencreds/, six JSON Schemas, the @logicsrc/opencreds reference implementation with CSV importers for five products, `logicsrc vault` and the standalone `opencreds` binary, and the spec page at logicsrc.com/opencreds. `vault` rather than `creds` because `creds` is already an alias of `logicsrc credentials`, and the two are different: one moves a pair between providers, the other stores a record. @logicsrc/validators now registers every schema by $id before compiling, so the database schema can $ref the item and manifest schemas rather than restating them. 120 tests, including CLI end-to-end coverage of the masking rules, exit codes, and the manifest-mismatch path. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QRQrfuwuYKKV5UB9kLHuX5
This commit is contained in:
parent
b1805d08e5
commit
13519e631a
51 changed files with 8105 additions and 8 deletions
|
|
@ -4,7 +4,15 @@ import type { ErrorObject } from "ajv";
|
|||
import { parse } from "yaml";
|
||||
import { isSchemaKind, schemas, type SchemaKind } from "./schemas.js";
|
||||
|
||||
const Ajv2020 = (Ajv2020Module as unknown as { default: new (options: Record<string, unknown>) => { compile: (schema: unknown) => { (data: unknown): boolean; errors?: ErrorObject[] | null } } }).default;
|
||||
type CompiledSchema = { (data: unknown): boolean; errors?: ErrorObject[] | null };
|
||||
|
||||
type AjvInstance = {
|
||||
compile: (schema: unknown) => CompiledSchema;
|
||||
addSchema: (schema: unknown) => unknown;
|
||||
getSchema: (id: string) => CompiledSchema | undefined;
|
||||
};
|
||||
|
||||
const Ajv2020 = (Ajv2020Module as unknown as { default: new (options: Record<string, unknown>) => AjvInstance }).default;
|
||||
const addFormats = (addFormatsModule as unknown as { default: (ajv: InstanceType<typeof Ajv2020>) => void }).default;
|
||||
|
||||
export type ValidationResult =
|
||||
|
|
@ -18,11 +26,24 @@ export function createValidator() {
|
|||
}
|
||||
|
||||
const _ajv = createValidator();
|
||||
const _compiledValidators = new Map<SchemaKind, ReturnType<typeof _ajv.compile>>();
|
||||
|
||||
// Every schema is registered up front, by $id, so that a schema which $refs
|
||||
// another one across files resolves. The OpenCreds database schema does this:
|
||||
// it refers to the item and manifest schemas rather than restating them, and
|
||||
// restating them is how two copies of a definition drift apart.
|
||||
for (const schema of Object.values(schemas)) {
|
||||
_ajv.addSchema(schema);
|
||||
}
|
||||
|
||||
const _compiledValidators = new Map<SchemaKind, CompiledSchema>();
|
||||
|
||||
function getCompiledValidator(kind: SchemaKind) {
|
||||
if (!_compiledValidators.has(kind)) {
|
||||
_compiledValidators.set(kind, _ajv.compile(schemas[kind]));
|
||||
// Already registered above, so look it up by $id — compiling it a second
|
||||
// time would throw on the duplicate id.
|
||||
const id = (schemas[kind] as { $id?: string }).$id;
|
||||
const registered = id ? _ajv.getSchema(id) : undefined;
|
||||
_compiledValidators.set(kind, registered ?? _ajv.compile(schemas[kind]));
|
||||
}
|
||||
return _compiledValidators.get(kind)!;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,15 @@ import ocDecisionSchema from "@logicsrc/schemas/opencontext-decision" with { typ
|
|||
import ocDiagnosticSchema from "@logicsrc/schemas/opencontext-diagnostic" with { type: "json" };
|
||||
import ocAuditEventSchema from "@logicsrc/schemas/opencontext-audit-event" with { type: "json" };
|
||||
|
||||
// OpenCreds. The database schema $refs the item and manifest schemas by $id,
|
||||
// so all six are registered together in index.ts before anything is compiled.
|
||||
import credsItemSchema from "@logicsrc/schemas/opencreds-item" with { type: "json" };
|
||||
import credsEnvelopeSchema from "@logicsrc/schemas/opencreds-envelope" with { type: "json" };
|
||||
import credsVaultMetaSchema from "@logicsrc/schemas/opencreds-vault-meta" with { type: "json" };
|
||||
import credsManifestSchema from "@logicsrc/schemas/opencreds-manifest" with { type: "json" };
|
||||
import credsDatabaseSchema from "@logicsrc/schemas/opencreds-database" with { type: "json" };
|
||||
import credsAuditEventSchema from "@logicsrc/schemas/opencreds-audit-event" with { type: "json" };
|
||||
|
||||
export const schemas = {
|
||||
agent: agentSchema,
|
||||
"account-audit-event": accountAuditEventSchema,
|
||||
|
|
@ -109,7 +118,13 @@ export const schemas = {
|
|||
"opencontext-provenance": ocProvenanceSchema,
|
||||
"opencontext-decision": ocDecisionSchema,
|
||||
"opencontext-diagnostic": ocDiagnosticSchema,
|
||||
"opencontext-audit-event": ocAuditEventSchema
|
||||
"opencontext-audit-event": ocAuditEventSchema,
|
||||
"opencreds-item": credsItemSchema,
|
||||
"opencreds-envelope": credsEnvelopeSchema,
|
||||
"opencreds-vault-meta": credsVaultMetaSchema,
|
||||
"opencreds-manifest": credsManifestSchema,
|
||||
"opencreds-database": credsDatabaseSchema,
|
||||
"opencreds-audit-event": credsAuditEventSchema
|
||||
} as const;
|
||||
|
||||
export type SchemaKind = keyof typeof schemas;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue