passport-bridge 0.16.1 → 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 +1 -1
- package/dist/cliKeys.js +7 -1
- 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/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/README.md
CHANGED
|
@@ -272,7 +272,7 @@ passport keys add railway # store a key you paste (stdin, never echoed)
|
|
|
272
272
|
passport exec -- railway up -e staging
|
|
273
273
|
```
|
|
274
274
|
|
|
275
|
-
- `keys move` finds CLI sign-ins (Railway, GitHub CLI, Vercel, Wrangler API tokens, Supabase, Stripe test keys, the AWS `default` profile) and tokens in Claude Code's settings `env`. For each it asks `[y/n]` with no default (an empty answer asks again; `--yes` moves them all), stores the key in Passport (`POST /api/my/keys`), then signs that CLI out
|
|
275
|
+
- `keys move` finds CLI sign-ins (Railway, GitHub CLI, Vercel, Wrangler API tokens, Supabase, Stripe test keys, the AWS `default` profile) and tokens in Claude Code's settings `env`. For each it asks `[y/n]` with no default (an empty answer asks again; `--yes` moves them all), stores the key in Passport (`POST /api/my/keys`), then signs that CLI out by removing only the credential: the token fields of `~/.railway/config.json` (project links stay), `token` in Vercel's `auth.json` (not revoked; the current team stays), Wrangler's sign-in keys in `default.toml`, the Supabase `access-token` file and its keychain token (saved database passwords stay), the Stripe profile's API keys and its live key in the keychain (account, color, and other profiles stay), the AWS profile's key lines, or the one settings entry. Files are written atomically with their mode kept. Vendor sign-outs don't run because they do more (`railway logout` unlinks every project, `vercel logout` revokes the token Passport just stored); only the GitHub CLI's `gh auth logout --hostname github.com` runs, adding `--user <active>` when several accounts are signed in, so other hosts and accounts stay. Keychain items are deleted by exact service and account (`security delete-generic-password` on macOS, `secret-tool clear` on Linux); where that isn't possible the row says which keychain copy may stay. Wrangler OAuth tokens are removed locally, not revoked. A sign-out that fails leaves the key in Passport and says what's left on disk. `.env` files are never touched: "Used by your app, so Passport leaves it." Browser-session sign-ins (Railway, Vercel, Wrangler OAuth) can't move; the line says how to make a token instead. From the CLI, a different key than the one already in Passport is refused; rotate it in Apps. The scan report sent afterwards carries provider counts only.
|
|
276
276
|
- `exec -- <cli> …` runs railway, gh, vercel, wrangler, supabase, stripe, aws, neonctl, or flyctl from PATH. It classifies the command here, asks `POST /api/my/exec/authorize`, and on allow sets only that vendor's variables (`GH_TOKEN`, `RAILWAY_API_TOKEN`, `VERCEL_TOKEN`, `CLOUDFLARE_API_TOKEN`, `SUPABASE_ACCESS_TOKEN`, `STRIPE_API_KEY`, `AWS_*`, `NEON_API_KEY`, `FLY_API_TOKEN`) in the child's environment, removing Passport's own and any stray vendor tokens. Output and exit code pass through. Afterwards it reports the exit code and duration (`POST /api/my/exec/result`, best effort, two seconds at most) so the session row reads Ran or Failed. It refuses paths, shells, `env`, and subcommands that would print the key, sign in again, mint longer-lived tokens, or run another program with the key (`railway run`, `gh auth`, gh extensions, `aws configure`, `vercel dev`, `fly tokens`).
|
|
277
277
|
- Asks wait for your approval in Passport (web or push) when you're at the keyboard or with `--wait <sec>`; otherwise exit 4 with the approval id: run `passport wait <id>`, then the command again. An approval is used once. Blocked or declined: exit 5. No key, or it stopped working: exit 3 ("Your Railway key in Passport stopped working. Update it in Apps."). Offline: exit 1, nothing runs, and exec never uses a key on this computer instead.
|
|
278
278
|
- In Claude Code, the guard rewrites a plain vendor command whose key is in Passport to `passport exec` (PreToolUse `updatedInput` with allow; a block stays a deny). When the rules ask, or someone is at the keyboard, the rewrite adds `--wait 120`, so the agent holds while the person approves: "Approve it on your phone or in Passport." Codex and Cursor get no rewrite: use `passport exec` there.
|
package/dist/cliKeys.js
CHANGED
|
@@ -130,8 +130,14 @@ export async function moveKeys(io) {
|
|
|
130
130
|
}
|
|
131
131
|
const removed = await removeLocalCopy(key, context, io.runner);
|
|
132
132
|
summary.moved.push({ vendor: key.vendor, label: key.label, keyId: stored.id, localCopy: removed.localCopy });
|
|
133
|
-
if (removed.localCopy === "removed")
|
|
133
|
+
if (removed.localCopy === "removed" && removed.note) {
|
|
134
|
+
// The file copy is gone; say plainly that a keychain copy may not be.
|
|
135
|
+
summary.left.push(removed.note);
|
|
136
|
+
io.result("warn", `${name}: stored in Passport, removed from ${key.location}. ${removed.note}`);
|
|
137
|
+
}
|
|
138
|
+
else if (removed.localCopy === "removed") {
|
|
134
139
|
io.result("done", `${name}: stored in Passport, removed from this computer`);
|
|
140
|
+
}
|
|
135
141
|
else {
|
|
136
142
|
summary.left.push(removed.left ?? `${key.location} still holds it.`);
|
|
137
143
|
io.result("warn", `${name}: stored in Passport. ${removed.left ?? ""}`.trim());
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type KeychainItem = {
|
|
2
|
+
service: string;
|
|
3
|
+
account: string;
|
|
4
|
+
};
|
|
5
|
+
export type Keychain = {
|
|
6
|
+
label: string;
|
|
7
|
+
items: KeychainItem[];
|
|
8
|
+
};
|
|
9
|
+
type Runner = (command: string, args: string[], env: NodeJS.ProcessEnv) => Promise<number>;
|
|
10
|
+
export declare function stripeKeychain(profile: string): Keychain;
|
|
11
|
+
export declare function supabaseKeychain(env: NodeJS.ProcessEnv): Keychain;
|
|
12
|
+
/** Delete each item; undefined when done, else one line saying what stays. */
|
|
13
|
+
export declare function removeKeychainItems(keychain: Keychain, env: NodeJS.ProcessEnv, platform: NodeJS.Platform, runner: Runner): Promise<string | undefined>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keychain copies a vendor CLI keeps beside its config file, removed after a
|
|
3
|
+
* key move so "removed from this computer" stays true. Only the exact items
|
|
4
|
+
* named here are deleted (one service and account each), never a sweep:
|
|
5
|
+
*
|
|
6
|
+
* - Stripe CLI: service `StripeCLI`, account `<profile>.live_mode_api_key`
|
|
7
|
+
* (stripe-cli `pkg/config`: `KeyManagementService`, `deleteLivemodeKey`).
|
|
8
|
+
* - Supabase CLI: service `Supabase CLI`, accounts `access-token` (legacy) and
|
|
9
|
+
* the profile name, `supabase` by default (supabase/cli
|
|
10
|
+
* `internal/utils/access_token.go`). Project database passwords live under
|
|
11
|
+
* the same service with the project ref as account and are never touched.
|
|
12
|
+
*
|
|
13
|
+
* macOS uses `security delete-generic-password -s <service> -a <account>`;
|
|
14
|
+
* Linux uses `secret-tool clear service <service> username <account>`, the
|
|
15
|
+
* attributes go-keyring writes. Elsewhere the item stays, with one line.
|
|
16
|
+
*/
|
|
17
|
+
import { findOnPath } from "./initInstall.js";
|
|
18
|
+
/** `security` exits 44 when no item matches: already gone. */
|
|
19
|
+
const SECURITY_NOT_FOUND = 44;
|
|
20
|
+
export function stripeKeychain(profile) {
|
|
21
|
+
return {
|
|
22
|
+
label: "The Stripe CLI's live key in the system keychain",
|
|
23
|
+
items: [{ service: "StripeCLI", account: `${profile}.live_mode_api_key` }]
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function supabaseKeychain(env) {
|
|
27
|
+
const profile = env.SUPABASE_PROFILE?.trim();
|
|
28
|
+
const accounts = new Set(["access-token", profile && /^[A-Za-z0-9._-]{1,64}$/.test(profile) ? profile : "supabase"]);
|
|
29
|
+
return {
|
|
30
|
+
label: "The Supabase CLI's access token in the system keychain",
|
|
31
|
+
items: [...accounts].map((account) => ({ service: "Supabase CLI", account }))
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Delete each item; undefined when done, else one line saying what stays. */
|
|
35
|
+
export async function removeKeychainItems(keychain, env, platform, runner) {
|
|
36
|
+
const tool = platform === "darwin" ? "security" : platform === "linux" ? "secret-tool" : undefined;
|
|
37
|
+
if (!tool)
|
|
38
|
+
return `${keychain.label}, if there is one, stays: Passport can't remove it on this system.`;
|
|
39
|
+
const binary = findOnPath(tool, env, platform);
|
|
40
|
+
if (!binary)
|
|
41
|
+
return `${keychain.label}, if there is one, stays: ${tool} isn't on your PATH.`;
|
|
42
|
+
let failed = false;
|
|
43
|
+
for (const { service, account } of keychain.items) {
|
|
44
|
+
const args = tool === "security"
|
|
45
|
+
? ["delete-generic-password", "-s", service, "-a", account]
|
|
46
|
+
: ["clear", "service", service, "username", account];
|
|
47
|
+
const code = await runner(binary, args, env);
|
|
48
|
+
if (code !== 0 && !(tool === "security" && code === SECURITY_NOT_FOUND))
|
|
49
|
+
failed = true;
|
|
50
|
+
}
|
|
51
|
+
return failed ? `${keychain.label} may still be there: ${tool} didn't finish.` : undefined;
|
|
52
|
+
}
|
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/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"
|