-
Notifications
You must be signed in to change notification settings - Fork 186
Fix NPE on null user in RP code path #4421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Darshit Chanpura <[email protected]>
brianf-aws
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for providing the fix! Do we need any backport labels?
Lets also monitor the CI.
| new OpenSearchStatusException( | ||
| "User " | ||
| + user.getName() | ||
| + (user == null ? null : user.getName()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If user is null and model group is public, does the user have access or not ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no.. null users are not granted access..
if you are talking from anonymous user login perspective then yes since anonymous users can access resource in two ways:
- Resource is shared with anonymous user or backend role (https://github.com/opensearch-project/security/blob/9e6047f99da4df3404e2d52f3afe4e49e508c3a5/src/main/java/org/opensearch/security/auth/BackendRegistry.java#L480)
- Resource is marked as public by following the new convention (https://github.com/opensearch-project/security/blob/main/RESOURCE_SHARING_AND_ACCESS_CONTROL.md#example-publicly-shared-resource)
WalkthroughThis pull request adds null-safety checks when constructing error messages for denied model group access. The change prevents potential NullPointerException when a user object is null by wrapping Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
@ylwu-amzn @dhrubo-os Can we get this merged into 3.4? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
plugin/src/main/java/org/opensearch/ml/helper/ModelAccessControlHelper.java (2)
109-109: Null-safety fix prevents NPE in error message construction.The ternary operator correctly guards against NPE when
useris null. This fix addresses the issue described in the PR whereUser.getName()was being invoked on a null user object in the resource authorization code path.However, the error message will now contain "User null is not authorized" which may not be the most user-friendly message for operators debugging access issues.
Consider using a more descriptive identifier for null users:
- + (user == null ? null : user.getName()) + + (user == null ? "<anonymous>" : user.getName())This would produce "User <anonymous> is not authorized" instead of "User null is not authorized", making the error message clearer for troubleshooting.
Also applies to: 185-185
176-176: Remove unnecessary blank line.This blank line doesn't add meaningful separation and can be removed to maintain consistency with the rest of the codebase.
- if (shouldUseResourceAuthz(ML_MODEL_GROUP_RESOURCE_TYPE)) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
plugin/src/main/java/org/opensearch/ml/helper/ModelAccessControlHelper.java(3 hunks)plugin/src/test/java/org/opensearch/ml/helper/ModelAccessControlHelperTests.java(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
plugin/src/test/java/org/opensearch/ml/helper/ModelAccessControlHelperTests.java (2)
common/src/main/java/org/opensearch/ml/common/CommonValue.java (1)
CommonValue(14-150)common/src/main/java/org/opensearch/ml/common/ResourceSharingClientAccessor.java (1)
ResourceSharingClientAccessor(13-42)
🔇 Additional comments (1)
plugin/src/test/java/org/opensearch/ml/helper/ModelAccessControlHelperTests.java (1)
490-552: Comprehensive test coverage for null-safety fix.These two test methods properly validate the null-safety fix in both scenarios:
- When
useris null, the error message correctly contains "User null is not authorized"- When
useris present, the error message correctly contains the actual usernameThe tests follow the existing patterns in the test class and properly clean up by resetting the
ResourceSharingClientto avoid side effects on other tests.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4421 +/- ##
============================================
+ Coverage 80.22% 80.25% +0.03%
- Complexity 10245 10259 +14
============================================
Files 858 858
Lines 44552 44552
Branches 5158 5160 +2
============================================
+ Hits 35742 35756 +14
+ Misses 6639 6624 -15
- Partials 2171 2172 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
Resolves NPE thrown when user is null and RP code path is executed:
We are updating migrate API such that all resources with no owners will now have a "default_owner" to be supplied upon calling migrate API.
(opensearch-project/security#5789)
These resources will not have public access by default. Instead will have to be shared publicly.
Related Issues
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.