Implementation:24kchengYe MemoMind MultiApiKeyTenantExtension authenticate
| Knowledge Sources | |
|---|---|
| Domains | Security, Authentication |
| Last Updated | 2026-10-28 00:00 GMT |
Overview
Concrete tool for authenticating requests via an owner API key plus comma-separated revocable client keys, using constant-time comparison to prevent timing attacks.
Description
The MultiApiKeyTenantExtension is the production tenant extension for MemoMind. It accepts:
- Owner key: HINDSIGHT_API_TENANT_API_KEY (required) - the primary credential
- Client keys: HINDSIGHT_API_TENANT_ADDITIONAL_API_KEYS (optional, comma-separated) - revocable credentials for clients
Authentication uses hmac.compare_digest for constant-time comparison, preventing timing attacks that could extract keys byte-by-byte.
Revocation: to revoke a client's access, remove their key from the env var and restart the container. The owner key is unaffected, ensuring the owner always retains access.
All authenticated requests (owner or client) use the same configured schema (single-tenant from the database perspective, but multi-credential at the application layer).
Usage
Configure this extension via HINDSIGHT_API_TENANT_EXTENSION in the production Docker deployment when you need revocable per-client credentials.
Code Reference
Source Location
- Repository: MemoMind
- File: deploy/server/tenant.py
- Lines: L14-39
Signature
class MultiApiKeyTenantExtension(TenantExtension):
def __init__(self, config: dict[str, str]):
...
async def authenticate(self, context: RequestContext) -> TenantContext:
...
async def authenticate_mcp(self, context: RequestContext) -> TenantContext:
...
async def list_tenants(self) -> list[Tenant]:
...
Import
from tenant import MultiApiKeyTenantExtension
# Or configured via env: HINDSIGHT_API_TENANT_EXTENSION=tenant:MultiApiKeyTenantExtension
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config["api_key"] | str | __init__ | Owner API key (required) |
| config["additional_api_keys"] | str | __init__ | Comma-separated client keys (optional) |
| context | RequestContext | authenticate | Request context with api_key field |
Outputs
| Name | Type | Description |
|---|---|---|
| tenant_context | TenantContext | Schema name for the authenticated tenant |
Usage Examples
Configuring Multi-Key Auth
# In .env file:
# HINDSIGHT_API_TENANT_EXTENSION=tenant:MultiApiKeyTenantExtension
# HINDSIGHT_API_TENANT_API_KEY=owner-secret-key
# HINDSIGHT_API_TENANT_ADDITIONAL_API_KEYS=client1-key,client2-key,client3-key
# To revoke client2: remove "client2-key" from the list and restart
# HINDSIGHT_API_TENANT_ADDITIONAL_API_KEYS=client1-key,client3-key