自动 mongodump:如何从 ps 输出中隐藏密码?

automated mongodump: how to hide password from ps output?

好的,我们有了 mongodump 工具,它有 --password 选项。一切都很好,除了这个简单的密码在 ps 输出中对每个人都可见。

我们的数据库有简单的 user/password 身份验证。

我发现唯一有用的就是这样做

echo secretpwd |  mongodump --username backup --oplog

ps 中没有密码痕迹,但仍在使用。

有没有更好的方法?

来自docs

Changed in version 3.0.2: If you wish mongodump to prompt the user for the password, pass the --username option without --password or specify an empty string as the --password value, as in --password "" .

看来你正在做的是推荐的方式。

此外,this 可以进一步提供帮助:

If the secret doesn't change between executions, use a special configuration file, ".appsecrets". Set the permissions of the file to be read-only by owner. Inside the file set an environment variable to the secret. The file needs to be in the home directory of the user running the command.

旧 post,但看起来 mongodump 的最新版本确实明确支持从标准输入读取密码。我在文档中没有看到任何相关信息,但是当我使用与 OP 中的命令类似的命令,mongodump 生成如下输出:

reading password from standard input

我不确定它是否比在 OP 中使用 echo 更好,但我将密码存储在一个文件中,然后像这样使用它:mongodb --username backup < /path/to/password.txt