policy auth_error ai_generated true

错误:自托管运行器注册令牌已过期。请生成新令牌并重新注册运行器。

Error: The self-hosted runner registration token has expired. Please generate a new token and re-register the runner.

ID: policy/github-actions-self-hosted-runner-token-expired

其他格式: JSON · Markdown 中文 · English
95%修复率
90%置信度
1证据数
2024-01-10首次发现

版本兼容性

版本状态引入弃用备注
GitHub Actions Runner v2.311.0 active
GitHub Actions Runner v2.312.0 active
GitHub Actions Runner v2.313.0 active

根因分析

GitHub 自托管运行器注册令牌具有可配置的过期时间(默认 1 小时),如果运行器注册过程延迟或令牌在过期后被存储并重用,注册将失败。

English

GitHub self-hosted runner registration tokens have a configurable expiration (default 1 hour) and if the runner registration process is delayed or the token is stored and reused after expiration, registration fails.

generic

官方文档

https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners

解决方案

  1. 从 GitHub 仓库设置生成新的注册令牌并重新注册运行器。
    示例:
      # 在 GitHub 上:设置 > 操作 > 运行器 > 新建自托管运行器 > 复制令牌
      # 在运行器机器上:
      ./config.sh remove --token OLD_TOKEN
      ./config.sh --url https://github.com/owner/repo --token NEW_TOKEN
      ./run.sh
  2. 使用 GitHub API 在脚本中自动化令牌生成,避免手动步骤。
    示例:
      # 使用 GitHub API 获取令牌
      TOKEN=$(curl -s -X POST -H "Authorization: token $GITHUB_PAT" \
        https://api.github.com/repos/owner/repo/actions/runners/registration-token | jq -r '.token')
      ./config.sh --url https://github.com/owner/repo --token $TOKEN
  3. 使用 Terraform 或 Ansible 等基础设施即代码工具管理运行器注册,确保每次生成全新的令牌。
    示例(Terraform):
      resource "github_actions_runner_registration_token" "this" {
        repository = "owner/repo"
      }
      # 然后在 provisioner 中使用令牌

无效尝试

常见但无效的做法:

  1. Restarting the runner service 90% 失败

    Restarting the runner service does not refresh the expired token; the token is only valid for initial registration, not for ongoing operations.

  2. Editing .runner file to extend token expiration 95% 失败

    Modifying the .runner file to extend the expiration date manually will not work because the token is validated server-side by GitHub.

  3. Deleting and re-adding with same token 85% 失败

    Deleting the runner from GitHub and re-adding it with the same expired token will still fail; a new token must be generated.