Skip to content

Feat/bearer auth#313

Merged
innomentats merged 3 commits into
chaitin:mainfrom
kingfs:feat/bearer-auth
Jul 16, 2026
Merged

Feat/bearer auth#313
innomentats merged 3 commits into
chaitin:mainfrom
kingfs:feat/bearer-auth

Conversation

@kingfs

@kingfs kingfs commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Remove the remaining daemon/CLI Basic Auth implementation, tests, environment remnants, and obsolete documentation.
  • Add optional daemon-wide Bearer Token authentication through AGENT_COMPOSE_AUTH_TOKEN; authentication remains disabled when the token is empty.
  • Require the daemon token for HTTP(S) control-plane APIs while preserving trusted Unix socket access without credentials.
  • Keep Health RPCs, Runtime LLM facade requests, Jupyter proxy traffic, and webhook ingestion on their existing independent authentication or trust
    boundaries.
  • Add agent-compose auth login, auth logout, and auth list commands.
  • Verify credentials before persisting them and automatically load tokens by normalized daemon site for subsequent CLI requests.
  • Store CLI credentials atomically in the platform user configuration directory with owner-only 0600 permissions.
  • Document the route policy, configuration format, proxy/UI requirements, and the capture/replay risk of sending Bearer tokens over plain HTTP.

Testing

  • task lint
    • Passed with 0 issues.
  • task build
    • Passed, including protobuf packages, runtime SDK packaging verification, and the Linux full-profile binary.
  • task test
    • Unit coverage: 74.43%
    • Integration coverage: 63.53%
    • E2E coverage: 62.47%
    • Combined coverage: 77.75%
  • task docs:build
    • Passed documentation rendering and schema checks.
  • go test ./cmd/agent-compose ./pkg/clientconfig ./pkg/config
    • 843 tests passed.
  • git diff origin/main...HEAD --check
    • Passed.
  • Scanned the change for common private-key and credential patterns; no secrets or private material were found.

Checklist

  • Documentation updated when behavior or configuration changed.
  • Tests added or updated for user-visible behavior.
  • No secrets, private endpoints, internal certificates, or local runtime state included.

@monkeyscan

monkeyscan Bot commented Jul 16, 2026

Copy link
Copy Markdown

PR Title: Feat/bearer auth

Commit: fb35475

本次 PR 引入了 Daemon Bearer 认证机制,包含三部分核心改动:

  1. 服务端中间件(daemon_auth.go):基于 SHA-256 哈希的常量时间比对,对 HTTP(S) 请求进行 Bearer Token 校验;豁免 Unix Socket、Health RPC、Runtime LLM Facade、Jupyter Proxy 和 Webhook ingestion 路径。
  2. CLI 认证命令(cli_auth.go):新增 auth login/logout/list 命令,支持验证 Token 后持久化到本地配置文件。
  3. 客户端配置持久化(pkg/clientconfig/auth.go):使用 YAML 格式原子写(临时文件+rename)存储 Token,默认路径为用户配置目录下的 agent-compose/config.yml,权限 0600。

整体设计思路清晰,常量时间比对、原子写入、Unix Socket 可信绕过大体正确。测试覆盖较全。但 clientconfig 层面存在并发安全隐患。

@kingfs

kingfs commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator Author

本次改动增加了可选的 Bearer Token 认证。

配置变化:

  • daemon 新增环境变量:

AGENT_COMPOSE_AUTH_TOKEN=

  • 未配置或为空:认证关闭,保持原有行为。
  • 配置非空 Token:HTTP/HTTPS 控制面接口必须认证。
  • 本地 Unix Socket 连接始终不需要 Token。
  • Health、LLM facade、Jupyter 和 webhook ingestion 不使用该 Token,继续使用各自的认证机制。

CLI 行为:

  • CLI 按 daemon 站点保存 Token。
  • 登录成功后,Token 默认保存在:

~/.config/agent-compose/config.yml

  • 配置文件权限为 0600。
  • 后续通过相同 --host 或 AGENT_COMPOSE_HOST 连接时,CLI 会自动携带 Token,无需再次指定。
  • 登出后,该站点的后续请求将不再携带 Token。

命令示例:

daemon 开启认证

export AGENT_COMPOSE_AUTH_TOKEN='your-token'
export HTTP_LISTEN='127.0.0.1:7410'
agent-compose daemon

CLI 验证并保存站点 Token

agent-compose --host http://127.0.0.1:7410
auth login --token 'your-token'

后续自动认证

agent-compose --host http://127.0.0.1:7410 status
agent-compose --host http://127.0.0.1:7410 ls
agent-compose --host http://127.0.0.1:7410 images

使用环境变量指定站点

export AGENT_COMPOSE_HOST=http://127.0.0.1:7410
agent-compose status
agent-compose ls

查看已保存的认证站点

agent-compose auth list

删除指定站点的 Token

agent-compose --host http://127.0.0.1:7410 auth logout

跨机器通信建议使用 HTTPS、SSH 隧道或 VPN。HTTP 虽然保留支持,但 Bearer Token 可能被监听和重放。

Comment thread pkg/clientconfig/auth.go Outdated
@monkeyscan

monkeyscan Bot commented Jul 16, 2026

Copy link
Copy Markdown

PR Title: Feat/bearer auth

Commit: 998bbfe

本次 PR 为客户端配置文件操作引入了基于 flock 的 Unix 平台咨询锁(advisory lock),以解决并发 CLI 登录/登出流程可能互相覆盖配置的问题。

主要变更:

  1. pkg/clientconfig/lock_unix.go(新增):使用 syscall.Flock 实现进程级互斥锁,锁文件与配置同目录,权限固定为 0o600,并通过 O_NOFOLLOW 防止符号链接攻击。
  2. pkg/clientconfig/auth.goSaveTokenRemoveToken 被包裹在 withConfigLock 中,确保完整的读-改-写事务串行化。
  3. pkg/clientconfig/auth_test.go:新增两个并发测试——一个验证 64 个 goroutine 并发写入不丢失数据,另一个通过 16 个子进程验证跨进程锁的有效性。
  4. 文档同步更新,说明锁机制的存在。

Unix 实现本身逻辑正确:defer 按 LIFO 顺序先解锁再关闭 fd,Chmod 确保权限不受 umask 影响,错误通过 errors.Join 聚合。但存在一个明显的平台兼容性缺口。

Comment thread pkg/clientconfig/auth.go

@innomentats innomentats left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@innomentats
innomentats merged commit 2199e9d into chaitin:main Jul 16, 2026
16 checks passed
@kingfs kingfs mentioned this pull request Jul 16, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants