Skip to content

Conversation

@YashodhanJoshi1
Copy link
Contributor

Fixes an issue where a native user in non-default account would get 401 for license api call, whereas we want all users to have get access to license call.

@github-actions github-actions bot added the ☢️ Bug Something isn't working label Dec 9, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

Failed to generate code suggestions for PR

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 9, 2025

Greptile Overview

Greptile Summary

Fixed RBAC issue where native users in non-default organizations received 401 errors when accessing the license API endpoint, causing infinite logout loops.

Key Changes:

  • Added import for db::org_users module to access list_orgs_by_user function
  • Implemented special authentication bypass for the "license" path in validate_credentials function
  • When a user is not found for the requested org but the path is "license", the code now checks if the user belongs to any organization using list_orgs_by_user
  • If the user belongs to at least one org, they're granted minimal access (UserRole::User) to view license info

Rationale:
The license endpoint (/license) is designed as an org-agnostic endpoint that should be accessible to any authenticated user across all their organizations (see comment in src/handler/http/request/license/mod.rs:102-104). However, the authentication flow was rejecting native users when they accessed this endpoint from a non-default org context.

Confidence Score: 3/5

  • This PR is mostly safe but has a potential security issue with error handling that should be addressed
  • The change correctly addresses the logout loop issue for native users, but uses unwrap_or_default() which could silently hide database errors and potentially allow unintended access if the database query fails. Additionally, there's a typo in the comment. The logic is sound otherwise and aligns with the intended behavior of the license endpoint.
  • The validator.rs file needs attention for the error handling in the license path check (lines 209-214)

Important Files Changed

File Analysis

Filename Score Overview
src/handler/http/auth/validator.rs 4/5 Added special RBAC handling for license endpoint to allow native users in non-default orgs to access license info without 401 errors

Sequence Diagram

sequenceDiagram
    participant Client
    participant Validator as validate_credentials
    participant UserDB as users::get_user
    participant OrgUsers as org_users::list_orgs_by_user
    participant Response as TokenValidationResponse

    Client->>Validator: Request to /license (from non-default org)
    Validator->>UserDB: get_user(org_id, user_id)
    UserDB-->>Validator: None (user not in this org)
    
    alt path == "license" (NEW)
        Validator->>OrgUsers: list_orgs_by_user(user_id)
        OrgUsers-->>Validator: Vec<UserOrgExpandedRecord>
        
        alt !orgs.is_empty()
            Validator->>Response: Create minimal access response
            Note over Response: is_valid=true<br/>user_role=User<br/>is_internal_user=true
            Validator-->>Client: Allow access (200)
        else orgs.is_empty()
            Validator->>Response: Create invalid response
            Note over Response: is_valid=false
            Validator-->>Client: Unauthorized (401)
        end
    else path != "license" (OLD behavior)
        Validator->>Response: Create invalid response
        Note over Response: is_valid=false
        Validator-->>Client: Unauthorized (401)
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Signed-off-by: Yashodhan Joshi <[email protected]>
YashodhanJoshi1 added a commit that referenced this pull request Dec 9, 2025
#9529 for v0.30.0

---------

Signed-off-by: Yashodhan Joshi <[email protected]>
Co-authored-by: Yashodhan Joshi <[email protected]>
@YashodhanJoshi1 YashodhanJoshi1 merged commit 4780a9e into main Dec 10, 2025
41 checks passed
@YashodhanJoshi1 YashodhanJoshi1 deleted the fix/license_native_rbac branch December 10, 2025 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☢️ Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants