5.6 KiB
Bot Authentication
General Bots implements bot authentication through session-based mechanisms, where bots are associated with user sessions and authenticated through the system.
Overview
Bot authentication in General Bots:
- Bots are registered in the database with unique IDs
- Sessions link users to specific bots
- No separate bot authentication - bots operate within user sessions
- Bot access controlled through user permissions
Bot Registration
Database Storage
Bots are stored in the bots table:
id- UUID primary keyname- Bot nameorg_id- Organization associationcreated_at- Registration timestampupdated_at- Last modification
Bot Configuration
Configuration stored in bot_configuration table:
- Bot-specific settings
- Key-value pairs from config.csv
- Runtime parameters
- Feature flags
Session-Based Bot Access
How It Works
- User authenticates (via Directory Service)
- User selects bot to interact with
- Session created linking user + bot
- All operations scoped to that bot
Session Structure
The user_sessions table structure:
- id: UUID
- user_id: UUID (User reference)
- bot_id: UUID (Bot reference)
- session_token: String
- expires_at: Timestamp
Bot Isolation
Data Isolation
Each bot has isolated:
- Message history
- Bot memories
- Knowledge bases
- Configuration
- Drive bucket
Cross-Bot Protection
- Sessions locked to single bot
- Cannot access other bot's data
- Queries filtered by bot_id
- Storage segregated by bucket
Bot Discovery
Listing Available Bots
Users can access bots based on:
- Organization membership
- Direct assignment
- Public availability
- Role-based access
Bot Selection
When starting conversation:
- List available bots
- User chooses bot
- Session created for that bot
- Bot context loaded
Bot Lifecycle
Creation
Bots created during bootstrap:
- Template found in
templates/ - Bot registered in database
- Configuration loaded
- Resources uploaded to drive storage
- Knowledge base indexed
Activation
Bot becomes active when:
- Registration complete
- Configuration valid
- Resources available
- No critical errors
Updates
Bot updates involve:
- Configuration changes
- Script modifications
- Knowledge base updates
- No authentication changes needed
Bot Permissions
Access Control
Bot access determined by:
- User's organization
- User's role
- Bot visibility settings
- Explicit assignments
Permission Levels
- Public: Anyone can access
- Organization: Org members only
- Private: Specific users only
- Admin: Administrators only
Configuration
Bot Identity
Each bot has in config.csv:
name,value
Bot Name,Customer Service Bot
Bot ID,auto-generated
Organization,org-123
Access Configuration
name,value
Access Level,organization
Allowed Roles,user;admin
Max Sessions,100
Security Considerations
No Bot Credentials
Important: Bots don't have:
- Passwords
- API keys
- Authentication tokens
- Login credentials
All authentication through user sessions.
Bot Impersonation Prevention
- Bots cannot authenticate independently
- Always require user context
- Audit trail through sessions
- No bot-to-bot communication
API Access
Bot Operations via API
All bot operations require user authentication:
// User must be authenticated first
fetch('/api/bot/message', {
headers: {
'Authorization': 'Bearer USER_SESSION_TOKEN'
},
body: JSON.stringify({
bot_id: 'bot-123',
message: 'Hello'
})
})
No Bot API Keys
Bots don't have separate API authentication:
- No bot tokens
- No bot API keys
- No service accounts for bots
- All through user sessions
Multi-Bot Scenarios
Switching Bots
Users can switch between bots:
- End current bot session
- Start new session with different bot
- Context switches to new bot
- History preserved separately
Concurrent Bot Access
Users can have multiple bot sessions:
- Different session IDs
- Separate contexts
- Independent conversations
- Isolated data access
Bot Monitoring
Authentication Metrics
Track bot access patterns:
- Sessions per bot
- User engagement
- Access attempts
- Permission denials
Audit Logging
Log bot interactions:
- Session creation
- Bot selection
- Configuration changes
- Access violations
Best Practices
- Use Organizations: Group bots by organization
- Configure Access Levels: Set appropriate visibility
- Monitor Usage: Track bot access patterns
- Regular Audits: Review bot permissions
- Document Bots: Maintain bot documentation
- Test Isolation: Verify data segregation
Common Issues
Bot Not Accessible
Causes:
- User not in organization
- Insufficient permissions
- Bot not activated
- Configuration error
Session Errors
Issues:
- Expired session
- Invalid bot ID
- Concurrent session limit
- Database connection
Implementation Notes
No Separate Auth Module
Bot authentication is integrated into:
- Session management
- User authentication
- Database queries
- Not a separate system
Future Considerations
Potential enhancements:
- Bot API tokens (not implemented)
- Service accounts (not implemented)
- Bot-to-bot communication (not implemented)
- Webhook authentication (not implemented)
Summary
Bot authentication in General Bots is inherently tied to user authentication. Bots don't authenticate independently but operate within the context of authenticated user sessions. This design ensures security through user-based access control while maintaining simplicity in the authentication model.