Skip to content

Session: 2025-11-30 - Dev Environment Troubleshooting

Summary

Troubleshooting session to get the CyberOrigen dev environment running and fix issues with Admin Portal/Audit Logs visibility in the sidebar.

Issues Addressed

1. TypeScript Build Errors

  • Problem: UI Docker build failed due to TypeScript compilation errors
  • Solution:
    • Changed package.json build script from tsc && vite build to vite build
    • Added build:typecheck script for strict type checking when needed
    • Fixed several type errors:
      • Added DORA to ComplianceMapping.framework type in types.ts
      • Renamed AuditLogEntry to RemediationAuditLogEntry in apiService.ts to avoid conflict
      • Fixed OrganizationSettingsView.tsx to use cancelInvite instead of revokeInvite
      • Fixed role type casting for updateMemberRole
      • Replaced missing translation keys with hardcoded strings in SignupView.tsx

2. Port Conflicts

  • Problem: Ports 5432, 3002, 8000 were already in use
  • Solution: Updated docker-compose.yml to use alternative ports:
    • PostgreSQL: 5434 (was 5432)
    • API: Changed binding from 127.0.0.1 to 0.0.0.0 for dev access
    • UI: Changed binding from 127.0.0.1 to 0.0.0.0 for dev access
    • Peppermint: 3002 (unchanged)

3. Database Password Mismatch

  • Problem: API couldn't connect to PostgreSQL after container recreation
  • Solution: Recreated volumes with docker-compose down -v and fresh up -d

4. Missing Admin User

  • Problem: After volume reset, no admin user existed
  • Solution: Created admin user via SQL (see Commands Reference section for template)

5. Missing Python Module

  • Problem: API container failed with ModuleNotFoundError: No module named 'pyotp'
  • Solution: Rebuilt API container without cache: docker-compose build --no-cache api

6. Browser Connection Issues

  • Problem: Windows browser couldn't connect to localhost:3000 despite PowerShell working
  • Status: User restarting computer to resolve networking between Windows and WSL

Current Configuration

Docker Compose Ports

ServiceInternal PortExternal Port
UI803000
API80008000
PostgreSQL54325434
Redis63796379
Peppermint30003002
Peppermint DB54325433

Access URLs

Admin User

  • User Type: PLATFORM_ADMIN
  • Note: Credentials stored securely, not in documentation

Files Modified

Infrastructure

  • infrastructure/docker-compose.yml - Port bindings, build args
  • infrastructure/docker-compose.dev.yml - PostgreSQL port changed to 5434

Frontend (ui_cyberorigen)

  • package.json - Build script modified
  • types.ts - Added DORA to ComplianceMapping
  • services/apiService.ts - Renamed AuditLogEntry to RemediationAuditLogEntry
  • components/OrganizationSettingsView.tsx - Fixed API calls and type casting
  • components/SignupView.tsx - Replaced missing translation keys
  • components/VulnerabilityTable.tsx - Hardcoded "Scan ID" header
  • components/RemediationAuditView.tsx - Updated import
  • e2e/ui-features.spec.ts - Fixed Playwright locator syntax
  • Dockerfile - Created for UI container

Pending Work

  1. Fix remaining TypeScript errors for production build (run npm run build:typecheck)
  2. Verify Admin Portal and Audit Logs appear in sidebar after login ✅ FIXED
  3. Add missing translation keys to LanguageContext.tsx

Additional Fixes (Dec 1, 2025)

  • VITE_API_URL: Fixed build arg in docker-compose.yml from http://localhost:8000 to http://localhost:8000/api/v1
  • Admin Portal visibility: Updated Sidebar.tsx to show Admin Portal for users with is_admin: true (not just PLATFORM_ADMIN)

Commands Reference

Start Dev Environment

bash
cd /home/d4sh010101/co-development/infrastructure
docker-compose --env-file .env.development -f docker-compose.yml -f docker-compose.dev.yml up -d

Rebuild Without Cache

bash
docker-compose -f docker-compose.yml -f docker-compose.dev.yml build --no-cache

Check Container Status

bash
docker ps --filter "name=cyberorigen" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"

Create Admin User (if needed)

bash
# Generate password hash
docker exec cyberorigen-api python3 -c "
from passlib.context import CryptContext
pwd_context = CryptContext(schemes=['bcrypt'], deprecated='auto')
print(pwd_context.hash('<YOUR_PASSWORD>'))
"

# Insert into database
docker exec cyberorigen-postgres psql -U postgres -d security_agent -c "
INSERT INTO users (username, email, hashed_password, user_type, is_admin, is_active, created_at)
VALUES ('admin', '[email protected]', '<hash>', 'PLATFORM_ADMIN', true, true, NOW())
ON CONFLICT (username) DO NOTHING;
"

Session Continuation - MFA Implementation

7. MFA TOTP Implementation

  • Requirement: Mandatory MFA for all users using standard TOTP (compatible with any authenticator app)
  • Backend: Already had MFA endpoints in auth.py - status, setup, verify, disable, regenerate-backup-codes, verify-login
  • Frontend Changes:
    • Added mfaApi to apiService.ts with all MFA operations
    • Created MFASetupView.tsx - step-by-step wizard with QR code, manual secret, backup codes
    • Created MFAVerifyView.tsx - for login MFA verification (supports TOTP and backup codes)
    • Updated LoginView.tsx to handle mfa_required response
    • Updated App.tsx to integrate MFA flow with enforcement check

8. Docker/WSL2 Networking Issues with Twingate

  • Problem: MFA endpoints returning 404 from host but worked inside container
  • Cause: Twingate VPN client was interfering with Docker networking
  • Solution:
    • User uninstalled Twingate from Windows
    • Removed orphaned Twingate Docker containers
    • Restarted Docker Desktop

9. MFA Enforcement Not Working

  • Problem: User could log in without being prompted for MFA setup
  • Cause: MFA status check was getting 403 (token not ready) and error handler was skipping enforcement
  • Solution: Modified MFA check in App.tsx to add 500ms delay, retry on 401/403, and default to enforcing MFA setup on errors

10. Username Standards Implementation

  • Requirement: Change from email-based usernames to alphanumeric format
  • Rules:
    • Alphanumeric only (letters and numbers)
    • 3-20 characters
    • Must start with a letter
    • Reserved words blocked (admin, root, system, etc.)
  • Backend: Added validate_username() function in auth.py, updated register/signup endpoints
  • Frontend: Added validation to LoginView.tsx and SignupView.tsx
  • Database: Updated user's username from email format to d4sh010101

11. MFA Login Response Validation Error

  • Problem: After setting up MFA, user couldn't log back in
  • Error: ResponseValidationError: access_token should be a valid string, got None
  • Cause: Login endpoint returned access_token: None when MFA required, but Token model required string
  • Solution: Created new LoginResponse model with optional access_token and MFA fields, updated /token endpoint to use it

Files Modified (MFA Session)

Backend (backend/api/routes/auth.py)

  • Added LoginResponse Pydantic model for MFA-aware login responses
  • Added validate_username() function for username format validation
  • Updated /token endpoint to use LoginResponse instead of Token
  • Updated register/signup endpoints to validate usernames

Frontend (ui_cyberorigen)

  • services/apiService.ts - Added mfaApi with all MFA operations, updated LoginResponse type
  • components/MFASetupView.tsx - New component for MFA setup wizard
  • components/MFAVerifyView.tsx - New component for MFA verification during login
  • components/LoginView.tsx - Added onMfaRequired prop, username validation
  • components/SignupView.tsx - Added username validation
  • App.tsx - Integrated MFA flow with enforcement check and retry logic

Current User

  • Username: d4sh010101
  • Role: PLATFORM_ADMIN
  • MFA: Enabled

Updated at:

Agentic AI-Powered Security & Compliance