-
Notifications
You must be signed in to change notification settings - Fork 1
guides_rbac
Comprehensive role-based access control system with hierarchies and fine-grained permissions.
- 📋 Übersicht
- ✨ Features
- 🚀 Quick Start
- 📖 RBAC Concepts
- 💡 Best Practices
- 🔧 Troubleshooting
- 📚 Weitere Ressourcen
- 📝 Changelog
Umfassende rollenbasierte Zugriffskontrolle mit Hierarchien, Vererbung und feingranularen Berechtigungen.
Stand: 22. Dezember 2025
Version: 1.3.0
Kategorie: ⚙️ Operations/Admin
- 👥 Role-Based Control - Admin, Operator, Analyst, Readonly (erweiterbar)
- 🏗️ Role Hierarchy - Inheritance of permissions (Admin → Operator → Analyst → Readonly)
- 🔐 Fine-Grained Permissions - Resource and action-based access control
- ⚡ Wildcard Support -
*for all resources or actions - 📝 Flexible Config - JSON/YAML role definitions
- 👤 User Management - User to role mapping
Das RBAC-System bietet:
- Rollenbasierte Zugriffskontrolle: Admin, Operator, Analyst, Readonly (erweiterbar)
- Rollenhierarchie: Vererbung von Berechtigungen (Admin → Operator → Analyst → Readonly)
- Resource-basierte Permissions: Feingranulare Kontrolle über Ressourcen und Aktionen
-
Wildcard-Support:
*für alle Ressourcen oder Aktionen - JSON/YAML-Konfiguration: Flexible Rollendefinition
- User-Role Mapping: Verwaltung von Benutzern und ihren Rollen
Eine Permission besteht aus:
-
resource: Ressource (z.B.
data,keys,config,audit,*) -
action: Aktion (z.B.
read,write,delete,rotate,*)
Beispiele:
{"data", "read"} // Daten lesen
{"keys", "rotate"} // Schlüssel rotieren
{"config", "*"} // Alle Aktionen auf Konfiguration
{"*", "*"} // Alle Ressourcen, alle Aktionen (Superuser)Eine Rolle gruppiert Permissions und kann von anderen Rollen erben:
{
"name": "operator",
"description": "Operator with data and key management",
"permissions": [
{"resource": "data", "action": "read"},
{"resource": "data", "action": "write"},
{"resource": "keys", "action": "rotate"}
],
"inherits": ["analyst"]
}admin (Superuser)
├─ operator (Data + Key Management)
│ └─ analyst (Read-only Data + Audit)
│ └─ readonly (Minimal Read Access)
└─ ...
# RBAC Konfigurationsdatei
export THEMIS_RBAC_CONFIG=/etc/themis/rbac.json
# User-Role Mapping
export THEMIS_RBAC_USERS=/etc/themis/users.json
# Features
export THEMIS_RBAC_ENABLE_INHERITANCE=true
export THEMIS_RBAC_ENABLE_WILDCARDS=true/etc/themis/rbac.json:
{
"roles": [
{
"name": "admin",
"description": "Administrator with full system access",
"permissions": [
{"resource": "*", "action": "*"}
],
"inherits": []
},
{
"name": "operator",
"description": "Operator with data and key management",
"permissions": [
{"resource": "data", "action": "read"},
{"resource": "data", "action": "write"},
{"resource": "data", "action": "delete"},
{"resource": "keys", "action": "read"},
{"resource": "keys", "action": "rotate"},
{"resource": "audit", "action": "read"}
],
"inherits": ["analyst"]
},
{
"name": "analyst",
"description": "Analyst with read-only data access",
"permissions": [
{"resource": "data", "action": "read"},
{"resource": "audit", "action": "read"},
{"resource": "metrics", "action": "read"}
],
"inherits": ["readonly"]
},
{
"name": "readonly",
"description": "Read-only user",
"permissions": [
{"resource": "metrics", "action": "read"},
{"resource": "health", "action": "read"}
],
"inherits": []
}
]
}/etc/themis/users.json:
{
"users": [
{
"user_id": "alice@example.com",
"roles": ["admin"],
"attributes": {
"department": "IT",
"location": "DE"
}
},
{
"user_id": "bob@example.com",
"roles": ["operator"],
"attributes": {
"department": "Operations"
}
},
{
"user_id": "charlie@example.com",
"roles": ["analyst", "readonly"],
"attributes": {
"department": "Analytics"
}
}
]
}#include "security/rbac.h"
using namespace themis::security;
// RBAC initialisieren
RBACConfig config;
config.config_path = "/etc/themis/rbac.json";
config.enable_role_inheritance = true;
config.enable_resource_wildcards = true;
RBAC rbac(config);
// User-Role Store laden
UserRoleStore users;
users.load("/etc/themis/users.json");// Benutzer-Rollen abrufen
auto user_roles = users.getUserRoles("alice@example.com");
// => ["admin"]
// Permission prüfen
bool can_write = rbac.checkPermission(user_roles, "data", "write");
// => true (admin hat *)
user_roles = users.getUserRoles("charlie@example.com");
// => ["analyst", "readonly"]
can_write = rbac.checkPermission(user_roles, "data", "write");
// => false (analyst hat nur read)
bool can_read = rbac.checkPermission(user_roles, "data", "read");
// => true (analyst hat read)// Neue Rolle definieren
Role custom_role;
custom_role.name = "data_engineer";
custom_role.description = "Data engineer with ETL permissions";
custom_role.permissions = {
{"data", "read"},
{"data", "write"},
{"data", "bulk_export"}
};
custom_role.inherits = {"analyst"};
rbac.addRole(custom_role);
// Speichern
rbac.saveConfig("/etc/themis/rbac.json");// Rolle zuweisen
users.assignRole("dave@example.com", "data_engineer");
// Rolle entziehen
users.revokeRole("dave@example.com", "readonly");
// Speichern
users.save("/etc/themis/users.json");auto user_roles = users.getUserRoles("bob@example.com");
auto permissions = rbac.getUserPermissions(user_roles);
for (const auto& perm : permissions) {
std::cout << perm.toString() << "\n";
// data:read
// data:write
// keys:rotate
// audit:read (inherited from analyst)
// metrics:read (inherited from readonly)
// ...
}#include "server/auth_middleware.h"
#include "security/rbac.h"
// RBAC initialisieren
auto rbac = std::make_shared<RBAC>(rbac_config);
auto users = std::make_shared<UserRoleStore>();
users->load("/etc/themis/users.json");
// In HTTP Handler
auto authorize_rbac = [rbac, users](const std::string& user_id,
const std::string& resource,
const std::string& action) -> bool {
auto roles = users->getUserRoles(user_id);
return rbac->checkPermission(roles, resource, action);
};
// Beispiel: Data-Zugriff autorisieren
if (!authorize_rbac(auth_result.user_id, "data", "write")) {
return json_error(403, "Forbidden: Insufficient permissions");
}// GET /api/rbac/roles - Liste alle Rollen
server.route("GET", "/api/rbac/roles", [&rbac](auto req) {
auto roles = rbac->listRoles();
return json_response({{"roles", roles}});
});
// GET /api/rbac/roles/:name - Rollendetails
server.route("GET", "/api/rbac/roles/:name", [&rbac](auto req) {
auto role = rbac->getRole(req.params["name"]);
if (!role) {
return json_error(404, "Role not found");
}
return json_response(role->toJson());
});
// POST /api/rbac/roles - Rolle erstellen
server.route("POST", "/api/rbac/roles", [&rbac](auto req) {
auto role = Role::fromJson(req.body);
rbac->addRole(role);
rbac->saveConfig("/etc/themis/rbac.json");
return json_response({{"ok", true}}, 201);
});
// DELETE /api/rbac/roles/:name - Rolle löschen
server.route("DELETE", "/api/rbac/roles/:name", [&rbac](auto req) {
rbac->removeRole(req.params["name"]);
rbac->saveConfig("/etc/themis/rbac.json");
return json_response({{"ok", true}});
});
// GET /api/rbac/users/:user_id/roles - Benutzer-Rollen
server.route("GET", "/api/rbac/users/:user_id/roles", [&users](auto req) {
auto roles = users->getUserRoles(req.params["user_id"]);
return json_response({{"user_id", req.params["user_id"]}, {"roles", roles}});
});
// POST /api/rbac/users/:user_id/roles - Rolle zuweisen
server.route("POST", "/api/rbac/users/:user_id/roles", [&users](auto req) {
auto role = req.body["role"].get<std::string>();
users->assignRole(req.params["user_id"], role);
users->save("/etc/themis/users.json");
return json_response({{"ok", true}});
});- Beschreibung: Voller Systemzugriff
-
Permissions:
*:*(alle Ressourcen, alle Aktionen) - Erbt: -
- Beschreibung: Daten- und Schlüsselverwaltung
-
Permissions:
-
data:read,data:write,data:delete -
keys:read,keys:rotate audit:read
-
- Erbt: analyst
- Beschreibung: Read-only Datenzugriff
-
Permissions:
data:readaudit:readmetrics:read
- Erbt: readonly
- Beschreibung: Minimaler Read-Access
-
Permissions:
metrics:readhealth:read
- Erbt: -
| Ressource | Beschreibung | Typische Aktionen |
|---|---|---|
data |
Datenbankdaten |
read, write, delete, bulk_export
|
keys |
Verschlüsselungsschlüssel |
read, create, rotate, delete
|
config |
Systemkonfiguration |
read, write
|
audit |
Audit-Logs | read |
metrics |
Metriken/Monitoring | read |
health |
Health-Check | read |
users |
Benutzerverwaltung |
read, write, delete
|
roles |
Rollenverwaltung |
read, write, delete
|
* |
Wildcard: Alle Ressourcen | - |
| Aktion | Beschreibung |
|---|---|
read |
Lesezugriff |
write |
Schreibzugriff (Erstellen/Ändern) |
delete |
Löschen |
create |
Explizites Erstellen |
rotate |
Schlüsselrotation |
bulk_export |
Massenexport |
* |
Wildcard: Alle Aktionen |
Weise Benutzern nur die minimal notwendigen Rollen zu:
// ❌ Schlecht: Zu viele Rechte
users.assignRole("analyst@example.com", "admin");
// ✅ Gut: Nur notwendige Rechte
users.assignRole("analyst@example.com", "analyst");Definiere spezifische Rollen, die von generischen erben:
{
"name": "data_scientist",
"permissions": [
{"resource": "models", "action": "read"},
{"resource": "models", "action": "train"}
],
"inherits": ["analyst"] // Erbt data:read, audit:read, etc.
}Überprüfe regelmäßig User-Role-Assignments:
// Alle Benutzer mit Admin-Rolle
auto admins = users.getRoleUsers("admin");
for (const auto& user_id : admins) {
THEMIS_INFO("Admin user: {}", user_id);
}// Rolle zuweisen + Audit Log
users.assignRole(user_id, role);
audit_logger.logSecurityEvent(
SecurityEventType::ROLE_CHANGED,
admin_user_id,
user_id,
{{"role", role}, {"action", "assigned"}}
);Trenne kritische Rollen:
// ❌ Schlecht: Eine Person hat alle Rollen
users.assignRole("alice@example.com", "admin");
users.assignRole("alice@example.com", "auditor");
// ✅ Gut: Verschiedene Personen
users.assignRole("alice@example.com", "admin");
users.assignRole("bob@example.com", "auditor");Problem: Benutzer hat Rolle, aber Permission-Check schlägt fehl.
Diagnose:
auto user = users.getUser("alice@example.com");
if (!user) {
THEMIS_ERROR("User not found");
}
auto roles = user->roles;
THEMIS_INFO("User roles: {}", fmt::join(roles, ", "));
auto permissions = rbac.getUserPermissions(roles);
for (const auto& perm : permissions) {
THEMIS_INFO("Permission: {}", perm.toString());
}Lösungen:
- Rolle existiert nicht →
rbac.getRole(role_name) - Rollenhierarchie zyklisch →
rbac.validateRoleHierarchy() - Permission falsch geschrieben → Groß-/Kleinschreibung prüfen
Problem: Rolle A erbt von B, B erbt von A.
Lösung:
bool valid = rbac.validateRoleHierarchy();
if (!valid) {
auto hierarchy = rbac.getRoleHierarchy();
THEMIS_ERROR("Invalid role hierarchy: {}", hierarchy.dump(2));
}Problem: loadConfig() schlägt fehl.
Lösung:
# Dateipfad prüfen
ls -la /etc/themis/rbac.json
# Berechtigungen
sudo chmod 644 /etc/themis/rbac.json
sudo chown themis:themis /etc/themis/rbac.json
# JSON-Syntax validieren
jq . /etc/themis/rbac.json- Permission Check: O(R × P) mit R=Rollen, P=Permissions pro Rolle
- Typischer Fall: < 1ms für 10 Rollen, 50 Permissions
- Caching: In-memory, keine Datenbankabfragen
// Permission-Cache (optional)
std::unordered_map<std::string, bool> perm_cache;
std::string cache_key = user_id + ":" + resource + ":" + action;
if (perm_cache.count(cache_key)) {
return perm_cache[cache_key];
}
bool allowed = rbac.checkPermission(roles, resource, action);
perm_cache[cache_key] = allowed;
return allowed;Hinweis: Cache-Invalidierung bei Rollenänderungen beachten!
- Nutze RBAC für Zugriffskontrolle auf personenbezogene Daten
- Definiere
pii:read,pii:write,pii:deletePermissions - Audit Log für alle RBAC-Änderungen
- Segregation of Duties durch separate Rollen
- Least Privilege Principle
- Audit Trail für Rollenänderungen
- PHI-Zugriff nur für autorisierte Rollen
-
phi:read,phi:writePermissions - Regelmäßige Access Reviews
Vorher (Scopes):
auth.addToken({"token123", "alice@example.com", {"admin", "config:write"}});Nachher (RBAC):
// Scopes → Rollen mappen
users.assignRole("alice@example.com", "admin");
// Permission-Check statt Scope-Check
if (!rbac.checkPermission(users.getUserRoles(user_id), "config", "write")) {
return json_error(403, "Forbidden");
}ThemisDB v1.3.4 | GitHub | Documentation | Discussions | License
Last synced: January 02, 2026 | Commit: 6add659
Version: 1.3.0 | Stand: Dezember 2025
- Übersicht
- Home
- Dokumentations-Index
- Quick Reference
- Sachstandsbericht 2025
- Features
- Roadmap
- Ecosystem Overview
- Strategische Übersicht
- Geo/Relational Storage
- RocksDB Storage
- MVCC Design
- Transaktionen
- Time-Series
- Memory Tuning
- Chain of Thought Storage
- Query Engine & AQL
- AQL Syntax
- Explain & Profile
- Rekursive Pfadabfragen
- Temporale Graphen
- Zeitbereichs-Abfragen
- Semantischer Cache
- Hybrid Queries (Phase 1.5)
- AQL Hybrid Queries
- Hybrid Queries README
- Hybrid Query Benchmarks
- Subquery Quick Reference
- Subquery Implementation
- Content Pipeline
- Architektur-Details
- Ingestion
- JSON Ingestion Spec
- Enterprise Ingestion Interface
- Geo-Processor Design
- Image-Processor Design
- Hybrid Search Design
- Fulltext API
- Hybrid Fusion API
- Stemming
- Performance Tuning
- Migration Guide
- Future Work
- Pagination Benchmarks
- Enterprise README
- Scalability Features
- HTTP Client Pool
- Build Guide
- Implementation Status
- Final Report
- Integration Analysis
- Enterprise Strategy
- Verschlüsselungsstrategie
- Verschlüsselungsdeployment
- Spaltenverschlüsselung
- Encryption Next Steps
- Multi-Party Encryption
- Key Rotation Strategy
- Security Encryption Gap Analysis
- Audit Logging
- Audit & Retention
- Compliance Audit
- Compliance
- Extended Compliance Features
- Governance-Strategie
- Compliance-Integration
- Governance Usage
- Security/Compliance Review
- Threat Model
- Security Hardening Guide
- Security Audit Checklist
- Security Audit Report
- Security Implementation
- Development README
- Code Quality Pipeline
- Developers Guide
- Cost Models
- Todo Liste
- Tool Todo
- Core Feature Todo
- Priorities
- Implementation Status
- Roadmap
- Future Work
- Next Steps Analysis
- AQL LET Implementation
- Development Audit
- Sprint Summary (2025-11-17)
- WAL Archiving
- Search Gap Analysis
- Source Documentation Plan
- Changefeed README
- Changefeed CMake Patch
- Changefeed OpenAPI
- Changefeed OpenAPI Auth
- Changefeed SSE Examples
- Changefeed Test Harness
- Changefeed Tests
- Dokumentations-Inventar
- Documentation Summary
- Documentation TODO
- Documentation Gap Analysis
- Documentation Consolidation
- Documentation Final Status
- Documentation Phase 3
- Documentation Cleanup Validation
- API
- Authentication
- Cache
- CDC
- Content
- Geo
- Governance
- Index
- LLM
- Query
- Security
- Server
- Storage
- Time Series
- Transaction
- Utils
Vollständige Dokumentation: https://makr-code.github.io/ThemisDB/