错误:自托管运行器注册令牌已过期。请生成新令牌并重新注册运行器。
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
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 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.
官方文档
https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners解决方案
-
从 GitHub 仓库设置生成新的注册令牌并重新注册运行器。 示例: # 在 GitHub 上:设置 > 操作 > 运行器 > 新建自托管运行器 > 复制令牌 # 在运行器机器上: ./config.sh remove --token OLD_TOKEN ./config.sh --url https://github.com/owner/repo --token NEW_TOKEN ./run.sh
-
使用 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 -
使用 Terraform 或 Ansible 等基础设施即代码工具管理运行器注册,确保每次生成全新的令牌。 示例(Terraform): resource "github_actions_runner_registration_token" "this" { repository = "owner/repo" } # 然后在 provisioner 中使用令牌
无效尝试
常见但无效的做法:
-
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.
-
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.
-
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.