Skip to content

fix(exec): pass -i to cocoon vm exec only when the caller attaches stdin#31

Merged
CMGS merged 2 commits into
mainfrom
fix/exec-stdin-opt-in
Jul 12, 2026
Merged

fix(exec): pass -i to cocoon vm exec only when the caller attaches stdin#31
CMGS merged 2 commits into
mainfrom
fix/exec-stdin-opt-in

Conversation

@tonicmuroq

Copy link
Copy Markdown
Contributor

Problem

cocoon v0.5.0 made vm exec stdin opt-in (docker semantics, cocoonstack/cocoon#119 area, commit 05dbae9): without -i the child's stdin closes immediately. vk builds the exec argv without -i while unconditionally wiring kubectl's stdin stream to the cocoon subprocess — so on hosts running cocoon >= v0.5.0, kubectl exec -i (and -it) silently delivers EOF to the guest command instead of the caller's input.

Fix

Map attach.Stdin() presence to -i:

  • RunInContainer receives a nil stdin reader exactly when kubectl exec runs without -i, so stdin != nil is the interactive signal.
  • Interactive execs get -i prepended and the stream wired as before.
  • Stdin-less execs (including the post-clone path, which already passes nil) keep their exact current argv and no longer wire an unused pipe (exec.Cmd nil Stdin = /dev/null, matching the new cocoon semantics).

Compatibility / rollout

  • Non-interactive execs are byte-identical to today on any cocoon version.
  • Interactive execs require cocoon >= v0.5.0 (older cocoon rejects -i as an unknown flag) — upgrade the cocoon binary before rolling this vk out. Note today's vk on cocoon v0.5.0 has interactive exec broken anyway, so ordering cocoon-first loses nothing.

Testing

  • go build ./... && go test ./... && go vet ./... clean.
  • Added an interactive case to TestBuildExecArgsAssemblesEnvAndArgv pinning -i placement before -e.

tonicmuroq and others added 2 commits July 12, 2026 19:35
cocoon v0.5.0 made vm exec stdin opt-in (docker semantics): without -i
the child's stdin closes immediately. vk wired kubectl's stdin stream to
the cocoon process unconditionally, so on v0.5.0+ hosts 'kubectl exec -i'
delivers EOF instead of the caller's input.

Map attach.Stdin() presence to -i: RunInContainer gets a nil reader when
kubectl exec runs without -i, so stdin-less execs (including post-clone)
keep their exact argv and no longer wire an unused pipe.

Requires cocoon >= v0.5.0 for interactive execs (older cocoon rejects -i
as an unknown flag); non-interactive execs are unaffected either way.
The -i opt-in landed in cocoon v0.4.8, not v0.5.0, and the note that
stdin-less execs skip -i does not hold on the websocket exec path (its
ignore-channel hands back a non-nil stdin reader), so the argv still
carries -i there — harmless on cocoon >= v0.4.8. Describe what the code
does instead of overstating the version/stream guarantees.
@CMGS CMGS merged commit 241f1a4 into main Jul 12, 2026
2 checks passed
@CMGS CMGS deleted the fix/exec-stdin-opt-in branch July 12, 2026 14: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