在 github 操作中克隆存储库时出错:无法读取“https://***@github.com”的密码:没有此类设备或地址

问题描述 投票:0回答:3

我有一个名为

FOO_SECRET
的存储库机密(它是具有细粒度范围的个人访问令牌)

但是以下工作流程步骤失败

      - name: clone repo
        working-directory: /tmp
        shell: bash
        run: |
          git clone \
            --branch ${{ env.DEFAULT_BRANCH }} \
            --single-branch \
              https://${{ secrets.FOO_SECRET }}@${{ matrix.repository }}

错误如下

fatal: could not read Password for 'https://***@github.com': No such device or address

这是为什么?

git github continuous-integration github-actions git-clone
3个回答
0
投票

比将令牌添加到克隆 URL 更安全的解决方案是将令牌作为环境变量传递并注册一个非常基本的凭证助手:

    runs-on: ubuntu-latest

    steps:
      - name: Setup git
        run: |
          git config --global user.email $env:GIT_EMAIL
          git config --global user.name $env:GIT_USER
          git config --global credential.helper "!f() { echo \`"username=`${GIT_USER}`npassword=`${GIT_PASS}\`"; }; f"
        shell: pwsh
        env:
          GIT_USER: "jessehouwing"
          GIT_EMAIL: "[email protected]"
          GIT_PASS: ${{ secrets.PUSHTOKEN }}

这样密码就永远不会存储在磁盘上,并且可以有选择地传递到需要访问令牌的任何步骤的环境。


-1
投票

我建议添加此步骤来配置 git 来克隆私有仓库:

      - name: Configure git for private modules
        env:
          GITHUB_API_TOKEN: ${{ secrets.FOO_SECRET }}
        run: git config --global url."https://x:${GITHUB_API_TOKEN}@github.com".insteadOf "https://github.com"

注意:我建议您使用 https://github.com/actions/checkout 从 github 签出存储库


-1
投票
git clone https://x-access-token:<TOKEN-HERE>@github.com/owner/repo.git

来源:注意

x-access-token
,那是精华部分

© www.soinside.com 2019 - 2024. All rights reserved.