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

CreateClassloaderEntitlement + extensions to parse logic #117754

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ldematte
Copy link
Contributor

Create a simple CreateClassloader entitlement, that can be used in this format:

entitled.module:
   - create_classloader

The PR expands the current parser to accept simple "just a string value" entitlements (previously they needed to be objects, with parameters).

It also refines the name mapping logic (entitlement name in YAML to class name) to account for "space" characters (like _ here). ATM any non-alpha character is considered a "space" character -- let me know if you think this is good or not (see tests).

This PR is small and simple on purpose: usages of CreateClassloader entitlement (in policies, code, IT tests) will be in a separate PR (I split this out as "preliminary work" to avoid having a gigantic PR).

@ldematte ldematte added >non-issue :Core/Infra/Core Core issues without another label auto-backport Automatically create backport pull requests when merged v9.0.0 v8.18.0 labels Nov 29, 2024
@ldematte ldematte requested review from prdoyle, jdconrad and a team November 29, 2024 11:06
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Nov 29, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@@ -143,6 +150,14 @@ protected Entitlement parseEntitlement(String scopeName, String entitlementType)
}
}

static String getEntitlementClassName(String entitlementType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, this is pretty clever, but something feels odd about allowing the policy files to specify any class they want (though the fact that you put the mandatory Entitlement suffix on there helps).

There's also a performance problem here, where we look up the entitlement class by name, scan it for annotations, and reflect on its constructor arguments every time we encounter it in a policy file. Perhaps we could memoize those the first time we find them, so we do the reflection at most once per entitlement class. I suppose this is an optimization we could do later on.

Anyway, no need to change this if you like it the way it is. Just thinking out loud.

Copy link
Contributor

Choose a reason for hiding this comment

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

This also allows multiple spellings of the same entitlement, like createClassloader and create_classloader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are probably right -- but we want to discuss it in a follow up I think (definitely with Jack, who decided for this approach). It could be as simple as an allowlist of names though.

This also allows multiple spellings of the same entitlement, like createClassloader and create_classloader.

Yes, I'm really on the fence for this - if we have an allowlist of names it would limit this case.
For now, I'm thinking of changing it to just look for _ (if that's what we want to use as a separator).
Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I'm fine even to merge this as-is and iterate on it. It's not like other teams will swoop in and start using these features before they're finalized anyway.

package org.elasticsearch.entitlement.runtime.policy;

public class CreateClassloaderEntitlement implements Entitlement {
@ExternalEntitlement
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 this annotation for? Does it differentiate entitlements that can appear in policy files versus those we just grant to the server?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking some more... if we instead had a list somewhere of "entitlements allowed in policy files" that would also allow us to scan those classes once at initialization, which would also solve the reflection perf problem I was mentioning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it differentiate entitlements that can appear in policy files versus those we just grant to the server?

Yes. These are the Entitlements that can be parsed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

which would also solve the reflection perf problem I was mentioning.

That, I think, would be a very nice thing to add in a follow-up!

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/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants