【问题标题】:How to fill a prompt asking for input with a secret in Github Actions?如何在 Github Actions 中填写要求输入密码的提示?
【发布时间】:2021-03-31 14:03:55
【问题描述】:

在作业中执行以下步骤:

name: Add Secret Key
  run: ssh-add - <<< "${{ secrets.SECRET_KEY }}"

系统提示我填写密码。

如何使用另一个秘密,例如"${{ secrets.PASSPHRASE }}" 来填充提示?

目前我收到此错误:

因为“Enter passphrase for (stdin):”这一步被跳过了

【问题讨论】:

    标签: bash github github-actions


    【解决方案1】:

    不应提示您输入密码,除非私钥最初是使用密码创建的。

    例如,考虑像actions/webfactory-ssh-agent 这样的动作,它来自Matthias Pigulla 在“Using a SSH deploy key in GitHub Actions to access private repositories”中所做的研究

    GitHub Actions 只能访问他们运行的存储库。因此,为了访问其他私有存储库,请创建一个具有足够访问权限的 SSH 密钥。
    然后,使用此操作在 Action 工作程序节点上通过 ssh-agent 使密钥可用。设置完成后,使用 ssh URL 的 git clone 命令就可以正常工作了。

    # .github/workflows/my-workflow.yml
    jobs:
        my_job:
            ...
            steps:
                - actions/checkout@v1
                # Make sure the @v0.4.1 matches the current version of the
                # action 
                - uses: webfactory/ssh-agent@v0.4.1
                  with:
                      ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
                - ... other steps
    

    它的README 确实包括:

    创建 SSH 密钥

    要创建新的 SSH 密钥,请按照此博文中的建议运行 ssh-keygen -t ed25519 -a 100 -f path/to/keyfile
    如果您需要使用一些较旧的服务器软件并需要 RSA 密钥,请尝试使用 ssh-keygen -t rsa -b 4096 -o -f path/to/keyfile

    这两个命令都会提示您输入密钥密码并将密钥保存在path/to/keyfile
    一般来说,有一个密码是一件好事,因为它会在你的磁盘上保持加密的密钥。

    但是,当在此操作中使用密钥时,您需要确保未指定密码:该密钥必须可以在不从输入中读取密码的情况下使用。由于密钥本身是使用 GitHub 的“秘密”功能存储的,所以无论如何它应该是相当安全的。

    【讨论】:

      猜你喜欢
      • 2013-12-21
      • 1970-01-01
      • 2012-08-11
      • 2019-04-21
      • 2011-05-08
      • 2013-05-23
      • 1970-01-01
      • 2020-04-16
      • 2019-08-15
      相关资源
      最近更新 更多