Skip to content
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

fixed security tests #484

Merged
merged 6 commits into from
Feb 10, 2023
Merged

Conversation

raj-chak
Copy link
Contributor

@raj-chak raj-chak commented Jul 6, 2022

Signed-off-by: Raj Chakravarthi [email protected]

Issue #, if available:
#300
#329

Description of changes:

CheckList:
[ ] Commits are signed per the DCO using --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.

@raj-chak raj-chak requested a review from a team July 6, 2022 15:33
@codecov-commenter
Copy link

Codecov Report

Merging #484 (a676235) into main (6a30e6b) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##               main     #484   +/-   ##
=========================================
  Coverage     76.72%   76.72%           
  Complexity      176      176           
=========================================
  Files           166      166           
  Lines          8370     8370           
  Branches       1232     1232           
=========================================
  Hits           6422     6422           
+ Misses         1343     1342    -1     
- Partials        605      606    +1     
Impacted Files Coverage Δ
...rg/opensearch/alerting/BucketLevelMonitorRunner.kt 76.15% <0.00%> (-0.77%) ⬇️
.../kotlin/org/opensearch/alerting/core/JobSweeper.kt 73.20% <0.00%> (-0.48%) ⬇️
...destinationmigration/DestinationConversionUtils.kt 70.00% <0.00%> (ø)
...nationmigration/DestinationMigrationCoordinator.kt 63.82% <0.00%> (+2.12%) ⬆️
...ing/model/destination/DestinationContextFactory.kt 78.57% <0.00%> (+3.57%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us.

@@ -155,19 +155,15 @@ class SecureEmailAccountRestApiIT : AlertingRestTestCase() {
deleteRoleAndRoleMapping(TEST_HR_ROLE)
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Maintain an empty line between tests.

@@ -85,7 +94,6 @@ class SecureMonitorRestApiIT : AlertingRestTestCase() {
}

// Create Monitor related security tests

fun `test create monitor with an user with alerting role`() {

createUserWithTestData(user, TEST_HR_INDEX, TEST_HR_ROLE, TEST_HR_BACKEND_ROLE)
Copy link
Member

Choose a reason for hiding this comment

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

Give the user ALERTING_INDEX_MONITOR_ACCESS cluster permission instead of ALERTING_FULL_ACCESS_ROLE.

Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we also need separate tests for ALERTING_FULL_ACCESS_ROLE
cc: @lezzago

}

// add alerting roles and search as userOne - must return 1 docs
createUserRolesMapping(ALERTING_FULL_ACCESS_ROLE, arrayOf(user))
Copy link
Member

Choose a reason for hiding this comment

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

Use this role instead: ALERTING_SEARCH_MONITOR_ONLY_ACCESS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -809,29 +811,27 @@ class SecureMonitorRestApiIT : AlertingRestTestCase() {
assertEquals("Delete monitor failed", RestStatus.OK, adminDeleteResponse.restStatus())
} finally {
deleteRoleAndRoleMapping(TEST_HR_ROLE)
deleteRoleMapping(ALERTING_FULL_ACCESS_ROLE)
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this a role and not a role mapping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it depends on how we added it. This seems to be correct

Comment on lines 1164 to 1158
var entity = "{\n" +
"\"cluster_permissions\": [\n" +
"\"$clusterPermissions\"\n" +
"],\n" +
"\"index_permissions\": [\n" +
"{\n" +
"\"index_patterns\": [\n" +
"\"$index\"\n" +
"],\n" +
"\"dls\": \"$dlsQuery\",\n" +
"\"fls\": [],\n" +
"\"masked_fields\": [],\n" +
"\"allowed_actions\": [\n" +
"\"crud\"\n" +
"]\n" +
"}\n" +
"],\n" +
"\"tenant_permissions\": []\n" +
"}"
Copy link
Member

Choose a reason for hiding this comment

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

I see duplicate codes for entity creation across the call. Can we abstract out the string construction logic in a helper method. It will provide consistent and simpler way for future additions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -85,7 +94,6 @@ class SecureMonitorRestApiIT : AlertingRestTestCase() {
}

// Create Monitor related security tests

fun `test create monitor with an user with alerting role`() {

createUserWithTestData(user, TEST_HR_INDEX, TEST_HR_ROLE, TEST_HR_BACKEND_ROLE)
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we also need separate tests for ALERTING_FULL_ACCESS_ROLE
cc: @lezzago

Comment on lines 873 to 886
createUser(user, user, arrayOf(TEST_HR_BACKEND_ROLE))
createTestIndex(TEST_HR_INDEX)
createCustomIndexRoleWithDocLevelSecurity(TEST_HR_ROLE, TEST_HR_INDEX, TERM_DLS_QUERY, getClusterPermissionsFromCustomRole(ALERTING_INDEX_MONITOR_ACCESS))
createUserRolesMapping(TEST_HR_ROLE, arrayOf(user))
Copy link
Member

Choose a reason for hiding this comment

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

Do we also need tests to verify cross user accesses such as between UserA and UserB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

different users were used to eliminate issues during parallel execution by the test engine while running tests, probably not required

Signed-off-by: Raj Chakravarthi <[email protected]>
Signed-off-by: Raj Chakravarthi <[email protected]>
@lezzago lezzago changed the base branch from main to 2.x November 2, 2022 20:45
@lezzago lezzago changed the base branch from 2.x to main November 2, 2022 20:45
@lezzago
Copy link
Member

lezzago commented Jan 19, 2023

@raj-chak can you please resolve the conflicts in the PR? Will take a look again after it has been resolved and get it reviewed quick

@deshsidd
Copy link

deshsidd commented Feb 8, 2023

@raj-chak Can we try to fix the tests and work to either merge or close this PR. This has been open for more than 6 months now.

cc @lezzago @getsaurabh02

@raj-chak
Copy link
Contributor Author

raj-chak commented Feb 8, 2023

@raj-chak Can we try to fix the tests and work to either merge or close this PR. This has been open for more than 6 months now.

cc @lezzago @getsaurabh02

yes I resolved conflicts and ran integration tests against a 2.5 docker cluster, they ran successfully. There were issues with build.gradle (mockit 5.1.0 change) and PercolateQueryBuilderExt.java ( org.opensearch.common.SetOnce instead of lucene). will check again

@getsaurabh02
Copy link
Member

@raj-chak Do we know the reason for these test failures?

@lezzago
Copy link
Member

lezzago commented Feb 10, 2023

@raj-chak Do we know the reason for these test failures?

The test failures are existing 3.0 failures coming from core. As the security integration tests pass and the changes are isolated to the security tests, we should know the failures are not caused by the PR.

@lezzago lezzago merged commit c51940f into opensearch-project:main Feb 10, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Feb 10, 2023
* fixed security tests

Signed-off-by: Raj Chakravarthi <[email protected]>
(cherry picked from commit c51940f)
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

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

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-484-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 c51940f5e2d14a00262f7f4675bbba2d930d2ede
# Push it to GitHub
git push --set-upstream origin backport/backport-484-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

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

raj-chak added a commit to raj-chak/alerting that referenced this pull request Feb 14, 2023
* fixed security tests

Signed-off-by: Raj Chakravarthi <[email protected]>
(cherry picked from commit c51940f)
AWSHurneyt pushed a commit that referenced this pull request Feb 14, 2023
* fixed security tests

Signed-off-by: Raj Chakravarthi <[email protected]>
(cherry picked from commit c51940f)
lezzago pushed a commit to lezzago/alerting-opensearch that referenced this pull request Jun 8, 2023
* fixed security tests

Signed-off-by: Raj Chakravarthi <[email protected]>
(cherry picked from commit c51940f)
lezzago added a commit that referenced this pull request Jun 8, 2023
* Added exception check once the .opendistro-alerting-config index is b… (#650)

* Added exception check once the .opendistro-alerting-config index is being created

During .opendistro-alerting-config index creation, if ResourceAlreadyExists exception is being raised, the flow will check first if the index is in yellow state and then it will re-try to index monitor

Signed-off-by: Stevan Buzejic <[email protected]>

* Formating of the file fixed

Signed-off-by: Stevan Buzejic <[email protected]>

Signed-off-by: Stevan Buzejic <[email protected]>

* refactored DeleteMonitor Action to be synchronious (#628) (#630)

* refactored DeleteMonitor Action to be synchronious

Signed-off-by: Petar Dzepina <[email protected]>

Signed-off-by: Petar Dzepina <[email protected]>
Co-authored-by: Petar Dzepina <[email protected]>

* [Backport 2.x] QueryIndex rollover when field mapping limit is reached (#729)

Signed-off-by: Petar Dzepina <[email protected]>

* Mappings fix backport 2.x (#730)

* Added support for "nested" mappings (#645)

* example

Signed-off-by: Petar Dzepina <[email protected]>

* fixed updating mappings for queryIndex

Signed-off-by: Petar Dzepina <[email protected]>

Signed-off-by: Petar Dzepina <[email protected]>

* mappings traversal bug fix (#669)

Signed-off-by: Petar Dzepina <[email protected]>

Signed-off-by: Petar Dzepina <[email protected]>

* Added unwrapping exception from core; added more debug logs (#728)

Signed-off-by: Petar Dzepina <[email protected]>

* Add DataSources test for future backports

Signed-off-by: Ashish Agrawal <[email protected]>

* fix  percolator mapping error when having field name 'type' (#726)

Signed-off-by: Raj Chakravarthi <[email protected]>

* [BUG] ExecuteMonitor inserting metadata doc during dry run (#758)

* execute monitor bugfix

Signed-off-by: Petar Dzepina <[email protected]>

* added IT

Signed-off-by: Petar Dzepina <[email protected]>

* fixed created retval when skipIndex=true

Signed-off-by: Petar Dzepina <[email protected]>

---------

Signed-off-by: Petar Dzepina <[email protected]>

* fix for ERROR alert state generation in doc-level monitors (#768)

Signed-off-by: Subhobrata Dey <[email protected]>

* Adjusting max field index setting dynamically for query index (#776)

* added adjusting max field index setting dynamicly for query index

Signed-off-by: Petar Dzepina <[email protected]>

* Multiple indices support in DocLevelMonitorInput (#784)

Signed-off-by: Petar Dzepina <[email protected]>

* Doc transform 2.x backport (#853)

* conflict resovle - backport from main to 2.x

Signed-off-by: Petar Dzepina <[email protected]>

* fixed module class names

Signed-off-by: Petar Dzepina <[email protected]>

---------

Signed-off-by: Petar Dzepina <[email protected]>

* Update config index schema if needed at the start of each monitor execution (#849)

* Update config index schema if needed at the start of each monitor execution

Signed-off-by: Ashish Agrawal <[email protected]>

* Mappings parsing fix (#851)

* fixed mappings parsing when field name named "properties" exists in mappings

Signed-off-by: Petar Dzepina <[email protected]>

* message typo fix

Signed-off-by: Petar Dzepina <[email protected]>

---------

Signed-off-by: Petar Dzepina <[email protected]>

* [Backport 2.x] Notification security fix (#861)

* Notification security fix (#852)

* added injecting whole user object in threadContext before calling notification APIs so that backend roles are available to notification plugin

Signed-off-by: Petar Dzepina <[email protected]>

* compile fix

Signed-off-by: Petar Dzepina <[email protected]>

* refactored user_info injection to use InjectSecurity

Signed-off-by: Petar Dzepina <[email protected]>

* ktlint fix

Signed-off-by: Petar Dzepina <[email protected]>

---------

Signed-off-by: Petar Dzepina <[email protected]>
(cherry picked from commit e0b7a5a)

* remove unneeded import

Signed-off-by: Ashish Agrawal <[email protected]>

---------

Signed-off-by: Ashish Agrawal <[email protected]>
Co-authored-by: Petar Dzepina <[email protected]>
Co-authored-by: Ashish Agrawal <[email protected]>

* Fixed a bug that prevented alerts from being generated for doc level monitors that use wildcard characters in index names. (#894)

Signed-off-by: AWSHurneyt <[email protected]>

* fixed security tests (#484) (#794)

* fixed security tests

Signed-off-by: Raj Chakravarthi <[email protected]>
(cherry picked from commit c51940f)

---------

Signed-off-by: Stevan Buzejic <[email protected]>
Signed-off-by: Petar Dzepina <[email protected]>
Signed-off-by: Ashish Agrawal <[email protected]>
Signed-off-by: Raj Chakravarthi <[email protected]>
Signed-off-by: Subhobrata Dey <[email protected]>
Signed-off-by: AWSHurneyt <[email protected]>
Co-authored-by: Stevan Buzejic <[email protected]>
Co-authored-by: Surya Sashank Nistala <[email protected]>
Co-authored-by: Petar Dzepina <[email protected]>
Co-authored-by: RAJ CHAKRAVARTHI <[email protected]>
Co-authored-by: Subhobrata Dey <[email protected]>
Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com>
Co-authored-by: AWSHurneyt <[email protected]>
Co-authored-by: RAJ CHAKRAVARTHI <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants