Skip to content

Normalize GitHub auth in generated pod spec for workspace secretRef#583

Merged
gjkim42 merged 1 commit intomainfrom
kelos-task-579
Mar 7, 2026
Merged

Normalize GitHub auth in generated pod spec for workspace secretRef#583
gjkim42 merged 1 commit intomainfrom
kelos-task-579

Conversation

@kelos-bot
Copy link

@kelos-bot kelos-bot bot commented Mar 7, 2026

What type of PR is this?

/kind bug

What this PR does / why we need it:

When a Workspace has secretRef configured, Kelos should normalize GitHub auth in the generated pod spec so it works for both the built-in images and custom images.

This PR makes two changes to internal/controller/job_builder.go:

  1. Sets GH_CONFIG_DIR=/workspace/.gh-config on the main agent container when workspace.secretRef is set. This gives gh a clean config directory on the shared workspace volume, so it does not read stale auth from ~/.config/gh/hosts.yml or any image-baked home-directory state. This works for both built-in and custom images without requiring image-specific entrypoint changes.

  2. Clears inherited credential helpers before setting the workspace helper. The clone command now uses -c credential.helper= -c credential.helper='<helper>' to first reset inherited helpers, and the persisted repo config uses --unset-all then --add to ensure a clean state. The helper persistence now runs only after a successful clone, so a partial clone failure cannot be masked by a later config command. The same pattern is applied to the branch-setup fetch command.

Which issue(s) this PR is related to:

Fixes #579

Special notes for your reviewer:

  • The GH_CONFIG_DIR env var is only set on the main container (not init containers), since init containers don't run gh commands.
  • The GH_CONFIG_DIR is NOT set when there is no secretRef, so workspaces without auth injection are unaffected.
  • Integration coverage was updated for the added GH_CONFIG_DIR env var and the new helper script shape.
  • make test and make test-integration both pass locally after the review follow-up.
  • No CRD or API changes are required.

Does this PR introduce a user-facing change?

Fix worker pods preferring stale gh CLI auth over injected workspace token by setting GH_CONFIG_DIR to a clean directory on the workspace volume and clearing inherited git credential helpers.

Summary by cubic

Normalize GitHub auth for workspaces with secretRef by setting a clean gh config dir and clearing inherited git credential helpers. Fixes #579 and ensures consistent auth for both built‑in and custom images.

  • Bug Fixes
    • Set GH_CONFIG_DIR=/workspace/.gh-config on the main agent container when workspace.secretRef is present. No change for init containers or workspaces without secretRef.
    • Clear inherited git credential helpers before applying the workspace helper. Clone and branch-setup use -c credential.helper= then -c credential.helper='<helper>', and repo config uses --unset-all then --add to persist the helper.

Written for commit 2a0e39d. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/controller/job_builder.go">

<violation number="1" location="internal/controller/job_builder.go:347">
P1: The new shell chain can hide clone failures because `--add credential.helper` runs unconditionally after `;`. Keep helper reconfiguration inside the `&&` success path.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

When a workspace has secretRef configured, set GH_CONFIG_DIR to a clean
directory on the shared workspace volume so the gh CLI does not read
stale auth from the container image's home directory. This works for
both built-in and custom agent images without requiring image-specific
entrypoint changes.

Also fix the git credential helper setup to explicitly clear inherited
credential helpers before setting the workspace helper, both for the
clone command (-c credential.helper= to reset, then -c
credential.helper='<helper>') and for the persisted repo config
(--unset-all then --add).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gjkim42 gjkim42 enabled auto-merge March 7, 2026 23:38
@gjkim42 gjkim42 added this pull request to the merge queue Mar 7, 2026
@gjkim42 gjkim42 removed this pull request from the merge queue due to a manual request Mar 7, 2026
@gjkim42 gjkim42 merged commit 629b4d3 into main Mar 7, 2026
14 of 15 checks passed
@gjkim42 gjkim42 deleted the kelos-task-579 branch March 7, 2026 23:47
gjkim42 added a commit that referenced this pull request Mar 8, 2026
Normalize GitHub auth in generated pod spec for workspace secretRef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worker pods can prefer stale gh auth over injected workspace token

1 participant