-
Notifications
You must be signed in to change notification settings - Fork 987
Description
What happened?
kubectl exec -i sets up a terminal that prevents disabling echoing. So when an application ask for a password, it is visible in the terminal.
$ kubectl exec -i pod/test -- passwd
New password: mypassword
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password: mypassword
Changing password for user root.
passwd: all authentication tokens updated successfully.
It may seem that adding the -t is the way to help out here, but -t merges stdout and stderr together on purpose, unfortunately. So when you try to redirect the output of such command into a variable (or stdout to a file), you will never see the "Password: " promt because it gets written into stdout because of how kubectl exec -it sets up the terminal using raw option.
$ STDOUT_RESULT="$( kubectl exec -i pod/test -- passwd )"
New password: mypassword
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password: mypassword
$ echo "${STDOUT_RESULT}"
Changing password for user root.
passwd: all authentication tokens updated successfully.
$ STDOUT_RESULT="$( kubectl exec -it pod/test -- passwd )"
# (Without any prompt, I have blindly typed two times `mypassword` into the terminal.)
$ echo "${STDOUT_RESULT}"
Changing password for user root.
New password:
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.
/sig cli
What did you expect to happen?
kubectl exec -i should set up terminal in a way that allows disabling echo. Alternatively, -t should distinguish between stdout and stderr.
How can we reproduce it (as minimally and precisely as possible)?
kubectl run test --image=registry.access.redhat.com/ubi9/ubi:9.3-1610@sha256:66233eebd72bb5baa25190d4f55e1dc3fff3a9b77186c1f91a0abdb274452072 -- sleep infinitykubectl exec -i pod/test -- passwd- see the password echoed
- STDOUT_RESULT="$( kubectl exec -it pod/test -- passwd )"
- observe the missing password prompt
Anything else we need to know?
I have used passwd as an example of a tool that ask for password on stderr and is available to everyone to reproduce this. It doesn't return much useful value on stdout, so here is a real word example of a cqlsh query that needs to ask for a password first:
(password echoed)
TOKEN="$( kubectl exec -i "service/scylla-client" -c scylla -- cqlsh --user cassandra -e "SELECT salted_hash from system_auth.roles WHERE role = 'cassandra'" )"
/opt/scylladb/python3/lib64/python3.11/getpass.py:91: GetPassWarning: Can not control echo on the terminal.
Warning: Password input may be echoed.
Password: cassandra
(no output but silently expects the password)
TOKEN="$( kubectl exec -it "service/scylla-client" -c scylla -- cqlsh --user cassandra -e "SELECT salted_hash from system_auth.roles WHERE role = 'cassandra'" )"
Kubernetes version
$ kubectl version
# paste output hereCloud provider
OS version
# On Linux:
$ cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.4 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.4 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
$ uname -a
Linux ubuntu-2204 5.15.0-100-generic kubernetes/kubernetes#110-Ubuntu SMP Wed Feb 7 13:27:48 UTC 2024 x86_64 x86_64 x86_64 GNU/LinuxInstall tools
Container runtime (CRI) and version (if applicable)
Related plugins (CNI, CSI, ...) and versions (if applicable)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status