feat(auth): user session isolation with JWT auth and RBAC (closes #13)#42
Open
mudassaralichouhan wants to merge 1 commit into
Open
Conversation
- Added user management functionality, including user registration, login, and JWT-based authentication.
- Introduced password hashing using PBKDF2-HMAC-SHA256 for secure password storage.
- Implemented Base64URL encoding/decoding for JWT segments.
- Enhanced CrawlerManager to support user ownership for crawl sessions, allowing only owners or admins to access their sessions.
- Updated CMakeLists.txt to include new authentication source files.
- Added comprehensive tests for authentication features, ensuring robustness and security.
These changes significantly improve the security and usability of the application by implementing a structured user authentication system.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an authentication subsystem (users, password hashing, JWT) and
enforces per-user ownership on crawl sessions, with role-based
access control (
USER,ADMIN). Sessions created by user A areinvisible to user B; admins see everyone's.
Closes #13
Acceptance criteria (from the issue)
CrawlSessionis linked to auserIdArchitecture
New module:
search_engine/authUser.hUserstruct,Roleenum (USER / ADMIN),AuthContextvalue typeUserStore.hIUserStoreinterface + thread-safeInMemoryUserStorePasswordHasher.{h,cpp}iter$saltB64$hashB64. 100k iterations by default; verify embeds the iteration count so existing hashes keep workingBase64Url.hJwt.{h,cpp}JwtIssuer/verifybacked by OpenSSL HMAC-SHA256. Claims:sub,username,role,iat,exp. Constant-time signature compare. Secret fromJWT_SECRETenv var with a noisy dev fallbackAPI endpoints (
AuthController)/api/auth/register{username, password, role?}→201 {id, username, role}(409 on duplicate; 8+ char password)/api/auth/login{username, password}→{token, tokenType, user}(same 401 for unknown user or bad password to prevent enumeration)/api/auth/meAuthController::extractAuth(req)static helper reads theAuthorization: Bearer …header and resolves it to anAuthContextfor use by other controllers.
SearchController gating
POST /api/crawl/add-site— requires Bearer; authenticated userbecomes the session owner.
stopPreviousSessionsonly affectssessions visible to the caller.
GET /api/crawl/status— requires Bearer; non-admin callers seeonly their own sessions.
Examples