Authentication
Bud Stack uses a comprehensive authentication system built on Keycloak and JWT tokens. This guide covers how authentication works, password policies, session management, and how to configure authentication settings via Helm.Authentication Overview
System Architecture
Bud Stack’s authentication system consists of:- Keycloak: Enterprise-grade identity and access management
- JWT Tokens: Secure, stateless authentication tokens
- Redis/Valkey: Token blacklist and session state
- budapp Service: Authentication logic and token management
Authentication Flow
- User submits credentials (email + password)
- budapp validates credentials with Keycloak
- Keycloak returns access and refresh tokens
- Tokens are stored securely in browser
- Access token auto-refreshes every 5 minutes
- Session expires after 30 minutes of inactivity
All authentication happens over HTTPS with industry-standard encryption. Passwords are never stored in plain text.
Login Requirements
Required Fields
When logging in, users must provide:| Field | Description | Validation |
|---|---|---|
| User’s registered email address | Must be valid email format | |
| Password | User’s password | Must meet password policy |
| User Type | Account type (ADMIN or CLIENT) | Must match actual user type |
User Type Enforcement
- Security Feature: User type must match the account’s actual type
- Prevents Privilege Escalation: Users cannot login as a different type
- Types:
ADMIN: Platform administratorsCLIENT: Regular users
Email Validation
Emails must:- Be in valid email format (user@domain.com)
- Be registered in the system
- Be associated with an active account
Password Policy
Password Requirements
All passwords must meet the following criteria:- Minimum Length: 8 characters
- Uppercase: At least 1 uppercase letter (A-Z)
- Lowercase: At least 1 lowercase letter (a-z)
- Digit: At least 1 number (0-9)
- Special Character: At least 1 special character (!@#$%^&*)
- No Whitespace: Cannot contain spaces or tabs
Password Security
Hashing & Storage:- Passwords are never stored in plain text
- Salted with
PASSWORD_SALTenvironment variable - Hashed using industry-standard algorithms
- Only the hash is stored in the database
First-Time Login & Password Reset
Forced Password Reset Flow
When a user must reset their password (first login or admin-initiated reset):-
Login Attempt
- User logs in with temporary password
- Receives successful authentication
-
Reset Flag Detection
- Response includes
"is_reset_password": true - Frontend detects this flag
- Response includes
-
Automatic Redirect
- User is redirected to password reset page
- Cannot access platform until password is changed
-
Set New Password
- User enters new password meeting all requirements
- Password is updated in both Keycloak and local database
-
Return to Login
- User logs in with new password
- Full access granted
When Password Reset is Required
Password reset is forced when:- First Login: Administrator creates account with temporary password
- Admin Action: Administrator resets user password
Password Reset via Email
Users can request password reset:- Click “Forgot Password” on login page
- Enter registered email address
- Receive password reset link via email
- Link valid for limited time
- Set new password and return to login
Session Management
Session Duration
Bud Stack uses a multi-tiered session system:| Component | Duration | Description |
|---|---|---|
| Access Token | 5 minutes | Used for API authentication |
| Token Auto-Refresh | Automatic | Seamless token renewal |
| Active Session | 30 minutes | From last user activity |
| Refresh Token | 7 days (default) | Maximum session lifespan |
How Sessions Work
1. Initial Login- User logs in successfully
- Receives access token (5-minute lifespan)
- Receives refresh token (7-day lifespan)
- Session timer starts at 30 minutes
- Access token auto-refreshes every 5 minutes
- Each interaction extends session timeout
- User stays logged in while active
- After 30 minutes of no activity
- Session expires automatically
- User must log in again
- Even with continuous activity
- Session ends after refresh token expires (7 days default)
- User must log in again for new session
Sessions are managed client-side with tokens stored in browser localStorage. Each device maintains independent sessions.
Session Expiration
Automatic Logout Triggers:- 30 minutes of inactivity
- Refresh token expiration (7 days)
- Manual logout by user
- Token invalidation by administrator
- Access token becomes invalid
- Refresh token cannot renew access
- User redirected to login page
- Must authenticate again
Token Blacklisting
On Logout:- Access token added to Redis blacklist
- Blacklist entry expires when token would naturally expire
- Prevents token reuse after logout
- Refresh token invalidated in Keycloak
- Stored in Redis/Valkey (fast lookup)
- TTL matches remaining token lifetime
- Automatic expiration and cleanup
- Checked on every authenticated request
Configuring Authentication in Helm
Token Lifetime Configuration
Authentication settings are configured via Helm values. You can customize token lifetimes for different environments.Application Token Settings
Configure budapp service token lifetimes: File:values.yaml or environment-specific file (e.g., values.production.yaml)
Security Features
Rate Limiting
Authentication endpoints have rate limits to prevent abuse:| Endpoint | Rate Limit | Window |
|---|---|---|
/auth/login | 10 requests | Per minute per IP |
/auth/register | 3 requests | Per 10 minutes per IP |
/auth/refresh-token | 20 requests | Per minute per user |
- HTTP 429 (Too Many Requests) response
Retry-Afterheader indicates wait time- Temporary block (1-10 minutes depending on endpoint)
Audit Logging
All authentication events are logged: Logged Events:- Login attempts (successful and failed)
- Password changes
- Password reset requests
- Token refreshes
- Logout events
- Account lockouts
- Timestamp
- User email
- IP address
- User agent
- Success/failure status
- Failure reason (if applicable)
Audit logs are stored in the database and can be viewed in the User Activity section for compliance and security monitoring.
Token Blacklist
Implementation:- Redis/Valkey for high-performance lookup
- Blacklist checked on every authenticated request
- Automatic expiration matching token lifetime
- Prevents token replay attacks
- Access tokens on logout
- Tokens from revoked sessions
- Tokens from deleted users
- Tokens from password changes
Troubleshooting
Common Issues
Session expires too quickly- Check
ACCESS_TOKEN_EXPIRE_MINUTESsetting - Verify
REFRESH_TOKEN_EXPIRE_MINUTESconfiguration - Review Keycloak session timeout settings
- Check Redis/Valkey is running and accessible
- Verify
JWT_SECRET_KEYis set correctly - Ensure refresh token hasn’t exceeded max lifespan
- Verify email service is configured
- Check Keycloak realm
resetPasswordAllowedis true - Review email delivery logs
- Check Keycloak brute force protection settings
- Reduce
failureFactorif too strict - Adjust
maxFailureWaitSecondsfor shorter lockouts
Related Documentation
Additional Resources
- Keycloak Documentation
- JWT.io - JWT token decoder
- SOPS - Secret encryption
- Helm Values Files
For security concerns or questions about authentication configuration, contact your system administrator or Bud Stack support at contact@bud.studio.