使用 subprocess.Popen(command) 时,密码会以任何方式暴露在终端日志中吗?
When using a subprocess.Popen(command), would a password be exposed in a terminal log in any way?
我需要多次执行命令,执行时要求输入密码。但是,也可以通过“--cpass”将密码指定为变量。
我想使用模块 getpass 首先安全地获取密码,然后执行命令(多次)类似于:
import getpass
import subprocess
password = getpass.getpass(prompt="Password: ", stream=None)
# later in a for-loop context:
....
subprocess.Popen([command, "--cpass", password],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
....
这种方法会 "leak" 或将密码以明文形式存储在某些终端日志中的某个地方吗?如果是这样,什么是更好的方法?
(不通过“--cpass”提供密码会导致每次执行命令时都提示输入密码,这对用户来说非常麻烦...)
根据docs:
Security Considerations
Unlike some other popen functions, this implementation will never implicitly call a system shell. This means that all characters, including shell metacharacters, can safely be passed to child processes.
这部分明确声称一切都可以“安全通过”,因此这将包括明文密码。
如果还有人不服气,通过进程正常通信大概可以传出密码
我需要多次执行命令,执行时要求输入密码。但是,也可以通过“--cpass”将密码指定为变量。 我想使用模块 getpass 首先安全地获取密码,然后执行命令(多次)类似于:
import getpass
import subprocess
password = getpass.getpass(prompt="Password: ", stream=None)
# later in a for-loop context:
....
subprocess.Popen([command, "--cpass", password],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
....
这种方法会 "leak" 或将密码以明文形式存储在某些终端日志中的某个地方吗?如果是这样,什么是更好的方法? (不通过“--cpass”提供密码会导致每次执行命令时都提示输入密码,这对用户来说非常麻烦...)
根据docs:
Security Considerations
Unlike some other popen functions, this implementation will never implicitly call a system shell. This means that all characters, including shell metacharacters, can safely be passed to child processes.
这部分明确声称一切都可以“安全通过”,因此这将包括明文密码。
如果还有人不服气,通过进程正常通信大概可以传出密码