fix(exec): honour empty --detach-keys in remote exec#28405
fix(exec): honour empty --detach-keys in remote exec#28405DeveshB-1 wants to merge 1 commit intocontainers:mainfrom
Conversation
bf350c3 to
ffb5019
Compare
|
[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore. |
|
As I commented on the other - quite similar - PR we have open for this issue: this is greatly overcomplicated. Why not just change |
|
Good call - updated to shadow |
|
|
||
| input := new(handlers.ExecCreateConfig) | ||
| if err := json.NewDecoder(r.Body).Decode(&input); err != nil { | ||
| if err := json.NewDecoder(r.Body).Decode(input); err != nil { |
There was a problem hiding this comment.
Good catch - accidentally dropped the & when rewriting the decode call. Restored.
| execSession.WaitWithDefaultTimeout() | ||
| Expect(execSession).Should(ExitWithError(137, "")) | ||
|
|
||
| It("podman exec --detach-keys empty string disables detach", func() { |
There was a problem hiding this comment.
This test does nothing. I don't think we have any testing for detach keys because it's difficult to verify in an automated fashion.
There was a problem hiding this comment.
You're right, that test was meaningless. Replaced it with a unit test in pkg/api/handlers/exec_create_config_test.go that directly verifies the JSON decoding of DetachKeys as a *string - covering absent field (nil), empty string (*""), and a real value. That's the actual behaviour the fix guarantees.
|
Thanks for the review @mheon, really appreciate the guidance! |
b44ddd7 to
f0b995e
Compare
Honny1
left a comment
There was a problem hiding this comment.
Code LGTM, I would like to see some extension of tests. Also would be great to add API tests.
| // This is the regression test for the bug where DetachKeys:"" was silently | ||
| // ignored because the zero value of string is indistinguishable from absent. | ||
| func TestExecCreateConfigDetachKeys(t *testing.T) { | ||
| tests := []struct { |
There was a problem hiding this comment.
I miss the test scenario with an empty body.
There was a problem hiding this comment.
Added an empty body ({}) test case - committed in the latest push.
|
Added API tests in |
|
@Honny1 do look into this |
|
Please squash down to 1 commit |
08a2726 to
8ac0d8b
Compare
|
Done - squashed to a single commit. |
| # Explicitly empty DetachKeys disables detach - exec create must accept it. | ||
| t POST containers/exec-detach-keys-test/exec \ | ||
| Cmd='["true"]' \ | ||
| DetachKeys='' \ |
There was a problem hiding this comment.
Nice, the last thing I miss is a scenario without DetachKeys.
There was a problem hiding this comment.
Added - the test now also covers exec create without DetachKeys and verifies the default is non-empty via .DetachKeys~.+.
0cd9721 to
e218ce7
Compare
|
Done @Honny1 - added the no- |
| 201 \ | ||
| .Id~[0-9a-f]\\{64\\} | ||
| eid=$(jq -r '.Id' <<<"$output") | ||
| t GET exec/$eid/json 200 .DetachKeys~.+ |
There was a problem hiding this comment.
not ok 1195 [20-containers] GET exec/74000e0395b9fcfd953a21e3a0330c5abceafbcb996aa19aba4afb6392d2afc9/json : .DetachKeys
# expected: ~ .+
# actual:
There was a problem hiding this comment.
Fixed — when DetachKeys is absent from the request, libpodConfig.DetachKeys was left as nil, and libpod's Inspect() returns "" for nil. Now we fall back to runtimeConfig.Engine.DetachKeys explicitly so the system default is stored and returned by inspect.
…efault
Use a *string field for DetachKeys in ExecCreateConfig so the JSON decoder
can distinguish an absent field (nil) from an explicitly-empty one ("").
Previously both mapped to the same empty string, causing DetachKeys:""
to be silently ignored.
When DetachKeys is absent from the request, store the system default from
runtimeConfig.Engine.DetachKeys so that exec inspect returns a meaningful
value rather than an empty string.
Adds unit tests for the JSON decoding and API tests covering all three
scenarios: no DetachKeys, empty DetachKeys, and a non-empty value.
Fixes: containers#28307
Signed-off-by: Devesh B <98201065+DeveshB-1@users.noreply.github.com>
2393461 to
2147234
Compare
|
looks like the api tests are failing still. |
Got it will look into it |
Fixes #28193
podman --remote exec --detach-keys ""was silently ignoring the empty value and falling back to the defaultctrl-p,ctrl-qdetach sequence.Root cause
In
pkg/api/handlers/compat/exec.go, the guard was:Go unmarshals both an absent field and
"DetachKeys": ""to the same zero value, so an explicit empty string was indistinguishable from absent — and was ignored.Fix
Read the raw JSON body alongside the typed decode to check whether
DetachKeyswas explicitly present. Apply the value whenever the key is present, even when empty. Mirrors the fix applied topodman runin v5.8.0.cc @mheon @baude