-
Notifications
You must be signed in to change notification settings - Fork 1
guides_rbac_authorization
Advanced authorization with role-based and attribute-based access control.
- 📋 Übersicht
- ✨ Features
- 🚀 Quick Start
- 📖 Authorization Models
- 💡 Best Practices
- 🔧 Troubleshooting
- 📚 Siehe auch
- 📝 Changelog
Diese Seite beschreibt die vollständige Zugriffskontrolle in ThemisDB mit zweistufigem Sicherheitsmodell:
- Token-basierte Authentifizierung mit Scopes (RBAC-Ebene)
- Policy Engine mit Attribute-Based Access Control (ABAC, Ranger-kompatibel)
Stand: 22. Dezember 2025
Version: 1.3.0
Kategorie: ⚙️ Operations/Admin
- 🔐 Two-Layer Security - Token-based + Policy Engine
- 👤 Scope-Based RBAC - Admin, config, data, metrics, CDC, PII scopes
- 📋 ABAC Policies - Ranger-compatible attribute-based control
- 🌐 IP Filtering - IP-prefix based access restrictions
- 📊 Audit Logging - All authorization decisions logged
- 📈 Prometheus Metrics - Authorization result tracking
- Token-basierte Authentifizierung mit Scopes (RBAC-Ebene)
- Policy Engine mit Attribute-Based Access Control (ABAC, Ranger-kompatibel)
ThemisDB implementiert ein zweistufiges Sicherheitsmodell:
-
Token-basiert: API-Clients senden
Authorization: Bearer <token>Header -
Scopes: Jeder Token hat einen Satz von Scopes (z. B.
admin,config:write,cdc:read,metrics:read) - Endpoint-Schutz: Sensitive Endpunkte prüfen erforderliche Scopes
- Schnelle Prüfung: Scope-Check erfolgt zuerst, bevor Policy Engine evaluiert wird
- PolicyEngine: Ranger-kompatible Attribute-Based Access Control
- Policies: YAML/JSON-Konfiguration mit subject/action/resource/conditions
- Feingranular: Kontrolle auf Resource-Pfad-Ebene mit Wildcard-Support
- IP-basiert: Optional IP-Präfix-Filtering (z.B. nur interne Netzwerke)
- Effect: Allow/Deny mit Deny-Overrides-Semantik
- Audit-Logs: Alle Autorisierungsentscheidungen werden geloggt
- Metriken: Prometheus-Zähler für Autorisierungsergebnisse
Evaluierungsreihenfolge:
- Token-Scope-Check (schnell, in-memory)
- Falls Scope vorhanden → Policy Engine Evaluation (wenn konfiguriert)
- Beide müssen erfolgreich sein für Zugriff
| Scope | Berechtigungen |
|---|---|
admin |
Voller Zugriff auf alle Endpoints (Superuser) |
config:read |
GET /config |
config:write |
POST /config (Hot-Reload) |
cdc:read |
GET /changefeed/*, CDC Stats |
cdc:admin |
POST /changefeed/retention (Konfiguration) |
metrics:read |
GET /metrics (Prometheus) |
data:read |
GET /entities/, /query/, /graph/, /vector/ |
data:write |
PUT/DELETE /entities/*, POST /query/aql (schreibend) |
pii:reveal |
GET /pii/reveal/{uuid} – Entschlüsselung pseudonymisierter Werte |
pii:erase |
DELETE /pii/{uuid} – DSGVO Art. 17 (soft/hard) |
Token werden in config/auth.json definiert (oder via ENV-Variablen):
{
"tokens": [
{
"token": "admin-secret-token-abc123",
"user_id": "admin",
"scopes": ["admin", "config:write", "config:read", "cdc:read", "cdc:admin", "metrics:read", "data:read", "data:write"]
},
{
"token": "readonly-token-def456",
"user_id": "monitoring",
"scopes": ["metrics:read", "cdc:read", "data:read"]
}
]
}Alternativ via Umgebungsvariablen (für Container):
THEMIS_AUTH_TOKENS='[{"token":"abc123","user_id":"admin","scopes":["admin"]}]'Clients senden Token im Authorization-Header:
# Erfolg (admin hat admin-Scope)
curl -H "Authorization: Bearer admin-secret-token-abc123" \
http://localhost:8765/config
# Verweigert (readonly hat keinen config:write-Scope)
curl -X POST -H "Authorization: Bearer readonly-token-def456" \
-H "Content-Type: application/json" \
-d '{"logging":{"level":"debug"}}' \
http://localhost:8765/config
# -> 403 ForbiddenMVP-Version schützt folgende Endpunkte:
-
POST /config→ Scope:config:write -
GET /config→ Scope:config:read -
GET /changefeed/*→ Scope:cdc:read -
POST /changefeed/retention→ Scope:cdc:admin -
GET /metrics→ Scope:metrics:read(optional, für private Deployments) - Admin-Endpoints (z. B.
/admin/*, falls vorhanden) → Scope:admin -
GET /policies/export/ranger→ Scope:admin -
POST /policies/import/ranger→ Scope:admin -
GET /pii/reveal/{uuid}→ Scope:pii:reveal(Admin-Token alternativ zulässig) -
DELETE /pii/{uuid}→ Scope:pii:erase(Admin-Token alternativ zulässig)
Zusätzlich stehen Policy-Management-Endpunkte zur Verfügung (Ranger-kompatibel):
-
GET /policies/export/ranger→ Scope:admin- Exportiert die aktuell geladene Policy-Liste in ein vereinfachtes Ranger-JSON-Format
- Nützlich für Audits und zur Übernahme in andere Systeme
-
POST /policies/import/ranger→ Scope:admin- Importiert Policies aus einem externen Ranger-Service und lädt sie in die interne PolicyEngine
- Erfordert Environment-Variablen für den Ranger-Client (siehe unten)
Datenendpunkte (/entities, /query, /graph, /vector) sind zunächst offen; optionale Aktivierung via Feature-Flag require_data_auth.
Prometheus /metrics enthält:
Token/Scope-basiert (RBAC):
-
themis_authz_success_total— Erfolgreiche Autorisierungen (Label:user_id,scope) -
themis_authz_denied_total— Verweigerte Zugriffe (Label:user_id,scope,reason) -
themis_authz_invalid_token_total— Ungültige/fehlende Token
Policy Engine (ABAC):
-
themis_policy_allow_total— Policies erlaubten Zugriff -
themis_policy_deny_total— Policies verweigerten Zugriff -
themis_policy_eval_total— Gesamtzahl Policy-Evaluierungen
Bei verweigertem Zugriff wird ein WARN-Log geschrieben:
WARN: Authorization denied for user 'monitoring': Missing required scope: config:write
Für vollständige Audit-Trails können strukturierte Logs (JSON) aktiviert werden (POST /config → logging.format = "json").
-
Token-Rotation: Aktuell statische Token; Rotation via Neustart oder
/configReload (geplant: Key-Rotation-API) - TLS: In Produktion IMMER hinter TLS-Proxy (nginx/Caddy); Token sonst plain-text übertragen
- Secrets-Management: Token nicht in Git committen; nutze Secrets-Manager (Vault, K8s Secrets)
- Least Privilege: Verteile minimale Scopes; Admin-Token nur für ops/debugging
-
Policy-Dateien:
config/policies.yamlwird beim Start automatisch geladen -
IP-Filtering: Nutze
allowed_ip_prefixesin Policies für sensible Endpunkte - Deny-Overrides: Explizite Deny-Policies überschreiben Allow-Policies
- Defense in Depth: Beide Ebenen (Scopes + Policies) müssen zustimmen für Zugriff
- id: unique-policy-id
name: Human-readable description
subjects: ["user1", "admin", "*"] # "*" = wildcard für alle
actions: ["read", "write", "delete", "query", "metrics.read", "pii.reveal"]
resources: ["/entities/users:*", "/metrics", "/pii/reveal/*"]
effect: allow # oder deny
allowed_ip_prefixes: ["10.0.", "192.168."] # optionalPolicies werden aus config/policies.yaml oder config/policies.json geladen:
- id: allow-metrics-readonly
name: readonly darf /metrics
subjects: ["readonly"]
actions: ["metrics.read"]
resources: ["/metrics"]
effect: allow
- id: deny-hr-external
name: HR-Daten nur intern
subjects: ["*"]
actions: ["read"]
resources: ["/entities/hr:*"]
effect: deny
# Nur wenn IP NICHT in allowed_ip_prefixes → deny
allowed_ip_prefixes: ["10.0.", "192.168.1."]-
Prefix-basiert:
/entities/users:*matched/entities/users:123 -
Exact:
/metricsmatched nur/metrics -
Wildcard:
*matched alles
Standard-Actions (erweiterbar):
-
read,write,delete,query,admin -
metrics.read,config.read,config.write -
cdc.read,cdc.admin -
pii.reveal,pii.erase -
vector.search,vector.write
- Deny-Overrides: Wenn eine Deny-Policy matched → Zugriff verweigert
- Allow-Policies: Mindestens eine Allow-Policy muss matchen
- Default: Wenn keine Policies konfiguriert sind → Allow (fail-open für Migration)
-
IP-Check: Wenn
allowed_ip_prefixesgesetzt, muss Client-IP matchen
# Export (für Backup/Audit)
curl -H "Authorization: Bearer $ADMIN_TOKEN" \
http://localhost:8765/policies/export/ranger > policies_backup.json
# Import (von externem Ranger-Service)
export THEMIS_RANGER_BASE_URL=https://ranger.example.com
export THEMIS_RANGER_SERVICE=themisdb
export THEMIS_RANGER_BEARER=ranger-token
curl -X POST -H "Authorization: Bearer $ADMIN_TOKEN" \
http://localhost:8765/policies/import/rangerToken mit metrics:read + cdc:read:
curl -H "Authorization: Bearer readonly-token-def456" \
http://localhost:8765/metricsToken mit config:write:
curl -X POST \
-H "Authorization: Bearer admin-secret-token-abc123" \
-H "Content-Type: application/json" \
-d '{"logging":{"level":"info"},"request_timeout_sec":60}' \
http://localhost:8765/configToken mit cdc:read:
curl -H "Authorization: Bearer readonly-token-def456" \
"http://localhost:8765/changefeed?from_seq=0&limit=100"curl -H "Authorization: Bearer $THEMIS_TOKEN_ADMIN" \
http://localhost:8765/policies/export/ranger# Admin-Token ODER Token mit Scope pii:reveal
curl -H "Authorization: Bearer %THEMIS_TOKEN_ADMIN%" \
http://localhost:8765/pii/reveal/11111111-1111-1111-1111-111111111111Antwort:
{"uuid":"11111111-1111-1111-1111-111111111111","value":"alice@example.com"}Setze Ranger-Umgebung (z. B. in Docker/K8s Secrets):
# Basis-URL und Service-Name
set THEMIS_RANGER_BASE_URL=https://ranger.example.com
set THEMIS_RANGER_SERVICE=themisdb
set THEMIS_RANGER_BEARER=YOUR_RANGER_TOKEN
# TLS (optional)
set THEMIS_RANGER_TLS_VERIFY=1
set THEMIS_RANGER_CA_CERT=C:\\certs\\ranger_ca.pemDann importieren:
curl -X POST -H "Authorization: Bearer %THEMIS_TOKEN_ADMIN%" \
http://localhost:8765/policies/import/rangerUnit-Tests:
-
tests/test_auth_middleware.cpp— Token/Scope-basierte Authentifizierung -
tests/test_policy_yaml.cpp— PolicyEngine YAML-Loading und Evaluation -
tests/test_http_policies_export.cpp— Ranger Export/Import Endpoints
Integration Tests:
- Scope + Policy kombinierte Prüfung in HTTP-Tests
# Build + Test
cmake --build build --config Release
# Auth-Middleware-Tests (RBAC)
.\build\Release\themis_tests.exe --gtest_filter=AuthMiddlewareTest.*
# Policy Engine Tests (ABAC)
.\build\Release\themis_tests.exe --gtest_filter=PolicyYamlTest.*Implementierungsstatus: ✅ Produktionsbereit
- ✅ Token-basierte Authentifizierung (RBAC mit Scopes)
- ✅ Policy Engine (ABAC mit Ranger-Kompatibilität)
- ✅ Dual-Layer Authorization (Scope-Check + Policy-Evaluation)
- ✅ IP-basierte Zugriffskontrolle (allowed_ip_prefixes)
- ✅ Deny-Overrides-Semantik
- ✅ Audit-Logging aller Authorization-Entscheidungen
- ✅ Prometheus-Metriken für beide Ebenen
- ✅ Policy Export/Import (Ranger-kompatibel)
- ✅ YAML/JSON Konfiguration
- ✅ PII-Reveal/Erase Scopes mit Policy-Integration
Bereits implementiert:
- ✅ ABAC-Schema (resource, action, subject, conditions)
- ✅ Policy-Evaluator mit Deny-Overrides
- ✅ Apache Ranger-kompatible Policies
- ✅ YAML/JSON Policy-Konfiguration
- ✅ IP-Präfix-Filtering
Zukünftig (optional):
- ⏳ Admin-UI für Policy-Verwaltung (Web-GUI)
- ⏳ Policy-Store in RocksDB (derzeit File-basiert)
- ⏳ Zeit-basierte Conditions (time windows)
- ⏳ Erweiterte Attribute (user groups, resource tags)
- ⏳ Policy-Caching/Performance-Optimierung
- Verschlüsselte Benutzertabelle (AES)
- Architecture-ACCESS-MODEL-IMPLEMENTATION-SUMMARY
- Architecture-ADR-003-pg-dump-sql-parser
- Architecture-BASEENTITY-PRINCIPLE
- Architecture-CACHE-STORAGE-INTEGRATION
- Architecture-CMAKE-ARCHITECTURE
- Architecture-CMAKE-FLAGS-REFERENCE
- Architecture-CMAKE-MODULAR-ARCHITECTURE
- Architecture-CONCERNS-ARCHITECTURE-DIAGRAM
- Architecture-CONCERNS-IMPLEMENTATION-SUMMARY
- Architecture-CONTENT-MODEL
- Architecture-COPILOT-THEMISDB-GRAPH-RAG-BACKEND-ARCHITECTURE
- Architecture-CRYPTO-AND-KEYS
- Architecture-FEATURE-FLAGS-REFERENCE
- Architecture-GPU-ARCHITECTURE-REVIEW-TEMPLATE
- Architecture-HTTP-SHUTDOWN-HARDENING
- Architecture-MIGRATION-GUIDE-CONCERNS
- Architecture-MIGRATION-GUIDE-v13-v14
- Architecture-MODULARIZATION-GUIDE
- Architecture-MODULAR-ARCHITECTURE-ROADMAP
- Architecture-MODULE-ARCHITECTURE-INDEX
- Architecture-P1D01-ISSMPLUGIN-DESIGN-REVIEW
- Architecture-P1-D01-ISSMPLUGIN-DESIGN-REVIEW
- Architecture-P1-D08-MAMBA-GOVERNANCE-CONTRACT
- Architecture-P1-P2-IMPLEMENTATION-COMPLETION-INDEX
- Architecture-PHASE0-COMPLETION-ASSESSMENT
- Architecture-PHASE3-QUERYENGINE-DI-ARCHITECTURE
- Architecture-PHASE4-INDEX-MANAGER-DI
- Architecture-POSTGRESQL-WIRE-PROTOCOL
- Architecture-QUERYENGINE-IMPLEMENTATION-GUIDE
- Architecture-QUERY-SCHEDULING
- Architecture-RAFT-CONSENSUS-DESIGN
- Architecture-README
- Architecture-README-SSM-HYBRID-IMPLEMENTATION
- Architecture-REFACTORING-SUMMARY
- Architecture-RESOURCE-POOLING
- Architecture-SOURCE-DIRECTORY-GUIDE
- Architecture-THEMIS-CORE-GUIDE
- Architecture-UNIFIED-ACCESS-MODEL
- Architecture-WAL-GRPC-MTLS-CONFIGURATION
- Architecture-WIRE-PROTOCOL-RETRY
- Architecture-boltzmann-observability-draft
- Architecture-experimental-logarithmic-vector-storage
- Architecture-llm-wiki-mvp-adr
- Architecture-rewrite-engine-architecture
- Architecture-rope-api-architecture
- Architecture-ssm-gguf-mamba-status
- Architecture-ssm-hybrid-analysis
- Architecture-ssm-hybrid-rollout-plan
- Architecture-ssm-plugin-interface-design-review
- Architecture-transaction-coordinators
- Architecture-wiki-secondary-index
- Architecture-wire-protocol
- Governance-DISABLED-STUB-POLICY
- Governance-DOCS-PR-POLICY
- Governance-GA-PROMOTION-SIGN-OFF
- Governance-GITHUB-MILESTONES-SETUP
- Governance-MATURITY-CLAIM-VERIFICATION-CHECKLIST
- Governance-MATURITY-EVIDENCE-REGISTRY
- Governance-MERGE-GATE-BOT-CONFIG
- Governance-MERGE-GATE-STATUS-LIVE
- Governance-PHASE3-ENFORCEMENT-RUNBOOK
- Governance-PHASE-1-CLOSURE-REPORT
- Governance-PHASE-CLOSURE-POLICY
- Governance-PHASE-DEPENDENCY-GRAPH
- Governance-PLUGIN-SUBMODULE-ROLLBACK
- Governance-PRODUCTION-READY-2026-DELIVERY-PLAN
- Governance-PR-VERSION-TARGETING
- Governance-PR-VERSION-TARGETING-BACKFILL
- Governance-QUERY-MODULE-STATUS
- Governance-README
- Governance-RELEASE-PROMOTION-GATE-POLICY
- Governance-RELEASE-VALIDATION-CHECKLIST
- Governance-SECURITY-MODULE-5671-EVIDENCE-SUMMARY
- Governance-SHARDING-P6-RESIDUAL-RISK-ACCEPTANCE
- Governance-SOURCECODE-COMPLIANCE-GOVERNANCE
- Governance-UPDATES-DEVELOPMENT-STATUS-SIGN-OFF
- Governance-WAVE-C-IMPLEMENTATION-COMPLETE
- Module-acceleration-Roadmap
- Module-access-model-Roadmap
- Module-ai-Roadmap
- Module-analytics-Roadmap
- Module-api-Roadmap
- Module-aql-Roadmap
- Module-auth-Roadmap
- Module-base-Roadmap
- Module-cache-Roadmap
- Module-cdc-Roadmap
- Module-chaos-Roadmap
- Module-chimera-Roadmap
- Module-config-Roadmap
- Module-content-Roadmap
- Module-core-Roadmap
- Module-distributed-knowledge-Roadmap
- Module-distributed-tensor-Roadmap
- Module-document-Roadmap
- Module-ethics-ai-Roadmap
- Module-evaluation-Roadmap
- Module-execution-Roadmap
- Module-exporters-Roadmap
- Module-failover-Roadmap
- Module-geo-Roadmap
- Module-governance-Roadmap
- Module-gpu-Roadmap
- Module-graph-Roadmap
- Module-image-analysis-Roadmap
- Module-importers-Roadmap
- Module-index-Roadmap
- Module-ingestion-Roadmap
- Module-llama-cpp-Roadmap
- Module-llm-Roadmap
- Module-llm-streaming-Roadmap
- Module-llm-wiki-Roadmap
- Module-maintenance-Roadmap
- Module-metadata-Roadmap
- Module-network-Roadmap
- Module-observability-Roadmap
- Module-onnx-clip-Roadmap
- Module-performance-Roadmap
- Module-plugins-Roadmap
- Module-process-Roadmap
- Module-projects-Roadmap
- Module-prompt-engineering-Roadmap
- Module-query-Roadmap
- Module-rag-Roadmap
- Module-replication-Roadmap
- Module-retrieval-Roadmap
- Module-rpc-grpc-Roadmap
- Module-scheduler-Roadmap
- Module-scraper-Roadmap
- Module-search-Roadmap
- Module-security-Roadmap
- Module-server-Roadmap
- Module-sharding-Roadmap
- Module-stable-diffusion-Roadmap
- Module-storage-Roadmap
- Module-temporal-Roadmap
- Module-tensor-Roadmap
- Module-themis-Roadmap
- Module-timeseries-Roadmap
- Module-toolbox-Roadmap
- Module-training-Roadmap
- Module-transaction-Roadmap
- Module-updates-Roadmap
- Module-user-storage-encrypted-Roadmap
- Module-utils-Roadmap
- Module-vector-search-Roadmap
- Module-voice-Roadmap
- Module-whisper-Roadmap