@xiaolikt/ai-vault 0.12.4 → 0.13.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/Cargo.lock +1 -1
- package/README.md +32 -0
- package/README.zh.md +11 -0
- package/crates/ai-vault/Cargo.toml +1 -1
- package/crates/ai-vault/src/cli.rs +9 -5
- package/crates/ai-vault/src/config.rs +6 -4
- package/crates/ai-vault/src/crypto.rs +3 -1
- package/crates/ai-vault/src/dialog.rs +3 -0
- package/crates/ai-vault/src/session.rs +13 -0
- package/package.json +6 -6
- package/packages/pi-ai-vault/README.md +2 -0
- package/packages/pi-ai-vault/README.zh.md +2 -0
- package/packages/pi-ai-vault/package.json +2 -2
- package/packages/pi-ai-vault/src/cli.ts +63 -12
- package/packages/pi-ai-vault/src/settings.ts +1 -1
- package/test/cli.sh +19 -0
- package/tests/bitwarden-tools.test.mjs +4 -1
- package/tests/vault-cli.test.mjs +56 -0
package/Cargo.lock
CHANGED
package/README.md
CHANGED
|
@@ -315,6 +315,15 @@ When `ai-vault` asks for its master password is a per-machine setting
|
|
|
315
315
|
| `never` | never asks. The key lives in `~/.ai-vault/agent.session.json` (0600) and **reads open no window either** | handing the agent a set of "use freely" passwords |
|
|
316
316
|
| `time` | asks again N hours after the unlock (default 8, `--hours`) | long bounded tasks |
|
|
317
317
|
| `session` | once per session; dies with it (default) | everyday |
|
|
318
|
+
| `vault.confirm` | whether each read opens a confirm window **while the session is unlocked** (default **off**). The master password that opened the session is the approval — a window the model cannot answer for you — and every read is still audited entry by entry. `on` puts a second window on every read; turning it off costs the master password, turning it back on is free | `off` for everyday; `on` to see each request before it is answered |
|
|
319
|
+
|
|
320
|
+
**Why `session` no longer means "every tab asks".** Every pi/omp process on the
|
|
321
|
+
machine shares one store-wide host secret (`~/.ai-vault/.host`, 0600), so a
|
|
322
|
+
session opened in one process is usable in the next: a second herdr tab, a
|
|
323
|
+
subagent, a `/fork` — none of them asks again while an unlocked session
|
|
324
|
+
exists. The secret is protected by exactly what protects the store and its
|
|
325
|
+
wrap key, the user's home directory; a token found on disk is still refused
|
|
326
|
+
without it.
|
|
318
327
|
|
|
319
328
|
```bash
|
|
320
329
|
ai-vault mode # show
|
|
@@ -357,6 +366,22 @@ In the extension: `/vault settings`, `/vault settings bitwarden.import always`.
|
|
|
357
366
|
writes it after a successful master-password unlock, it is cleared when the
|
|
358
367
|
policy goes back to `session`, and `/bw lock` clears it too.
|
|
359
368
|
|
|
369
|
+
### Where the settings live
|
|
370
|
+
|
|
371
|
+
Not in a file. They are inside `store.json`, sealed under the same key as the
|
|
372
|
+
passwords, so reading or changing them needs the store's key — a password, or
|
|
373
|
+
a session opened with one. There is nothing to edit on disk: flipping a byte
|
|
374
|
+
of the store is a tamper and the whole store is refused. A plaintext
|
|
375
|
+
`config.json` from an older version is brought inside at the next unlock, but
|
|
376
|
+
only its harmless keys travel; `confirm = false` and `unlock = never` are not
|
|
377
|
+
taken from a file, so an edit made while the file was still plain text grants
|
|
378
|
+
nothing.
|
|
379
|
+
|
|
380
|
+
Every change that **lowers** protection costs the master password — `unlock =
|
|
381
|
+
never`, keeping the Bitwarden or Ente key on disk, importing Bitwarden hits
|
|
382
|
+
without asking. Turning `confirm` *on* is free; it is off by default, so
|
|
383
|
+
turning it off costs nothing until you have turned it on.
|
|
384
|
+
|
|
360
385
|
## Extension commands
|
|
361
386
|
|
|
362
387
|
```
|
|
@@ -523,6 +548,13 @@ may *use* passwords but cannot *get around you* to take them.
|
|
|
523
548
|
about stopping an agent that has been injected.
|
|
524
549
|
- `notes` appear only in `get` (after approval); `list` never prints them.
|
|
525
550
|
|
|
551
|
+
- **A token is bound to who signed it, and re-signed by its own signer.** A
|
|
552
|
+
session file records whether the host's secret or the store key signed it
|
|
553
|
+
and is checked with that key only, so a token created one way is refused —
|
|
554
|
+
not deleted — when presented the other way. And a later call never re-signs
|
|
555
|
+
it under the caller's key: a human's terminal session that the pi process
|
|
556
|
+
used once stays the human's.
|
|
557
|
+
|
|
526
558
|
### Known limits
|
|
527
559
|
|
|
528
560
|
- In `session` mode the model's bash **can** read a token file, but it does it
|
package/README.zh.md
CHANGED
|
@@ -254,6 +254,9 @@ vault_get "github"
|
|
|
254
254
|
| `never` | 永远不问。密钥写在 `~/.ai-vault/agent.session.json`(0600),**读取也不再弹确认窗** | 把一批「随便用」的密码交给 agent |
|
|
255
255
|
| `time` | 解锁后 N 小时(默认 8,`--hours` 可改)再问一次 | 有边界的长任务 |
|
|
256
256
|
| `session` | 每个会话问一次,会话结束就失效(默认) | 日常 |
|
|
257
|
+
| `vault.confirm` | 会话解锁期间,每次读取是否**再弹一次确认窗**(默认**关**)。打开会话的主密码就是授权——那个窗口模型替你答不了——每次读取仍逐条写审计。`on` 是每次读取都再弹一次;关要主密码,开回去免费 | 日常用 `off`;想每个请求在被回答前看一眼就 `on` |
|
|
258
|
+
|
|
259
|
+
**为什么 `session` 不再是「每个 tab 都要问」。** 机器上所有 pi/omp 进程共用一个库级 host secret(`~/.ai-vault/.host`,0600),所以一个进程开的会话在下一个进程里直接可用:第二个 herdr tab、子代理、`/fork`——只要还有解锁着的会话,谁都不会再要密码。这个 secret 和库、和 wrap key 受同一种保护(你的 home 目录);磁盘上捡到的令牌没有它照样被拒。
|
|
257
260
|
|
|
258
261
|
```bash
|
|
259
262
|
ai-vault mode # 看当前模式
|
|
@@ -288,6 +291,12 @@ ai-vault settings bitwarden.hours 24
|
|
|
288
291
|
|
|
289
292
|
`bw-session put/get/clear` 就是那个落盘密钥的读写口:插件在主密码解锁成功后写入,切回 `session` 模式时自动清掉,`/bw lock` 也会清掉。
|
|
290
293
|
|
|
294
|
+
### 设置存在哪里
|
|
295
|
+
|
|
296
|
+
不在文件里。设置在 `store.json` 里面,和密码用同一把 key 封在一起,所以读写设置都需要库的 key——主密码,或一个用它打开的会话。磁盘上没有东西可改:动 `store.json` 一个字节就是篡改,整个库会被拒。旧版留下的明文 `config.json` 会在下次解锁时带进去,但只带无害的键;`confirm = false` 和 `unlock = never` 不会从文件里来,所以趁文件还是明文时做的改动什么都换不到。
|
|
297
|
+
|
|
298
|
+
所有**降低**保护的改动都要主密码——`unlock = never`、把 Bitwarden / Ente 的密钥落盘、不询问就导入 Bitwarden 条目。把 `confirm` **打开**是免费的;它默认是关的,所以不动它就不花钱。
|
|
299
|
+
|
|
291
300
|
## 插件里的命令
|
|
292
301
|
|
|
293
302
|
```
|
|
@@ -393,6 +402,8 @@ pi-ai-vault 只是这套 CLI 的客户端,本身不保存 Ente 的任何密钥
|
|
|
393
402
|
- `bw_reveal` 默认关闭;擦洗只在值长度 ≥ 6 时生效,防不住网络外传和单向哈希——`bw_run` / `bw_inject` 的价值是值不进对话,不是防住被注入的 agent。
|
|
394
403
|
- `notes` 只在 `get`(授权之后)里出现,`list` 不输出它。
|
|
395
404
|
|
|
405
|
+
- **令牌绑定签名者,重签也只用原来的签名者。** 会话文件记着它是用宿主 secret 还是库 key 签的,只用那把 key 校验;换一种方式出示的令牌会被拒绝,但不会被删掉。之后的调用也绝不会用调用方的 key 重签它:一个人在终端开的会话被 pi 进程用过一次,仍然是那个人的。
|
|
406
|
+
|
|
396
407
|
### 已知边界
|
|
397
408
|
|
|
398
409
|
- `session` 模式下,模型的 bash **能**读到令牌文件,但拿到也没用:插件开的会话用宿主内存里的 secret 签名,bash 没有 secret,第一次用就会被判「文件被改」而作废(连 `list` 都做不了,还会把那个文件删掉)。只有**你在终端手敲** `ai-vault unlock` 开出来的会话(用 wrap key 签名)才能被同用户进程 `list`——那种会话本来就没有窗口可以绕,这是「同一用户」的固有暴露面。真正收紧要靠不同的用户或容器。
|
|
@@ -605,11 +605,15 @@ fn persist(paths: &Paths, session: &Session) {
|
|
|
605
605
|
let _ = if auto {
|
|
606
606
|
session::save_auto(paths, session)
|
|
607
607
|
} else {
|
|
608
|
-
//
|
|
609
|
-
//
|
|
610
|
-
match
|
|
611
|
-
Ok(
|
|
612
|
-
Err(e) =>
|
|
608
|
+
// Write it back under the key it was signed with, never the caller's
|
|
609
|
+
// own: the caller got here only by holding that key, so it has it.
|
|
610
|
+
let (host, wrap) = match signing_keys(paths) {
|
|
611
|
+
Ok(keys) => keys,
|
|
612
|
+
Err(e) => return drop(e),
|
|
613
|
+
};
|
|
614
|
+
match session.resigner(host, wrap) {
|
|
615
|
+
Some(signer) => session.save(paths, &signer),
|
|
616
|
+
None => Ok(()), // an unsigned file is not ours to re-sign; leave it
|
|
613
617
|
}
|
|
614
618
|
};
|
|
615
619
|
}
|
|
@@ -79,14 +79,16 @@ pub struct UnlockPolicy {
|
|
|
79
79
|
#[serde(default = "default_hours")]
|
|
80
80
|
pub hours: i64,
|
|
81
81
|
/// Whether each read of an entry opens a confirm window while the session
|
|
82
|
-
/// is unlocked.
|
|
83
|
-
/// is
|
|
82
|
+
/// is unlocked. Off by default: the master password that opened the
|
|
83
|
+
/// session is the approval (a window the model cannot answer for you),
|
|
84
|
+
/// and every read is still audited entry by entry. On means the second
|
|
85
|
+
/// window on every read, for someone who wants to see each request.
|
|
84
86
|
#[serde(default = "default_confirm")]
|
|
85
87
|
pub confirm: bool,
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
fn default_confirm() -> bool {
|
|
89
|
-
|
|
91
|
+
false
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
fn default_hours() -> i64 {
|
|
@@ -211,7 +213,7 @@ mod tests {
|
|
|
211
213
|
// A config written by the previous version had only `unlock`.
|
|
212
214
|
let parsed: Config = serde_json::from_str(r#"{"unlock":{"mode":"time","hours":4}}"#).unwrap();
|
|
213
215
|
assert_eq!(parsed.unlock.mode, UnlockMode::Time);
|
|
214
|
-
|
|
216
|
+
assert!(!parsed.unlock.confirm, "a config from before the switch reads as off: the unlock is the approval");
|
|
215
217
|
assert_eq!(parsed.bitwarden.import, ImportPolicy::Ask);
|
|
216
218
|
assert_eq!(parsed.bitwarden.store.hours, 8);
|
|
217
219
|
}
|
|
@@ -312,7 +312,9 @@ mod tests {
|
|
|
312
312
|
let v1 = StoreFile { v: 1, salt: salt.iter().map(|b| format!("{b:02x}")).collect(), kdf: Some(kdf), ct: base64::engine::general_purpose::STANDARD.encode(blob) };
|
|
313
313
|
let (payload, _) = open_with_passphrase(&v1, "pw").unwrap();
|
|
314
314
|
assert_eq!(payload.items[0].name, "GitHub");
|
|
315
|
-
|
|
315
|
+
// A store from before the switch carries no `confirm`; it reads as the
|
|
316
|
+
// default, which is off: the unlock is the approval.
|
|
317
|
+
assert!(!payload.config.unlock.confirm);
|
|
316
318
|
}
|
|
317
319
|
|
|
318
320
|
#[test]
|
|
@@ -593,6 +593,9 @@ pub fn for_dialog(value: &str, max: usize) -> String {
|
|
|
593
593
|
/// A password. `revealable` puts a link in the window that shows what was typed:
|
|
594
594
|
/// right for a master password (a typo is expensive), not for an entry's own
|
|
595
595
|
/// password (it is read back with `vault_get` anyway).
|
|
596
|
+
/// `revealable` is read on Windows only (the "show what was typed" link);
|
|
597
|
+
/// zenity and osascript have no such link, so the parameter is unused there.
|
|
598
|
+
#[cfg_attr(not(target_os = "windows"), allow(unused_variables))]
|
|
596
599
|
pub fn prompt_secret(title: &str, label: &str, revealable: bool) -> Answer<String> {
|
|
597
600
|
#[cfg(target_os = "macos")]
|
|
598
601
|
{
|
|
@@ -120,6 +120,19 @@ impl Session {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
/// The signer this session was signed with, for writing it back unchanged.
|
|
124
|
+
/// A session is signed by whoever opened it; a later call made with the
|
|
125
|
+
/// other kind of key must not re-sign it under its own, or the opener
|
|
126
|
+
/// loses their own session (a human token used once by the pi process
|
|
127
|
+
/// became unusable at the terminal).
|
|
128
|
+
pub fn resigner(&self, host_secret: Option<String>, wrap_key: Option<String>) -> Option<Signer> {
|
|
129
|
+
match self.signed_by.as_deref() {
|
|
130
|
+
Some("host") => host_secret.map(Signer::Host),
|
|
131
|
+
Some("wrap") => wrap_key.map(Signer::Wrap),
|
|
132
|
+
_ => None,
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
123
136
|
/// (Re)sign this session and record who signed it. Called before every save.
|
|
124
137
|
pub fn sign(&mut self, signer: &Signer) {
|
|
125
138
|
self.signed_by = Some(signer.label().to_string());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xiaolikt/ai-vault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "One machine-wide encrypted secret store for AI coding agents: the ai-vault Rust CLI (npm-installable, Linux/macOS/Windows) plus the pi-ai-vault extension for pi and omp.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"optionalDependencies": {
|
|
36
|
-
"@xiaolikt/ai-vault-linux-x64": "0.
|
|
37
|
-
"@xiaolikt/ai-vault-linux-arm64": "0.
|
|
38
|
-
"@xiaolikt/ai-vault-win32-x64": "0.
|
|
39
|
-
"@xiaolikt/ai-vault-darwin-arm64": "0.
|
|
40
|
-
"@xiaolikt/ai-vault-darwin-x64": "0.
|
|
36
|
+
"@xiaolikt/ai-vault-linux-x64": "0.13.0",
|
|
37
|
+
"@xiaolikt/ai-vault-linux-arm64": "0.13.0",
|
|
38
|
+
"@xiaolikt/ai-vault-win32-x64": "0.13.0",
|
|
39
|
+
"@xiaolikt/ai-vault-darwin-arm64": "0.13.0",
|
|
40
|
+
"@xiaolikt/ai-vault-darwin-x64": "0.13.0"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"bin",
|
|
@@ -57,6 +57,8 @@ When the local store asks for its master password is a per-machine setting (`/va
|
|
|
57
57
|
| Mode | Behaviour |
|
|
58
58
|
|---|---|
|
|
59
59
|
| `never` | never asks, and reads open no window — the "the agent may use these freely" passwords |
|
|
60
|
+
|
|
61
|
+
By default (`session`) a read opens no window either: the master password that unlocked the session is the approval, and every read is audited. `/vault confirm on` puts a window on every read.
|
|
60
62
|
| `time` | asks again N hours after the unlock (default 8) |
|
|
61
63
|
| `session` | once per session, dies with it (default) |
|
|
62
64
|
|
|
@@ -52,6 +52,8 @@ omp plugin install npm:pi-ai-vault # omp,同一个包
|
|
|
52
52
|
| 模式 | 行为 |
|
|
53
53
|
|---|---|
|
|
54
54
|
| `never` | 永远不问,读取也不弹确认窗——「agent 可以自由使用」的那批密码 |
|
|
55
|
+
|
|
56
|
+
默认(`session`)读取同样不弹窗:解锁会话的主密码就是授权,每次读取仍记审计。`/vault confirm on` 让每次读取都弹窗。
|
|
55
57
|
| `time` | 解锁后 N 小时(默认 8)再问一次 |
|
|
56
58
|
| `session` | 每个会话一次,会话结束失效(默认) |
|
|
57
59
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-ai-vault",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "pi extension for ai-vault: one machine-wide encrypted secret store, live Bitwarden and Ente Auth. Works in pi and in omp (the omp fork reads the same manifest).",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"security"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@xiaolikt/ai-vault": "0.
|
|
28
|
+
"@xiaolikt/ai-vault": "0.13.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@earendil-works/pi-coding-agent": "^1.5.0",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { createHmac, randomBytes } from "node:crypto";
|
|
11
11
|
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
12
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
12
|
+
import { chmodSync, existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
13
|
import { createRequire } from "node:module";
|
|
14
14
|
import { homedir } from "node:os";
|
|
15
15
|
import { delimiter, dirname, extname, join } from "node:path";
|
|
@@ -216,14 +216,31 @@ function message(stderr: string, fallback: string): string {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
|
-
* The secret
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
219
|
+
* The secret every pi/omp process on this machine shares for the sessions
|
|
220
|
+
* it unlocked. It lives in `<store>/.host` (0600), next to the store and its
|
|
221
|
+
* `.wrap` key, so it is protected by exactly what protects them: the user's
|
|
222
|
+
* home directory.
|
|
223
|
+
*
|
|
224
|
+
* It used to be minted per process, which meant every herdr tab, every
|
|
225
|
+
* subagent and every `/new` had its own secret and could not read a session
|
|
226
|
+
* another one had opened — so each of them asked for the master password
|
|
227
|
+
* again. One secret per store fixes that: a session opened in one tab is
|
|
228
|
+
* usable in the next.
|
|
229
|
+
*
|
|
230
|
+
* What this does not change: a session file is still signed with this secret,
|
|
231
|
+
* so the model's bash still cannot use a token it finds on disk *unless* it
|
|
232
|
+
* also reads `.host`. That is the same exposure as `.wrap` — the "same user"
|
|
233
|
+
* line the README already draws — and the per-read confirm window is the
|
|
234
|
+
* control on top of it, unchanged.
|
|
224
235
|
*/
|
|
225
236
|
export class HostSecret {
|
|
226
237
|
#value: string | undefined;
|
|
238
|
+
#file: string | undefined;
|
|
239
|
+
|
|
240
|
+
/** Point the secret at a store directory: the first `value` reads or creates it there. */
|
|
241
|
+
attach(storeDir: string): void {
|
|
242
|
+
this.#file = join(storeDir, ".host");
|
|
243
|
+
}
|
|
227
244
|
|
|
228
245
|
get present(): boolean {
|
|
229
246
|
return this.#value !== undefined;
|
|
@@ -234,15 +251,19 @@ export class HostSecret {
|
|
|
234
251
|
if (secret && secret.length >= 32) this.#value = secret;
|
|
235
252
|
}
|
|
236
253
|
|
|
237
|
-
/** 32 fresh bytes, hex —
|
|
254
|
+
/** 32 fresh bytes, hex — a new secret for this store; every live session is voided. */
|
|
238
255
|
rotate(): string {
|
|
239
|
-
|
|
240
|
-
|
|
256
|
+
const fresh = randomBytes(32).toString("hex");
|
|
257
|
+
this.#value = fresh;
|
|
258
|
+
if (this.#file) this.#persist(fresh);
|
|
259
|
+
return fresh;
|
|
241
260
|
}
|
|
242
261
|
|
|
243
|
-
/** The secret,
|
|
262
|
+
/** The secret: the store's, read or created on first use. */
|
|
244
263
|
get value(): string {
|
|
245
|
-
|
|
264
|
+
if (this.#value) return this.#value;
|
|
265
|
+
this.#value = this.#read() ?? this.rotate();
|
|
266
|
+
return this.#value;
|
|
246
267
|
}
|
|
247
268
|
|
|
248
269
|
/** Environment for a CLI child: marks us as the host and passes the secret. */
|
|
@@ -257,15 +278,45 @@ export class HostSecret {
|
|
|
257
278
|
.update(`allow:${token}:${entry.toLowerCase()}:${answer ? "y" : "n"}`)
|
|
258
279
|
.digest("hex");
|
|
259
280
|
}
|
|
281
|
+
|
|
282
|
+
#read(): string | undefined {
|
|
283
|
+
if (!this.#file) return undefined;
|
|
284
|
+
try {
|
|
285
|
+
const text = readFileSync(this.#file, "utf8").trim();
|
|
286
|
+
if (/^[0-9a-f]{64}$/.test(text)) return text;
|
|
287
|
+
} catch {
|
|
288
|
+
/* not there yet */
|
|
289
|
+
}
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
#persist(secret: string): void {
|
|
294
|
+
if (!this.#file) return;
|
|
295
|
+
try {
|
|
296
|
+
writeFileSync(this.#file, `${secret}\n`, { mode: 0o600 });
|
|
297
|
+
chmodSync(this.#file, 0o600);
|
|
298
|
+
} catch {
|
|
299
|
+
/* a read-only store directory: the secret stays in memory for this process */
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** The store directory, by the CLI's own rule: `AI_VAULT_DIR`, else `~/.ai-vault`. */
|
|
305
|
+
export function storeDir(): string {
|
|
306
|
+
return process.env.AI_VAULT_DIR || join(homedir(), ".ai-vault");
|
|
260
307
|
}
|
|
261
308
|
|
|
262
309
|
export class VaultCli {
|
|
263
310
|
private readonly launch = resolveLaunch();
|
|
264
311
|
/** The program that gets started: `AI_VAULT_BIN` when that was set. */
|
|
265
312
|
readonly bin = this.launch?.program;
|
|
266
|
-
/**
|
|
313
|
+
/** One per store, shared by every process that uses it: `<store>/.host`. */
|
|
267
314
|
host = new HostSecret();
|
|
268
315
|
|
|
316
|
+
constructor() {
|
|
317
|
+
this.host.attach(storeDir());
|
|
318
|
+
}
|
|
319
|
+
|
|
269
320
|
get available(): boolean {
|
|
270
321
|
return this.bin !== undefined;
|
|
271
322
|
}
|
|
@@ -24,7 +24,7 @@ export interface Settings {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export const DEFAULT_SETTINGS: Settings = {
|
|
27
|
-
vault: { unlock: "session", hours: 8, confirm:
|
|
27
|
+
vault: { unlock: "session", hours: 8, confirm: false, auto: false },
|
|
28
28
|
bitwarden: { unlock: "session", hours: 8, import: "ask", persisted: false, expiresAt: null },
|
|
29
29
|
ente: { unlock: "session", hours: 8, persisted: false, expiresAt: null },
|
|
30
30
|
};
|
package/test/cli.sh
CHANGED
|
@@ -79,6 +79,10 @@ setting() {
|
|
|
79
79
|
}
|
|
80
80
|
# The value of one setting, as `settings KEY` prints it.
|
|
81
81
|
setting_value() { python3 -c "import json,sys;print(json.load(open(sys.argv[1]))['value'])" "$1"; }
|
|
82
|
+
# The per-read window is off by default (the unlock is the approval). Everything
|
|
83
|
+
# below about the relay, the denial and the grant is about that window, so it is
|
|
84
|
+
# turned on for this store first, the way a user would.
|
|
85
|
+
setting vault.confirm true >/dev/null
|
|
82
86
|
# relay <entry> <y|n>: a signed approval for the host's token.
|
|
83
87
|
relay() {
|
|
84
88
|
local ap
|
|
@@ -90,6 +94,21 @@ SESS="$XDG_RUNTIME_DIR/ai-vault/sessions/$TOKEN.json"
|
|
|
90
94
|
[[ -f "$SESS" ]] && ok "the token file lives under XDG_RUNTIME_DIR" || bad "token file missing"
|
|
91
95
|
[[ "$(stat -c %a "$SESS")" == "600" ]] && ok "the token file is 0600" || bad "the token file is not 0600"
|
|
92
96
|
|
|
97
|
+
echo "== the default: a read after unlock opens no window =="
|
|
98
|
+
export AI_VAULT_DIR="$TMP/store-default"
|
|
99
|
+
printf 'correct horse' | "$BIN" init --password-stdin --json >/dev/null
|
|
100
|
+
TD=$(printf 'correct horse' | env -u AI_VAULT_HOST -u AI_VAULT_HOST_SECRET "$BIN" unlock --password-stdin --json | json token)
|
|
101
|
+
printf 'D3FAULT\n' | "$BIN" add --name Quiet --username u --password-stdin --yes --token "$TD" >/dev/null
|
|
102
|
+
unset DISPLAY WAYLAND_DISPLAY
|
|
103
|
+
"$BIN" get Quiet --token "$TD" --json >"$TMP/quiet" 2>"$TMP/quieterr"
|
|
104
|
+
[[ $? -eq 0 ]] && ok "a bare read succeeds with no window and no relay" || bad "the default read needed a window: $(head -1 "$TMP/quieterr")"
|
|
105
|
+
grep -q '"via": *"unlocked-no-confirm"' "$TMP/quiet" && ok "and is labelled unlocked-no-confirm" || bad "via is wrong"
|
|
106
|
+
grep -q '"reason": *"confirm-off"' "$AI_VAULT_DIR/audit.log" && ok "the read is audited as confirm-off" || bad "not audited"
|
|
107
|
+
setting_default() { printf 'correct horse\n' | env -u AI_VAULT_HOST -u AI_VAULT_HOST_SECRET "$BIN" settings "$@" --password-stdin --token "$TD" --json; }
|
|
108
|
+
setting_default vault.confirm >"$TMP/cf"
|
|
109
|
+
[[ "$(python3 -c 'import json,sys;print(json.load(open(sys.argv[1]))["value"])' "$TMP/cf")" == "false" ]] && ok "a fresh store reads vault.confirm as false" || bad "default is not false: $(head -c 160 "$TMP/cf")"
|
|
110
|
+
export AI_VAULT_DIR="$TMP/store"
|
|
111
|
+
|
|
93
112
|
echo "== add / list =="
|
|
94
113
|
check "add needs a window for the password" 3 bash -c "'$BIN' add --name GitHub --username octo --token '$TOKEN'"
|
|
95
114
|
check "add with a typed password" 0 bash -c "printf 'p1ssw0rd' | '$BIN' add --name GitHub --username octo --uri https://github.com --password-stdin --yes --token '$TOKEN' --json"
|
|
@@ -238,7 +238,10 @@ test("a session switch while the master password is being typed discards the unl
|
|
|
238
238
|
() => "resolved",
|
|
239
239
|
(error) => error.message,
|
|
240
240
|
);
|
|
241
|
-
|
|
241
|
+
// Wait for the dialog to open, with a real deadline: a fixed number of
|
|
242
|
+
// setImmediate ticks raced under a full test run.
|
|
243
|
+
const deadline = Date.now() + 10_000;
|
|
244
|
+
while (!answer && Date.now() < deadline) await new Promise((resolve) => setTimeout(resolve, 5));
|
|
242
245
|
assert.equal(typeof answer, "function", "the password dialog opened");
|
|
243
246
|
|
|
244
247
|
await b.fire("session_switch", { reason: "new" }, ctx.ctx);
|
package/tests/vault-cli.test.mjs
CHANGED
|
@@ -22,6 +22,11 @@ before(async () => {
|
|
|
22
22
|
answers.master(dir, PW, PW);
|
|
23
23
|
await boot.cmd("init", makeCtx().ctx);
|
|
24
24
|
assert.ok(existsSync(STORE), "init created the shared store");
|
|
25
|
+
// The per-read window is off by default (the unlock is the approval). These
|
|
26
|
+
// tests are about the window itself: grant, denial, the signed relay — so
|
|
27
|
+
// it is turned on for this store, the way a user would.
|
|
28
|
+
const on = setSetting("vault.confirm", "true");
|
|
29
|
+
assert.equal(on.status, 0, on.stderr);
|
|
25
30
|
});
|
|
26
31
|
|
|
27
32
|
after(() => answers.deny(dir, false));
|
|
@@ -371,3 +376,54 @@ test("vault_get falls back to Bitwarden for a non-login hit and imports it with
|
|
|
371
376
|
assert.equal(JSON.stringify(listed).includes("4111111111111111"), false, "list must mask the card number");
|
|
372
377
|
});
|
|
373
378
|
|
|
379
|
+
|
|
380
|
+
test("two processes on one machine share the host secret: a session opened in one is usable in the other", async () => {
|
|
381
|
+
// Each `bind()` is a fresh extension; each VaultCli is a fresh process as far
|
|
382
|
+
// as the secret goes. Before, each minted its own and the second could not
|
|
383
|
+
// read what the first had opened — so every herdr tab asked again.
|
|
384
|
+
const { VaultCli } = await import("../packages/pi-ai-vault/src/cli.ts");
|
|
385
|
+
const { mkdtempSync, readFileSync, statSync } = await import("node:fs");
|
|
386
|
+
const { join } = await import("node:path");
|
|
387
|
+
const previous = process.env.AI_VAULT_DIR;
|
|
388
|
+
const store = mkdtempSync(join(process.env.TMPDIR ?? "/tmp", "ai-vault-shared-"));
|
|
389
|
+
process.env.AI_VAULT_DIR = store;
|
|
390
|
+
try {
|
|
391
|
+
const a = new VaultCli();
|
|
392
|
+
const b = new VaultCli();
|
|
393
|
+
assert.notEqual(a.host.value, undefined);
|
|
394
|
+
assert.equal(a.host.value, b.host.value, "both read the same <store>/.host");
|
|
395
|
+
const secret = readFileSync(join(store, ".host"), "utf8").trim();
|
|
396
|
+
assert.equal(secret, a.host.value);
|
|
397
|
+
assert.equal(statSync(join(store, ".host")).mode & 0o777, 0o600);
|
|
398
|
+
|
|
399
|
+
// A session minted under a's secret is accepted by a call made under b's.
|
|
400
|
+
const init = await a.json(["init", "--requester", "tab-a", "--password-stdin"], { stdin: `${PW}\n` });
|
|
401
|
+
const status = await b.json(["status", "--token", init.token]);
|
|
402
|
+
assert.equal(status.unlocked, true);
|
|
403
|
+
assert.equal(status.requester, "tab-a");
|
|
404
|
+
} finally {
|
|
405
|
+
if (previous === undefined) delete process.env.AI_VAULT_DIR;
|
|
406
|
+
else process.env.AI_VAULT_DIR = previous;
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
test("by default a read after unlock opens no window: the unlock is the approval (and it is audited)", async () => {
|
|
411
|
+
// Through the raw CLI on a fresh store, so the default is the CLI's and not
|
|
412
|
+
// whatever this file's other tests set on the shared one.
|
|
413
|
+
const { mkdtempSync, readFileSync } = await import("node:fs");
|
|
414
|
+
const { join } = await import("node:path");
|
|
415
|
+
const { spawnSync } = await import("node:child_process");
|
|
416
|
+
const bin = process.env.AI_VAULT_BIN;
|
|
417
|
+
const dir = mkdtempSync(join(process.env.TMPDIR ?? "/tmp", "ai-vault-default-"));
|
|
418
|
+
const run = (args, input) => spawnSync(bin, args, { input, env: { ...process.env, AI_VAULT_DIR: dir, AI_VAULT_HOST: "", AI_VAULT_HOST_SECRET: "" }, encoding: "utf8" });
|
|
419
|
+
assert.equal(run(["init", "--password-stdin"], `${PW}\n`).status, 0);
|
|
420
|
+
const token = JSON.parse(run(["unlock", "--password-stdin", "--json"], `${PW}\n`).stdout).token;
|
|
421
|
+
assert.equal(run(["add", "--name", "DefaultRead", "--username", "u", "--password-stdin", "--yes", "--token", token], "default-pw\n").status, 0);
|
|
422
|
+
// No --answer-stdin, no approval: the bare read must succeed with no window.
|
|
423
|
+
const read = run(["get", "DefaultRead", "--token", token, "--json"]);
|
|
424
|
+
assert.equal(read.status, 0, read.stderr);
|
|
425
|
+
assert.equal(JSON.parse(read.stdout).via, "unlocked-no-confirm");
|
|
426
|
+
const audit = readFileSync(join(dir, "audit.log"), "utf8");
|
|
427
|
+
assert.match(audit, /"event":"read_allow","item":"DefaultRead"/, "the read is still audited");
|
|
428
|
+
assert.match(audit, /"reason":"confirm-off"/, "and says the window was off");
|
|
429
|
+
});
|