passport-bridge 0.16.0 → 0.16.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 +15 -13
- package/dist/bridgeExchange.d.ts +11 -1
- package/dist/bridgeExchange.js +12 -1
- package/dist/cliArgs.js +1 -0
- package/dist/cliAutopilot.d.ts +2 -0
- package/dist/cliAutopilot.js +4 -0
- package/dist/cliClient.js +2 -1
- package/dist/cliExec.js +2 -1
- package/dist/cliInit.d.ts +12 -1
- package/dist/cliInit.js +43 -10
- package/dist/cliKeys.js +15 -4
- package/dist/cliLoosening.d.ts +34 -0
- package/dist/cliLoosening.js +107 -0
- package/dist/cliOutput.d.ts +10 -1
- package/dist/cliOutput.js +60 -3
- package/dist/cliSupport.d.ts +9 -0
- package/dist/cliSupport.js +25 -0
- package/dist/completion.js +1 -1
- package/dist/initKeysStep.js +17 -2
- package/dist/initUi.d.ts +43 -2
- package/dist/initUi.js +174 -32
- package/dist/keysKeychain.d.ts +14 -0
- package/dist/keysKeychain.js +52 -0
- package/dist/keysLocal.d.ts +37 -2
- package/dist/keysLocal.js +117 -82
- package/dist/keysLocalEdit.d.ts +13 -0
- package/dist/keysLocalEdit.js +153 -0
- package/dist/passport.js +4 -7
- package/dist/pluginPin.d.ts +1 -1
- package/dist/pluginPin.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/keysLocal.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type ExecVendor } from "./execVendors.js";
|
|
2
|
+
import { type Keychain } from "./keysKeychain.js";
|
|
3
|
+
export { withoutAwsProfileKeys, withoutJsonFields, withoutTomlKeys } from "./keysLocalEdit.js";
|
|
2
4
|
export type LocalSecret = {
|
|
3
5
|
token: string;
|
|
4
6
|
} | {
|
|
@@ -10,6 +12,25 @@ export type Removal = {
|
|
|
10
12
|
kind: "logout";
|
|
11
13
|
command: string;
|
|
12
14
|
args: string[];
|
|
15
|
+
}
|
|
16
|
+
/** Delete these fields of the object at `object` (a path of keys) in a JSON file. */
|
|
17
|
+
| {
|
|
18
|
+
kind: "json-fields";
|
|
19
|
+
path: string;
|
|
20
|
+
object: string[];
|
|
21
|
+
fields: string[];
|
|
22
|
+
}
|
|
23
|
+
/** Delete these keys of one table (`[]` is the root) in a TOML file. */
|
|
24
|
+
| {
|
|
25
|
+
kind: "toml-keys";
|
|
26
|
+
path: string;
|
|
27
|
+
table: string[];
|
|
28
|
+
keys: string[];
|
|
29
|
+
}
|
|
30
|
+
/** A file that holds only the credential. */
|
|
31
|
+
| {
|
|
32
|
+
kind: "credential-file";
|
|
33
|
+
path: string;
|
|
13
34
|
} | {
|
|
14
35
|
kind: "settings-env";
|
|
15
36
|
path: string;
|
|
@@ -19,6 +40,12 @@ export type Removal = {
|
|
|
19
40
|
path: string;
|
|
20
41
|
profile: string;
|
|
21
42
|
};
|
|
43
|
+
/** Railway's sign-in fields on `user` (railwayapp/cli `RailwayUser`); `id` and everything else stay. */
|
|
44
|
+
export declare const RAILWAY_CREDENTIAL_FIELDS: string[];
|
|
45
|
+
/** Wrangler's sign-in keys in `config/default.toml` (workers-auth `readStoredAuthState`). */
|
|
46
|
+
export declare const WRANGLER_CREDENTIAL_KEYS: string[];
|
|
47
|
+
/** One Stripe profile's API keys (stripe-cli `profile.go`); account, device, color, and other profiles stay. */
|
|
48
|
+
export declare const STRIPE_CREDENTIAL_KEYS: string[];
|
|
22
49
|
export type LocalKey = {
|
|
23
50
|
vendor: ExecVendor;
|
|
24
51
|
kind: string;
|
|
@@ -32,21 +59,29 @@ export type LocalKey = {
|
|
|
32
59
|
removal?: Removal;
|
|
33
60
|
/** What the sign-out does, in the confirmation question. */
|
|
34
61
|
removalWords: string;
|
|
62
|
+
/** Keychain copies the CLI keeps beside the file, removed with it. */
|
|
63
|
+
keychain?: Keychain;
|
|
35
64
|
};
|
|
36
65
|
export type LocalContext = {
|
|
37
66
|
env: NodeJS.ProcessEnv;
|
|
38
67
|
home?: string;
|
|
39
68
|
platform?: NodeJS.Platform;
|
|
40
69
|
};
|
|
70
|
+
/** The host-level (active) `oauth_token` and `user` of one host in gh's hosts.yml. */
|
|
71
|
+
export declare function ghActiveAccount(text: string, host: string): {
|
|
72
|
+
token?: string;
|
|
73
|
+
user?: string;
|
|
74
|
+
multiAccount: boolean;
|
|
75
|
+
};
|
|
41
76
|
export declare function claudeSettingsFile(env: NodeJS.ProcessEnv, home: string): string;
|
|
42
77
|
/** Every key this computer holds that Passport could take, CLI sign-ins first. */
|
|
43
78
|
export declare function findLocalKeys(context: LocalContext): LocalKey[];
|
|
44
|
-
/** Drop only the key lines of one profile; everything else stays byte for byte. */
|
|
45
|
-
export declare function withoutAwsProfileKeys(text: string, profile: string): string;
|
|
46
79
|
export type RemovalRunner = (command: string, args: string[], env: NodeJS.ProcessEnv) => Promise<number>;
|
|
80
|
+
/** `note`: the file copy is gone but a keychain copy may remain. */
|
|
47
81
|
export type RemovalResult = {
|
|
48
82
|
localCopy: "removed" | "logout_failed";
|
|
49
83
|
left?: string;
|
|
84
|
+
note?: string;
|
|
50
85
|
};
|
|
51
86
|
/**
|
|
52
87
|
* Remove this computer's copy after it is safely in Passport. A sign-out that
|
package/dist/keysLocal.js
CHANGED
|
@@ -3,26 +3,45 @@
|
|
|
3
3
|
* tokens in Claude Code's settings, with the value (held in memory only, sent
|
|
4
4
|
* once to Passport) and how to remove the local copy afterwards.
|
|
5
5
|
*
|
|
6
|
-
* Removal
|
|
7
|
-
* `
|
|
8
|
-
* `
|
|
9
|
-
*
|
|
10
|
-
*
|
|
6
|
+
* Removal takes away the credential and nothing else. Most vendor sign-outs do
|
|
7
|
+
* more: `railway logout` resets the whole config (every project link),
|
|
8
|
+
* `vercel logout` revokes the token Passport just stored and forgets the
|
|
9
|
+
* current team, `supabase logout` sweeps saved database passwords, and
|
|
10
|
+
* `wrangler logout` ignores an API token. So Passport edits the vendor's own
|
|
11
|
+
* file instead, removing only the credential fields, atomically and keeping
|
|
12
|
+
* the file's mode. Only the GitHub CLI keeps its own sign-out, for the one
|
|
13
|
+
* account on github.com: it touches nothing else and owns the keyring entry.
|
|
14
|
+
* `.env` files are never read for moving and never edited: apps need them.
|
|
11
15
|
*
|
|
12
16
|
* Every read is bounded; nothing here prints or logs a value.
|
|
13
17
|
*/
|
|
14
18
|
import { spawn } from "node:child_process";
|
|
15
|
-
import {
|
|
16
|
-
import { closeSync, fsyncSync, lstatSync, openSync, readFileSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync, constants } from "node:fs";
|
|
19
|
+
import { readFileSync, statSync, unlinkSync } from "node:fs";
|
|
17
20
|
import { homedir } from "node:os";
|
|
18
|
-
import {
|
|
21
|
+
import { join, relative, isAbsolute } from "node:path";
|
|
19
22
|
import { readBoundedUtf8File } from "./boundedFile.js";
|
|
20
23
|
import { EXEC_TOKEN_PAGES, EXEC_VENDOR_NAMES } from "./execVendors.js";
|
|
21
24
|
import { findOnPath } from "./initInstall.js";
|
|
25
|
+
import { removeKeychainItems, stripeKeychain, supabaseKeychain } from "./keysKeychain.js";
|
|
26
|
+
import { withoutAwsProfileKeys, withoutJsonFields, withoutTomlKeys, writeAtomic } from "./keysLocalEdit.js";
|
|
27
|
+
export { withoutAwsProfileKeys, withoutJsonFields, withoutTomlKeys } from "./keysLocalEdit.js";
|
|
22
28
|
import { parseGhHosts, parseIni, parseTomlSubset } from "./scanParse.js";
|
|
23
29
|
import { AWS_ACCESS_KEY_ID, isPlaceholder, normalizeValue } from "./scanRules.js";
|
|
24
30
|
const MAX_BYTES = 1024 * 1024;
|
|
25
31
|
const LOGOUT_TIMEOUT_MS = 20_000;
|
|
32
|
+
/** Railway's sign-in fields on `user` (railwayapp/cli `RailwayUser`); `id` and everything else stay. */
|
|
33
|
+
export const RAILWAY_CREDENTIAL_FIELDS = ["token", "accessToken", "refreshToken", "tokenExpiresAt"];
|
|
34
|
+
/** Wrangler's sign-in keys in `config/default.toml` (workers-auth `readStoredAuthState`). */
|
|
35
|
+
export const WRANGLER_CREDENTIAL_KEYS = ["api_token", "oauth_token", "refresh_token", "expiration_time", "scopes"];
|
|
36
|
+
/** One Stripe profile's API keys (stripe-cli `profile.go`); account, device, color, and other profiles stay. */
|
|
37
|
+
export const STRIPE_CREDENTIAL_KEYS = [
|
|
38
|
+
"test_mode_api_key",
|
|
39
|
+
"test_mode_pub_key",
|
|
40
|
+
"test_mode_key_expires_at",
|
|
41
|
+
"live_mode_api_key",
|
|
42
|
+
"live_mode_pub_key",
|
|
43
|
+
"live_mode_key_expires_at"
|
|
44
|
+
];
|
|
26
45
|
function homeOf(context) {
|
|
27
46
|
return context.home ?? (context.env.HOME || context.env.USERPROFILE || homedir());
|
|
28
47
|
}
|
|
@@ -67,9 +86,6 @@ function real(value) {
|
|
|
67
86
|
? normalized
|
|
68
87
|
: undefined;
|
|
69
88
|
}
|
|
70
|
-
function logout(vendor, command, args) {
|
|
71
|
-
return { kind: "logout", command, args };
|
|
72
|
-
}
|
|
73
89
|
const SIGN_OUT = {
|
|
74
90
|
railway: "sign the Railway CLI out on this computer",
|
|
75
91
|
gh: "sign the GitHub CLI out on this computer",
|
|
@@ -92,10 +108,19 @@ function ghKeys(context, home) {
|
|
|
92
108
|
const text = read(path);
|
|
93
109
|
if (text === undefined)
|
|
94
110
|
return [];
|
|
95
|
-
const
|
|
96
|
-
const token =
|
|
111
|
+
const account = ghActiveAccount(text, "github.com");
|
|
112
|
+
const token = real(account.token) ??
|
|
113
|
+
parseGhHosts(text)
|
|
114
|
+
.find((entry) => entry.host === "github.com")
|
|
115
|
+
?.tokens.map(real)
|
|
116
|
+
.find(Boolean);
|
|
97
117
|
if (!token)
|
|
98
118
|
return [];
|
|
119
|
+
// With several accounts on github.com (gh 2.40+ `users:`), name the active
|
|
120
|
+
// one: gh refuses to guess without a terminal, and the others stay.
|
|
121
|
+
const args = ["auth", "logout", "--hostname", "github.com"];
|
|
122
|
+
if (account.multiAccount && account.user)
|
|
123
|
+
args.push("--user", account.user);
|
|
99
124
|
return [
|
|
100
125
|
{
|
|
101
126
|
vendor: "gh",
|
|
@@ -103,11 +128,49 @@ function ghKeys(context, home) {
|
|
|
103
128
|
label: "GitHub CLI token",
|
|
104
129
|
location: display(path, home),
|
|
105
130
|
secret: { token },
|
|
106
|
-
|
|
131
|
+
// gh's own sign-out removes one account on one host and keeps other hosts,
|
|
132
|
+
// other accounts, and config.yml. It also clears that account's keyring entry.
|
|
133
|
+
removal: { kind: "logout", command: "gh", args },
|
|
107
134
|
removalWords: SIGN_OUT.gh
|
|
108
135
|
}
|
|
109
136
|
];
|
|
110
137
|
}
|
|
138
|
+
/** The host-level (active) `oauth_token` and `user` of one host in gh's hosts.yml. */
|
|
139
|
+
export function ghActiveAccount(text, host) {
|
|
140
|
+
const out = { multiAccount: false };
|
|
141
|
+
const unquote = (value) => value.replace(/^(["'])(.*)\1$/, "$2");
|
|
142
|
+
let inHost = false;
|
|
143
|
+
let indent;
|
|
144
|
+
for (const line of text.split(/\r?\n/)) {
|
|
145
|
+
if (!line.trim() || line.trimStart().startsWith("#"))
|
|
146
|
+
continue;
|
|
147
|
+
const top = /^([^\s#:][^:]*):\s*$/.exec(line);
|
|
148
|
+
if (top) {
|
|
149
|
+
inHost = unquote(top[1].trim()) === host;
|
|
150
|
+
indent = undefined;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (!inHost)
|
|
154
|
+
continue;
|
|
155
|
+
const depth = line.length - line.trimStart().length;
|
|
156
|
+
indent ??= depth;
|
|
157
|
+
if (depth !== indent)
|
|
158
|
+
continue;
|
|
159
|
+
const field = /^\s+([A-Za-z_]+):\s*(.*?)\s*$/.exec(line);
|
|
160
|
+
if (!field)
|
|
161
|
+
continue;
|
|
162
|
+
if (field[1] === "oauth_token")
|
|
163
|
+
out.token = unquote(field[2]);
|
|
164
|
+
else if (field[1] === "user")
|
|
165
|
+
out.user = unquote(field[2]);
|
|
166
|
+
else if (field[1] === "users")
|
|
167
|
+
out.multiAccount = true;
|
|
168
|
+
}
|
|
169
|
+
// A GitHub login, so it is safe as an argument.
|
|
170
|
+
if (out.user !== undefined && !/^[A-Za-z0-9-]{1,39}$/.test(out.user))
|
|
171
|
+
delete out.user;
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
111
174
|
function railwayKeys(home) {
|
|
112
175
|
const path = join(home, ".railway", "config.json");
|
|
113
176
|
const parsed = json(path);
|
|
@@ -124,7 +187,8 @@ function railwayKeys(home) {
|
|
|
124
187
|
label: "Railway account token",
|
|
125
188
|
location,
|
|
126
189
|
secret: { token },
|
|
127
|
-
|
|
190
|
+
// Not `railway logout`: it resets the whole config, every project link included.
|
|
191
|
+
removal: { kind: "json-fields", path, object: ["user"], fields: RAILWAY_CREDENTIAL_FIELDS },
|
|
128
192
|
removalWords: SIGN_OUT.railway
|
|
129
193
|
}
|
|
130
194
|
];
|
|
@@ -165,7 +229,8 @@ function vercelKeys(context, home) {
|
|
|
165
229
|
label: "Vercel token",
|
|
166
230
|
location: display(path, home),
|
|
167
231
|
secret: { token },
|
|
168
|
-
|
|
232
|
+
// Not `vercel logout`: it revokes the token Passport just stored and forgets the current team.
|
|
233
|
+
removal: { kind: "json-fields", path, object: [], fields: ["token"] },
|
|
169
234
|
removalWords: SIGN_OUT.vercel
|
|
170
235
|
}
|
|
171
236
|
];
|
|
@@ -217,7 +282,8 @@ function wranglerKeys(context, home) {
|
|
|
217
282
|
label: "Cloudflare API token",
|
|
218
283
|
location,
|
|
219
284
|
secret: { token },
|
|
220
|
-
|
|
285
|
+
// Not `wrangler logout`: with only an API token it says "Not logged in" and leaves it.
|
|
286
|
+
removal: { kind: "toml-keys", path, table: [], keys: WRANGLER_CREDENTIAL_KEYS },
|
|
221
287
|
removalWords: SIGN_OUT.wrangler
|
|
222
288
|
}
|
|
223
289
|
];
|
|
@@ -248,7 +314,9 @@ function supabaseKeys(context, home) {
|
|
|
248
314
|
label: "Supabase access token",
|
|
249
315
|
location: display(path, home),
|
|
250
316
|
secret: { token },
|
|
251
|
-
|
|
317
|
+
// Not `supabase logout`: it also sweeps every linked project's saved database password.
|
|
318
|
+
removal: { kind: "credential-file", path },
|
|
319
|
+
keychain: supabaseKeychain(context.env),
|
|
252
320
|
removalWords: SIGN_OUT.supabase
|
|
253
321
|
}
|
|
254
322
|
];
|
|
@@ -259,7 +327,8 @@ function stripeKeys(context, home) {
|
|
|
259
327
|
if (text === undefined)
|
|
260
328
|
return [];
|
|
261
329
|
const tables = parseTomlSubset(text);
|
|
262
|
-
const
|
|
330
|
+
const table = tables.has("default") ? ["default"] : ["profiles", "default"];
|
|
331
|
+
const profile = tables.get(table.join("\u0000"));
|
|
263
332
|
const token = real(profile?.test_mode_api_key);
|
|
264
333
|
if (!token || !/^(?:sk|rk)_test_/.test(token))
|
|
265
334
|
return [];
|
|
@@ -270,7 +339,9 @@ function stripeKeys(context, home) {
|
|
|
270
339
|
label: "Stripe test key",
|
|
271
340
|
location: display(path, home),
|
|
272
341
|
secret: { token },
|
|
273
|
-
|
|
342
|
+
// Not `stripe logout`: depending on the version it drops the whole profile or its account details.
|
|
343
|
+
removal: { kind: "toml-keys", path, table, keys: STRIPE_CREDENTIAL_KEYS },
|
|
344
|
+
keychain: stripeKeychain("default"),
|
|
274
345
|
removalWords: SIGN_OUT.stripe
|
|
275
346
|
}
|
|
276
347
|
];
|
|
@@ -370,68 +441,8 @@ export function findLocalKeys(context) {
|
|
|
370
441
|
];
|
|
371
442
|
}
|
|
372
443
|
// ---- removal ----------------------------------------------------------------
|
|
373
|
-
/** Same-directory temporary file, fsync, rename; through a dotfile symlink. */
|
|
374
|
-
function writeAtomic(path, text) {
|
|
375
|
-
let target = path;
|
|
376
|
-
try {
|
|
377
|
-
if (lstatSync(path).isSymbolicLink())
|
|
378
|
-
target = realpathSync(path);
|
|
379
|
-
}
|
|
380
|
-
catch {
|
|
381
|
-
/* write the path itself */
|
|
382
|
-
}
|
|
383
|
-
let mode = 0o600;
|
|
384
|
-
try {
|
|
385
|
-
mode = statSync(target).mode & 0o777;
|
|
386
|
-
}
|
|
387
|
-
catch {
|
|
388
|
-
/* new file */
|
|
389
|
-
}
|
|
390
|
-
const temporary = join(dirname(target), `.passport-keys-${randomBytes(12).toString("hex")}.tmp`);
|
|
391
|
-
let descriptor;
|
|
392
|
-
try {
|
|
393
|
-
descriptor = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, mode);
|
|
394
|
-
writeFileSync(descriptor, text, "utf8");
|
|
395
|
-
fsyncSync(descriptor);
|
|
396
|
-
closeSync(descriptor);
|
|
397
|
-
descriptor = undefined;
|
|
398
|
-
renameSync(temporary, target);
|
|
399
|
-
}
|
|
400
|
-
finally {
|
|
401
|
-
if (descriptor !== undefined)
|
|
402
|
-
closeSync(descriptor);
|
|
403
|
-
try {
|
|
404
|
-
unlinkSync(temporary);
|
|
405
|
-
}
|
|
406
|
-
catch {
|
|
407
|
-
/* already renamed */
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
444
|
function removeSettingsEnv(path, names) {
|
|
412
|
-
|
|
413
|
-
const parsed = JSON.parse(text);
|
|
414
|
-
const env = parsed.env;
|
|
415
|
-
if (!env || typeof env !== "object")
|
|
416
|
-
return false;
|
|
417
|
-
for (const name of names)
|
|
418
|
-
delete env[name];
|
|
419
|
-
writeAtomic(path, `${JSON.stringify(parsed, null, 2)}\n`);
|
|
420
|
-
return true;
|
|
421
|
-
}
|
|
422
|
-
/** Drop only the key lines of one profile; everything else stays byte for byte. */
|
|
423
|
-
export function withoutAwsProfileKeys(text, profile) {
|
|
424
|
-
let inProfile = false;
|
|
425
|
-
const out = [];
|
|
426
|
-
for (const line of text.split(/(?<=\n)/)) {
|
|
427
|
-
const header = /^\s*\[([^\]]+)\]\s*$/.exec(line.replace(/\r?\n$/, ""));
|
|
428
|
-
if (header)
|
|
429
|
-
inProfile = header[1].trim() === profile;
|
|
430
|
-
if (inProfile && /^\s*aws_(?:access_key_id|secret_access_key|session_token|security_token)\s*=/i.test(line))
|
|
431
|
-
continue;
|
|
432
|
-
out.push(line);
|
|
433
|
-
}
|
|
434
|
-
return out.join("");
|
|
445
|
+
writeAtomic(path, withoutJsonFields(readFileSync(path, "utf8"), ["env"], names));
|
|
435
446
|
}
|
|
436
447
|
const defaultRunner = (command, args, env) => new Promise((resolveCode) => {
|
|
437
448
|
const child = spawn(command, args, { stdio: "ignore", env, shell: false });
|
|
@@ -480,13 +491,37 @@ export async function removeLocalCopy(key, context, runner = defaultRunner) {
|
|
|
480
491
|
if (removal.kind === "settings-env") {
|
|
481
492
|
removeSettingsEnv(removal.path, removal.names);
|
|
482
493
|
}
|
|
494
|
+
else if (removal.kind === "json-fields") {
|
|
495
|
+
const text = readFileSync(removal.path, "utf8");
|
|
496
|
+
const next = withoutJsonFields(text, removal.object, removal.fields);
|
|
497
|
+
if (next !== text)
|
|
498
|
+
writeAtomic(removal.path, next);
|
|
499
|
+
}
|
|
500
|
+
else if (removal.kind === "toml-keys") {
|
|
501
|
+
const text = readFileSync(removal.path, "utf8");
|
|
502
|
+
const next = withoutTomlKeys(text, removal.table, removal.keys);
|
|
503
|
+
if (next !== text)
|
|
504
|
+
writeAtomic(removal.path, next);
|
|
505
|
+
}
|
|
506
|
+
else if (removal.kind === "credential-file") {
|
|
507
|
+
try {
|
|
508
|
+
unlinkSync(removal.path);
|
|
509
|
+
}
|
|
510
|
+
catch (error) {
|
|
511
|
+
if (error.code !== "ENOENT")
|
|
512
|
+
throw error;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
483
515
|
else {
|
|
484
516
|
const text = readFileSync(removal.path, "utf8");
|
|
485
517
|
writeAtomic(removal.path, withoutAwsProfileKeys(text, removal.profile));
|
|
486
518
|
}
|
|
487
519
|
if (stillThere(key, context))
|
|
488
520
|
return { localCopy: "logout_failed", left: `${key.location} still holds the key.` };
|
|
489
|
-
|
|
521
|
+
if (!key.keychain)
|
|
522
|
+
return { localCopy: "removed" };
|
|
523
|
+
const note = await removeKeychainItems(key.keychain, context.env, context.platform ?? process.platform, runner).catch(() => `${key.keychain.label} may still be there.`);
|
|
524
|
+
return note ? { localCopy: "removed", note } : { localCopy: "removed" };
|
|
490
525
|
}
|
|
491
526
|
catch {
|
|
492
527
|
return { localCopy: "logout_failed", left: `Passport couldn't change ${key.location}. It still holds the key.` };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Same-directory temporary file, fsync, rename; through a dotfile symlink. */
|
|
2
|
+
export declare function writeAtomic(path: string, text: string): void;
|
|
3
|
+
/**
|
|
4
|
+
* Delete `fields` from the object at `object` in a JSON document. The rest is
|
|
5
|
+
* written back with the file's own indent, BOM, and trailing newline, so a
|
|
6
|
+
* file the vendor wrote (serde_json or JSON.stringify pretty output) changes
|
|
7
|
+
* only where a field was.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withoutJsonFields(text: string, object: string[], fields: string[]): string;
|
|
10
|
+
/** Drop `keys` (and a multi-line array value) from one TOML table; every other line stays byte for byte. */
|
|
11
|
+
export declare function withoutTomlKeys(text: string, table: string[], keys: string[]): string;
|
|
12
|
+
/** Drop only the key lines of one profile; everything else stays byte for byte. */
|
|
13
|
+
export declare function withoutAwsProfileKeys(text: string, profile: string): string;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File edits for `passport keys move`: remove a credential from a vendor's
|
|
3
|
+
* own file and leave every other byte as it was. Writes are atomic (same
|
|
4
|
+
* folder temporary file, fsync, rename) and keep the file's mode.
|
|
5
|
+
*/
|
|
6
|
+
import { randomBytes } from "node:crypto";
|
|
7
|
+
import { closeSync, constants, fchmodSync, fsyncSync, lstatSync, openSync, realpathSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
/** Same-directory temporary file, fsync, rename; through a dotfile symlink. */
|
|
10
|
+
export function writeAtomic(path, text) {
|
|
11
|
+
let target = path;
|
|
12
|
+
try {
|
|
13
|
+
if (lstatSync(path).isSymbolicLink())
|
|
14
|
+
target = realpathSync(path);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
/* write the path itself */
|
|
18
|
+
}
|
|
19
|
+
let mode = 0o600;
|
|
20
|
+
try {
|
|
21
|
+
mode = statSync(target).mode & 0o777;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
/* new file */
|
|
25
|
+
}
|
|
26
|
+
const temporary = join(dirname(target), `.passport-keys-${randomBytes(12).toString("hex")}.tmp`);
|
|
27
|
+
let descriptor;
|
|
28
|
+
try {
|
|
29
|
+
descriptor = openSync(temporary, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL, mode);
|
|
30
|
+
// The umask can narrow the mode at creation; keep the original exactly.
|
|
31
|
+
fchmodSync(descriptor, mode);
|
|
32
|
+
writeFileSync(descriptor, text, "utf8");
|
|
33
|
+
fsyncSync(descriptor);
|
|
34
|
+
closeSync(descriptor);
|
|
35
|
+
descriptor = undefined;
|
|
36
|
+
renameSync(temporary, target);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (descriptor !== undefined)
|
|
40
|
+
closeSync(descriptor);
|
|
41
|
+
try {
|
|
42
|
+
unlinkSync(temporary);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
/* already renamed */
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Delete `fields` from the object at `object` in a JSON document. The rest is
|
|
51
|
+
* written back with the file's own indent, BOM, and trailing newline, so a
|
|
52
|
+
* file the vendor wrote (serde_json or JSON.stringify pretty output) changes
|
|
53
|
+
* only where a field was.
|
|
54
|
+
*/
|
|
55
|
+
export function withoutJsonFields(text, object, fields) {
|
|
56
|
+
const bom = text.charCodeAt(0) === 0xfeff ? "" : "";
|
|
57
|
+
const body = bom ? text.slice(1) : text;
|
|
58
|
+
const parsed = JSON.parse(body);
|
|
59
|
+
let target = parsed;
|
|
60
|
+
for (const key of object) {
|
|
61
|
+
target =
|
|
62
|
+
target && typeof target === "object" && !Array.isArray(target) && Object.hasOwn(target, key)
|
|
63
|
+
? target[key]
|
|
64
|
+
: undefined;
|
|
65
|
+
}
|
|
66
|
+
if (!target || typeof target !== "object" || Array.isArray(target))
|
|
67
|
+
return text;
|
|
68
|
+
const record = target;
|
|
69
|
+
if (!fields.some((field) => Object.hasOwn(record, field)))
|
|
70
|
+
return text;
|
|
71
|
+
for (const field of fields)
|
|
72
|
+
delete record[field];
|
|
73
|
+
const indent = /^[ \t]+(?=")/m.exec(body)?.[0] ?? "";
|
|
74
|
+
const trailing = /\s*$/.exec(body)?.[0] ?? "";
|
|
75
|
+
return `${bom}${JSON.stringify(parsed, null, indent)}${trailing}`;
|
|
76
|
+
}
|
|
77
|
+
function tableOf(header) {
|
|
78
|
+
const inner = /^\s*\[\[?\s*(.*?)\s*\]\]?\s*(?:#.*)?$/.exec(header)?.[1];
|
|
79
|
+
if (inner === undefined)
|
|
80
|
+
return undefined;
|
|
81
|
+
const parts = [];
|
|
82
|
+
for (const match of inner.matchAll(/\s*("(?:[^"\\]|\\.)*"|'[^']*'|[A-Za-z0-9_-]+)\s*(?:\.|$)/g)) {
|
|
83
|
+
const part = match[1];
|
|
84
|
+
parts.push(part.startsWith('"') || part.startsWith("'") ? part.slice(1, -1) : part);
|
|
85
|
+
}
|
|
86
|
+
return parts;
|
|
87
|
+
}
|
|
88
|
+
/** Brackets still open after this TOML value text, ignoring quoted strings and comments. */
|
|
89
|
+
function openBrackets(value, depth) {
|
|
90
|
+
let quote;
|
|
91
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
92
|
+
const char = value[i];
|
|
93
|
+
if (quote) {
|
|
94
|
+
if (char === "\\" && quote === '"')
|
|
95
|
+
i += 1;
|
|
96
|
+
else if (char === quote)
|
|
97
|
+
quote = undefined;
|
|
98
|
+
}
|
|
99
|
+
else if (char === '"' || char === "'")
|
|
100
|
+
quote = char;
|
|
101
|
+
else if (char === "#")
|
|
102
|
+
break;
|
|
103
|
+
else if (char === "[" || char === "{")
|
|
104
|
+
depth += 1;
|
|
105
|
+
else if (char === "]" || char === "}")
|
|
106
|
+
depth -= 1;
|
|
107
|
+
}
|
|
108
|
+
return depth;
|
|
109
|
+
}
|
|
110
|
+
/** Drop `keys` (and a multi-line array value) from one TOML table; every other line stays byte for byte. */
|
|
111
|
+
export function withoutTomlKeys(text, table, keys) {
|
|
112
|
+
const wanted = new Set(keys);
|
|
113
|
+
const target = table.join("\u0000");
|
|
114
|
+
let current = "";
|
|
115
|
+
let skipping = 0;
|
|
116
|
+
const out = [];
|
|
117
|
+
for (const line of text.split(/(?<=\n)/)) {
|
|
118
|
+
const bare = line.replace(/\r?\n$/, "");
|
|
119
|
+
if (skipping > 0) {
|
|
120
|
+
skipping = openBrackets(bare, skipping);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
if (/^\s*\[/.test(bare)) {
|
|
124
|
+
const path = tableOf(bare);
|
|
125
|
+
if (path)
|
|
126
|
+
current = path.join("\u0000");
|
|
127
|
+
out.push(line);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const match = /^\s*("(?:[^"\\]|\\.)*"|'[^']*'|[A-Za-z0-9_-]+)\s*=\s*(.*)$/.exec(bare);
|
|
131
|
+
const key = match ? match[1].replace(/^(["'])(.*)\1$/, "$2") : undefined;
|
|
132
|
+
if (current === target && key !== undefined && wanted.has(key)) {
|
|
133
|
+
skipping = Math.max(0, openBrackets(match[2], 0));
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
out.push(line);
|
|
137
|
+
}
|
|
138
|
+
return out.join("");
|
|
139
|
+
}
|
|
140
|
+
/** Drop only the key lines of one profile; everything else stays byte for byte. */
|
|
141
|
+
export function withoutAwsProfileKeys(text, profile) {
|
|
142
|
+
let inProfile = false;
|
|
143
|
+
const out = [];
|
|
144
|
+
for (const line of text.split(/(?<=\n)/)) {
|
|
145
|
+
const header = /^\s*\[([^\]]+)\]\s*$/.exec(line.replace(/\r?\n$/, ""));
|
|
146
|
+
if (header)
|
|
147
|
+
inProfile = header[1].trim() === profile;
|
|
148
|
+
if (inProfile && /^\s*aws_(?:access_key_id|secret_access_key|session_token|security_token)\s*=/i.test(line))
|
|
149
|
+
continue;
|
|
150
|
+
out.push(line);
|
|
151
|
+
}
|
|
152
|
+
return out.join("");
|
|
153
|
+
}
|
package/dist/passport.js
CHANGED
|
@@ -10,7 +10,7 @@ import { completionResult, profilesResult, useProfileResult, versionResult } fro
|
|
|
10
10
|
import { describedToolPayload } from "./cliDescribe.js";
|
|
11
11
|
import { connect, managePayload } from "./cliConnect.js";
|
|
12
12
|
import { firstText, hasNonText, payloadOf, refusalOf, requireSuccess } from "./cliResult.js";
|
|
13
|
-
import { callerFrom, endpoint, failure, firstSentence, readBoundedJson, resolveCliAuth, safeApiError, sanitize, sleep, timedFetch, timeoutMs } from "./cliSupport.js";
|
|
13
|
+
import { callerFrom, endpoint, failure, firstSentence, holdForCommand, passportOrigin, readBoundedJson, resolveCliAuth, safeApiError, sanitize, sleep, timedFetch, timeoutMs } from "./cliSupport.js";
|
|
14
14
|
import { readBoundedUtf8Descriptor } from "./boundedFile.js";
|
|
15
15
|
import { runCliSession, writeCliSessionFailure } from "./cliSession.js";
|
|
16
16
|
export { refusalOf } from "./cliResult.js";
|
|
@@ -590,9 +590,7 @@ export async function main(argv = process.argv.slice(2), env = process.env, io =
|
|
|
590
590
|
stderr: process.stderr
|
|
591
591
|
}) {
|
|
592
592
|
const controller = new AbortController();
|
|
593
|
-
const
|
|
594
|
-
process.once("SIGINT", cancel);
|
|
595
|
-
process.once("SIGTERM", cancel);
|
|
593
|
+
const release = holdForCommand(() => controller.abort(new Error("Cancelled.")));
|
|
596
594
|
const runtime = {
|
|
597
595
|
env,
|
|
598
596
|
stdin: io.stdin ?? process.stdin,
|
|
@@ -612,7 +610,7 @@ export async function main(argv = process.argv.slice(2), env = process.env, io =
|
|
|
612
610
|
return result.exitCode ?? 0;
|
|
613
611
|
}
|
|
614
612
|
catch (error) {
|
|
615
|
-
const cliError = asFailure(error);
|
|
613
|
+
const cliError = asFailure(error, args && passportOrigin(args, env));
|
|
616
614
|
if (args?.command === "session")
|
|
617
615
|
await writeCliSessionFailure(runtime, cliError);
|
|
618
616
|
else
|
|
@@ -620,8 +618,7 @@ export async function main(argv = process.argv.slice(2), env = process.env, io =
|
|
|
620
618
|
return cliError.exitCode;
|
|
621
619
|
}
|
|
622
620
|
finally {
|
|
623
|
-
|
|
624
|
-
process.removeListener("SIGTERM", cancel);
|
|
621
|
+
release();
|
|
625
622
|
}
|
|
626
623
|
}
|
|
627
624
|
function isEntrypoint() {
|
package/dist/pluginPin.d.ts
CHANGED
package/dist/pluginPin.js
CHANGED
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.16.
|
|
1
|
+
export declare const VERSION = "0.16.2";
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Keep in lockstep with bridge/package.json.
|
|
2
|
-
export const VERSION = "0.16.
|
|
2
|
+
export const VERSION = "0.16.2";
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passport-bridge",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "passport-bridge",
|
|
9
|
-
"version": "0.16.
|
|
9
|
+
"version": "0.16.2",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@modelcontextprotocol/sdk": "1.30.0"
|