【问题标题】:Auth error trying to copy a repo with Github Actions尝试使用 Github Actions 复制 repo 时出现身份验证错误
【发布时间】:2021-01-23 23:50:30
【问题描述】:

我有一堆使用 Azure Pipelines for CI/CD 的存储库,我现在正尝试将其移植到 Github Actions。这是我正在研究的第一个:https://github.com/Azure/AzureAuth/tree/fix-ghaction

我已经让它 99% 正常工作,但我在一个步骤中遇到了一个奇怪的身份验证错误。 repo 被镜像到另一个组织(cloudyr),我使用这个步骤来做镜像:

  - name: Copy to Cloudyr
    if: runner.os == 'Linux'
    env:
      token: "${{ secrets.ghPat }}"
    run: |
      export CLOUDYR_REPO=$(echo $GITHUB_REPOSITORY | sed "s/Azure/cloudyr/")
      git push --prune https://$token@github.com/${CLOUDYR_REPO}.git +refs/remotes/origin/*:refs/heads/* +refs/tags/*:refs/tags/*

这会从存储库机密中检索 PAT,并执行 git push。它在 Azure Pipelines 上运行良好,但现在失败并出现以下错误:

Run export CLOUDYR_REPO=$(echo $GITHUB_REPOSITORY | sed "s/Azure/cloudyr/")
remote: Permission to cloudyr/AzureAuth.git denied to github-actions[bot].
fatal: unable to access 'https://github.com/cloudyr/AzureAuth.git/': The requested URL returned error: 403
Error: Process completed with exit code 128.

谁能解释造成这种情况的原因以及如何解决?我拥有对 Azure/AzureAuth 和 cloudyr/AzureAuth 存储库的管理员访问权限。我还检查了 PAT 是否有效。

失败日志在这里:https://github.com/Azure/AzureAuth/runs/1228152900?check_suite_focus=true

【问题讨论】:

    标签: git github github-actions


    【解决方案1】:

    GitHub Actions 使用 http.extraheader 选项之一存储配置选项,以在自定义授权标头中发送用于克隆存储库的原始令牌。这是一个坏主意,因为它会在您使用另一个存储库时与 Git 添加的 Authorization 标头冲突,并且颁发的令牌仅对原始存储库有效。

    如果您想推送到不同的存储库,则需要通过执行以下操作取消设置该配置选项:

    git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | \
        xargs -L1 git config --unset-all
    

    此外,您应该避免在用户名字段中传递授权令牌。虽然 GitHub 对此进行了过滤,但用户名字段更有可能出现在日志中,因此最好使用虚拟名称将其传递到密码字段中,如下所示:

    git push --prune https://token:$token@github.com/${CLOUDYR_REPO}.git
    

    【讨论】:

    • 感谢您的信息(此 GHA 行为是否记录在任何地方?)。我试过了,但现在它给出了一个不同的错误:To https://github.com/cloudyr/AzureAuth.git ! [remote rejected] master (refusing to delete the current branch: refs/heads/master) ! [remote rejected] origin/fix-ghaction -> fix-ghaction (shallow update not allowed) error: failed to push some refs to 'https://github.com/cloudyr/AzureAuth.git'
    • 我不知道它是否记录在任何地方。有一个关于它的错误报告,但它没有改变,因为 Apple Git 已经破坏了凭证管理器的行为,这是解决这个问题的正确方法。至于您的新错误消息,这是一个完全不同的问题,并且此评论框太小而无法充分回答。请您换个问题问一下好吗?
    猜你喜欢
    • 1970-01-01
    • 2021-05-24
    • 2021-09-07
    • 1970-01-01
    • 2021-02-06
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多