kubectl/pkg/cmd/exec
hunshcn b600e51f90 kubectl: strict check for exec command (#138214)
* kubectl: strict check for exec command

Fix https://github.com/kubernetes/kubectl/issues/1745

The current implementation doesn't properly check for arguments between
the resource name and the dash separator. This can lead to unexpected
behavior when using commands like 'kubectl exec -it pod-0 bash -- run.sh',
which should raise an error but doesn't.

This fix ensures that when a dash separator (--) is used, there are no
extra arguments between the resource name and the dash.

- Only allow argsLenAtDash == 0 or == 1 (exactly one arg before --)
- Add test for extra args between pod and --
- Add test for flag-like args without dash separator

* test: add kubectl exec container flag coverage

* Apply suggestion from @soltysh

Co-authored-by: Maciej Szulik <soltysh@gmail.com>

---------

Co-authored-by: Maciej Szulik <soltysh@gmail.com>

Kubernetes-commit: b528be0a5658083db98e4a757483a36e1a83e27c
2026-04-23 08:37:14 +08:00
..
exec.go kubectl: strict check for exec command (#138214) 2026-04-23 08:37:14 +08:00
exec_test.go kubectl: strict check for exec command (#138214) 2026-04-23 08:37:14 +08:00