Skip to content

feat: support moi apikey authorization for memoria#31

Open
loveRhythm1990 wants to merge 2 commits intomatrixorigin:0316-beta-launchfrom
loveRhythm1990:lr90/local_apikey
Open

feat: support moi apikey authorization for memoria#31
loveRhythm1990 wants to merge 2 commits intomatrixorigin:0316-beta-launchfrom
loveRhythm1990:lr90/local_apikey

Conversation

@loveRhythm1990
Copy link
Collaborator

@loveRhythm1990 loveRhythm1990 commented Mar 16, 2026

What type of PR is this?

  • feat (new feature)
  • fix (bug fix)
  • docs (documentation)
  • style (formatting, no code change)
  • refactor (code change that neither fixes a bug nor adds a feature)
  • perf (performance improvement)
  • test (adding or updating tests)
  • chore (maintenance, tooling)
  • build / ci (build or CI changes)

Which issue(s) this PR fixes

Fixes # https://github.com/matrixorigin/matrixflow/issues/8580

What this PR does / why we need it

新增 --apikey 认证模式,支持通过外部 Remote Auth Service 将 API Key 解析为独立的 per-user MatrixOne 数据库连接。

核心改动:

  • dependencies.py:新增 AuthContext 统一认证上下文,通过 X-API-Key / Authorization: Bearer 头自动分发到 apikey 或 token 模式
  • remote_auth_service.py:新增 Remote Auth Service 客户端,调用 POST /apikey/connection 解析 API Key,带 TTL 缓存
  • database.py:新增 get_user_session_factory() per-user 引擎缓存(lru_cache(128)),首次连接自动建表
  • config.py:新增 remote_auth_service_urlconn_cache_ttl 配置项
  • main.py:apikey 模式下跳过自动 governance scheduler,仅支持按需触发
  • middleware.py:Rate limiter 支持从 X-API-Key 头提取客户端标识
  • cli.pymemoria init --apikey 生成对应 mcp.json 配置,与 --token 互斥
  • mcp_local/server.py:MCP 入口新增 --apikey 参数
  • 所有 router(memory / snapshots / user_ops)统一使用 AuthContext 依赖注入,token 模式完全不受影响

新增文件:docs/apikey-mode.md(使用文档)、docs/design-apikey-mode.md(架构设计文档)、tests/unit/test_apikey_auth.py(25 个测试用例)

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.

1 participant