feat(auth): dashboard authentication system (#65)#160
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughДобавлена полноценная email/password аутентификация с GORM-моделями, хранилищами и миграциями, серверными обработчиками/маршрутами и middleware; реализована интеграция forward-auth с Authentik и админская панель + фронтенд-интерфейсы для регистрации, настроек и управления приглашениями/пользователями. Changes
Sequence DiagramsequenceDiagram
participant Client as Клиент
participant Router as Route Guard
participant Auth as Auth Service
participant DB as База данных
participant Authentik as Authentik Proxy
Note over Client,Auth: Email/password login
Client->>Router: POST /api/auth/user-login
Router->>Auth: validateCredentials(email,password)
Auth->>DB: GetUserByEmail(email)
DB-->>Auth: User record
Auth->>Auth: verify bcrypt(password)
Auth->>DB: CreateSession(userID, expires)
DB-->>Auth: Session (id)
Auth->>Client: Set `engram_auth` cookie + 200
Note over Client,Authentik: Authentik forward-auth
Client->>Authentik: Request (via proxy) with X-Authentik-Email
Authentik->>Auth: Forward request
Auth->>Auth: check request IP ∈ trustedProxies
alt trusted and header present
Auth->>DB: GetUserByEmail(headerEmail)
DB-->>Auth: User or nil
alt user not found and auto-provision
Auth->>DB: CreateUser(email, role=operator)
DB-->>Auth: New User
end
Auth->>Auth: set role in context
Auth->>Client: forward allowed
else not trusted or no header
Auth->>Client: forward denied or pass through
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.11.4)Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions Comment |
|
@coderabbitai review focus:security |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 5483 🏁 Script executed: Length of output: 0 🏁 Script executed: Length of output: 11407 🏁 Script executed: Length of output: 7173 🏁 Script executed: Length of output: 57620
Security Review —
|
| # | Severity | File | Issue |
|---|---|---|---|
| 1 | 🔴 Critical | auth_handlers.go |
Rate-limit key includes TCP port |
| 2 | 🟠 High | auth_handlers.go |
engram_auth cookie missing Secure |
| 3 | 🟠 High | middleware.go |
Authentik IPv6 proxy check broken |
| 4 | 🟡 Medium | auth_handlers.go |
loginAttempts map never GC'd |
| 5 | 🟡 Medium | auth_handlers.go |
TOCTOU in setup |
| 6 | 🟡 Medium | middleware.go |
Unsanitised X-Request-ID |
| 7 | 🔵 Low | useAuth.ts / router |
isAdmin false for master-token sessions |
| 8 | 🔵 Low | auth_handlers.go |
No email format validation |
| 9 | 🔵 Low | auth_handlers.go |
SameSite=Lax vs Strict inconsistency |
| 10 | 🔵 Low | auth_handlers.go |
Invitation handler re-reads cookie |
There was a problem hiding this comment.
Code Review
This pull request implements a comprehensive authentication and user management system, including email/password login, invitation-based registration, and Authentik SSO integration. It introduces new database models, stores, and migrations for users, invitations, and sessions, as well as backend handlers and frontend views for setup and administration. Feedback identifies critical error handling gaps in the user update logic that could bypass security checks and suggests improving the UI by replacing disruptive alerts with inline error messages.
…h reactive error state - auth_handlers.go: handle errors from CountAdmins() and GetUserByID() in UpdateUser handler; previously ignored errors could bypass last-admin guard - AdminView.vue: replace alert() calls with usersError/invitationsError reactive refs for consistent declarative error display
Summary
Adds user/password authentication with invitation-based registration and optional Authentik SSO to the engram dashboard. Closes #65.
Backend (6 commits)
Data Model (migration 080)
userstable: email, bcrypt password_hash, role (admin/operator), disabledinvitationstable: single-use registration codes with created_by/used_by trackingsessionstable: DB-backed sessions with expiryAuth Endpoints
POST /api/auth/setup— first-time admin account creationPOST /api/auth/user-login— email/password login with rate limiting (5/min/IP)POST /api/auth/user-logout— session invalidationGET /api/auth/me— current user infoGET /api/auth/setup-needed— check if setup requiredPOST /api/auth/register— invitation-based registrationPOST /api/admin/invitations— generate invitation codes (admin only)GET /api/admin/invitations— list invitations (admin only)GET /api/admin/users— list users without password hashes (admin only)PUT /api/admin/users/{id}— disable/enable/promote/demote (admin only)Middleware
engram_auth) alongside existing token authX-Authentik-Email) with trusted proxy whitelistFrontend (2 commits)
Security
Summary by CodeRabbit