Skip to content

feat: Add Gateway Token authentication for remote access#54

Open
ku1x wants to merge 5 commits intoTianyiDataScience:mainfrom
ku1x:main
Open

feat: Add Gateway Token authentication for remote access#54
ku1x wants to merge 5 commits intoTianyiDataScience:mainfrom
ku1x:main

Conversation

@ku1x
Copy link
Copy Markdown

@ku1x ku1x commented Mar 24, 2026

Summary

This PR adds Gateway Token authentication for remote access to Control Center, enabling secure deployment on headless servers.

Changes

New Features

  • Gateway Token Authentication: Users can now login using their Gateway token (gateway.auth.token)
  • Auto-start Hook: Control Center can automatically start when Gateway starts
  • Remote Access Ready: Designed for headless server deployments

New Files

File Description
src/auth/simple-auth.ts Simplified token authentication middleware
src/auth/pairing-store.ts Device pairing storage (alternative auth method)
src/auth/pairing-middleware.ts Pairing authentication middleware
src/auth/pairing-ui.ts Login and pairing UI pages
src/auth/gateway-auth.ts Gateway WebSocket authentication
src/auth/gateway-middleware.ts Gateway auth middleware
auto-start.sh Auto-start script
start.sh Startup script

Configuration

Add to .env:

GATEWAY_TOKEN=your-gateway-token
UI_BIND_ADDRESS=0.0.0.0

Use Case

This is particularly useful for:

  • Headless server deployments
  • Remote access via reverse proxy (Claw Cloud, Tailscale, etc.)
  • Secure token-based authentication

Security

  • No hardcoded credentials in code
  • .env is excluded via .gitignore
  • Token is read from OpenClaw config file

Testing

  1. Start Control Center: UI_MODE=true npx tsx src/index.ts
  2. Access at http://localhost:4310
  3. Login with Gateway token

This PR is based on the original MIT-licensed project and maintains the same license.

KuAi added 5 commits March 24, 2026 14:29
- Add pairing-store.ts: manage paired devices and access tokens
- Add pairing-middleware.ts: authentication middleware
- Add pairing-ui.ts: login and pairing pages
- Add server-patch.ts: integration with Control Center server
- Update config.ts: add PAIRING_AUTH_ENABLED flag
- Add start.sh: convenient startup script
- Update .env: enable pairing auth and remote binding

This allows secure remote access to Control Center with:
1. Device pairing via 6-digit code
2. Access token authentication
3. Device management (list/revoke)
- Add PAIRING_AUTH_ENABLED config flag
- Add authMiddleware to server request handler
- Redirect unauthenticated users to /login page
- Add gateway-auth.ts: WebSocket client for Gateway token verification
- Add gateway-middleware.ts: auth middleware using Gateway's node.pair.verify
- Replace pairing auth with Gateway token auth
- Users can now login with their Gateway token (gateway.auth.token)

This approach:
- Reuses Gateway's existing security mechanism
- No separate pairing system needed
- Does not affect OpenClaw/Gateway operation
- Add simple-auth.ts: direct token comparison
- Remove complex WebSocket auth (gateway-auth.ts, gateway-middleware.ts)
- Read Gateway token from openclaw.json automatically
- Login with gateway.auth.token (KuiClaw1997)
- Add hook in ~/.openclaw/hooks/control-center-start/
- Automatically starts Control Center when Gateway starts
- Enabled via: openclaw hooks enable control-center-start
@TianyiDataScience
Copy link
Copy Markdown
Owner

谢谢你做这条 PR。远程 Gateway Token 认证这个方向我认同,而且这是很值得补的一块。

这次我先没有直接 merge,主要是因为它现在和最新 main 的 auth / hall / server 热区冲突比较多,GitHub 也是 dirty 状态。对这种安全相关改动,我想把 review 和回归验证做得更稳一点。

如果你愿意继续推,我会建议先基于最新 main rebase,再把“配对 / 认证核心链路”和“UI / 启动脚本 / 其他附带改动”尽量拆开。这样会更容易安全地往前推进。

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