Skip to content

fix(k8s): resolve attach pod name and su password on GKE Autopilot#159

Merged
ptone merged 1 commit intomainfrom
fix/k8s-attach-pod-name-and-su
Apr 14, 2026
Merged

fix(k8s): resolve attach pod name and su password on GKE Autopilot#159
ptone merged 1 commit intomainfrom
fix/k8s-attach-pod-name-and-su

Conversation

@ameer00
Copy link
Copy Markdown
Contributor

@ameer00 ameer00 commented Apr 14, 2026

Summary

  • Fix scion attach using bare agent name instead of grove-prefixed pod name (e.g., hello vs sciontest--hello), causing GKE Warden rejection
  • Fix su - scion password prompt on GKE Autopilot where pods run as non-root with allowPrivilegeEscalation=false

Test plan

  • Verified attach works with grove-prefixed pod names on GKE Autopilot
  • Verified no password prompt when container already runs as target user
  • Tested with Claude Code, Gemini CLI, OpenCode, and Codex harnesses

🤖 Generated with Claude Code

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 14, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request initializes the project's design documentation, including the backlog, progress logs, and release notes. It also introduces two key fixes to the Kubernetes runtime: correctly resolving pod names with grove prefixes and implementing a runtime check to skip the 'su' command if the container is already running as the target user, which prevents password prompts on GKE Autopilot. A security improvement was suggested to prevent potential shell injection by passing the username as a positional argument to the shell script instead of using string interpolation.

Comment on lines +1755 to +1757
execCmd := []string{"sh", "-c", fmt.Sprintf(
`if [ "$(whoami)" = "%s" ]; then exec tmux attach -t scion; else exec su - %s -c "tmux attach -t scion"; fi`,
username, username)}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

Building shell commands by interpolating variables like username into a script string using fmt.Sprintf is susceptible to shell injection if the variable contains special characters (e.g., quotes, semicolons, or spaces). A more secure and robust approach is to pass the variable as a positional argument to the shell. This ensures the value is treated strictly as data and avoids any interpretation as part of the shell script structure.

Suggested change
execCmd := []string{"sh", "-c", fmt.Sprintf(
`if [ "$(whoami)" = "%s" ]; then exec tmux attach -t scion; else exec su - %s -c "tmux attach -t scion"; fi`,
username, username)}
execCmd := []string{"sh", "-c",
"if [ \"$(whoami)\" = \"$1\" ]; then exec tmux attach -t scion; else exec su - \"$1\" -c \"tmux attach -t scion\"; fi",
"--", username}

@ameer00 ameer00 force-pushed the fix/k8s-attach-pod-name-and-su branch from 7da28aa to 284462c Compare April 14, 2026 02:04
The Attach function used the bare agent name as the pod name, but K8s
pods have a grove-prefixed name (e.g., "sciontest--hello" instead of
"hello"), causing GKE Warden to reject the exec request. Fix by using
agent.ContainerID after lookup.

Additionally, on GKE Autopilot pods that run as non-root with
allowPrivilegeEscalation=false, the `su - scion` wrapper prompts for a
password. Fix with a runtime whoami check that skips su when already
running as the target user.
@ameer00 ameer00 force-pushed the fix/k8s-attach-pod-name-and-su branch from 284462c to 2caa1d0 Compare April 14, 2026 16:02
@ptone ptone merged commit 5a28182 into main Apr 14, 2026
3 of 4 checks passed
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