Skip to content

fix: clear gh token env vars when switching accounts - #8

Merged
mergify[bot] merged 1 commit into
mainfrom
codex/fix-614-in-setupgh
Jul 3, 2026
Merged

fix: clear gh token env vars when switching accounts#8
mergify[bot] merged 1 commit into
mainfrom
codex/fix-614-in-setupgh

Conversation

@kostua16

@kostua16 kostua16 commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Switch-account now clears gh token environment variables for the target host so an isolated GH_CONFIG_DIR is not shadowed by inherited auth env state.
  • Added workflow coverage for the env-token-shadowing case and tightened the existing isolated-config assertions.
  • Updated docs to reflect the new switch-account behavior.

Root cause

  • gh auth status and later workflow steps could still see GH_TOKEN or GITHUB_TOKEN, which took precedence over the isolated config directory and made the switched account look inconsistent.

References

  • src/main.ts
  • .github/workflows/test-action.yml
  • README.md
  • action.yml

Additional info

  • Impact on system: later gh commands now observe the intended isolated account instead of an inherited env token.
  • Impact on support activities: fewer confusing auth failures and less manual cleanup when workflows reuse environments.

Testing

  • Not run (not requested)

@mergify

mergify Bot commented Jul 3, 2026

Copy link
Copy Markdown

Queued — the merge queue status continues in this comment ↓.

@mergify

mergify Bot commented Jul 3, 2026

Copy link
Copy Markdown

Merge Queue Status

  • Entered queue2026-07-03 06:25 UTC · Rule: default · triggered by @kostua16 with the merge queue checkbox
  • Checks skipped · PR is already up-to-date
  • Merged2026-07-03 06:25 UTC · at 77f2f0e96caa46cdbb9927723c11a41135683942

This pull request spent 19 seconds in the queue, including 2 seconds running CI.

Required conditions to merge

@mergify mergify Bot added the queued label Jul 3, 2026
@mergify
mergify Bot merged commit eac56e3 into main Jul 3, 2026
4 checks passed
@mergify mergify Bot removed the queued label Jul 3, 2026
Comment thread src/main.ts
const result = await $({ reject: false })`gh auth status --hostname ${hostname}`;
const result = await $({
reject: false,
env: envWithoutGhTokens(),

Copy link
Copy Markdown

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 getAuthStatus affects the non-switch-account path too

Because getAuthStatus is also used by the default (switch-account: false) flow at the else if ((await getAuthStatus(hostname)).ok) branch, removing GH_TOKEN/GITHUB_TOKEN from the probe is not scoped to switch-account. Previously, when a workflow provided a token input and had GH_TOKEN set in the environment, gh auth status succeeded 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 to loginWithToken, which persists the provided token to the resolved config dir (the global $HOME/.config/gh when 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 it to have Kilo Code address this issue.

Comment thread src/main.ts
core.exportVariable("GH_CONFIG_DIR", ghConfigDir);
await loginWithToken(hostname, token);
core.exportVariable("GH_TOKEN", token);
clearGhTokenEnvForHost(hostname);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: switch-account no longer exports GH_TOKEN and also clears GITHUB_TOKEN

Two behavior changes from replacing core.exportVariable("GH_TOKEN", token) with clearGhTokenEnvForHost(hostname): (1) Workflows that previously relied on $GH_TOKEN being exported by this action after switch-account: true will now find it empty — a breaking change for existing consumers. (2) clearGhTokenEnvForHost sets both GH_TOKEN and GITHUB_TOKEN (or the enterprise equivalents) to "", which clobbers any job/workflow-level GITHUB_TOKEN/GITHUB_ENTERPRISE_TOKEN that subsequent non-gh steps may depend on, with no opt-out. The README/action.yml describe the high-level intent but don't surface these side effects; consider documenting them or verifying intended consumers are unaffected.


Reply with @kilocode-bot fix it to have Kilo Code address this issue.

@kilo-code-bot

kilo-code-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
src/main.ts 163 Stripping token env vars in getAuthStatus affects the non-switch-account path too (extra gh auth login / persistence on fresh runners); scope or document.
src/main.ts 233 switch-account no longer exports GH_TOKEN and also clears GITHUB_TOKEN — breaking change for consumers relying on $GH_TOKEN, and clobbers job/workflow-level GITHUB_TOKEN/GITHUB_ENTERPRISE_TOKEN.
Files Reviewed (5 files)
  • .codegraph/.gitignore - 0 issues
  • .github/workflows/test-action.yml - 0 issues
  • README.md - 0 issues
  • action.yml - 0 issues
  • src/main.ts - 2 issues

Fix these issues in Kilo Cloud


Reviewed by glm-5.2-short · Input: 47.6K · Output: 17.1K · Cached: 474.5K

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant