You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Action报错:无法解析back2code/ssh-key-to-gitsecret,仓库未找到

问题说明

我创建了个人访问令牌并保存为名为PA_TOKEN的机密。使用atc-ubuntu-latest作为运行环境时,工作流完全无法启动;换成ubuntu-latest后,又出现报错:

Unable to resolve action back2code/ssh-key-to-gitsecret, repository not found

我的GitHub Actions工作流代码如下:

name: Generate and save SSH key

on:
  workflow_dispatch:

jobs:
  generate-ssh-key:
    runs-on: [ atc-ubuntu-latest ]

    steps:
      - name: Generate SSH Key
        id: ssh-key-gen
        run: |
          ssh-keygen -t rsa -b 4096 -C "ffff@example.com" -f ssh_key -q -N ""
          public_key=$(cat ssh_key.pub)
          echo "$public_key"

      - name : Create/Update Secrets
        uses: back2code/ssh-key-to-gitsecret@v0.0.1
        with:
          name: BITBUCKET_SSH_PRIVATE_KEY
          keyfilename: ssh_key
          pa_token: ${{ secrets.PA_TOKEN }}

解决办法

1. 处理atc-ubuntu-latest无法启动的问题

atc-ubuntu-latest不是GitHub官方提供的托管运行环境,官方可用的Ubuntu环境包括ubuntu-latest(当前对应22.04)、ubuntu-22.04、ubuntu-20.04等。如果这是你自己搭建的自托管运行器,需要确认它已正确注册到仓库/组织且处于在线状态;如果没有特殊需求,直接替换为官方的ubuntu-latest即可。

2. 解决action仓库找不到的报错

back2code/ssh-key-to-gitsecret这个Action仓库不存在(可能已被删除、改名或未公开),可以改用官方维护的actions/github-script,通过GitHub API直接实现密钥存入机密的功能,修改后的工作流示例:

name: Generate and save SSH key

on:
  workflow_dispatch:

jobs:
  generate-ssh-key:
    runs-on: ubuntu-latest
    permissions:
      repository-secrets: write # 必须授予修改机密的权限

    steps:
      - name: Generate SSH Key
        id: ssh-key-gen
        run: |
          ssh-keygen -t rsa -b 4096 -C "ffff@example.com" -f ssh_key -q -N ""
          # 将私钥内容传入step输出变量
          echo "private_key<<EOF" >> "$GITHUB_OUTPUT"
          cat ssh_key >> "$GITHUB_OUTPUT"
          echo "EOF" >> "$GITHUB_OUTPUT"
          # 打印公钥验证生成结果
          cat ssh_key.pub

      - name: Create/Update Repository Secret
        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.PA_TOKEN }}
          script: |
            const { private_key } = context.steps['ssh-key-gen'].outputs;
            // 获取仓库公钥用于加密机密内容
            const pubKeyRes = await github.rest.actions.getPublicKey({
              owner: context.repo.owner,
              repo: context.repo.repo,
            });
            const publicKey = pubKeyRes.data.key;
            const keyId = pubKeyRes.data.key_id;

            // 加密私钥
            const crypto = require('crypto');
            const encryptedValue = crypto.publicEncrypt(
              {
                key: publicKey,
                padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
                oaepHash: 'sha256'
              },
              Buffer.from(private_key)
            ).toString('base64');

            // 创建或更新机密
            await github.rest.actions.createOrUpdateRepoSecret({
              owner: context.repo.owner,
              repo: context.repo.repo,
              secret_name: 'BITBUCKET_SSH_PRIVATE_KEY',
              encrypted_value: encryptedValue,
              key_id: keyId
            });

注意事项

  • 确保PA_TOKEN拥有repo权限(组织仓库需额外配置组织权限),才能操作仓库机密;
  • 工作流必须添加permissions: repository-secrets: write,否则会因权限不足无法修改机密。

内容的提问来源于stack exchange,提问作者grigor martirosyan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 04:26:20