The authentication system in Hallucinate App is built around UCAN (User Controlled Authorization Networks) principles, providing a decentralized and capability-based security model. This enables secure access control across all decentralized components.
-
Auth Manager (
auth.js
,auth.py
)- Implementation of UCAN-based authentication with capability verification
- Management of principals, capabilities, and delegations
- Support for both production and mock implementations for development
-
Keystore (
keystore.js
,keystore.py
)- Secure storage for API keys with encryption
- Key rotation and lifecycle management
- Integration with platform-specific secure storage mechanisms
-
Auth-Keystore Integration (
auth_keystore_integration.js
,auth_keystore_integration.py
)- Capability-based access control for API keys
- Authorized key management operations
- Secure credential rotation workflows
-
Secure Module Managers
- Capability verification for resource operations
- Granular access control to sensitive operations
- Security audit logging
The application implements a capability-based security model where:
- Principals: Entities that can issue and receive capabilities (users, services)
- Capabilities: Permissions granted to principals (e.g.,
model:load
,key:access
) - Resources: Target objects for capabilities (e.g., specific models, datasets)
- Delegations: Transfer of capabilities between principals
Example capabilities:
{
can: "model:load",
with: "bert-base-uncased"
}
- Principals are created and capabilities are issued to them
- Capabilities are encoded as UCAN tokens with cryptographic verification
- Operations require presenting a valid capability token
- Tokens are verified before allowing access to protected resources
- Capabilities can be delegated to other principals with restrictions
The application features a comprehensive security dashboard that provides:
- Principal Management: Create and manage security principals
- Capability Management: Issue, revoke, and monitor capabilities
- API Key Management: Securely store, rotate, and manage API keys
- Security Testing: Built-in tests for all security components
- Status Monitoring: Real-time view of the security system status
When extending the application:
- Always verify capabilities before allowing access to protected resources
- Never hardcode API keys - always use the keystore with proper capability verification
- Follow the principle of least privilege when issuing capabilities
- Implement audit logging for all security-sensitive operations
- Regularly rotate credentials using the secure rotation workflows
All modules requiring authentication or handling sensitive data should:
- Accept an auth token parameter in their API methods
- Verify the token's capabilities before performing operations
- Log security events for audit purposes
- Use the resource pool to access authentication services
Example integration pattern:
async function loadModel(modelId, options = {}) {
// Verify capability token
if (!options.authToken) {
throw new Error('Authentication required');
}
const hasCapability = await authManager.verifyCapability(
options.authToken,
{ can: 'model:load', with: modelId }
);
if (!hasCapability) {
throw new Error('Unauthorized: missing required capability');
}
// Proceed with authorized operation
// ...
}
The application includes automated tests for all security components. Run the security tests:
- From the dashboard using the "Security Tests" button
- Through the test handler using:
testHandler.testModule('auth')
- Directly from test scripts:
npm run test:security
Planned security enhancements include:
- Integration with decentralized identity systems (DIDs)
- Support for federated authentication across multiple nodes
- Enhanced audit logging and security analytics
- Integration with external key management systems