Files
lijiaoqiao/platform-token-runtime
Your Name ad776e4079 fix: P0/P1 security fixes across gateway, token-runtime, and supply-api
P0 fixes:
- platform-token-runtime: Add store.Save() after Refresh token update (P0-3)
- platform-token-runtime: Add sync.RWMutex to InMemoryRuntimeStore (P0-4)
- platform-token-runtime: Add bearer token auth to /audit-events endpoint (P0-5)
- gateway: Fail startup in production if PASSWORD_ENCRYPTION_KEY uses default (P0-1)
- gateway: Require explicit CORS_ALLOW_ORIGINS in production (P0-2)

P1 fixes:
- gateway: Add TrustedProxies config field + env var GATEWAY_TRUSTED_PROXIES (P1-5)
- gateway: Sanitize X-Request-ID header to prevent log injection (P1-6)
- gateway: Strip internal error details from error responses to clients (P1-7)
- supply-api: Upgrade deriveDEK from trivial byte-rotation to HKDF-SHA256 (P1-1)
- supply-api: Reject HS256/HS384/HS512 in production, require RSA (P1-2)

Code quality fixes:
- supply-api: Add BruteForceMaxAttempts + BruteForceLockoutDuration to AuthConfig (MED-12)
- supply-api: Add TrustedProxies to token_auth_middleware (IP spoofing protection)
- supply-api: Use shared pathutil.SplitPath instead of duplicate splitPath
- supply-api: Fix query_key_reject_middleware call sites with trustedProxies param
- gateway: Wire TrustedProxies into AuthMiddlewareConfig and extractClientIP
- gateway: Add CORSAllowOrigins to AuthConfig, wire into CORSMiddleware
- gateway: Fix CompletionsHandle to have context and RecordResult like ChatCompletions
- gateway: Add sanitizeRequestID helper for X-Request-ID log injection prevention
- gateway: Add os import for PASSWORD_ENCRYPTION_KEY check
- gateway: Add strings import to handler.go for sanitizeRequestID

Environment issues documented in TEST_ENVIRONMENT_ISSUES.md
2026-04-17 14:36:02 +08:00
..

Platform Token Runtime

token 生命周期、introspection 与审计查询服务。

当前真实状态

  • 服务入口是 cmd/platform-token-runtime/main.go,装配逻辑收口在 internal/app/bootstrap.go
  • 当前可用接口包括 issuerefreshrevokeintrospectaudit-events
  • TOKEN_RUNTIME_ENV=dev 且未显式注入 store 时bootstrap 会自动使用内存 runtime store 与内存 audit store。
  • TOKEN_RUNTIME_ENV=stagingTOKEN_RUNTIME_ENV=prod 时,必须显式注入 runtime store 与 audit store当前仓库仍未提供持久化 store因此这两种环境会快速失败而不是伪装成可上线服务。
  • audit-events 当前始终保持可查询接口语义;默认内存 audit store 会返回真实事件,未提供查询能力的自定义 emitter 会返回空结果而不是 501 占位响应。

设计边界

  1. 仅支持 Authorization: Bearer <token> 入站。
  2. 外部 query keykeyapi_keytoken)一律拒绝。
  3. 不在任何响应或审计字段中输出 access token 明文。

本地运行

cd "/home/long/project/立交桥/platform-token-runtime"
go run ./cmd/platform-token-runtime

默认监听 :18081。可通过以下环境变量覆盖:

export TOKEN_RUNTIME_ADDR=":18081"
export TOKEN_RUNTIME_ENV="dev"

验证命令

模块级验证:

cd "/home/long/project/立交桥/platform-token-runtime"
GOCACHE=/tmp/lijiaoqiao-go-cache-platform-token-runtime go test ./...

仓库级统一验证:

cd "/home/long/project/立交桥"
bash scripts/ci/repo_integrity_check.sh

关键文件

  • internal/app/bootstrap.go环境判断、runtime store / audit store 装配。
  • internal/httpapi/token_api.goHTTP 接口与审计查询输出。
  • internal/auth/service/runtime_store.go:内存 runtime store。
  • internal/auth/service/audit_store.go:内存 audit store 与审计查询。