Skip to content

Conversation

@ldematte
Copy link
Contributor

@ldematte ldematte commented Nov 21, 2024

This PR expands PolicyManager to actually use Policy and Entitlement classes for checks, instead of hardcoding them.

It also introduces a separate PluginsResolver, with a dedicated function to map a Class to a Plugin (name). PluginsResolver is initialized with data from PluginsLoader, and then its resolve function is used internally in PolicyManager to find a plugin policy (and then test against the entitlements declared in the policy).

@ldematte ldematte marked this pull request as ready for review November 29, 2024 15:01
@ldematte ldematte requested a review from a team as a code owner November 29, 2024 15:01
@ldematte ldematte changed the title [WIP] Integrate PluginsLoader with PolicyManager [Entitlements] Integrate PluginsLoader with PolicyManager Nov 29, 2024
@ldematte ldematte added auto-backport Automatically create backport pull requests when merged and removed WIP labels Nov 29, 2024
@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)

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.

This looks good for a first pass. As a followup, I think we need to do more work at initialization time. A lot of the mapping between module and entitlements is lazy and linear here, but it should be very quick hash lookups.


public void checkFlagEntitlement(Class<?> callerClass, FlagEntitlementType type) {
private static List<Entitlement> lookupEntitlementsForModule(Policy policy, String moduleName) {
for (int i = 0; i < policy.scopes.size(); ++i) {
Copy link
Member

Choose a reason for hiding this comment

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

Why are we scanning module names, this could be a map right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The map is lazily created, but it could be done at initialization time instead. I will move that in a follow up.

Copy link
Contributor

@prdoyle prdoyle left a comment

Choose a reason for hiding this comment

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

I am an unending source of nit picks.

@ldematte
Copy link
Contributor Author

ldematte commented Dec 5, 2024

I think we need to do more work at initialization time

I agree, I will move the lazy map creation to initialization time in a followup today

@ldematte ldematte added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Dec 5, 2024
@elasticsearchmachine elasticsearchmachine merged commit 724e052 into elastic:main Dec 5, 2024
16 checks passed
@ldematte ldematte deleted the entitlements/integrate-plugin-loader-with-policy-manager branch December 5, 2024 09:29
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x

ldematte added a commit to ldematte/elasticsearch that referenced this pull request Dec 5, 2024
…7239)

This PR expands `PolicyManager` to actually use `Policy` and
`Entitlement` classes for checks, instead of hardcoding them.

It also introduces a separate `PluginsResolver`, with a dedicated
function to map a Class to a Plugin (name). `PluginsResolver` is
initialized with data from `PluginsLoader`, and then its resolve
function is used internally in `PolicyManager` to find a plugin policy
(and then test against the entitlements declared in the policy).
elasticsearchmachine pushed a commit that referenced this pull request Dec 5, 2024
…118055)

This PR expands `PolicyManager` to actually use `Policy` and
`Entitlement` classes for checks, instead of hardcoding them.

It also introduces a separate `PluginsResolver`, with a dedicated
function to map a Class to a Plugin (name). `PluginsResolver` is
initialized with data from `PluginsLoader`, and then its resolve
function is used internally in `PolicyManager` to find a plugin policy
(and then test against the entitlements declared in the policy).
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 auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) :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.

4 participants