getmyenv 0.12.0 → 0.12.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/README.md CHANGED
@@ -49,7 +49,7 @@ my-app/
49
49
  ```
50
50
 
51
51
  <!-- cli:help -->
52
- Output of `npx getmyenv --help` (0.12.0):
52
+ Output of `npx getmyenv --help` (0.12.2):
53
53
 
54
54
  ```text
55
55
  Usage: getmyenv [options] [command]
@@ -111,7 +111,7 @@ One Vault password per account unlocks your private key on your device. Each con
111
111
 
112
112
  ## CI and servers
113
113
 
114
- Create a server token for one context on the dashboard CLI page. It holds that context's key.
114
+ Create a server token for one context in Project settings, Tokens. It holds that context's key.
115
115
 
116
116
  ```bash
117
117
  export GETMYENV_TOKEN=... # server token from the dashboard
@@ -120,7 +120,7 @@ npx getmyenv run -- node server.js
120
120
 
121
121
  Server tokens are read-only. `set` needs the folder token from browser sign-in, or a guest project. `printf %s "$VALUE" | npx getmyenv set API_KEY --stdin` keeps the value out of argv.
122
122
 
123
- - `GETMYENV_TOKEN`: a token from the dashboard CLI page.
123
+ - `GETMYENV_TOKEN`: a server token from Project settings, Tokens.
124
124
  - `GETMYENV_CONFIG_DIR`: machine key and cache (default `~/.config/getmyenv`). Use a persistent volume in containers.
125
125
  - `GETMYENV_API_URL`: API origin. https only, http for localhost.
126
126
  - `GETMYENV_MACHINE_LABEL`: the machine name shown in approval requests.
@@ -2,8 +2,8 @@ import { createHash } from "node:crypto";
2
2
  import { VAULT_UNLOCK_MS } from "@getmyenv/shared";
3
3
  /**
4
4
  * Unlocked open context keys, remembered in the OS keychain (macOS Keychain,
5
- * Windows Credential Manager, Linux Secret Service) for a few hours so `run`
6
- * on an open context does not ask for the Vault password every time.
5
+ * Windows Credential Manager, Linux Secret Service) for a few hours so `run`,
6
+ * `set` and `import` on an open context do not ask for the Vault password every time.
7
7
  * Never the Vault password or the private key.
8
8
  */
9
9
  const SERVICE = "getmyenv";
package/dist/lib/vault.js CHANGED
@@ -20,12 +20,32 @@ export function fetchVault(linked) {
20
20
  export async function writeKey(linked, target) {
21
21
  if (!versions.has(target.id))
22
22
  memo.delete(target.id);
23
+ const cached = await cachedWriteKey(linked, target);
24
+ if (cached)
25
+ return cached;
23
26
  const key = await contextKey(linked, { ...target, sealedKey: undefined }, { create: true });
24
27
  const keyVersion = versions.get(target.id);
25
28
  if (keyVersion === undefined)
26
29
  throw new Error(`No key version for ${target.slug}. Run the command again.`);
27
30
  return { key, keyVersion };
28
31
  }
32
+ /** An open context key from the keychain, with the version from a fresh vault response. No password. */
33
+ async function cachedWriteKey(linked, target) {
34
+ if (memo.has(target.id) || linked.who.token.kind === "server" || target.protection !== "open")
35
+ return null;
36
+ const account = keychainFor(linked);
37
+ if (!account)
38
+ return null;
39
+ const ctx = (await fetchVault(linked)).contexts.find((c) => c.id === target.id);
40
+ if (!ctx || ctx.protection !== "open" || !ctx.hasKey || !ctx.sealedKey)
41
+ return null;
42
+ const key = await readCachedContextKey(account, ctx.id, JSON.stringify(ctx.sealedKey));
43
+ if (!key)
44
+ return null;
45
+ memo.set(ctx.id, key);
46
+ versions.set(ctx.id, ctx.keyVersion);
47
+ return { key, keyVersion: ctx.keyVersion };
48
+ }
29
49
  /** The context key, unlocking with the Vault password when needed. */
30
50
  export async function contextKey(linked, target, opts = {}) {
31
51
  const cached = memo.get(target.id);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "getmyenv",
3
- "version": "0.12.0",
3
+ "version": "0.12.2",
4
4
  "description": "CLI for getmyenv, an encrypted store for environment variables and secrets. We store ciphertext only.",
5
5
  "type": "module",
6
6
  "bin": {