@feltdb/feltkit 0.2.0 → 0.3.0
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/dist/cli/deploy.js +9 -0
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/main.js +128 -7
- package/dist/cli/main.js.map +1 -1
- package/dist/dashboard/assets/index-D9529PVz.js +15 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/errors.d.ts +3 -1
- package/dist/errors.js +1 -0
- package/dist/errors.js.map +1 -1
- package/dist/runtime/authority.d.ts +1 -0
- package/dist/runtime/authority.js +3 -0
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/credentials.d.ts +159 -27
- package/dist/runtime/credentials.js +389 -14
- package/dist/runtime/credentials.js.map +1 -1
- package/dist/runtime/decisions.d.ts +14 -4
- package/dist/runtime/decisions.js +39 -10
- package/dist/runtime/decisions.js.map +1 -1
- package/dist/runtime/integrations.d.ts +5 -0
- package/dist/runtime/integrations.js +20 -3
- package/dist/runtime/integrations.js.map +1 -1
- package/dist/runtime/readiness.js +3 -3
- package/dist/runtime/readiness.js.map +1 -1
- package/dist/runtime/runtime.d.ts +3 -0
- package/dist/runtime/runtime.js +27 -0
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/services.d.ts +23 -4
- package/dist/runtime/services.js +60 -1
- package/dist/runtime/services.js.map +1 -1
- package/dist/server/admin.d.ts +56 -2
- package/dist/server/admin.js +176 -9
- package/dist/server/admin.js.map +1 -1
- package/package.json +3 -3
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/skills/feltkit-build/SKILL.md +14 -4
- package/skills/feltkit-services/SKILL.md +29 -7
- package/dist/dashboard/assets/index-Bm4qCYpv.js +0 -15
|
@@ -1,32 +1,407 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential custody for AppPort Services.
|
|
3
|
+
*
|
|
4
|
+
* AppPort Services stores only references (`credential-ref:<id>`). It asks the host's
|
|
5
|
+
* custody for the value inside the one effect that needs it (signing a webhook, calling
|
|
6
|
+
* a model provider), and, from 0.8.0, hands the host a value to keep (`credential.store`)
|
|
7
|
+
* without ever persisting it itself. AppPort Services contains no secret store; this
|
|
8
|
+
* module is FeltKit's, the host side of that contract (`SecretCustody`):
|
|
9
|
+
*
|
|
10
|
+
* 1. The environment variable wins:
|
|
11
|
+
* credential-ref:stripe-signing → FELTKIT_CREDENTIAL_STRIPE_SIGNING
|
|
12
|
+
* When it is set the reference is read-only here (status `writable: false`): the
|
|
13
|
+
* value belongs to whoever runs the process (a secret manager, a .env they control).
|
|
14
|
+
* 2. Otherwise the local encrypted vault, in development and test:
|
|
15
|
+
* .feltkit/<env>/credentials.vault AES-256-GCM, whole document encrypted
|
|
16
|
+
* .feltkit/<env>/credentials.key one random 32-byte key
|
|
17
|
+
* Both files are 0600 and written atomically under a lock file; `.feltkit/` is
|
|
18
|
+
* gitignored and never part of `feltkit build`/`deploy` output. The vault keeps the
|
|
19
|
+
* current value of each reference and its version history (numbers and times only).
|
|
20
|
+
* 3. Production: environment variables only, unless the operator explicitly opts in to
|
|
21
|
+
* a vault with FELTKIT_CREDENTIAL_VAULT=1 and FELTKIT_CREDENTIAL_VAULT_KEY (32 bytes,
|
|
22
|
+
* base64/base64url, from the host's secret manager; never written to disk by FeltKit).
|
|
23
|
+
* Without the opt-in `store` refuses with CUSTODY_READ_ONLY and says what to set.
|
|
24
|
+
*
|
|
25
|
+
* Values never reach FeltDB, the activity log, evidence, an API response, an error
|
|
26
|
+
* message, a log line, or agent context. `describe`/`status` report whether a reference
|
|
27
|
+
* resolves, from where, and its version, never the value.
|
|
28
|
+
*/
|
|
29
|
+
import { closeSync, chmodSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync, statSync, unlinkSync, writeSync } from "node:fs";
|
|
30
|
+
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
|
|
31
|
+
import { join } from "node:path";
|
|
1
32
|
const ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$/;
|
|
33
|
+
const PREFIX = "credential-ref:";
|
|
34
|
+
const VAULT_FORMAT = "feltkit.credential-vault/1";
|
|
35
|
+
const MAX_VALUE_BYTES = 16 * 1024;
|
|
2
36
|
/** The environment variable that holds the value for a credential id. */
|
|
3
37
|
export function credentialVariable(secretId) {
|
|
4
38
|
return `FELTKIT_CREDENTIAL_${secretId.replace(/[^A-Za-z0-9]/g, "_").toUpperCase()}`;
|
|
5
39
|
}
|
|
6
|
-
|
|
40
|
+
/** `credential-ref:<id>` or a bare id → the id, or null when it is not a valid reference. */
|
|
41
|
+
export function credentialId(ref) {
|
|
42
|
+
const id = ref.startsWith(PREFIX) ? ref.slice(PREFIX.length) : ref;
|
|
43
|
+
return ID.test(id) ? id : null;
|
|
44
|
+
}
|
|
45
|
+
/** A provider name or reference → the reference (`anthropic` → `credential-ref:anthropic`). */
|
|
46
|
+
export function toCredentialRef(refOrProvider) {
|
|
47
|
+
const id = credentialId(refOrProvider.trim());
|
|
48
|
+
if (!id)
|
|
49
|
+
throw custodyError("INVALID_REQUEST", "A credential reference is credential-ref:<id> (letters, digits, . _ : -).");
|
|
50
|
+
return `${PREFIX}${id}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Whether text looks like secret material rather than a reference: a known key prefix,
|
|
54
|
+
* or a long, high-entropy token. Used to keep a pasted key out of reference fields.
|
|
55
|
+
*/
|
|
56
|
+
export function looksLikeSecret(text) {
|
|
57
|
+
const value = text.trim();
|
|
58
|
+
if (!value || value.startsWith(PREFIX))
|
|
59
|
+
return false;
|
|
60
|
+
if (/^(sk-|sk-ant-|sk_live_|sk_test_|rk_live_|xai-|AIza|ghp_|gho_|github_pat_|gsk_|glpat-|xox[abpr]-|hf_|pk_live_)/.test(value))
|
|
61
|
+
return true;
|
|
62
|
+
if (value.length < 32 || /\s/.test(value) || !/[0-9]/.test(value) || !/[A-Za-z]/.test(value))
|
|
63
|
+
return false;
|
|
64
|
+
const counts = new Map();
|
|
65
|
+
for (const ch of value)
|
|
66
|
+
counts.set(ch, (counts.get(ch) ?? 0) + 1);
|
|
67
|
+
let entropy = 0;
|
|
68
|
+
for (const n of counts.values())
|
|
69
|
+
entropy -= (n / value.length) * Math.log2(n / value.length);
|
|
70
|
+
return entropy >= 4;
|
|
71
|
+
}
|
|
72
|
+
/** Remove every occurrence of `secret` (and obvious key shapes) from text. */
|
|
73
|
+
export function redactSecret(text, secret) {
|
|
74
|
+
let out = String(text);
|
|
75
|
+
if (secret && secret.length >= 4)
|
|
76
|
+
out = out.split(secret).join("[redacted]");
|
|
77
|
+
return out.replace(/\b(sk|key|xai|gsk|ghp)[-_][A-Za-z0-9_-]{12,}/g, "[redacted]");
|
|
78
|
+
}
|
|
79
|
+
function custodyError(code, message) {
|
|
80
|
+
return Object.assign(new Error(message), { code, name: "CredentialCustodyError" });
|
|
81
|
+
}
|
|
82
|
+
export function isCustodyError(error) {
|
|
83
|
+
return error?.name === "CredentialCustodyError";
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* One environment's vault. Every read decrypts the file (so a value stored by the CLI is
|
|
87
|
+
* visible to a running server at once); every write is read-modify-write under a lock
|
|
88
|
+
* file, to a temporary 0600 file that is fsynced and renamed over the vault.
|
|
89
|
+
*/
|
|
90
|
+
export class CredentialVault {
|
|
91
|
+
file;
|
|
92
|
+
keyFile;
|
|
93
|
+
#dir;
|
|
94
|
+
#key;
|
|
95
|
+
#aad;
|
|
96
|
+
#cache = null;
|
|
97
|
+
constructor(options) {
|
|
98
|
+
this.#dir = options.dir;
|
|
99
|
+
this.file = join(options.dir, "credentials.vault");
|
|
100
|
+
this.keyFile = options.key ? null : join(options.dir, "credentials.key");
|
|
101
|
+
if (options.key && options.key.length !== 32)
|
|
102
|
+
throw custodyError("CUSTODY_UNAVAILABLE", "The credential vault key must be exactly 32 bytes.");
|
|
103
|
+
this.#key = options.key;
|
|
104
|
+
this.#aad = Buffer.from(`${VAULT_FORMAT}:${options.scope}`);
|
|
105
|
+
}
|
|
106
|
+
#readKey(create) {
|
|
107
|
+
if (this.#key)
|
|
108
|
+
return this.#key;
|
|
109
|
+
const file = this.keyFile;
|
|
110
|
+
if (existsSync(file)) {
|
|
111
|
+
const key = Buffer.from(readFileSync(file, "utf8").trim(), "base64url");
|
|
112
|
+
if (key.length !== 32)
|
|
113
|
+
throw custodyError("CUSTODY_UNAVAILABLE", `${file} is not a 32-byte vault key. Move it aside to start an empty vault (stored values are then lost).`);
|
|
114
|
+
return key;
|
|
115
|
+
}
|
|
116
|
+
if (!create)
|
|
117
|
+
return null;
|
|
118
|
+
mkdirSync(this.#dir, { recursive: true, mode: 0o700 });
|
|
119
|
+
const key = randomBytes(32);
|
|
120
|
+
writeAtomic(file, `${key.toString("base64url")}\n`);
|
|
121
|
+
return key;
|
|
122
|
+
}
|
|
123
|
+
read() {
|
|
124
|
+
if (!existsSync(this.file))
|
|
125
|
+
return { entries: {} };
|
|
126
|
+
const stat = statSync(this.file);
|
|
127
|
+
if (this.#cache && this.#cache.mtimeMs === stat.mtimeMs && this.#cache.size === stat.size)
|
|
128
|
+
return this.#cache.doc;
|
|
129
|
+
const key = this.#readKey(false);
|
|
130
|
+
if (!key)
|
|
131
|
+
throw custodyError("CUSTODY_UNAVAILABLE", `The credential vault ${this.file} exists but its key does not. Restore the key, or move the vault aside (stored values are then lost).`);
|
|
132
|
+
let doc;
|
|
133
|
+
try {
|
|
134
|
+
const envelope = JSON.parse(readFileSync(this.file, "utf8"));
|
|
135
|
+
if (envelope.format !== VAULT_FORMAT)
|
|
136
|
+
throw new Error("format");
|
|
137
|
+
const decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(envelope.iv, "base64"));
|
|
138
|
+
decipher.setAAD(this.#aad);
|
|
139
|
+
decipher.setAuthTag(Buffer.from(envelope.tag, "base64"));
|
|
140
|
+
const plain = Buffer.concat([decipher.update(Buffer.from(envelope.data, "base64")), decipher.final()]);
|
|
141
|
+
doc = JSON.parse(plain.toString("utf8"));
|
|
142
|
+
plain.fill(0);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
// Never echo file contents.
|
|
146
|
+
throw custodyError("CUSTODY_UNAVAILABLE", `The credential vault ${this.file} could not be decrypted with its key (wrong key, another environment's vault, or a modified file).`);
|
|
147
|
+
}
|
|
148
|
+
if (!doc || typeof doc.entries !== "object")
|
|
149
|
+
doc = { entries: {} };
|
|
150
|
+
this.#cache = { mtimeMs: stat.mtimeMs, size: stat.size, doc };
|
|
151
|
+
return doc;
|
|
152
|
+
}
|
|
153
|
+
get(id) {
|
|
154
|
+
return this.read().entries[id] ?? null;
|
|
155
|
+
}
|
|
156
|
+
/** Apply `change` to the current document under the lock and write it back. */
|
|
157
|
+
update(change) {
|
|
158
|
+
mkdirSync(this.#dir, { recursive: true, mode: 0o700 });
|
|
159
|
+
const release = lock(`${this.file}.lock`);
|
|
160
|
+
try {
|
|
161
|
+
this.#cache = null;
|
|
162
|
+
const doc = structuredClone(this.read());
|
|
163
|
+
const result = change(doc);
|
|
164
|
+
const key = this.#readKey(true);
|
|
165
|
+
const iv = randomBytes(12);
|
|
166
|
+
const cipher = createCipheriv("aes-256-gcm", key, iv);
|
|
167
|
+
cipher.setAAD(this.#aad);
|
|
168
|
+
const plain = Buffer.from(JSON.stringify(doc), "utf8");
|
|
169
|
+
const data = Buffer.concat([cipher.update(plain), cipher.final()]);
|
|
170
|
+
plain.fill(0);
|
|
171
|
+
const envelope = { format: VAULT_FORMAT, alg: "AES-256-GCM", iv: iv.toString("base64"), tag: cipher.getAuthTag().toString("base64"), data: data.toString("base64") };
|
|
172
|
+
writeAtomic(this.file, `${JSON.stringify(envelope)}\n`);
|
|
173
|
+
this.#cache = null;
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
release();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/** Write to a 0600 temporary file in the same directory, fsync, rename over `path`. */
|
|
182
|
+
function writeAtomic(path, content) {
|
|
183
|
+
const temp = `${path}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
184
|
+
const fd = openSync(temp, "wx", 0o600);
|
|
185
|
+
try {
|
|
186
|
+
writeSync(fd, content);
|
|
187
|
+
fsyncSync(fd);
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
closeSync(fd);
|
|
191
|
+
}
|
|
192
|
+
chmodSync(temp, 0o600);
|
|
193
|
+
renameSync(temp, path);
|
|
194
|
+
chmodSync(path, 0o600);
|
|
195
|
+
}
|
|
196
|
+
const sleep = (ms) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
197
|
+
/** An exclusive lock file shared by every process using the vault (the dev server, the CLI). */
|
|
198
|
+
function lock(file) {
|
|
199
|
+
const deadline = Date.now() + 5000;
|
|
200
|
+
for (;;) {
|
|
201
|
+
try {
|
|
202
|
+
const fd = openSync(file, "wx", 0o600);
|
|
203
|
+
writeSync(fd, String(process.pid));
|
|
204
|
+
closeSync(fd);
|
|
205
|
+
return () => {
|
|
206
|
+
try {
|
|
207
|
+
unlinkSync(file);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
/* already gone */
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
if (error.code !== "EEXIST")
|
|
216
|
+
throw error;
|
|
217
|
+
try {
|
|
218
|
+
// A lock older than 10 s belongs to a process that died mid-write.
|
|
219
|
+
if (Date.now() - statSync(file).mtimeMs > 10_000)
|
|
220
|
+
unlinkSync(file);
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
/* raced with its owner */
|
|
224
|
+
}
|
|
225
|
+
if (Date.now() > deadline)
|
|
226
|
+
throw custodyError("CUSTODY_UNAVAILABLE", `The credential vault is locked by another process (${file}).`);
|
|
227
|
+
sleep(25);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* FeltKit's credential custody: environment variables first, then the environment's
|
|
233
|
+
* encrypted vault. Implements AppPort Services' `SecretCustody` (withSecret, store,
|
|
234
|
+
* status, remove).
|
|
235
|
+
*/
|
|
236
|
+
export class HostCredentials {
|
|
7
237
|
#env;
|
|
8
|
-
|
|
9
|
-
|
|
238
|
+
#vault;
|
|
239
|
+
#readOnlyReason;
|
|
240
|
+
constructor(options = {}) {
|
|
241
|
+
this.#env = options.env ?? process.env;
|
|
242
|
+
this.#vault = options.vault ?? null;
|
|
243
|
+
this.#readOnlyReason = options.readOnlyReason ?? "This environment keeps credentials in the host's environment only.";
|
|
244
|
+
}
|
|
245
|
+
/** Whether this custody can store values (some reference may still be env-pinned). */
|
|
246
|
+
get writable() {
|
|
247
|
+
return this.#vault !== null;
|
|
248
|
+
}
|
|
249
|
+
/** Where stored values go, for display. */
|
|
250
|
+
get location() {
|
|
251
|
+
return this.#vault ? "local encrypted vault" : "environment variables";
|
|
10
252
|
}
|
|
11
253
|
async withSecret(input, use) {
|
|
12
254
|
const id = input.reference.secretId;
|
|
13
255
|
if (!ID.test(id))
|
|
14
|
-
throw
|
|
256
|
+
throw custodyError("INVALID_REQUEST", `Invalid credential id "${id}"`);
|
|
15
257
|
const variable = credentialVariable(id);
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
258
|
+
const fromEnv = this.#env[variable];
|
|
259
|
+
if (fromEnv)
|
|
260
|
+
return use({ value: fromEnv, secretId: id, version: 1, kind: "environment" });
|
|
261
|
+
const entry = this.#vault?.get(id);
|
|
262
|
+
if (entry && entry.state === "active" && entry.value) {
|
|
263
|
+
return use({ value: entry.value, secretId: id, version: entry.version, ...(entry.kind ? { kind: entry.kind } : {}), ...(entry.provider ? { provider: entry.provider } : {}) });
|
|
20
264
|
}
|
|
21
|
-
|
|
265
|
+
// Names the variable, never a value.
|
|
266
|
+
throw custodyError("CREDENTIAL_UNAVAILABLE", this.#vault
|
|
267
|
+
? `Credential "${id}" is not set: enter it in Studio (Models, Integrations, or Services → Credentials), run \`feltkit credential set ${PREFIX}${id}\`, or define ${variable}.`
|
|
268
|
+
: `Credential "${id}" is not set: define ${variable} in the environment.`);
|
|
22
269
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
const id =
|
|
270
|
+
/** Store a new version. Never returns or echoes the value. */
|
|
271
|
+
async store(input) {
|
|
272
|
+
const id = input.reference.secretId;
|
|
273
|
+
if (!ID.test(id))
|
|
274
|
+
throw custodyError("INVALID_REQUEST", "Invalid credential id.");
|
|
275
|
+
const value = input.value;
|
|
276
|
+
if (typeof value !== "string" || !value.trim())
|
|
277
|
+
throw custodyError("INVALID_REQUEST", "A credential value must be a non-empty string.");
|
|
278
|
+
if (value.trim().startsWith(PREFIX))
|
|
279
|
+
throw custodyError("INVALID_REQUEST", "That is a credential reference, not a value. Enter the key itself.");
|
|
280
|
+
if (Buffer.byteLength(value) > MAX_VALUE_BYTES)
|
|
281
|
+
throw custodyError("INVALID_REQUEST", `A credential value is limited to ${MAX_VALUE_BYTES} bytes.`);
|
|
282
|
+
const readOnly = this.readOnlyReason(id);
|
|
283
|
+
if (readOnly || !this.#vault)
|
|
284
|
+
throw custodyError("CUSTODY_READ_ONLY", readOnly ?? this.#readOnlyReason);
|
|
285
|
+
const vault = this.#vault;
|
|
286
|
+
const material = value.trim();
|
|
287
|
+
const storedAt = new Date().toISOString();
|
|
288
|
+
const version = vault.update((doc) => {
|
|
289
|
+
const previous = doc.entries[id];
|
|
290
|
+
const next = (previous?.version ?? 0) + 1;
|
|
291
|
+
doc.entries[id] = {
|
|
292
|
+
value: material,
|
|
293
|
+
version: next,
|
|
294
|
+
state: "active",
|
|
295
|
+
storedAt,
|
|
296
|
+
updatedAt: storedAt,
|
|
297
|
+
...(input.reference.provider ? { provider: input.reference.provider } : {}),
|
|
298
|
+
...(input.reference.kind ? { kind: input.reference.kind } : {}),
|
|
299
|
+
history: [...(previous?.history ?? []), { version: next, storedAt }].slice(-50),
|
|
300
|
+
};
|
|
301
|
+
return next;
|
|
302
|
+
});
|
|
303
|
+
return { version, storedAt };
|
|
304
|
+
}
|
|
305
|
+
async status(input) {
|
|
306
|
+
const d = this.describe(input.reference.secretId);
|
|
307
|
+
return { state: d.state, writable: d.writable, ...(d.version !== undefined ? { version: d.version } : {}), ...(d.updatedAt ? { updatedAt: d.updatedAt } : {}), ...(d.location ? { location: d.location } : {}) };
|
|
308
|
+
}
|
|
309
|
+
/** Why a value cannot be stored for this reference here, naming what to set instead; null when it can. */
|
|
310
|
+
readOnlyReason(ref) {
|
|
311
|
+
const id = credentialId(ref);
|
|
312
|
+
if (!id)
|
|
313
|
+
return null;
|
|
314
|
+
const variable = credentialVariable(id);
|
|
315
|
+
if (this.#env[variable])
|
|
316
|
+
return `This environment's credential ${PREFIX}${id} comes from the host (${variable}); change it there. A stored value would never be used while the variable is set.`;
|
|
317
|
+
if (!this.#vault)
|
|
318
|
+
return `${this.#readOnlyReason} Set ${variable} on the host.`;
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
/** Revoke: the stored value is erased; the reference reports "revoked". */
|
|
322
|
+
async remove(input) {
|
|
323
|
+
const id = input.reference.secretId;
|
|
26
324
|
if (!ID.test(id))
|
|
27
|
-
|
|
325
|
+
throw custodyError("INVALID_REQUEST", "Invalid credential id.");
|
|
28
326
|
const variable = credentialVariable(id);
|
|
29
|
-
|
|
327
|
+
if (this.#env[variable])
|
|
328
|
+
throw custodyError("CUSTODY_READ_ONLY", `${PREFIX}${id} comes from the host (${variable}); unset it there.`);
|
|
329
|
+
if (!this.#vault)
|
|
330
|
+
throw custodyError("CUSTODY_READ_ONLY", `${this.#readOnlyReason} Unset ${variable} on the host.`);
|
|
331
|
+
this.#vault.update((doc) => {
|
|
332
|
+
const entry = doc.entries[id];
|
|
333
|
+
if (!entry)
|
|
334
|
+
return;
|
|
335
|
+
const at = new Date().toISOString();
|
|
336
|
+
doc.entries[id] = { ...entry, value: "", state: "revoked", updatedAt: at };
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
/** Every reference the vault holds material or history for. */
|
|
340
|
+
stored() {
|
|
341
|
+
if (!this.#vault)
|
|
342
|
+
return [];
|
|
343
|
+
try {
|
|
344
|
+
return Object.keys(this.#vault.read().entries).map((id) => `${PREFIX}${id}`);
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
return [];
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
/** Whether a reference resolves, from where, and its version. Never returns the value. */
|
|
351
|
+
describe(ref) {
|
|
352
|
+
const id = credentialId(ref);
|
|
353
|
+
const shown = ref.startsWith(PREFIX) ? ref : id ? `${PREFIX}${id}` : ref;
|
|
354
|
+
if (!id)
|
|
355
|
+
return { ref: shown, variable: null, present: false, source: null, state: "missing", location: null, writable: false };
|
|
356
|
+
const variable = credentialVariable(id);
|
|
357
|
+
if (this.#env[variable])
|
|
358
|
+
return { ref: shown, variable, present: true, source: "environment", state: "set", location: `environment variable ${variable}`, writable: false };
|
|
359
|
+
let entry = null;
|
|
360
|
+
try {
|
|
361
|
+
entry = this.#vault?.get(id) ?? null;
|
|
362
|
+
}
|
|
363
|
+
catch {
|
|
364
|
+
entry = null;
|
|
365
|
+
}
|
|
366
|
+
const writable = this.#vault !== null;
|
|
367
|
+
const location = this.#vault ? "local encrypted vault" : `environment variable ${variable}`;
|
|
368
|
+
if (!entry)
|
|
369
|
+
return { ref: shown, variable, present: false, source: null, state: "missing", location, writable };
|
|
370
|
+
const state = entry.state === "revoked" ? "revoked" : "set";
|
|
371
|
+
return { ref: shown, variable, present: state === "set", source: "vault", state, location, writable, version: entry.version, updatedAt: entry.updatedAt };
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/** Environment-variable custody only (no vault): what production uses without the opt-in. */
|
|
375
|
+
export class EnvironmentCredentials extends HostCredentials {
|
|
376
|
+
constructor(env = process.env, readOnlyReason) {
|
|
377
|
+
super({ env, ...(readOnlyReason ? { readOnlyReason } : {}) });
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* The custody for one environment.
|
|
382
|
+
*
|
|
383
|
+
* development, test vault in `dir` (key in dir/credentials.key)
|
|
384
|
+
* production environment variables only, unless FELTKIT_CREDENTIAL_VAULT=1 with
|
|
385
|
+
* FELTKIT_CREDENTIAL_VAULT_KEY (the vault lives in
|
|
386
|
+
* FELTKIT_CREDENTIAL_VAULT_DIR, else `dir`)
|
|
387
|
+
* other (staging…) the same rule as production
|
|
388
|
+
*/
|
|
389
|
+
export function credentialsFor(options) {
|
|
390
|
+
const env = options.env ?? process.env;
|
|
391
|
+
if (options.development)
|
|
392
|
+
return new HostCredentials({ env, vault: new CredentialVault({ dir: options.dir, scope: options.scope }) });
|
|
393
|
+
const optIn = env.FELTKIT_CREDENTIAL_VAULT === "1" || env.FELTKIT_CREDENTIAL_VAULT === "true";
|
|
394
|
+
if (!optIn) {
|
|
395
|
+
return new HostCredentials({
|
|
396
|
+
env,
|
|
397
|
+
readOnlyReason: `The ${options.environment} environment's credentials come from the host's environment variables (opt in to a vault with FELTKIT_CREDENTIAL_VAULT=1 and FELTKIT_CREDENTIAL_VAULT_KEY).`,
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
const raw = env.FELTKIT_CREDENTIAL_VAULT_KEY;
|
|
401
|
+
const key = raw ? Buffer.from(raw.trim(), /[+/=]/.test(raw) ? "base64" : "base64url") : null;
|
|
402
|
+
if (!key || key.length !== 32) {
|
|
403
|
+
throw custodyError("CUSTODY_UNAVAILABLE", "FELTKIT_CREDENTIAL_VAULT=1 needs FELTKIT_CREDENTIAL_VAULT_KEY: exactly 32 random bytes, base64-encoded, from the host's secret manager.");
|
|
30
404
|
}
|
|
405
|
+
return new HostCredentials({ env, vault: new CredentialVault({ dir: env.FELTKIT_CREDENTIAL_VAULT_DIR || options.dir, key, scope: options.scope }) });
|
|
31
406
|
}
|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vL,CAAC;IACD,OAAO,IAAI,eAAe,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,eAAe,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,4BAA4B,IAAI,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;AACvJ,CAAC"}
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
* - Otherwise the environment's Intelligence selection picks a server-side runtime by
|
|
13
13
|
* protocol: OpenAI chat completions (`openai`, `openai-compatible`, which covers
|
|
14
14
|
* local servers such as Ollama, vLLM, and llama.cpp) or Anthropic Messages.
|
|
15
|
-
* - Credentials are resolved from FeltKit's custody (FELTKIT_CREDENTIAL_<ID
|
|
16
|
-
* call and never leave the server: not in configuration views, errors, logs, or
|
|
15
|
+
* - Credentials are resolved from FeltKit's custody (FELTKIT_CREDENTIAL_<ID>, else the
|
|
16
|
+
* environment's encrypted vault; runtime/credentials.ts) inside the call and never leave the server: not in configuration views, errors, logs, or
|
|
17
17
|
* records.
|
|
18
18
|
* - Nothing falls back silently. A missing selection, missing credential, timeout,
|
|
19
19
|
* refused credential, provider error, malformed answer, or unsupported decision kind
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
import type { DecisionBatch, DecisionBatchEvaluation, DecisionRequest, DecisionResult, DecisionRuntime, DecisionRuntimeCapabilities, DecisionRuntimeMetadata } from "@feltdb/core";
|
|
27
27
|
import { FeltKitError } from "../errors.js";
|
|
28
|
+
import { type Principal } from "./authority.js";
|
|
28
29
|
import type { FeltKitRuntime } from "./runtime.js";
|
|
29
30
|
export type { DecisionRuntime, DecisionRequest, DecisionResult, DecisionRuntimeCapabilities, DecisionRuntimeMetadata } from "@feltdb/core";
|
|
30
31
|
export type ModelProblem = "not_configured" | "intelligence_disabled" | "unknown_protocol" | "credential_missing" | "timeout" | "unavailable" | "credential_refused" | "provider_error" | "malformed" | "unsupported";
|
|
@@ -82,6 +83,14 @@ export interface ModelStatus {
|
|
|
82
83
|
ref: string | null;
|
|
83
84
|
variable: string | null;
|
|
84
85
|
present: boolean;
|
|
86
|
+
/** Where the value is kept ("environment variable FELTKIT_CREDENTIAL_X", "local encrypted vault"). Never the value. */
|
|
87
|
+
location?: string | null;
|
|
88
|
+
source?: "environment" | "vault" | null;
|
|
89
|
+
state?: "set" | "missing" | "revoked";
|
|
90
|
+
version?: number;
|
|
91
|
+
updatedAt?: string;
|
|
92
|
+
/** Whether a value can be stored for it here (Studio, `feltkit credential set`). */
|
|
93
|
+
writable?: boolean;
|
|
85
94
|
};
|
|
86
95
|
runtime: {
|
|
87
96
|
metadata: DecisionRuntimeMetadata;
|
|
@@ -114,14 +123,15 @@ export declare class ModelHost {
|
|
|
114
123
|
/**
|
|
115
124
|
* Select this environment's provider and model in AppPort Services Intelligence. Host
|
|
116
125
|
* code only (the CLI, tests, development Studio): production Studio does not expose it.
|
|
117
|
-
* The credential is a reference; its value
|
|
126
|
+
* The credential is a reference; its value is kept by FeltKit's custody (an environment
|
|
127
|
+
* variable FELTKIT_CREDENTIAL_<ID>, or the environment's encrypted vault), never here.
|
|
118
128
|
*/
|
|
119
129
|
select(input: {
|
|
120
130
|
provider: string;
|
|
121
131
|
model: string;
|
|
122
132
|
endpoint?: string | null;
|
|
123
133
|
credentialRef?: string;
|
|
124
|
-
}): Promise<ModelStatus>;
|
|
134
|
+
}, as?: Principal): Promise<ModelStatus>;
|
|
125
135
|
status(): Promise<ModelStatus>;
|
|
126
136
|
/**
|
|
127
137
|
* Ask the environment's model. Supported kinds only; the answer must be one of the
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getIntelligenceProvider } from "@appport/services";
|
|
2
|
-
import { FeltKitError } from "../errors.js";
|
|
2
|
+
import { FeltKitError, isFeltKitError } from "../errors.js";
|
|
3
3
|
import { systemPrincipal } from "./authority.js";
|
|
4
|
+
import { redactSecret } from "./credentials.js";
|
|
4
5
|
const CODE = {
|
|
5
6
|
not_configured: "CONFIGURATION",
|
|
6
7
|
intelligence_disabled: "CONFIGURATION",
|
|
@@ -73,7 +74,7 @@ async function post(connection, url, headers, body) {
|
|
|
73
74
|
}
|
|
74
75
|
const text = await response.text();
|
|
75
76
|
if (response.status === 401 || response.status === 403) {
|
|
76
|
-
throw modelError("credential_refused", `${connection.provider} refused the credential (HTTP ${response.status}).`, "Nothing was decided. Replace the
|
|
77
|
+
throw modelError("credential_refused", `${connection.provider} refused the credential (HTTP ${response.status}).`, "Nothing was decided. Replace the API key (Studio → Models, `feltkit credential set`, or its FELTKIT_CREDENTIAL_<ID> variable), or check the key's access to this model.", { provider: connection.provider, status: response.status });
|
|
77
78
|
}
|
|
78
79
|
if (!response.ok) {
|
|
79
80
|
throw modelError("provider_error", `${connection.provider} answered HTTP ${response.status}: ${scrub(text, connection.credential).slice(0, 200)}`, "Nothing was decided. Check the model name and the provider's status.", { provider: connection.provider, status: response.status });
|
|
@@ -180,22 +181,27 @@ export class ModelHost {
|
|
|
180
181
|
/**
|
|
181
182
|
* Select this environment's provider and model in AppPort Services Intelligence. Host
|
|
182
183
|
* code only (the CLI, tests, development Studio): production Studio does not expose it.
|
|
183
|
-
* The credential is a reference; its value
|
|
184
|
+
* The credential is a reference; its value is kept by FeltKit's custody (an environment
|
|
185
|
+
* variable FELTKIT_CREDENTIAL_<ID>, or the environment's encrypted vault), never here.
|
|
184
186
|
*/
|
|
185
|
-
async select(input) {
|
|
187
|
+
async select(input, as) {
|
|
186
188
|
const intelligence = this.#runtime.services.intelligence;
|
|
187
189
|
if (!intelligence)
|
|
188
190
|
throw new FeltKitError("CONFIGURATION", "The Intelligence service is not enabled.", { hint: "Add services: { intelligence: true } to feltkit({ ... })." });
|
|
189
191
|
if (!getIntelligenceProvider(input.provider))
|
|
190
192
|
throw new FeltKitError("INVALID_ARGUMENT", `Unknown provider "${input.provider}".`);
|
|
191
193
|
if (input.credentialRef && !/^credential-ref:[A-Za-z0-9][A-Za-z0-9._:-]{0,199}$/.test(input.credentialRef)) {
|
|
192
|
-
|
|
194
|
+
// Never echo what was sent: it may be a key pasted into the wrong field.
|
|
195
|
+
throw new FeltKitError("INVALID_ARGUMENT", "A credential reference must look like credential-ref:<id>; what was sent is not one and was not stored. If it was an API key, enter it in the API key field (Studio → Models) or with `feltkit credential set`: it is stored in this environment's custody, never in configuration.");
|
|
193
196
|
}
|
|
194
197
|
try {
|
|
195
|
-
|
|
198
|
+
// `as`: a person selecting it (development Studio), authorized as them (intelligence.write).
|
|
199
|
+
await this.#runtime.services.asPrincipal(as ?? this.#writer, (v) => intelligence.set({ ...this.#runtime.services.scope, provider: input.provider, model: input.model, endpoint: input.endpoint ?? null, ...(input.credentialRef ? { credentialRef: input.credentialRef } : {}) }, v));
|
|
196
200
|
}
|
|
197
201
|
catch (error) {
|
|
198
|
-
|
|
202
|
+
if (isFeltKitError(error) && (error.code === "FORBIDDEN" || error.code === "UNAUTHORIZED"))
|
|
203
|
+
throw new FeltKitError(error.code, `${as?.id ?? "This principal"} may not change the model (intelligence.write).`, { hint: "Use a dev user whose role grants intelligence.* (the starter's admin role)." });
|
|
204
|
+
throw new FeltKitError("INVALID_ARGUMENT", redactSecret(error.message, input.credentialRef));
|
|
199
205
|
}
|
|
200
206
|
return this.status();
|
|
201
207
|
}
|
|
@@ -225,7 +231,18 @@ export class ModelHost {
|
|
|
225
231
|
protocol: selection.protocol,
|
|
226
232
|
model: selection.model,
|
|
227
233
|
endpoint: selection.endpoint,
|
|
228
|
-
credential: {
|
|
234
|
+
credential: {
|
|
235
|
+
required,
|
|
236
|
+
ref: selection.credentialRef ?? null,
|
|
237
|
+
variable: described?.variable ?? null,
|
|
238
|
+
present: described?.present ?? false,
|
|
239
|
+
location: described?.location ?? null,
|
|
240
|
+
source: described?.source ?? null,
|
|
241
|
+
state: described?.state ?? "missing",
|
|
242
|
+
writable: described?.writable ?? false,
|
|
243
|
+
...(described?.version !== undefined ? { version: described.version } : {}),
|
|
244
|
+
...(described?.updatedAt ? { updatedAt: described.updatedAt } : {}),
|
|
245
|
+
},
|
|
229
246
|
runtime: null,
|
|
230
247
|
problems: [],
|
|
231
248
|
};
|
|
@@ -238,10 +255,22 @@ export class ModelHost {
|
|
|
238
255
|
status.runtime = { metadata: runtime.metadata(), capabilities: runtime.capabilities() };
|
|
239
256
|
}
|
|
240
257
|
if (required && !selection.credentialRef) {
|
|
241
|
-
status.problems.push({
|
|
258
|
+
status.problems.push({
|
|
259
|
+
problem: "credential_missing",
|
|
260
|
+
message: `${selection.provider} needs an API key and none is attached.`,
|
|
261
|
+
fix: this.#runtime.credentials.writable
|
|
262
|
+
? "Enter the API key in Studio → Models and save, or run `feltkit model set --provider … --model … --api-key-stdin`."
|
|
263
|
+
: `Attach a credential reference with \`feltkit model set --credential credential-ref:${selection.provider}\` and set FELTKIT_CREDENTIAL_${selection.provider.toUpperCase().replace(/[^A-Z0-9]/g, "_")} on the host.`,
|
|
264
|
+
});
|
|
242
265
|
}
|
|
243
266
|
else if (selection.credentialRef && !described?.present) {
|
|
244
|
-
status.problems.push({
|
|
267
|
+
status.problems.push({
|
|
268
|
+
problem: "credential_missing",
|
|
269
|
+
message: described?.state === "revoked" ? `The API key for ${selection.credentialRef} was removed.` : `No API key is stored for ${selection.credentialRef}.`,
|
|
270
|
+
fix: described?.writable
|
|
271
|
+
? `Enter the API key in Studio → Models (stored in the ${described.location}), run \`feltkit credential set ${selection.credentialRef}\`, or set ${described.variable} in the environment.`
|
|
272
|
+
: `Set ${described?.variable ?? "its FELTKIT_CREDENTIAL_<ID> variable"} in this environment's process environment from your secret manager (never in code or FeltDB).`,
|
|
273
|
+
});
|
|
245
274
|
}
|
|
246
275
|
status.ready = status.problems.length === 0;
|
|
247
276
|
return status;
|