Skip to content

Security: endomorphosis/hallucinate_app

Security

SECURITY.md

Security Architecture in Hallucinate App

Authentication System

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.

Key Components

  1. 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
  2. Keystore (keystore.js, keystore.py)

    • Secure storage for API keys with encryption
    • Key rotation and lifecycle management
    • Integration with platform-specific secure storage mechanisms
  3. 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
  4. Secure Module Managers

    • Capability verification for resource operations
    • Granular access control to sensitive operations
    • Security audit logging

Capability Model

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"
}

Authentication Flow

  1. Principals are created and capabilities are issued to them
  2. Capabilities are encoded as UCAN tokens with cryptographic verification
  3. Operations require presenting a valid capability token
  4. Tokens are verified before allowing access to protected resources
  5. Capabilities can be delegated to other principals with restrictions

Security Dashboard

The application features a comprehensive security dashboard that provides:

  1. Principal Management: Create and manage security principals
  2. Capability Management: Issue, revoke, and monitor capabilities
  3. API Key Management: Securely store, rotate, and manage API keys
  4. Security Testing: Built-in tests for all security components
  5. Status Monitoring: Real-time view of the security system status

Best Practices

When extending the application:

  1. Always verify capabilities before allowing access to protected resources
  2. Never hardcode API keys - always use the keystore with proper capability verification
  3. Follow the principle of least privilege when issuing capabilities
  4. Implement audit logging for all security-sensitive operations
  5. Regularly rotate credentials using the secure rotation workflows

Integration with Other Modules

All modules requiring authentication or handling sensitive data should:

  1. Accept an auth token parameter in their API methods
  2. Verify the token's capabilities before performing operations
  3. Log security events for audit purposes
  4. 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
  // ...
}

Security Testing

The application includes automated tests for all security components. Run the security tests:

  1. From the dashboard using the "Security Tests" button
  2. Through the test handler using: testHandler.testModule('auth')
  3. Directly from test scripts: npm run test:security

Future Enhancements

Planned security enhancements include:

  1. Integration with decentralized identity systems (DIDs)
  2. Support for federated authentication across multiple nodes
  3. Enhanced audit logging and security analytics
  4. Integration with external key management systems

There aren’t any published security advisories