Commit 58012cf
authored
feat(auth): add scoped API keys for Astra (#244)
## What type of PR is this?
- [x] feat (new feature)
- [x] 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)
- [x] test (adding or updating tests)
- [ ] chore (maintenance, tooling)
- [ ] build / ci (build or CI changes)
## Which issue(s) this PR fixes
Related: #245
This reference intentionally does not automatically close the
cross-repository issue.
## What this PR does / why we need it
Provide reusable, least-privilege credentials for Astra account sign-in
and optional memory sharing.
- Add API-key scopes and stable `GET /auth/whoami` identity metadata.
- Enforce identity/read/write/key-management scopes across REST and MCP.
- Prevent identity-only/read-only/read-write connection keys from
administering groups, managing keys, or reaching unclassified
authenticated routes.
- Preserve scopes during rotation and maintain explicit compatibility
for legacy/default keys.
- Reject unauthorized memory access before per-user memory provisioning.
- Make whoami verify the current database grant rather than trust a warm
replica-local cache, so login/refresh observes revocation made through
another API replica.
- Decouple MCP authorization from metrics invalidation. Explicitly
require `memory:write` for `memory_apply`, `memory_rebuild_index` and
`memory_tune_params`.
- Classify exact dispatch names rather than sanitized tracking labels;
reject unclassified tools by default, including with master credentials.
- Apply the same admission to requests and notifications, with real
HTTP/database regression coverage.
## Verification
### Latest MCP review-fix update (58744ff)
- `cargo test --locked -p memoria-api --lib`: 93 passed.
- `cargo test --locked -p memoria-api --test api_e2e test_scoped_ --
--nocapture`: 3 passed.
- `cargo test --locked -p memoria-api --test api_e2e test_mcp_ --
--nocapture`: 16 passed.
- HTTP tests used isolated local MatrixOne databases. The new regression
checks all three missed write tools, notification handling,
write-authorized positive controls, readable tools, identity-only denial
and unknown/malformed names.
- Persisted-state assertions confirm denied requests/notifications do
not tune retrieval parameters, while the same write-authorized operation
does.
- Targeted Rust formatting and `git diff --check`: passed.
- No user test data was cleared or local Memoria service replaced.
### Previously recorded verification
Local validation before push:
- Memoria API compile checks and targeted auth/MCP scope unit tests
passed.
- Real-database scoped-key API tests passed, including
group-administration denial and uncached whoami revocation.
- Seven legacy API-key regression tests passed.
- Astra-to-real-Memoria API v1 contract passed for identity-only,
read-only, read-write, master-key rejection, stable account identity and
revocation.
- Latest upstream main was merged; its intervening changes have no net
source-tree delta relative to the tested Memoria implementation.
- `git diff --check` passed.
Production OAuth and GitOps deployment are not covered by these API
tests.
## Cross-repository dependencies
- Astra login, scoped credential lifecycle and user models:
matrixorigin/Astra#704
- Website follow-up (login separated from memory sharing and local
testing): matrixorigin/memoria-website#216
- Initial website integration, already merged:
matrixorigin/memoria-website#213
No MatrixOne source changes are included.1 parent 00f7948 commit 58012cf
8 files changed
Lines changed: 1395 additions & 99 deletions
File tree
- docs
- memoria/crates
- memoria-api
- src
- routes
- tests
- memoria-storage/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
110 | 118 | | |
111 | 119 | | |
112 | 120 | | |
| |||
0 commit comments