diff --git a/pkg/bindings/containers/attach.go b/pkg/bindings/containers/attach.go index 121775f6ff..4b3c7d7fbe 100644 --- a/pkg/bindings/containers/attach.go +++ b/pkg/bindings/containers/attach.go @@ -80,9 +80,14 @@ func Attach(ctx context.Context, nameOrID string, stdin io.Reader, stdout io.Wri if options.Changed("DetachKeys") { params.Add("detachKeys", options.GetDetachKeys()) - detachKeysInBytes, err = term.ToBytes(options.GetDetachKeys()) - if err != nil { - return fmt.Errorf("invalid detach keys: %w", err) + // Empty string disables detaching; do not attempt to parse + if options.GetDetachKeys() == "" { + detachKeysInBytes = []byte{} + } else { + detachKeysInBytes, err = term.ToBytes(options.GetDetachKeys()) + if err != nil { + return fmt.Errorf("invalid detach keys: %w", err) + } } } if isSet.stdin { diff --git a/test/system/030-run.bats b/test/system/030-run.bats index 70840d92aa..ab7daf3bd4 100644 --- a/test/system/030-run.bats +++ b/test/system/030-run.bats @@ -1226,6 +1226,14 @@ EOF run_podman rm $ctr_name } +# Regression test for https://github.com/containers/podman/issues/27414 +# bats test_tags=ci:parallel +@test "podman run with empty --detach-keys" { + # Empty string should disable detaching, not error with "invalid detach keys" + run_podman run --rm --detach-keys="" $IMAGE echo "success" + is "$output" "success" "empty detach-keys should work" +} + # 15895: --privileged + --systemd = hide /dev/ttyNN # bats test_tags=ci:parallel @test "podman run --privileged as root with systemd will not mount /dev/tty" {