feat(libraryagent): 允许显式 peer uid 连接
build / build (push) Successful in 1m54s

容器里的治理进程以固定非 root 用户运行,agent 原先只接受与自身同 uid 的连接,
socket 挂进容器后一律被拒(peer uid is not allowed)。新增 --allow-peer-uid,
默认仍只允许同 uid,放行清单只能由部署参数给出,避免"挂上就能连"。
This commit is contained in:
姚章浩
2026-11-16 23:15:34 +08:00
parent 2066bedbbe
commit 0b753e550e
5 changed files with 38 additions and 5 deletions
+16
View File
@@ -10,6 +10,8 @@ import (
"os"
"os/signal"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"
@@ -33,9 +35,23 @@ func main() {
flag.StringVar(&config.Project, "project", "weknora071full", "Compose project owning the writers")
flag.StringVar(&config.Writers, "writers", "app", "declared writer services")
nonWriters := flag.String("non-writers", defaultNonWriters, "service=reason for every other project service")
allowUIDs := flag.String("allow-peer-uid", "", "extra peer uids allowed to connect (comma separated; default: same uid only)")
flag.DurationVar(&config.MaxDuration, "max-duration", 10*time.Minute, "upper bound for one operation")
describe := flag.Bool("describe", false, "print the fixed configuration and exit")
flag.Parse()
if strings.TrimSpace(*allowUIDs) != "" {
for _, raw := range strings.Split(*allowUIDs, ",") {
raw = strings.TrimSpace(raw)
if raw == "" {
continue
}
uid, err := strconv.ParseUint(raw, 10, 32)
if err != nil {
log.Fatalf("--allow-peer-uid 需要十进制 uid:%q", raw)
}
config.AllowedPeerUIDs = append(config.AllowedPeerUIDs, uint32(uid))
}
}
config.NonWriters = *nonWriters
agent, err := libraryagent.New(config)