Skip to content

Commit 903bd26

Browse files
committed
chore: remove global github token
1 parent 8b4567c commit 903bd26

File tree

10 files changed

+39
-24
lines changed

10 files changed

+39
-24
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ runner-manager
44

55
# Runner 数据目录(按需取消注释)
66
# runners/
7+
# 各 runner 目录下的 GitHub 检查 token(若 runners/ 被纳入版本库请取消下一行注释)
8+
# **/.github_check_token
79

810
# 本地配置(若含敏感信息建议加入)
911
config.yaml

config.yaml.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
server:
66
port: 8080
77
addr: 0.0.0.0
8-
github:
9-
token: ""
108
runners:
119
base_path: ./runners
1210
items: [] # 预置 Runner 列表,也可通过 Web 界面添加

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
| [配置说明](config.md) | `config.yaml` 各字段说明与示例 |
88
| [Docker 部署](docker.md) | 镜像构建、运行、挂载与 Make 目标 |
99
| [添加 Runner](adding-runner.md) | 从 GitHub 获取 Token、界面添加、多 Runner 同机部署 |
10-
| [安全与校验](security.md) | 鉴权、路径安全、唯一性约束 |
10+
| [安全与校验](security.md) | 鉴权、路径安全、唯一性、Token 与敏感文件 |
1111
| [开发与构建](development.md) | Go 构建、本地开发、API(health/version)、Makefile |
1212

1313
[← 返回项目首页](../README.md)

docs/adding-runner.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242

4343
**使用 Docker 或 DinD 时**:若在「快速添加」中填写了 Token 并提交,服务会**先自动执行安装脚本**(下载并解压 runner 到该目录),再执行**向 GitHub 注册**`config.sh`,超时 2 分钟)并启动;无需事先手动执行 `install-runner.sh`。若自动安装失败(如网络问题),可按 [Docker 部署](docker.md) 中「Docker/DinD 下自动注册的前提」手动安装后,重新获取 Token 再在界面提交或在该目录下手动执行 `config.sh`
4444

45-
## 注册结果与定时检查
45+
## 注册结果与 GitHub 显示检查
4646

47-
- **注册结果**:每次在界面使用 Token 执行注册后,结果会写入该 runner 目录下的 `.registration_result.json`(成功或失败原因),并在列表与详情中显示。
48-
- **GitHub 显示检查**:服务内建定时任务每 5 分钟检查各 runner 是否已在 GitHub 的 Actions Runners 列表中显示。需在 `config.yaml` 中配置 `github.token`(需 scope:组织用 `admin:org`,仓库用 `repo`)。检查结果写入各 runner 目录的 `.github_status.json`,并在界面「注册 / GitHub」列与详情中展示。
47+
- **注册结果**仅使用添加时在表单中填写的 Token(从 GitHub 复制的短期 token)。每次在界面使用 Token 执行注册后,结果会写入该 runner 目录下的 `.registration_result.json`(成功或失败原因),并在列表与详情中显示。
48+
- **GitHub 显示检查**(可选):服务内建定时任务约每 5 分钟检查各 runner 是否已在 GitHub 的 Actions Runners 列表中显示。若需此功能,请在该 runner 安装目录下放置 `.github_check_token` 文件,内容为 PAT(需 scope:组织用 `admin:org`,仓库用 `repo`)。检查结果写入各 runner 目录的 `.github_status.json`,并在界面「注册 / GitHub」列与详情中展示。
4949

5050
## 一台机器多 Runner
5151

docs/config.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@ cp config.yaml.example config.yaml
1212
|------|------|------|
1313
| `server.port` | HTTP 服务端口 | `8080` |
1414
| `server.addr` | 监听地址;空则仅绑定端口(等价所有接口) ||
15-
| `github.token` | 预留,用于今后通过 GitHub API 获取 token 等能力 | 当前未使用 |
1615
| `runners.base_path` | 所有 Runner 安装目录的根路径 | `./runners` |
1716
| `runners.items` | 预置的 Runner 列表 | 也可通过 Web 界面添加 |
1817

18+
「GitHub 显示检查」所需的 token 仅在各 runner 目录下配置,见 [添加 Runner](adding-runner.md) 中的说明。
19+
1920
## 示例
2021

2122
```yaml
2223
server:
2324
port: 8080
2425
addr: 0.0.0.0
25-
github:
26-
token: ""
2726
runners:
2827
base_path: ./runners
2928
items: []

docs/docker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ docker run -d --name runner-manager \
2828

2929
- **`-p 8080:8080`**:宿主机端口映射,保证能从本机访问管理界面。
3030
- **`-v $(pwd)/config.yaml:/app/config.yaml`**:挂载配置文件,修改后重启容器即可生效;不挂载则使用镜像内默认配置,无法持久化。
31-
- **`-v $(pwd)/runners:/app/runners`**:挂载 Runner 安装目录,Runner 二进制与注册信息都保存在此;不挂载则容器删除后所有 Runner 丢失。
31+
- **`-v $(pwd)/runners:/app/runners`**:挂载 Runner 安装目录,Runner 二进制与注册信息都保存在此;不挂载则容器删除后所有 Runner 丢失。若需界面「GitHub 显示」状态检查,请在各自 runner 子目录(如 `runners/xxx/`)下放置 `.github_check_token` 文件。
3232
- 镜像内工作目录为 `/app``-config` 默认为 `/app/config.yaml``config.yaml``runners.base_path` 需为 `/app/runners`(或与挂载路径一致)。
3333

3434
### 前台调试(带 -it)

docs/security.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@
1414
- **添加**:禁止与已有 Runner 同名。
1515
- **编辑**:名称不可修改,与磁盘目录名一致。
1616

17+
## Token 与敏感文件
18+
19+
- **config.yaml**:已列入 `.gitignore`,若含敏感信息请勿提交到仓库。
20+
- **各 runner 目录下的 `.github_check_token`**:用于该 runner 的「GitHub 显示检查」,内容为 PAT。建议限制文件权限(如 `chmod 600`),若 `runners/` 被纳入版本库,请在 `.gitignore` 中加入 `**/.github_check_token` 避免泄露。
21+
1722
[← 返回文档索引](README.md)

internal/config/config.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ var mu sync.Mutex
1414
// Config 应用配置
1515
type Config struct {
1616
Server ServerConfig `yaml:"server"`
17-
GitHub GitHubConfig `yaml:"github"`
1817
Runners RunnersConfig `yaml:"runners"`
1918
}
2019

@@ -24,11 +23,6 @@ type ServerConfig struct {
2423
Addr string `yaml:"addr"`
2524
}
2625

27-
// GitHubConfig GitHub 相关配置(可选,用于 API 获取 token)
28-
type GitHubConfig struct {
29-
Token string `yaml:"token"`
30-
}
31-
3226
// RunnersConfig Runner 根配置
3327
type RunnersConfig struct {
3428
BasePath string `yaml:"base_path"` // 所有 runner 安装的根目录

internal/githubcheck/check.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package githubcheck
33
import (
44
"encoding/json"
55
"net/http"
6+
"os"
7+
"path/filepath"
68
"strconv"
79
"strings"
810
"time"
@@ -12,9 +14,10 @@ import (
1214
)
1315

1416
const (
15-
apiBase = "https://api.github.com"
16-
apiTimeout = 30 * time.Second
17-
apiPerPage = 100 // 单页数量,减少漏判(GitHub 默认 30)
17+
apiBase = "https://api.github.com"
18+
apiTimeout = 30 * time.Second
19+
apiPerPage = 100 // 单页数量,减少漏判(GitHub 默认 30)
20+
runnerTokenFile = ".github_check_token" // 各 runner 目录下可选文件,内容为用于 List runners API 的 PAT
1821
)
1922

2023
// githubRunnersResponse 与 GitHub API 返回结构一致
@@ -29,18 +32,32 @@ type githubRunnersResponse struct {
2932
}
3033

3134
// Run 根据配置对每个 runner 调用 GitHub API 检查是否已在 GitHub 显示,并写入 .github_status.json
35+
// Token 仅从该 runner 目录下的 .github_check_token 读取,无则跳过该 runner
3236
func Run(cfg *config.Config) {
33-
if cfg == nil || cfg.GitHub.Token == "" {
37+
if cfg == nil {
3438
return
3539
}
3640
client := &http.Client{Timeout: apiTimeout}
3741
for _, item := range cfg.Runners.Items {
3842
installDir := item.InstallPath(cfg.Runners.BasePath)
39-
registered := checkOne(client, cfg.GitHub.Token, item.TargetType, item.Target, item.Name)
43+
token := tokenForRunner(installDir)
44+
if token == "" {
45+
continue
46+
}
47+
registered := checkOne(client, token, item.TargetType, item.Target, item.Name)
4048
_ = runner.WriteGitHubStatus(installDir, registered)
4149
}
4250
}
4351

52+
// tokenForRunner 返回该 runner 用于 GitHub 检查的 token:从 installDir 下的 .github_check_token 读取,不存在或为空则返回空
53+
func tokenForRunner(installDir string) string {
54+
b, err := os.ReadFile(filepath.Join(installDir, runnerTokenFile))
55+
if err != nil {
56+
return ""
57+
}
58+
return strings.TrimSpace(string(b))
59+
}
60+
4461
// isValidTargetFormat 与 handler.validateTarget 规则一致,避免对无效 target 发起 API 请求;targetType 会规范为小写
4562
func isValidTargetFormat(targetType, target string) bool {
4663
raw := strings.TrimSpace(target)

templates/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ <h1>Runner Fleet - GitHub Actions Runner 管理</h1>
170170

171171
<div class="card">
172172
<h2>Runner 列表</h2>
173-
<p style="color: var(--muted); font-size: 12px; margin: 0 0 12px 0;">注册结果由添加时写入;「GitHub 显示」由定时任务每 5 分钟检查(需在 <code>config.yaml</code> 中配置 <code>github.token</code>)。</p>
173+
<p style="color: var(--muted); font-size: 12px; margin: 0 0 12px 0;">「注册结果」由添加时若填写 Token 执行注册并写入。「GitHub 显示」由定时任务约每 5 分钟检查(可选:在该 runner 目录下放置 <code>.github_check_token</code> 后即会检查)。</p>
174174
<table>
175175
<thead>
176176
<tr>
@@ -205,7 +205,7 @@ <h2>Runner 列表</h2>
205205
{{end}}
206206
{{else}}
207207
{{if .RegistrationMessage}}
208-
<br><span class="github-unknown">GitHub 待检查</span>
208+
<br><span class="github-unknown">GitHub 待检查(可选)</span>
209209
{{end}}
210210
{{end}}
211211
</td>
@@ -441,7 +441,7 @@ <h3 id="modalTitle">Runner 配置</h3>
441441
var ghEl = document.getElementById('vRegisteredOnGitHub');
442442
if (gh === true) ghEl.innerHTML = '<span class="github-yes">已在 GitHub 显示</span>';
443443
else if (gh === false) ghEl.innerHTML = '<span class="github-no">未在 GitHub 显示</span>';
444-
else ghEl.textContent = '未检查(请配置 config.yaml 中 github.token 并等待定时检查)';
444+
else ghEl.textContent = 'GitHub 显示未检查(可选:在该 runner 目录下放置 .github_check_token 后,由定时任务约每 5 分钟检查)';
445445
document.getElementById('vGitHubCheckAt').textContent = data.github_check_at || '—';
446446
const startStopSpan = document.getElementById('modalStartStopSpan');
447447
const startBtn = document.getElementById('modalStartBtnFooter');

0 commit comments

Comments
 (0)