Authentication, authorization, and key management service for NeuralLog, using OpenFGA for fine-grained authorization and Redis for key storage.
NeuralLog Auth provides centralized authentication, authorization, and key management for all NeuralLog services. It uses OpenFGA (Fine-Grained Authorization) with PostgreSQL persistence to implement a robust authorization system that supports multi-tenancy. It also manages Key Encryption Keys (KEKs) for the zero-knowledge architecture, storing encrypted KEK blobs in Redis.
- Multi-tenant Authorization: Secure isolation between tenants with proper namespacing
- Fine-grained Access Control: Control access at the resource level
- Centralized Auth Service: Single source of truth for authorization decisions
- Client SDKs: Easy integration with other services
- Scalable Architecture: Designed for high performance and reliability
- Zero-Knowledge Key Management: Manages encrypted KEK blobs without access to the keys themselves
- Key Rotation: Supports key rotation for enhanced security
- User-specific Key Provisioning: Provisions keys to specific users with appropriate access controls
The auth service consists of:
- Auth API: RESTful API for authentication, authorization, and key management
- OpenFGA: Fine-grained authorization engine
- PostgreSQL: Persistence layer for authorization data
- Redis: Storage for KEK versions and encrypted KEK blobs
- Client SDKs: Libraries for integrating with other services
The key hierarchy in NeuralLog consists of three levels:
-
Master Secret: The root of the key hierarchy, derived from the tenant ID and recovery phrase. This is never stored anywhere and is only used to derive the Master KEK.
-
Master KEK: Derived from the Master Secret, this key is used to encrypt and decrypt Operational KEKs. It is never stored anywhere and is only held in memory during client operations.
-
Operational KEKs: Derived from the Master KEK, these keys are used for actual data encryption and decryption. They are versioned to support key rotation and are stored encrypted in the server for distribution to authorized users.
KEK versions are used to support key rotation and access control. Each KEK version has a unique ID and a status:
- Active: The current version used for encryption and decryption.
- Decrypt-Only: A previous version that can be used for decryption but not for encryption.
- Deprecated: A version that is no longer used and should be phased out.
- Node.js 18+
- Docker and Docker Compose
- PostgreSQL 14+
- Redis 6+
# Clone the repository
git clone https://github.com/your-org/neurallog-auth.git
cd neurallog-auth
# Install dependencies
npm install
# Build the project
npm run build# Start the services
npm run docker:compose:up
# Stop the services
npm run docker:compose:downimport { AuthClient } from '@neurallog/auth-client';
// Initialize the client
const authClient = new AuthClient({
authServiceUrl: 'http://localhost:3040',
tenantId: 'tenant1'
});
// Check if a user has access to a resource
const hasAccess = await authClient.check({
user: 'user:123',
permission: 'read',
resource: 'log:test-log'
});
if (hasAccess) {
// Allow the operation
} else {
// Deny the operation
}import express from 'express';
import { authMiddleware } from '@neurallog/auth-client/middleware';
import { AuthClient } from '@neurallog/auth-client';
const app = express();
const authClient = new AuthClient({
authServiceUrl: 'http://localhost:3040',
tenantId: 'tenant1'
});
// Protect routes with the auth middleware
app.use('/api', authMiddleware(authClient));
app.listen(3000, () => {
console.log('Server started on port 3000');
});POST /api/auth/check- Check if a user has permission to access a resourcePOST /api/auth/grant- Grant a permission to a userPOST /api/auth/revoke- Revoke a permission from a userGET /api/auth/permissions- List permissions for a user or resource
POST /api/tenants- Create a new tenantGET /api/tenants- List all tenantsDELETE /api/tenants/:tenantId- Delete a tenant
GET /kek/versions- Get all KEK versions for the tenantGET /kek/versions/active- Get the active KEK version for the tenantPOST /kek/versions- Create a new KEK versionPUT /kek/versions/:id/status- Update the status of a KEK versionPOST /kek/rotate- Rotate the KEK, creating a new version and optionally removing users
GET /kek/blobs/users/:userId/versions/:versionId- Get a KEK blob for a user and versionGET /kek/blobs/users/:userId- Get all KEK blobs for a userGET /kek/blobs/me- Get all KEK blobs for the current userPOST /kek/blobs- Provision a KEK blob for a userDELETE /kek/blobs/users/:userId/versions/:versionId- Delete a KEK blob
Detailed documentation is available in the docs directory:
For integration guides and tutorials, visit the NeuralLog Documentation Site.
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
MIT
- NeuralLog Server - Core server functionality
- NeuralLog Web - Web interface components
- NeuralLog TypeScript Client SDK - TypeScript client SDK