-
Notifications
You must be signed in to change notification settings - Fork 0
fix: clear gh token env vars when switching accounts #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # CodeGraph data files — local to each machine, not for committing. | ||
| # Ignore everything in .codegraph/ except this file itself, so transient | ||
| # files (the database, daemon.pid, sockets, logs) never show up in git. | ||
| * | ||
| !.gitignore |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,7 +158,11 @@ function sanitizeAuthStatusOutput(output: string) { | |
| } | ||
|
|
||
| async function getAuthStatus(hostname: string) { | ||
| const result = await $({ reject: false })`gh auth status --hostname ${hostname}`; | ||
| const result = await $({ | ||
| reject: false, | ||
| env: envWithoutGhTokens(), | ||
| extendEnv: false, | ||
| })`gh auth status --hostname ${hostname}`; | ||
| const output = sanitizeAuthStatusOutput( | ||
| [result.stdout, result.stderr].filter(Boolean).join("\n"), | ||
| ); | ||
|
|
@@ -179,6 +183,18 @@ async function setAuthOutputFromStatus(hostname: string, warning: string) { | |
| return authStatus.ok; | ||
| } | ||
|
|
||
| function ghTokenEnvNamesForHost(hostname: string) { | ||
| return hostname === "github.com" | ||
| ? ["GH_TOKEN", "GITHUB_TOKEN"] | ||
| : ["GH_ENTERPRISE_TOKEN", "GITHUB_ENTERPRISE_TOKEN"]; | ||
| } | ||
|
|
||
| function clearGhTokenEnvForHost(hostname: string) { | ||
| for (const name of ghTokenEnvNamesForHost(hostname)) { | ||
| core.exportVariable(name, ""); | ||
| } | ||
| } | ||
|
|
||
| const installedVersion = await getInstalledVersion(); | ||
| if (installedVersion && !skipMatchingVersion) { | ||
| core.info(`Using existing GH CLI ${installedVersion} from PATH`); | ||
|
|
@@ -214,7 +230,7 @@ if (!token) { | |
| ghConfigDir = createGhConfigDir(); | ||
| core.exportVariable("GH_CONFIG_DIR", ghConfigDir); | ||
| await loginWithToken(hostname, token); | ||
| core.exportVariable("GH_TOKEN", token); | ||
| clearGhTokenEnvForHost(hostname); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: Two behavior changes from replacing Reply with |
||
| await setAuthOutputFromStatus( | ||
| hostname, | ||
| `gh auth status --hostname ${hostname} failed after switch-account login; setting auth=false.`, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: Stripping token env vars in
getAuthStatusaffects the non-switch-account path tooBecause
getAuthStatusis also used by the default (switch-account: false) flow at theelse if ((await getAuthStatus(hostname)).ok)branch, removingGH_TOKEN/GITHUB_TOKENfrom the probe is not scoped to switch-account. Previously, when a workflow provided atokeninput and hadGH_TOKENset in the environment,gh auth statussucceeded via that env token and the action skipped login. Now the stripped probe sees no stored auth on a fresh runner, fails, and the action falls through tologinWithToken, which persists the provided token to the resolved config dir (the global$HOME/.config/ghwhen not switching). This can overwrite previously stored credentials on self-hosted/persistent runners and is a behavior change not exercised by the added tests. Consider scoping the env-stripping to the switch-account path, or document that the default path now writes the provided token to the user's gh config.Reply with
@kilocode-bot fix itto have Kilo Code address this issue.