-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fix remote exec ignoring --detach-keys option #27442
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix remote exec ignoring --detach-keys option #27442
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: shiavm006 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
test/system/075-exec.bats
Outdated
| # Test with custom detach keys - should not error | ||
| # (actual detach behavior is hard to test in non-interactive mode, | ||
| # but we can verify the option is accepted) | ||
| run_podman exec --detach-keys="ctrl-x,ctrl-x" $cid echo "detach-keys-test" | ||
| is "$output" "detach-keys-test" "exec with custom detach-keys works" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't test anything really, you must ensure you actually test the detach sequence. These test would pass with or without this patch.
It is has been a while since I looked at this but there are some rather nasty bugs around detaching logic, #25083 may be a starting point maybe with this change you can get it to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into testing actual detach behavior but it requires PTY/interactive terminal setup which is tricky in automated tests.
should i ?
Keep a simpler test that just verifies no error (but document it doesn't test behavior)
I'll also look at #25083 to see if there's a pattern I can follow.
The remote client completely ignores the --detach-keys option for exec
sessions. The ExecStartAndAttach() function in pkg/bindings/containers/attach.go
hardcodes empty detach keys ([]byte{}) instead of using the detach keys
stored in the exec session configuration.
This prevents users from detaching from exec sessions using custom key
sequences, making the --detach-keys option ineffective.
This commit fixes the issue by:
1. Extracting detach keys from the exec session after inspection
2. Parsing them using term.ToBytes() (unless empty string)
3. Using the parsed keys in both detach.Copy() calls
The fix maintains backward compatibility:
- Exec sessions without detach keys -> empty string -> []byte{} (unchanged)
- Empty detach keys (--detach-keys="") -> empty string -> []byte{} (correct)
- Custom detach keys -> parsed and used (new functionality)
Related to PR containers#25083 and issue containers#25089 which track comprehensive detach
key functionality. A proper interactive test for detach behavior exists
in test/system/450-interactive.bats but is currently skipped for remote
exec pending additional infrastructure work.
Signed-off-by: shiavm006 <shivammittal42006@gmail.com>
7b4e29b to
180570a
Compare
|
@Luap99 |
|
Currently we seems to send the detach keys to the server and handles it there. If I try podman-remote on main I get So basically the issue is that the remote client didn't know the server detached and tried to remove the exec session so it still make sense to move the detach keys to the client side so we can catch and handle the detach error here. And then you need to make sure the remote client handles the detach error and With your patch here it actually worse So we definitely need the proper tests and code to make it actually work, just by adding the keys you make it worse unfortunately. The reason the common change in #25083 is needed is because currently the detach check is broken in that it only works when bytes are read one by one which may not be always the case but it may not be strictly needed for this fix. Overall the exec REST API interface is quite awkward but I don't see how we could chnage it much so we need to make it work with what we got. |
I see now that the full solution requires more comprehensive changes like those |
Problem
The remote client completely ignores the
--detach-keysoption forpodman execsessions. Users cannot detach from exec sessions using custom key sequences.The
ExecStartAndAttach()function inpkg/bindings/containers/attach.gohardcodes empty detach keys:This fix complements the recent fix for empty
--detach-keys=""in PR #27425 , maintaining consistency across attach, run, start, and exec commands.