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

Fork or replace elasticsearch dependencies #114

Closed
5 of 9 tasks
nknize opened this issue Feb 22, 2021 · 25 comments · Fixed by #1332
Closed
5 of 9 tasks

Fork or replace elasticsearch dependencies #114

nknize opened this issue Feb 22, 2021 · 25 comments · Fixed by #1332
Assignees
Labels
distributed framework >FORK Related to the fork process Meta Meta issue, not directly linked to a PR

Comments

@nknize
Copy link
Collaborator

nknize commented Feb 22, 2021

The elasticsearch build relies on the following libraries independently built by elastic.co:

This issue is to track the tasks needed to fork into the following repos:

  • Mirror fork JNA
  • Mirror fork Secure Mock
  • Mirror fork MockSocket

Update the OpenSearch build files for these dependencies

  • server/build.gradle
  • client/rest/build.gradle
  • client/sniffer/build.gradle
  • gradle/local-distribution.gradle
  • test/framework/build.gradle

Remove the exclusions for thirdPartyAudit task

@dblock
Copy link
Member

dblock commented Apr 16, 2021

We've initially forked, but chose to, for now, archive securemock, mocksocket and jna-build and use the existing dependencies.

@dblock dblock changed the title Fork Elasticsearch Dependencies fork or replace elasticsearch dependencies May 28, 2021
@dblock dblock changed the title fork or replace elasticsearch dependencies Fork or replace elasticsearch dependencies May 28, 2021
@VachaShah VachaShah self-assigned this Jul 16, 2021
@VachaShah
Copy link
Collaborator

securemock: The grant permissions feature provided by securemock does not look to be readily available in the new mockito version. We could either upstream the changes to mockito or fork the repo. If we successfully upstream the changes, we would also have to upgrade mockito version in OpenSearch since the version currently being used is 1.9.5.

mocksocket: The grant permissions feature on top of Socket and ServerSocket apis could also either be upstreamed to mockito or something similar that can house it. It could also be implemented as a utility in OpenSearch or the repo could be forked similar to securemock.

@dblock @saratvemulapalli @CEHENKLE thoughts?

@dblock
Copy link
Member

dblock commented Jul 20, 2021

Thanks @VachaShah,

  1. What are these "grant permissions" features used for? Is this something we want in OpenSearch and why?
  2. Assuming we want to keep these features, are they incremental on top of mockito?

If (2) is true, I think we should start by extracting the features into a new OSS library that is dependent on mockito, rather than a fork, so we can have a clear cut dependency. If that's not possible, definitely upstream.

Either way we want to be upgrading mockito, the version used here is ancient.

@VachaShah
Copy link
Collaborator

  1. The grant permissions features are the main features provided by both the repos, for securemock: Allows creating mocks in tests without having to grant dangerous permissions to all of your code and for mocksocket: Allows using sockets without having to grant dangerous permissions to all of your code. They look like useful features but I am open to your thoughts!
  2. For being incremental, the securemock and mocksocket repos are pretty old (last updated about 5 years ago with mockito 1.9.5) so if/when we put it on top of mockito, there might be quite a few changes since we would be using the latest mockito version. For one of the instances, I saw securemock is using some CGLIB functionality but mockito has moved away from it in the newer versions and they now use ByteBuddy. There might be other things as well which might need to be changed.

Definitely agree on upgrading the mockito version!

@dblock
Copy link
Member

dblock commented Jul 21, 2021

  1. The grant permissions features are the main features provided by both the repos, for securemock: Allows creating mocks in tests without having to grant dangerous permissions to all of your code and for mocksocket: Allows using sockets without having to grant dangerous permissions to all of your code. They look like useful features but I am open to your thoughts!

Can you help me understand how that's useful? This is used in tests on throwaway CI infrastructure, and not at runtime. So why does one need it?

@VachaShah
Copy link
Collaborator

I think from what I understood from the repos, it helps avoid giving permissions to all of the code for mocking and for using sockets during tests. I see that this practice has also been used for other codebases in the test framework: https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/resources/org/opensearch/bootstrap/test-framework.policy. Let me know if you think this might not be required for us.

@dblock
Copy link
Member

dblock commented Jul 21, 2021

I think from what I understood from the repos, it helps avoid giving permissions to all of the code for mocking and for using sockets during tests. I see that this practice has also been used for other codebases in the test framework: https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/resources/org/opensearch/bootstrap/test-framework.policy. Let me know if you think this might not be required for us.

Ok, but why? ;) This is used in tests. What bad things happen if this code doesn't exist and those permissions are given? I have not read a good reason why one would want this. Maybe @nknize can explain?

@VachaShah
Copy link
Collaborator

Honestly, I am also unclear on what the consequences would be of removing it. But whether we decide to keep it or remove it, we can update the mockito version. If we decide to keep it though, there will be an interdependency where the functionalities of securemock will have to be implemented on the newer version of mockito and we would update the version of mockito on OpenSearch as well.

@xuezhou25
Copy link
Contributor

Elasticsearch rebuilds JNA to strip out native libraries for platforms that not supported by elastic.
Are we going change JNA dependency from elastic rebuild version to a GA version and ignore the strip out action?
@dblock

@nknize
Copy link
Collaborator Author

nknize commented Jul 27, 2021

Without mocksocket core opensearch would need to grant the following so integration tests could be executed:

grant {
  // give permission to **all** core code just for tests
  permission java.net.SocketPermission "*", "accept,connect,resolve";
};

These permissions would be carried forward in the production clusters making them vulnerable. With mocksocket those permissions are granted to the mocksocket jar only which is used in the MockNioTransport inside the test framework.

@dblock
Copy link
Member

dblock commented Jul 27, 2021

Thanks for the clear explanation @nknize, I understand why we need mocksocket. Let's reproduce this verbatim in our mocksocket fork's README or somewhere else where it's not going to be lost @VachaShah.

@dblock
Copy link
Member

dblock commented Jul 27, 2021

Elasticsearch rebuilds JNA to strip out native libraries for platforms that not supported by elastic.
Are we going change JNA dependency from elastic rebuild version to a GA version and ignore the strip out action?
@dblock

My vote would be yes.

I don't see why we would keep restricting platforms. While we may not be releasing a package that has been tested on some platform, it doesn't feel right to artificially prevent others from trying to run on those platforms, reporting bugs, etc. Looking for @nknize to agree/disagree here as well to make sure I'm not missing more history or context.

@VachaShah
Copy link
Collaborator

Thanks for the clear explanation @nknize, I understand why we need mocksocket. Let's reproduce this verbatim in our mocksocket fork's README or somewhere else where it's not going to be lost @VachaShah.

Sure, will do!

Without mocksocket core opensearch would need to grant the following so integration tests could be executed:

grant {
  // give permission to **all** core code just for tests
  permission java.net.SocketPermission "*", "accept,connect,resolve";
};

These permissions would be carried forward in the production clusters making them vulnerable. With mocksocket those permissions are granted to the mocksocket jar only which is used in the MockNioTransport inside the test framework.

@nknize Thanks for the explanation, that really helps! For securemock, it gives permissions to mockito during the tests, does this apply to securemock as well?

@adnapibar
Copy link
Contributor

adnapibar commented Jul 27, 2021

Elasticsearch rebuilds JNA to strip out native libraries for platforms that not supported by elastic.
Are we going change JNA dependency from elastic rebuild version to a GA version and ignore the strip out action?
@dblock

My vote would be yes.

I don't see why we would keep restricting platforms. While we may not be releasing a package that has been tested on some platform, it doesn't feel right to artificially prevent others from trying to run on those platforms, reporting bugs, etc. Looking for @nknize to agree/disagree here as well to make sure I'm not missing more history or context.

Here is the list of native libraries that JNA supports - https://github.com/java-native-access/jna/tree/master/lib/native
Does It makes sense to include these libraries for the platforms which we probably won't support (e.g. Android)?

@dblock
Copy link
Member

dblock commented Jul 27, 2021

Elasticsearch rebuilds JNA to strip out native libraries for platforms that not supported by elastic.
Are we going change JNA dependency from elastic rebuild version to a GA version and ignore the strip out action?
@dblock

My vote would be yes.
I don't see why we would keep restricting platforms. While we may not be releasing a package that has been tested on some platform, it doesn't feel right to artificially prevent others from trying to run on those platforms, reporting bugs, etc. Looking for @nknize to agree/disagree here as well to make sure I'm not missing more history or context.

Here is the list of native libraries that JNA supports - https://github.com/java-native-access/jna/tree/master/lib/native
Does It makes sense to include these libraries for the platforms which we probably won't support (e.g. Android)?

Those seem minor, or aren't they? Are we worried about the bit of disk space? Rebuilding native bits has its own risks.

@adnapibar
Copy link
Contributor

Elasticsearch rebuilds JNA to strip out native libraries for platforms that not supported by elastic.
Are we going change JNA dependency from elastic rebuild version to a GA version and ignore the strip out action?
@dblock

My vote would be yes.
I don't see why we would keep restricting platforms. While we may not be releasing a package that has been tested on some platform, it doesn't feel right to artificially prevent others from trying to run on those platforms, reporting bugs, etc. Looking for @nknize to agree/disagree here as well to make sure I'm not missing more history or context.

Here is the list of native libraries that JNA supports - https://github.com/java-native-access/jna/tree/master/lib/native
Does It makes sense to include these libraries for the platforms which we probably won't support (e.g. Android)?

Those seem minor, or aren't they? Are we worried about the bit of disk space? Rebuilding native bits has its own risks.

I'm not worried about the disk space, but there must be some reason why elastic chose to go this route. We should find that out and if that seems like an unreasonable reason we can start using the upstream JNA.

@adnapibar
Copy link
Contributor

Those seem minor, or aren't they? Are we worried about the bit of disk space? Rebuilding native bits has its own risks.

I'm not worried about the disk space, but there must be some reason why elastic chose to go this route. We should find that out and if that seems like an unreasonable reason we can start using the upstream JNA.

The original intent is explained here https://discuss.elastic.co/t/why-elasticsearch-has-separate-jna-library/194986/4
Maybe this no longer holds true.

@dblock
Copy link
Member

dblock commented Jul 28, 2021

I don't see any real problems or bugs in that explanation, only FUD.

@reta
Copy link
Collaborator

reta commented Sep 1, 2021

@dblock my apologies, I cannot update the description of the issue but we could put checks on:

[X] client/rest/build.gradle
[X] client/sniffer/build.gradle

Those are out of scope now, thank you!

@VachaShah do you need help with this issue? There are a few options (besides forking and giving all permissions) which we could explore, what do you think?

@VachaShah VachaShah removed their assignment Sep 1, 2021
@VachaShah
Copy link
Collaborator

@reta Thank you for the offer! @xuezhou25 will be working on this.

@dblock
Copy link
Member

dblock commented Sep 1, 2021

@reta since you PRed #1187, you've got a leg ahead on all of us already. We have mountains of other things we want to do - would you rather pick this one up?

@reta
Copy link
Collaborator

reta commented Sep 1, 2021

@dblock absolutely, @xuezhou25 how does it sound to you?

@CEHENKLE
Copy link
Member

CEHENKLE commented Sep 1, 2021

@reta Cool beans! Thank you :)

@xuezhou25
Copy link
Contributor

@reta My plan is still forking and giving all permissions to mocksocket & securemock. Since you have the better solution and are ahead of us, it's all yours! :)

@reta
Copy link
Collaborator

reta commented Sep 1, 2021

@xuezhou25 thank you, since there is a dedicated security manager for testing, I will try to prototype the dedicated security checks in there, hopefully (:crossed_fingers: ) the forks will not be needed anymore.

Rishikesh1159 referenced this issue in Rishikesh1159/OpenSearch Apr 14, 2023
Signed-off-by: Poojita Raj <poojiraj@amazon.com>
Rishikesh1159 referenced this issue in Rishikesh1159/OpenSearch Apr 18, 2023
Signed-off-by: Poojita Raj <poojiraj@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributed framework >FORK Related to the fork process Meta Meta issue, not directly linked to a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants