Skip to content

Conversation

@jdconrad
Copy link
Contributor

@jdconrad jdconrad commented Feb 4, 2025

This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This removes a limitation where constructors cannot properly support type-erasure with different types of data structures for internal entitlement generation and external entitlement generation (for example List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.

For testing I converted FileEntitlement to use a static method for the policy parser as this is going to be replaced by FilesEntitlement in the near future.

@jdconrad jdconrad requested a review from rjernst February 4, 2025 20:02
@jdconrad jdconrad added auto-backport Automatically create backport pull requests when merged test-entitlements labels Feb 4, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Feb 4, 2025
@elasticsearchmachine
Copy link
Collaborator

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

@jdconrad
Copy link
Contributor Author

jdconrad commented Feb 4, 2025

@elasticmachine run elasticsearch-ci/part-3-entitlements

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.

Looks good, a couple thoughts

try {
return (Entitlement) entitlementConstructor.newInstance(parameterValues);
if (entitlementConstructor != null) {
return (Entitlement) entitlementConstructor.newInstance(parameterValues);
Copy link
Member

Choose a reason for hiding this comment

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

Would it be simpler to keep a MethodHandle and invoke that? Then there would be no difference between the ctor and static method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did a quick prototype of this, but it adds additional complexity for error handling, and doesn't save much in lookup. I'm still open to this, but think I would want to do it as a different PR where we look at simplifying the entirety of the method a bit more.

Policy expected = new Policy(
"test-policy.yaml",
List.of(new Scope("entitlement-module-name", List.of(new FileEntitlement("test/path/to/file", "read_write"))))
List.of(new Scope("entitlement-module-name", List.of(FileEntitlement.create("test/path/to/file", "read_write"))))
Copy link
Member

Choose a reason for hiding this comment

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

It's probably worth having explicit test(s) that check the behavior when eg a ctor and method are both annotated, similar to ManyConstructorsEntitlement already here. ie let's not rely on FileEntitlement, let's have explicit tests for this feature of the parser.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add these.

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

);
}

public void testMultipleMethodsAnnotated() throws IOException {
Copy link
Member

Choose a reason for hiding this comment

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

Can we also have a error test for a non-static method having the annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Good call.

@jdconrad
Copy link
Contributor Author

jdconrad commented Feb 5, 2025

@elasticmachine run elasticsearch-ci/part-1-entitlements

Copy link
Contributor

@ldematte ldematte left a comment

Choose a reason for hiding this comment

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

LGTM 2
GH status for the CI is "stuck", CI actually passed, I think you are free to merge 👍

@jdconrad jdconrad merged commit 534e171 into elastic:main Feb 5, 2025
20 of 22 checks passed
jdconrad added a commit to jdconrad/elasticsearch that referenced this pull request Feb 5, 2025
…elastic#121706)

This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This 
removes a limitation where constructors cannot properly support type-erasure with different types of 
data structures for internal entitlement generation and external entitlement generation (for example 
List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce 
that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
jdconrad added a commit to jdconrad/elasticsearch that referenced this pull request Feb 5, 2025
…elastic#121706)

This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This 
removes a limitation where constructors cannot properly support type-erasure with different types of 
data structures for internal entitlement generation and external entitlement generation (for example 
List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce 
that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.18
8.x
9.0

jdconrad added a commit to jdconrad/elasticsearch that referenced this pull request Feb 5, 2025
…elastic#121706)

This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This 
removes a limitation where constructors cannot properly support type-erasure with different types of 
data structures for internal entitlement generation and external entitlement generation (for example 
List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce 
that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
elasticsearchmachine pushed a commit that referenced this pull request Feb 5, 2025
…#121706) (#121796)

This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This 
removes a limitation where constructors cannot properly support type-erasure with different types of 
data structures for internal entitlement generation and external entitlement generation (for example 
List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce 
that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
elasticsearchmachine pushed a commit that referenced this pull request Feb 5, 2025
…#121706) (#121797)

This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This 
removes a limitation where constructors cannot properly support type-erasure with different types of 
data structures for internal entitlement generation and external entitlement generation (for example 
List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce 
that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
elasticsearchmachine pushed a commit that referenced this pull request Feb 5, 2025
…#121706) (#121795)

This updates the PolicyParser to allow static methods to have an ExternalEntitlement annotation. This 
removes a limitation where constructors cannot properly support type-erasure with different types of 
data structures for internal entitlement generation and external entitlement generation (for example 
List<Object> from the parser and List<SomeData> from an internal builder). We continue to enforce 
that only one constructor/method may be annotated with ExternalEntitlement per Entitlement class.
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 >refactoring Team:Core/Infra Meta label for core/infra team v8.18.1 v8.19.0 v9.0.1 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants