Skip to content

Conversation

@jdconrad
Copy link
Contributor

@jdconrad jdconrad commented Apr 28, 2025

Generates a test file with the following information and format:

{
    "component": "<component name>",
    "locations": [
        {
            "representative_class": <class name with package>,
            "module": "<module name>"
        },
        ...
    ]
}

For painless:

{
    "component": "lang-painless",
    "locations": [
        {
            "representative_class": "org/objectweb/asm/tree/analysis/Analyzer.class",
            "module": "org.objectweb.asm.tree.analysis"
        },
        ...
    ]
}

Then it copies the following files into the jar for consumption by unit tests:

* META-INF/test-build-info.json
* META-INF/es-plugins/<plugin name>/plugin-descriptor.properties
* META-INF/es-plugins/<plugin name>/entitlement-policy.yaml

For server, the files in the jar become the following:

* META-INF/test-build-info.json

This should provide enough information for BootstrapForTesting to be able to build a mapping of caller class to policy file using the class file to look up the jar or directory within the class path and then associating that with it's specified module and finally using the specified module to look up the appropriate entitlement policy. caller class -> specified module -> entitlement policy

@jdconrad jdconrad requested a review from a team as a code owner April 28, 2025 22:46
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Apr 28, 2025
@prdoyle
Copy link
Contributor

prdoyle commented May 5, 2025

We could reduce redundancy by mapping just package names to modules, instead of every individual class. That should make the file much smaller.

@prdoyle
Copy link
Contributor

prdoyle commented May 5, 2025

Jack pointed out that this already has just one entry per jar/directory.

In that case, I wonder if the structure should include that jar/directory info, if only for troubleshooting. Even if we don't need it to make our use case work, it could be easier for humans if the jar/directory is present in the file.

Update: the reason for using the representative class instead of the jar/directory is because its location could be different at runtime depending on which tests are running. If we're not careful, that info could be not just useless, but misleading.

@jdconrad
Copy link
Contributor Author

@ryan @ldematte @mark-vieira Patrick and I believe this is ready for another round of review. Thanks!

Copy link
Contributor

@mark-vieira mark-vieira left a comment

Choose a reason for hiding this comment

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

One additional clarification but otherwise LGTM.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM

@jdconrad jdconrad added v8.19.0 auto-backport Automatically create backport pull requests when merged labels May 21, 2025
@jdconrad jdconrad merged commit f7a7f0b into elastic:main May 21, 2025
18 checks passed
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.19

jdconrad added a commit to jdconrad/elasticsearch that referenced this pull request May 21, 2025
…ts (elastic#127486)

Generates a test file with the following information and format:

{
    "component": "<component name>",
    "locations": [
        {
            "representative_class": <class name with package>,
            "module": "<module name>"
        },
        ...
    ]
}

For painless:

{
    "component": "lang-painless",
    "locations": [
        {
            "representative_class": "org/objectweb/asm/tree/analysis/Analyzer.class",
            "module": "org.objectweb.asm.tree.analysis"
        },
        ...
    ]
}

Then it copies the following files into the jar for consumption by unit tests:

* META-INF/plugin-test-build-info.json
* META-INF/es-plugins/<plugin name>/plugin-descriptor.properties
* META-INF/es-plugins/<plugin name>/entitlement-policy.yaml

For server, the files in the jar become the following:

* META-INF/server-test-build-info.json

This should provide enough information for BootstrapForTesting to be 
able to build a mapping of caller class to policy file using the class file 
to look up the jar or directory within the class path and then associating 
that with it's specified module and finally using the specified module to 
look up the appropriate entitlement policy. 

caller class -> specified module -> entitlement policy


---------

Co-authored-by: Patrick Doyle <[email protected]>
elasticsearchmachine pushed a commit that referenced this pull request May 22, 2025
…ts (#127486) (#128280)

Generates a test file with the following information and format:

{
    "component": "<component name>",
    "locations": [
        {
            "representative_class": <class name with package>,
            "module": "<module name>"
        },
        ...
    ]
}

For painless:

{
    "component": "lang-painless",
    "locations": [
        {
            "representative_class": "org/objectweb/asm/tree/analysis/Analyzer.class",
            "module": "org.objectweb.asm.tree.analysis"
        },
        ...
    ]
}

Then it copies the following files into the jar for consumption by unit tests:

* META-INF/plugin-test-build-info.json
* META-INF/es-plugins/<plugin name>/plugin-descriptor.properties
* META-INF/es-plugins/<plugin name>/entitlement-policy.yaml

For server, the files in the jar become the following:

* META-INF/server-test-build-info.json

This should provide enough information for BootstrapForTesting to be 
able to build a mapping of caller class to policy file using the class file 
to look up the jar or directory within the class path and then associating 
that with it's specified module and finally using the specified module to 
look up the appropriate entitlement policy. 

caller class -> specified module -> entitlement policy


---------

Co-authored-by: Patrick Doyle <[email protected]>
ldematte added a commit to ldematte/elasticsearch that referenced this pull request May 22, 2025
ldematte added a commit that referenced this pull request May 22, 2025
…solver) (#127719)

This PR introduces a test-specific ScopeResolver to use with PolicyManager for checking entitlements within test code running in a test runner (unit tests and integ tests, where code is running withing the same JVM).
The information for resolving component and module names is derived from the file created in #127486
ldematte added a commit to ldematte/elasticsearch that referenced this pull request May 22, 2025
…solver) (elastic#127719)

This PR introduces a test-specific ScopeResolver to use with PolicyManager for checking entitlements within test code running in a test runner (unit tests and integ tests, where code is running withing the same JVM).
The information for resolving component and module names is derived from the file created in elastic#127486
elasticsearchmachine pushed a commit that referenced this pull request May 22, 2025
…solver) (#127719) (#128301)

This PR introduces a test-specific ScopeResolver to use with PolicyManager for checking entitlements within test code running in a test runner (unit tests and integ tests, where code is running withing the same JVM).
The information for resolving component and module names is derived from the file created in #127486
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 >non-issue Team:Core/Infra Meta label for core/infra team v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants