Skip to content

[KAN-66] Enforce role-based access across Cruise microservices - #144

Merged
huytran2005 merged 9 commits into
mainfrom
codex/KAN-66-rbac
Nov 4, 2026
Merged

huytran2005 merged 9 commits into
mainfrom
codex/KAN-66-rbac

Conversation

@hannng4416

@hannng4416 hannng4416 commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Context & Motivation

KAN-66 — Implement Role-Based Access Control, covering KAN-67 through KAN-72.
Internal service APIs previously lacked consistent checks for the eight system roles.
This change enforces permissions even when callers bypass the gateway and use service ports directly.

Technical Changes

  • Immutable role/permission matrix in cruise-common; reject unknown roles and undefined API families.
  • Shared authorization middleware returns 401 for invalid identity, 403 for insufficient permissions and 503 for identity-service outages.
  • Apply authorization to auth, itinerary, activity and POS. Validate JWT signature, issuer, expiry, token type, revocation and current user state through auth access-context verification.
  • Replace spoofable caller-role headers with the verified role. Preserve existing credential/token proof endpoint contracts.
  • Expose administrator role discovery and current-user permission discovery. Persist user creation/deletion audit records in the same transaction; provide deployment SQL.
  • Require an explicit production JWT secret. Keep the filter enabled in domain tests with explicit authenticated fixtures.

Subtasks & Commits Mapping

Subtask Summary Commit Scope
KAN-67 Define roles and permissions 96051dc Backend
KAN-68 Authorization middleware 544d4d1 Backend
KAN-69 Restrict API access and audit identity mutations 6806833 Backend
KAN-70 Permission-rule unit tests ffccb39 Backend
KAN-71 Unauthorized and invalid-token API tests fdd10b6 Backend
KAN-72 Cross-role access tests across four services 1b468a8 Backend

Verification & Test Evidence

  • Local mvn -q test: 1,953 passed; 0 failures, errors or skips across six modules.
  • Local mvn -q -DskipTests package: all modules package successfully.
  • Auth integration tests use real signed JWTs and H2 user state. Domain cross-role tests exercise the production filter and mock only remote identity verification; the introspection client has separate loopback HTTP tests.
  • Java 25, compiler target 21, Maven 3.9.15. Tests ran on 2 November 2026.

Review / Deployment Notes

  • Review the operational role matrix and apply docs/db/KAN-66-identity-audit.sql when schema changes are managed manually.
  • Passenger access is limited to itinerary/catalog until a trusted auth-user-to-passenger ownership mapping exists.
  • Revocation storage remains the existing in-memory implementation; restart-safe/distributed revocation is not claimed.
  • PostgreSQL deployment and browser/staging acceptance remain pending. Current CI verification is recorded in the follow-up below.
  • Companion frontend: the KAN-66 branch in Cruise-JavaCLass/Cruise-web.
  • The three unrelated bugs after the RBAC story in the source document are excluded.

Follow-up: audit null-safety, SonarCloud duplication and current main (3 November 2026)

  • Guard a missing user role in recordIdentityChange: persist UNKNOWN in the audit instead of throwing on .name(). Regression tests cover both create/delete paths with audit enabled; existing-role audit values stay intact.
  • Centralized RBAC filter registration and remote verifier wiring in cruise-common; service configuration classes now import the shared setup.
  • Latest local verification of auth and common: 298 tests passed. Full backend CI on the latest commit: 1,963 tests passed, 0 failures/errors/skips.
  • SonarCloud Quality Gate now passes: new-code duplication 0.0% (previously 3.2%, required ≤3%) and new-code coverage 82.8% (required ≥80%).
  • GitHub Build & Test and SonarCloud Code Analysis pass on final head b31822825e9eced5b7a2d1916bfb87b6a6664568.
  • Merged current main after upstream PRs [CRUI-124] fix: prevent concurrent duplicate open shift creation #142/[KAN-701] fix(auth): support field aliases in verify-password and normalize admin delete roles #143; resolved UserController by retaining upstream role normalization and KAN-66 request validation. No merge conflict remains.
  • The six original task commits remain intact, followed by the review fixes and main synchronization commits. This PR has not been merged; staging remains pending.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5818dd87-a1d4-4bf9-b891-deb3aefba910
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@hannng4416
hannng4416 marked this pull request as ready for review November 3, 2026 03:49
@huytran2005
huytran2005 self-requested a review November 3, 2026 04:14
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@huytran2005
huytran2005 merged commit 0633b9b into main Nov 4, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants