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

Support .opensearch-knn-model index as system index with security enabled #827

Conversation

martin-gaievski
Copy link
Member

@martin-gaievski martin-gaievski commented Mar 29, 2023

Description

With this change plugin's integ tests can be execute in remote cluster with enabled security plugin. It will work with latest security plugin code, we don't need to repeat opensearch-project/security#2480 similarly to 2.6 branch/release.

Main implemented ideas are:

  • setup https client using pre-generated certificates (certificates and https setup and settings are copied from AD)
  • do not delete our model system index, only cleanup all docs and models
  • user permissions are elevated temporarily on backend side by stashing thread context in model related operations
  • test logic has been changed to use model APIs instead of direct upload to training index

Issues Resolved

opensearch-project/security#2265

Check List

  • New functionality includes testing.
    • All tests pass
  • Commits are signed as 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.

@martin-gaievski martin-gaievski added Infrastructure Changes to infrastructure, testing, CI/CD, pipelines, etc. backport 2.x v2.7.0 labels Mar 29, 2023
@martin-gaievski martin-gaievski force-pushed the support-integ-tests-on-secured-cluster branch from 871e286 to ed83707 Compare March 29, 2023 00:36
@codecov-commenter
Copy link

codecov-commenter commented Mar 29, 2023

Codecov Report

Merging #827 (47c667c) into main (59cc733) will increase coverage by 0.03%.
The diff coverage is 96.61%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@             Coverage Diff              @@
##               main     #827      +/-   ##
============================================
+ Coverage     85.14%   85.18%   +0.03%     
- Complexity     1079     1081       +2     
============================================
  Files           151      151              
  Lines          4370     4394      +24     
  Branches        390      390              
============================================
+ Hits           3721     3743      +22     
- Misses          472      474       +2     
  Partials        177      177              
Impacted Files Coverage Δ
...main/java/org/opensearch/knn/indices/ModelDao.java 82.67% <96.61%> (+0.93%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@martin-gaievski
Copy link
Member Author

martin-gaievski commented Mar 30, 2023

checks for this PR will fail until we get fresh distribution build, current blocker is security plugin, PR is opensearch-project/security#2608

@martin-gaievski martin-gaievski marked this pull request as ready for review March 30, 2023 16:34
@martin-gaievski martin-gaievski requested a review from a team March 30, 2023 16:34
@jmazanec15
Copy link
Member

we don't need to repeat opensearch-project/security#2480 similarly to 2.6 branch/release.

What do you mean by this? I think we need to revert this for 2.x until we add special access to system index in code.


@Override
protected RestClient getClient() {
return adminClient();
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we should use admin client for all requests.

Copy link
Member Author

Choose a reason for hiding this comment

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

let me check, if there will be more case where normal client is enough I'll update the logic and use admin client only where needed

String indexName = (String) index.get("index");
final String indexName = (String) index.get("index");
if (isIndexCleanupRequired(indexName)) {
wipeIndexContent(MODEL_INDEX_NAME);
Copy link
Member

Choose a reason for hiding this comment

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

Why is MODEL_INDEX_NAME used here and not indexName?

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

assertNull(statsMap.get(StatNames.MODEL_INDEX_STATUS.getName()));
// Check that model health status is null since model index is not created to system yet
assertNull(statsMap.get(StatNames.MODEL_INDEX_STATUS.getName()));
}

createModelSystemIndex();
Copy link
Member

Choose a reason for hiding this comment

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

May be we should move this line of code into the if condition as we want to create it when it doesn't exist

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

@martin-gaievski
Copy link
Member Author

opensearch-project/security#2480

I did development/testing on main of security plugin, that does have opensearch-project/security#2274. That was my understanding, that we need to keep model index as system and make tests work.

If we revert the security plugin change then I think it will just work, model index became normal index

@martin-gaievski martin-gaievski force-pushed the support-integ-tests-on-secured-cluster branch from ce86540 to 75a772c Compare April 1, 2023 00:29
@@ -178,6 +178,7 @@ dependencies {
testImplementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.14.2'
testImplementation group: 'org.objenesis', name: 'objenesis', version: '3.2'
testImplementation group: 'net.bytebuddy', name: 'byte-buddy-agent', version: '1.14.2'
api "org.opensearch:common-utils:${version}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why we need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

GetResponse getResponse = getRequestBuilder.execute().get();
Map<String, Object> responseMap = getResponse.getSourceAsMap();
return Model.getModelFromSourceMap(responseMap);
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please add some comment which can explain what we want to achieve here? I also don't see the usage of context variable. May be I am missing something here.

Copy link
Member Author

@martin-gaievski martin-gaievski Apr 3, 2023

Choose a reason for hiding this comment

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

ack, also variable assignment is required by Java

@@ -404,8 +407,10 @@ public void get(String modelId, ActionListener<GetModelResponse> actionListener)
*/
@Override
public void search(SearchRequest request, ActionListener<SearchResponse> actionListener) {
request.indices(MODEL_INDEX_NAME);
client.search(request, actionListener);
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above

modelDao.delete(modelID, listener);
} catch (Exception e) {
logger.error(e);
listener.onFailure(e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we do this then do we need above line where we are logging the error?

Copy link
Member Author

Choose a reason for hiding this comment

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

probably not needed, checked k-NN implementations, we log exception with the proper error message in there https://github.com/martin-gaievski/k-NN/blob/support-integ-tests-on-secured-cluster/src/main/java/org/opensearch/knn/index/KNNSettings.java#L412. Will remove in revision

@martin-gaievski martin-gaievski force-pushed the support-integ-tests-on-secured-cluster branch from 7095ec8 to 60681e6 Compare April 3, 2023 18:07
CHANGELOG.md Outdated
@@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* Add CHANGELOG ([#800](https://github.com/opensearch-project/k-NN/pull/800))
* Bump byte-buddy version from 1.12.22 to 1.14.2 ([#804](https://github.com/opensearch-project/k-NN/pull/804))
* Bump numpy version from 1.22.x to 1.24.2 ([#811](https://github.com/opensearch-project/k-NN/pull/811))
* Add support for integ tests on secured cluster ([#827](https://github.com/opensearch-project/k-NN/pull/827))
Copy link
Member

Choose a reason for hiding this comment

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

Change this to "Support .opensearch-knn-model index as system index with security enabled"

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

// temporary setting thread context to default, this is needed to allow actions on model system index
// when security plugin is enabled
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
client.execute(
Copy link
Member

Choose a reason for hiding this comment

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

This doesnt touch the model system index. Is this needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

);
// temporary setting thread context to default, this is needed to allow actions on model system index
// when security plugin is enabled
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesnt touch the model system index. Is this still needed?

@@ -583,59 +624,76 @@ private void updateModelGraveyardToDelete(
StepListener<AcknowledgedResponse> step,
Optional<Exception> exception
) {
// temporary setting thread context to default, this is needed to allow actions on model system index
// when security plugin is enabled
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
Copy link
Member

Choose a reason for hiding this comment

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

This doesnt touch the model system index. Is this still needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

updated modelDao, removed context stashes where we access metadata

@martin-gaievski martin-gaievski changed the title Add support for integ tests on secured cluster Support .opensearch-knn-model index as system index with security enabled Apr 3, 2023
@martin-gaievski martin-gaievski force-pushed the support-integ-tests-on-secured-cluster branch from 27e70ad to d426aea Compare April 3, 2023 23:02
@martin-gaievski martin-gaievski force-pushed the support-integ-tests-on-secured-cluster branch 2 times, most recently from de3e487 to 0fc30b9 Compare April 4, 2023 00:46
@martin-gaievski martin-gaievski force-pushed the support-integ-tests-on-secured-cluster branch 2 times, most recently from a5100ef to fb1111d Compare April 4, 2023 21:01
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
…ng calls

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
Signed-off-by: Martin Gaievski <gaievski@amazon.com>

Fixing issues related to exception handling

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
@martin-gaievski martin-gaievski force-pushed the support-integ-tests-on-secured-cluster branch from fb1111d to 47c667c Compare April 4, 2023 22:32
Copy link
Member

@jmazanec15 jmazanec15 left a comment

Choose a reason for hiding this comment

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

Looks good to me thanks!

@martin-gaievski martin-gaievski merged commit b94b030 into opensearch-project:main Apr 5, 2023
@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-827-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 b94b030afc74efc1fae5c5c7528edc25974a3fec
# Push it to GitHub
git push --set-upstream origin backport/backport-827-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-827-to-2.x.

@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.7 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.7 2.7
# Navigate to the new working tree
cd .worktrees/backport-2.7
# Create a new branch
git switch --create backport/backport-827-to-2.7
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 b94b030afc74efc1fae5c5c7528edc25974a3fec
# Push it to GitHub
git push --set-upstream origin backport/backport-827-to-2.7
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.7

Then, create a pull request where the base branch is 2.7 and the compare/head branch is backport/backport-827-to-2.7.

martin-gaievski added a commit to martin-gaievski/k-NN that referenced this pull request Apr 5, 2023
…bled (opensearch-project#827)

* Add support for integ tests on secured cluster

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit b94b030)
martin-gaievski added a commit to martin-gaievski/k-NN that referenced this pull request Apr 5, 2023
…bled (opensearch-project#827)

* Add support for integ tests on secured cluster

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit b94b030)
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
martin-gaievski added a commit to martin-gaievski/k-NN that referenced this pull request Apr 5, 2023
…bled (opensearch-project#827)

* Add support for integ tests on secured cluster

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit b94b030)
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
martin-gaievski added a commit to martin-gaievski/k-NN that referenced this pull request Apr 5, 2023
…bled (opensearch-project#827)

* Add support for integ tests on secured cluster

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit b94b030)
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
martin-gaievski added a commit to martin-gaievski/k-NN that referenced this pull request Apr 5, 2023
…bled (opensearch-project#827)

* Add support for integ tests on secured cluster

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit b94b030)
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
martin-gaievski added a commit to martin-gaievski/k-NN that referenced this pull request Apr 5, 2023
…bled (opensearch-project#827)

* Add support for integ tests on secured cluster

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit b94b030)
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
martin-gaievski added a commit to martin-gaievski/k-NN that referenced this pull request Apr 6, 2023
…bled (opensearch-project#827)

* Add support for integ tests on secured cluster

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit b94b030)
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit 99300b1)
martin-gaievski added a commit that referenced this pull request Apr 6, 2023
…bled (#827) (#842)

* Add support for integ tests on secured cluster


(cherry picked from commit b94b030)

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
martin-gaievski added a commit that referenced this pull request Apr 6, 2023
…bled (#827) (#843)

* Add support for integ tests on secured cluster

Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit b94b030)
Signed-off-by: Martin Gaievski <gaievski@amazon.com>
(cherry picked from commit 99300b1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport 2.7 Infrastructure Changes to infrastructure, testing, CI/CD, pipelines, etc. v2.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants