Hon*_*Ooi 1 git github github-actions
我有一堆使用 Azure Pipelines 进行 CI/CD 的存储库,我现在正在尝试将其移植到 Github Actions。这是我正在研究的第一个:https://github.com/Azure/AzureAuth/tree/fix-ghaction
我已经完成了 99% 的工作,但在某一步骤中我遇到了奇怪的身份验证错误。该存储库已镜像到另一个组织(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/*
Run Code Online (Sandbox Code Playgroud)
这会从存储库机密中检索 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.
Run Code Online (Sandbox Code Playgroud)
谁能解释一下造成这种情况的原因以及如何解决它?我对 Azure/AzureAuth 和 cloudyr/AzureAuth 存储库拥有管理员访问权限。我还检查了 PAT 是否有效。
失败的日志位于: https: //github.com/Azure/AzureAuth/runs/1228152900 ?check_suite_focus=true
GitHub Actions 存储一个配置选项,使用选项之一http.extraheader
发送原始令牌以在自定义授权标头中克隆存储库。这是一个坏主意,因为当您使用另一个存储库时,它会与 Git 添加的授权标头发生冲突,并且颁发的令牌仅对原始存储库有效。
如果您想推送到不同的存储库,那么您需要通过执行以下操作来取消设置该配置选项:
git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | \
xargs -L1 git config --unset-all
Run Code Online (Sandbox Code Playgroud)
此外,您应该避免在用户名字段中传递授权令牌。虽然 GitHub 对此进行了过滤,但用户名字段更有可能出现在日志中,因此最佳实践是使用虚拟名称将其传递到密码字段中,如下所示:
git push --prune https://token:$token@github.com/${CLOUDYR_REPO}.git
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3023 次 |
最近记录: |