missing RBAC #2286

Merged
mfreeman451 merged 1 commit from refs/pull/2286/head into main 2025-10-06 00:22:12 +00:00
mfreeman451 commented 2025-10-06 00:22:04 +00:00 (Migrated from github.com)
Owner

Imported from GitHub pull request.

Original GitHub pull request: #1714
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/1714
Original created: 2025-10-06T00:22:04Z
Original updated: 2025-10-06T00:23:25Z
Original head: carverauto/serviceradar:core/auth_issue
Original base: main
Original merged: 2025-10-06T00:22:12Z by @mfreeman451

PR Type

Enhancement


Description

  • Add comprehensive RBAC (Role-Based Access Control) system

  • Upgrade JWT library to v5 for enhanced security

  • Configure role-based route protection for API endpoints

  • Define user roles and granular permissions structure


Diagram Walkthrough

flowchart LR
  A["JWT v4"] --> B["JWT v5"]
  C["Basic Auth"] --> D["RBAC System"]
  D --> E["User Roles"]
  D --> F["Role Permissions"]
  D --> G["Route Protection"]
  E --> H["admin/operator/viewer"]
  F --> I["Granular API Access"]
  G --> J["Protected Endpoints"]

File Walkthrough

Relevant files
Dependencies
go.mod
Upgrade JWT library dependency                                                     

go.mod

  • Add golang-jwt/jwt/v5 v5.2.2 dependency for enhanced JWT handling
+1/-0     
go.sum
Update dependency checksums                                                           

go.sum

  • Add checksums for golang-jwt/jwt/v5 v5.2.2 package
+2/-0     
Enhancement
configmap.yaml
Implement RBAC configuration system                                           

k8s/demo/base/configmap.yaml

  • Add comprehensive RBAC configuration with user roles mapping
  • Define role permissions for admin, operator, and viewer roles
  • Configure route protection for API endpoints with HTTP method-specific
    access
  • Implement granular access control for config, devices, and alerts APIs
+33/-0   

Imported from GitHub pull request. Original GitHub pull request: #1714 Original author: @mfreeman451 Original URL: https://github.com/carverauto/serviceradar/pull/1714 Original created: 2025-10-06T00:22:04Z Original updated: 2025-10-06T00:23:25Z Original head: carverauto/serviceradar:core/auth_issue Original base: main Original merged: 2025-10-06T00:22:12Z by @mfreeman451 --- ### **PR Type** Enhancement ___ ### **Description** - Add comprehensive RBAC (Role-Based Access Control) system - Upgrade JWT library to v5 for enhanced security - Configure role-based route protection for API endpoints - Define user roles and granular permissions structure ___ ### Diagram Walkthrough ```mermaid flowchart LR A["JWT v4"] --> B["JWT v5"] C["Basic Auth"] --> D["RBAC System"] D --> E["User Roles"] D --> F["Role Permissions"] D --> G["Route Protection"] E --> H["admin/operator/viewer"] F --> I["Granular API Access"] G --> J["Protected Endpoints"] ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Dependencies</strong></td><td><table> <tr> <td> <details> <summary><strong>go.mod</strong><dd><code>Upgrade JWT library dependency</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> go.mod - Add golang-jwt/jwt/v5 v5.2.2 dependency for enhanced JWT handling </details> </td> <td><a href="https://github.com/carverauto/serviceradar/pull/1714/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6">+1/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> <tr> <td> <details> <summary><strong>go.sum</strong><dd><code>Update dependency checksums</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> go.sum - Add checksums for golang-jwt/jwt/v5 v5.2.2 package </details> </td> <td><a href="https://github.com/carverauto/serviceradar/pull/1714/files#diff-3295df7234525439d778f1b282d146a4f1ff6b415248aaac074e8042d9f42d63">+2/-0</a>&nbsp; &nbsp; &nbsp; </td> </tr> </table></td></tr><tr><td><strong>Enhancement</strong></td><td><table> <tr> <td> <details> <summary><strong>configmap.yaml</strong><dd><code>Implement RBAC configuration system</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> k8s/demo/base/configmap.yaml <ul><li>Add comprehensive RBAC configuration with user roles mapping<br> <li> Define role permissions for admin, operator, and viewer roles<br> <li> Configure route protection for API endpoints with HTTP method-specific <br>access<br> <li> Implement granular access control for config, devices, and alerts APIs</ul> </details> </td> <td><a href="https://github.com/carverauto/serviceradar/pull/1714/files#diff-f4548beaa0a3a01a46971c82c5647a0f3f49eb38d66dd939d06d19018173fcd6">+33/-0</a>&nbsp; &nbsp; </td> </tr> </table></td></tr></tr></tbody></table> </details> ___
qodo-code-review[bot] commented 2025-10-06 00:22:27 +00:00 (Migrated from github.com)
Author
Owner

Imported GitHub PR comment.

Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1714#issuecomment-3369555421
Original created: 2025-10-06T00:22:27Z

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
Insecure secret management

Description: Hardcoded placeholder secrets (jwt_secret and a bcrypt hash placeholder) in config may be
accidentally deployed if not replaced, leading to weak or predictable authentication.
configmap.yaml [125-129]

Referred Code
"jwt_secret": "PLACEHOLDER_WILL_BE_REPLACED",
"jwt_expiration": "24h",
"local_users": {
  "admin": "PLACEHOLDER_BCRYPT_HASH_WILL_BE_REPLACED"
},
Overly permissive authorization

Description: Broad wildcard route patterns and permissive role permissions (e.g., admin: [""],
device:
, alert:*) risk unintended access if the enforcement layer matches routes or
actions too loosely.
configmap.yaml [141-160]

Referred Code
"route_protection": {
  "/api/admin/*": ["admin"],
  "/api/config/*": {
    "GET": ["viewer", "operator", "admin"],
    "POST": ["operator", "admin"],
    "PUT": ["operator", "admin"],
    "DELETE": ["admin"]
  },
  "/api/devices/*": {
    "GET": ["viewer", "operator", "admin"],
    "POST": ["operator", "admin"],
    "PUT": ["operator", "admin"],
    "DELETE": ["admin"]
  },
  "/api/alerts/*": {
    "GET": ["viewer", "operator", "admin"],
    "POST": ["operator", "admin"],
    "PUT": ["operator", "admin"],
    "DELETE": ["admin"]
  }
Inconsistent JWT validation

Description: Adding github.com/golang-jwt/jwt/v5 alongside existing v4 checksums suggests mixed usage;
if tokens are validated with differing libs or algorithms, it may enable bypass due to
inconsistent verification.
go.mod [74-74]

Referred Code
github.com/golang-jwt/jwt/v5 v5.2.2 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
No custom compliance provided

Follow the guide to enable custom compliance check.

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
- Requires Further Human Verification
🏷️ - Compliance label
Imported GitHub PR comment. Original author: @qodo-code-review[bot] Original URL: https://github.com/carverauto/serviceradar/pull/1714#issuecomment-3369555421 Original created: 2025-10-06T00:22:27Z --- ## PR Compliance Guide 🔍 <!-- https://github.com/carverauto/serviceradar/commit/ef70e00a53af8cf5c72e8bb92ab6323b9112593f --> Below is a summary of compliance checks for this PR:<br> <table><tbody><tr><td colspan='2'><strong>Security Compliance</strong></td></tr> <tr><td rowspan=3>⚪</td> <td><details><summary><strong>Insecure secret management </strong></summary><br> <b>Description:</b> Hardcoded placeholder secrets (<code>jwt_secret</code> and a bcrypt hash placeholder) in config may be <br>accidentally deployed if not replaced, leading to weak or predictable authentication.<br> <strong><a href='https://github.com/carverauto/serviceradar/pull/1714/files#diff-f4548beaa0a3a01a46971c82c5647a0f3f49eb38d66dd939d06d19018173fcd6R125-R129'>configmap.yaml [125-129]</a></strong><br> <details open><summary>Referred Code</summary> ```yaml "jwt_secret": "PLACEHOLDER_WILL_BE_REPLACED", "jwt_expiration": "24h", "local_users": { "admin": "PLACEHOLDER_BCRYPT_HASH_WILL_BE_REPLACED" }, ``` </details></details></td></tr> <tr><td><details><summary><strong>Overly permissive authorization </strong></summary><br> <b>Description:</b> Broad wildcard route patterns and permissive role permissions (e.g., <code>admin: ["*"]</code>, <br><code>device:*</code>, <code>alert:*</code>) risk unintended access if the enforcement layer matches routes or <br>actions too loosely.<br> <strong><a href='https://github.com/carverauto/serviceradar/pull/1714/files#diff-f4548beaa0a3a01a46971c82c5647a0f3f49eb38d66dd939d06d19018173fcd6R141-R160'>configmap.yaml [141-160]</a></strong><br> <details open><summary>Referred Code</summary> ```yaml "route_protection": { "/api/admin/*": ["admin"], "/api/config/*": { "GET": ["viewer", "operator", "admin"], "POST": ["operator", "admin"], "PUT": ["operator", "admin"], "DELETE": ["admin"] }, "/api/devices/*": { "GET": ["viewer", "operator", "admin"], "POST": ["operator", "admin"], "PUT": ["operator", "admin"], "DELETE": ["admin"] }, "/api/alerts/*": { "GET": ["viewer", "operator", "admin"], "POST": ["operator", "admin"], "PUT": ["operator", "admin"], "DELETE": ["admin"] } ``` </details></details></td></tr> <tr><td><details><summary><strong>Inconsistent JWT validation </strong></summary><br> <b>Description:</b> Adding <code>github.com/golang-jwt/jwt/v5</code> alongside existing v4 checksums suggests mixed usage; <br>if tokens are validated with differing libs or algorithms, it may enable bypass due to <br>inconsistent verification.<br> <strong><a href='https://github.com/carverauto/serviceradar/pull/1714/files#diff-33ef32bf6c23acb95f5902d7097b7a1d5128ca061167ec0716715b0b9eeaa5f6R74-R74'>go.mod [74-74]</a></strong><br> <details open><summary>Referred Code</summary> ```txt github.com/golang-jwt/jwt/v5 v5.2.2 // indirect github.com/gorilla/securecookie v1.1.2 // indirect ``` </details></details></td></tr> <tr><td colspan='2'><strong>Ticket Compliance</strong></td></tr> <tr><td>⚪</td><td><details><summary>🎫 <strong>No ticket provided </summary></strong> - [ ] Create ticket/issue <!-- /create_ticket --create_ticket=true --> </details></td></tr> <tr><td colspan='2'><strong>Codebase Duplication Compliance</strong></td></tr> <tr><td>⚪</td><td><details><summary><strong>Codebase context is not defined </strong></summary> Follow the <a href='https://qodo-merge-docs.qodo.ai/core-abilities/rag_context_enrichment/'>guide</a> to enable codebase context checks. </details></td></tr> <tr><td colspan='2'><strong>Custom Compliance</strong></td></tr> <tr><td>⚪</td><td><details><summary><strong>No custom compliance provided</strong></summary> Follow the <a href='https://qodo-merge-docs.qodo.ai/tools/compliance/'>guide</a> to enable custom compliance check. </details></td></tr> <tr><td align="center" colspan="2"> <!-- placeholder --> <!-- /compliance --update_compliance=true --> </td></tr></tbody></table> <details><summary>Compliance status legend</summary> 🟢 - Fully Compliant<br> 🟡 - Partial Compliant<br> 🔴 - Not Compliant<br> ⚪ - Requires Further Human Verification<br> 🏷️ - Compliance label<br> </details>
qodo-code-review[bot] commented 2025-10-06 00:23:25 +00:00 (Migrated from github.com)
Author
Owner

Imported GitHub PR comment.

Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1714#issuecomment-3369556635
Original created: 2025-10-06T00:23:25Z

PR Code Suggestions

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
High-level
Decouple API routes from roles

Modify the RBAC configuration to map API routes to permissions instead of
directly to roles. This change decouples the route structure from the role
definitions, making the system more flexible and easier to maintain.

Examples:

k8s/demo/base/configmap.yaml [141-161]
            "route_protection": {
              "/api/admin/*": ["admin"],
              "/api/config/*": {
                "GET": ["viewer", "operator", "admin"],
                "POST": ["operator", "admin"],
                "PUT": ["operator", "admin"],
                "DELETE": ["admin"]
              },
              "/api/devices/*": {
                "GET": ["viewer", "operator", "admin"],

 ... (clipped 11 lines)

Solution Walkthrough:

Before:

# configmap.yaml
...
"rbac": {
  "role_permissions": {
    "operator": ["config:read", "config:write", ...],
    "viewer": ["config:read", "device:read", ...]
  },
  "route_protection": {
    "/api/config/*": {
      "GET": ["viewer", "operator", "admin"],
      "POST": ["operator", "admin"]
    },
    ...
  }
}

After:

# configmap.yaml
...
"rbac": {
  "role_permissions": {
    "operator": ["config:read", "config:write", ...],
    "viewer": ["config:read", "device:read", ...]
  },
  "route_permissions": { # Renamed from route_protection
    "/api/config/*": {
      "GET": "config:read",
      "POST": "config:write"
    },
    ...
  }
}

Suggestion importance[1-10]: 9

__

Why: This is a critical architectural suggestion that addresses a fundamental design flaw in the new RBAC system, significantly improving its scalability and maintainability by decoupling routes from roles.

High
Security
Refine operator permissions for consistency

To align with route protections and the principle of least privilege, replace
wildcard permissions for the operator role with explicit read and write
permissions for device and alert.

k8s/demo/base/configmap.yaml [138]

-"operator": ["config:read", "config:write", "device:*", "alert:*"],
+"operator": ["config:read", "config:write", "device:read", "device:write", "alert:read", "alert:write"],
  • Apply / Chat
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies an inconsistency between the operator role's wildcard permissions and the specific route_protection rules, which deny delete access. Applying this change enhances security and configuration clarity.

Medium
General
Remove redundant role assignments

Remove the redundant operator and viewer roles from the admin user's role list,
as the admin role already grants all permissions via a wildcard.

k8s/demo/base/configmap.yaml [132]

-"admin": ["admin", "operator", "viewer"],
+"admin": ["admin"],
  • Apply / Chat
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly identifies that assigning operator and viewer roles to the admin user is redundant because the admin role already has wildcard permissions. This change improves configuration clarity and maintainability.

Low
  • More
Imported GitHub PR comment. Original author: @qodo-code-review[bot] Original URL: https://github.com/carverauto/serviceradar/pull/1714#issuecomment-3369556635 Original created: 2025-10-06T00:23:25Z --- ## PR Code Suggestions ✨ <!-- ef70e00 --> Explore these optional code suggestions: <table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=1>High-level</td> <td> <details><summary>Decouple API routes from roles</summary> ___ **Modify the RBAC configuration to map API routes to permissions instead of <br>directly to roles. This change decouples the route structure from the role <br>definitions, making the system more flexible and easier to maintain.** ### Examples: <details> <summary> <a href="https://github.com/carverauto/serviceradar/pull/1714/files#diff-f4548beaa0a3a01a46971c82c5647a0f3f49eb38d66dd939d06d19018173fcd6R141-R161">k8s/demo/base/configmap.yaml [141-161]</a> </summary> ```yaml "route_protection": { "/api/admin/*": ["admin"], "/api/config/*": { "GET": ["viewer", "operator", "admin"], "POST": ["operator", "admin"], "PUT": ["operator", "admin"], "DELETE": ["admin"] }, "/api/devices/*": { "GET": ["viewer", "operator", "admin"], ... (clipped 11 lines) ``` </details> ### Solution Walkthrough: #### Before: ```yaml # configmap.yaml ... "rbac": { "role_permissions": { "operator": ["config:read", "config:write", ...], "viewer": ["config:read", "device:read", ...] }, "route_protection": { "/api/config/*": { "GET": ["viewer", "operator", "admin"], "POST": ["operator", "admin"] }, ... } } ``` #### After: ```yaml # configmap.yaml ... "rbac": { "role_permissions": { "operator": ["config:read", "config:write", ...], "viewer": ["config:read", "device:read", ...] }, "route_permissions": { # Renamed from route_protection "/api/config/*": { "GET": "config:read", "POST": "config:write" }, ... } } ``` <details><summary>Suggestion importance[1-10]: 9</summary> __ Why: This is a critical architectural suggestion that addresses a fundamental design flaw in the new RBAC system, significantly improving its scalability and maintainability by decoupling routes from roles. </details></details></td><td align=center>High </td></tr><tr><td rowspan=1>Security</td> <td> <details><summary>Refine operator permissions for consistency</summary> ___ **To align with route protections and the principle of least privilege, replace <br>wildcard permissions for the <code>operator</code> role with explicit <code>read</code> and <code>write</code> <br>permissions for <code>device</code> and <code>alert</code>.** [k8s/demo/base/configmap.yaml [138]](https://github.com/carverauto/serviceradar/pull/1714/files#diff-f4548beaa0a3a01a46971c82c5647a0f3f49eb38d66dd939d06d19018173fcd6R138-R138) ```diff -"operator": ["config:read", "config:write", "device:*", "alert:*"], +"operator": ["config:read", "config:write", "device:read", "device:write", "alert:read", "alert:write"], ``` - [ ] **Apply / Chat** <!-- /improve --apply_suggestion=1 --> <details><summary>Suggestion importance[1-10]: 8</summary> __ Why: The suggestion correctly identifies an inconsistency between the `operator` role's wildcard permissions and the specific `route_protection` rules, which deny delete access. Applying this change enhances security and configuration clarity. </details></details></td><td align=center>Medium </td></tr><tr><td rowspan=1>General</td> <td> <details><summary>Remove redundant role assignments</summary> ___ **Remove the redundant <code>operator</code> and <code>viewer</code> roles from the <code>admin</code> user's role list, <br>as the <code>admin</code> role already grants all permissions via a wildcard.** [k8s/demo/base/configmap.yaml [132]](https://github.com/carverauto/serviceradar/pull/1714/files#diff-f4548beaa0a3a01a46971c82c5647a0f3f49eb38d66dd939d06d19018173fcd6R132-R132) ```diff -"admin": ["admin", "operator", "viewer"], +"admin": ["admin"], ``` - [ ] **Apply / Chat** <!-- /improve --apply_suggestion=2 --> <details><summary>Suggestion importance[1-10]: 5</summary> __ Why: The suggestion correctly identifies that assigning `operator` and `viewer` roles to the `admin` user is redundant because the `admin` role already has wildcard permissions. This change improves configuration clarity and maintainability. </details></details></td><td align=center>Low </td></tr> <tr><td align="center" colspan="2"> - [ ] More <!-- /improve --more_suggestions=true --> </td><td></td></tr></tbody></table>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
carverauto/serviceradar!2286
No description provided.