opensearch-project / security

🔐 Secure your cluster with TLS, numerous authentication backends, data masking, audit logging as well as role-based access control on indices, documents, and fields
https://opensearch.org/docs/latest/security-plugin/index/
Apache License 2.0
180 stars 263 forks source link

Fix NPE getting metaFields from mapperService on a close index request #4497

Closed cwperks closed 1 day ago

cwperks commented 3 days ago

Description

Fixes a NullPointerException that occurs on a Closed index request. This fixes an issue seen after the merge of https://github.com/opensearch-project/security/pull/4370 which made a change to get the list of metaFields from the mapperService in core. On close index requests, indexService.mapperService() can return null so the call to indexService.mapperService().getMetadataFields() throws an NPE.

This fix checks for Close index requests and handles the scenario accordingly. Closed indices are not searchable so there's no need to have a list of metaFields for a closed index.

The close index API operation closes an index. Once an index is closed, you cannot add data to it or search for any data within the index.

Ref: https://opensearch.org/docs/latest/api-reference/index-apis/close-index/

Bug fix

Issues Resolved

Check List

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.

codecov[bot] commented 3 days ago

Codecov Report

Attention: Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 65.21%. Comparing base (6dedfb4) to head (0a6cde9).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/opensearch-project/security/pull/4497/graphs/tree.svg?width=650&height=150&src=pr&token=rBpySfQXMt&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project)](https://app.codecov.io/gh/opensearch-project/security/pull/4497?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project) ```diff @@ Coverage Diff @@ ## main #4497 +/- ## ========================================== - Coverage 65.21% 65.21% -0.01% ========================================== Files 313 313 Lines 22047 22053 +6 Branches 3559 3561 +2 ========================================== + Hits 14378 14381 +3 - Misses 5895 5897 +2 - Partials 1774 1775 +1 ``` | [Files](https://app.codecov.io/gh/opensearch-project/security/pull/4497?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project) | Coverage Δ | | |---|---|---| | [...figuration/SecurityFlsDlsIndexSearcherWrapper.java](https://app.codecov.io/gh/opensearch-project/security/pull/4497?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fopensearch%2Fsecurity%2Fconfiguration%2FSecurityFlsDlsIndexSearcherWrapper.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=opensearch-project#diff-c3JjL21haW4vamF2YS9vcmcvb3BlbnNlYXJjaC9zZWN1cml0eS9jb25maWd1cmF0aW9uL1NlY3VyaXR5RmxzRGxzSW5kZXhTZWFyY2hlcldyYXBwZXIuamF2YQ==) | `91.66% <70.00%> (-5.96%)` | :arrow_down: |
opensearch-trigger-bot[bot] commented 1 day ago

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/security/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/security/backport-2.x
# Create a new branch
git switch --create backport/backport-4497-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 34da6e86fbcdaf2b87a3dadf33e1c53e425b280e
# Push it to GitHub
git push --set-upstream origin backport/backport-4497-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/security/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-4497-to-2.x.