Skip to content

Bootstrap entitlements for testing #129268

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

Open
wants to merge 56 commits into
base: main
Choose a base branch
from

Conversation

prdoyle
Copy link
Contributor

@prdoyle prdoyle commented Jun 11, 2025

Add entitlement enforcement during ordinary unit tests.

This does not yet cover tests that run ES nodes; only ordinary unit tests.

See ES-11597.

@prdoyle prdoyle self-assigned this Jun 11, 2025
@prdoyle prdoyle added >test Issues or PRs that are addressing/adding tests test-windows Trigger CI checks on Windows auto-backport Automatically create backport pull requests when merged v8.19.0 v9.1.0 :Core/Infra/Entitlements Entitlements infrastructure labels Jun 11, 2025
@prdoyle prdoyle force-pushed the bootstrap-entitlements-for-testing branch 4 times, most recently from e1166dc to d331569 Compare June 17, 2025 12:34
prdoyle added 4 commits June 17, 2025 09:15
…source.

Using getResource makes this sensitive to unrelated classpath entries,
such as the entitlement bridge library, that get prepended to the classpath.
Using the root logger makes this sensitive to unrelated
logging, such as from the entitlement library.
…titlements.

Taking the actual module name from the class doesn't work in tests,
where those classes are loaded from the classpath and so their module
info is misleading.
@prdoyle prdoyle force-pushed the bootstrap-entitlements-for-testing branch 2 times, most recently from 7bcefba to ba15751 Compare June 17, 2025 14:37
@@ -45,4 +45,16 @@ configure(childProjects.values()) {
*/
apply plugin: 'elasticsearch.build'
}

// This is for any code potentially included in the server at runtime.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just add this to the plugin-scanner project for now. In general we want to move more configuration where it belongs. adding code that might be needed in the future in sometime just adds clutter for now.

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 needs to apply to every lib except plugin-scanner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Really, plugin-scanner shouldn't be in libs in the first place.)

Copy link
Contributor

@breskeby breskeby left a comment

Choose a reason for hiding this comment

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

I added some remarks regarding the build changes that I think we need to address.

@@ -184,7 +184,7 @@ private ChangelogEntry makeHighlightsEntry(int pr, boolean notable) {
}

private String getResource(String name) throws Exception {
return Files.readString(Paths.get(Objects.requireNonNull(this.getClass().getResource(name)).toURI()), StandardCharsets.UTF_8);
return Files.readString(Paths.get(Objects.requireNonNull(this.getClass().getResource(name)).toURI()), StandardCharsets.UTF_8).replace("\r", "");
Copy link
Contributor

Choose a reason for hiding this comment

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

what is that for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test wasn't working on Windows. Tag @brianseeders

@mosche
Copy link
Contributor

mosche commented Jun 26, 2025

@prdoyle I noticed that file entitlement checks likely don't work at all in tests as they are using org.apache.lucene.tests.mockfile.FilterFileSystem rather than the default file system. In policy checker we're allowing everything that's not using the default file system.
We should probably tackle file permissions separately to not increase the scope of this PR even further.


// Fire up entitlements
try {
TestEntitlementBootstrap.bootstrap(javaTmpDir, maybePath(System.getProperty("tests.config")));
Copy link
Contributor

Choose a reason for hiding this comment

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

I can only find a single reference of tests.config where this references elasticsearch.yml, though bootstrap expects a dir.

mvn -Dtests.gce=true -Dtests.config=/path/to/config/file/elasticsearch.yml clean test
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I don't recall why I added that now. 🤔

import java.util.stream.Stream;

public class TestPathLookup implements PathLookup {
final Map<BaseDir, Collection<Path>> tempDirPaths;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: tempDirPaths should better be renamed to baseDirPaths or similar

prdoyle added 3 commits June 26, 2025 17:36
This test works by altering the logging on the root logger.
With entitlements enabled, that will cause additional log statements to appear,
which interferes with the test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged :Core/Infra/Entitlements Entitlements infrastructure Team:Core/Infra Meta label for core/infra team >test Issues or PRs that are addressing/adding tests test-windows Trigger CI checks on Windows v8.19.0 v9.2.0
5 participants