如何将凭证烘焙到 git 的 docker 镜像中?

YAC*_*YAC 6 linux git authentication docker alpine-linux

这实际上是我上一个问题的后续问题。

我正在尝试使用 docker 托管个人笔记 Web 服务,并希望备份该服务生成的数据(我的笔记)。目前,我计划使用 git 来提交、拉取和推送到存储库以实现我的目的。

要执行 git pull 和 push,我的 docker 映像需要托管我的凭据。实现这一目标最简单但安全的方法是什么?

到目前为止我所做的:

  • 我选择Alpine作为我的服务图像的基础图像。
  • 因为我只需要 git 的凭据,所以我认为将 git 凭据助手放入映像中可能会解决我的问题。我可以在构建时将凭据保存到帮助程序,并在运行时使用它们。
  • libsecret根据这篇文章,我用谷歌搜索了一段时间,决定将其用作我的 git 凭证助手。
  • 我已经安装libsecret并设置了我的 git 凭证助手git-credential-libsecret

git-credential-libsecret但是,到目前为止我还无法发挥作用。以下是我遇到的几个问题:

  • 首先我测试了一下git-credential-libsecret get,出现如下错误:

    CRITICAL **: could not connect to Secret Service: Cannot spawn a message bus without a machine-id: Unable to load /var/lib/dbus/machine-id or /etc/machine-id: Failed to open file */var/lib/dbus/machine-id*: No such file or directory

    • 我(可能?)通过安装dbus并运行解决了这个问题dbus-uuidgen > /var/lib/dbus/machine-id
  • 然后我再次尝试跑步git-credential-libsecret get。这一次,报道称:

    CRITICAL **: could not connect to Secret Service: Cannot autolaunch D-Bus without X11 $DISPLAY

    • 我尝试安装dbus-x11并运行dbus-launch --sh-syntax从这里),但这次没有运气。错误仍在继续。

总之,我想知道:

  1. 我是否朝着正确的方向(使用 git 凭证助手)实现我的目标?
  2. 如果是这样,我该如何解决X11问题?
  3. 还有其他快速、干净的方法来通过版本控制在 docker 中备份数据吗?

max*_*630 3

如果您的 git 提供商支持使用公钥的 ssh,我认为最简单的方法是切换到它们。您也不必复制您的密码。

你需要: