Skip to content

Forward CIRCLE_TOKEN env vars to remote validate commands#336

Open
hanabel1 wants to merge 3 commits into
mainfrom
hm/forward-circle-token-to-sidecar
Open

Forward CIRCLE_TOKEN env vars to remote validate commands#336
hanabel1 wants to merge 3 commits into
mainfrom
hm/forward-circle-token-to-sidecar

Conversation

@hanabel1
Copy link
Copy Markdown
Contributor

@hanabel1 hanabel1 commented May 13, 2026

Summary

  • Commands run on a sidecar via chunk validate --remote couldn't reach CircleCI APIs (e.g. smarter-testing endpoints) because no host credentials crossed the SSH boundary.
  • openSSHSession now forwards CIRCLE_TOKEN / CIRCLECI_TOKEN from the host environment through the existing ExecOverSSH envVars hook, mirroring how the local validate path picks them up implicitly.
  • Added a small unit test covering the new hostForwardEnv helper.

Test plan

  • task fmt, task lint, go test -race ./... all pass.
  • End-to-end manual check: CIRCLE_TOKEN=… chunk validate --remote --cmd 'printf "CIRCLE_TOKEN length: %s\n" "${#CIRCLE_TOKEN}"' prints the expected non-zero length (70-char personal token reached the remote shell).
  • Reviewer to confirm AcceptEnv on the sidecar sshd doesn't need widening (test above succeeded without changes).

🤖 Generated with Claude Code

Commands run on a sidecar via 'chunk validate --remote' couldn't reach
CircleCI APIs (e.g. smarter-testing endpoints) because no credentials
crossed the SSH boundary. Forward CIRCLE_TOKEN and CIRCLECI_TOKEN from
the host environment via the existing ExecOverSSH envVars hook, matching
the way the local case picks them up implicitly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@hanabel1 hanabel1 force-pushed the hm/forward-circle-token-to-sidecar branch from 9dfa670 to 0fb6486 Compare May 14, 2026 21:30
…g in is installed on every template sidecar.
Comment thread internal/cmd/validate.go Outdated
// remote validate commands authenticate to CircleCI APIs (e.g. smarter-testing
// endpoints) using the caller's credentials, mirroring the local behavior
// where these are picked up implicitly from the environment.
func hostForwardEnv() map[string]string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we have something to this already for the normal command execution?

Comment thread internal/cmd/validate.go Outdated
// where these are picked up implicitly from the environment.
func hostForwardEnv() map[string]string {
env := map[string]string{}
for _, name := range []string{config.EnvCircleToken, config.EnvCircleCIToken} {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we want to pull this off the config object. The circle token can be read from a file/keychain so it won't necessarily be in the environment

Copy link
Copy Markdown
Contributor

@michael-webster michael-webster left a comment

Choose a reason for hiding this comment

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

Left a comment, but I think we want this to use the config we load instead of assuming an env var. We really don't want to depend on the API token being in an env var.

The CircleCI token can be persisted to the on-disk config (and in the
future a keychain backend), so reading it only from os.Getenv silently
dropped the token for users who authenticated via `chunk auth`. Source
it from config.Resolve instead so the canonical priority chain applies,
and forward the single resolved value as CIRCLE_TOKEN.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@michael-webster michael-webster self-requested a review May 18, 2026 21:31
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.

2 participants