Skip to content

Conversation

@jonathan-buttner
Copy link
Contributor

@jonathan-buttner jonathan-buttner commented Feb 27, 2025

This PR refactors the authorization logic to accomplish a few things:

  • I removed the revocation logic since we don't need it right now and it complicates things
  • Authorization happens after the node boots up and on a interval of every 10 minutes + between 0 - 5 minutes of jitter

Testing

I manually tested by spinning up an EIS gateway and ensuring that the authorization requests were received to simulate success. I also tested by modifying the gateway to return an empty response to simulate revoking authorization.

@jonathan-buttner jonathan-buttner added >non-issue :ml Machine learning Team:ML Meta label for the ML team auto-backport Automatically create backport pull requests when merged Feature:GenAI Features around GenAI v9.0.0 v8.18.0 v8.18.1 v8.19.0 v9.0.1 v9.1.0 labels Feb 27, 2025
@@ -1,288 +0,0 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not revoking anymore so we don't need these tests.

);
}

private record DefaultModelConfig(Model model, MinimalServiceSettings settings) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically moved all this logic to the new ElasticInferenceServiceAuthorizationHandler class.

return authorizedModels;
}

private void handleRevokedDefaultConfigs(Set<String> authorizedDefaultModelIds) {
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 got removed since we're no longer revoking.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jonathan-buttner I think I was imprecise here and misunderstood how the endpoint configurations work. We still need to be able to revoke default endpoints if we disable EIS for a project. I thought a restart would still give us this behavior, but with periodic tries in place restarts do not do anything special.
I think we need to keep the revokations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok! Thanks for clarifying. I'll add the functionality back 👍

responseString = responseString + " " + useChatCompletionUrlMessage(model);
}
listener.onFailure(new ElasticsearchStatusException(responseString, RestStatus.BAD_REQUEST));
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noticed we had a fall through bug that luckily is getting picked up by the if-block below but figured I'd fix it anyway.


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.ElasticsearchWrapperException;
Copy link
Contributor Author

@jonathan-buttner jonathan-buttner Feb 27, 2025

Choose a reason for hiding this comment

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

I would just consider this class completely new and don't even look at the old code when reviewing.

private synchronized void setAuthorizedContent(ElasticInferenceServiceAuthorizationModel auth) {
logger.debug("Received authorization response");
var authorizedTaskTypesAndModels = authorizedContent.get().taskTypesAndModels.merge(auth)
.newLimitedToTaskTypes(EnumSet.copyOf(implementedTaskTypes));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As a performance improvement we could check if the new authorization response is the same as the previous on and skip the rest of the logic here.

@@ -0,0 +1,137 @@
/*
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 is the previous ElasticInferenceServiceAuthorizationHandler class.

assertThat(limitedAuth, is(ElasticInferenceServiceAuthorizationModel.newDisabledService()));
}

public void testMerge_CombinesCorrectly() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New merge method tests.

@@ -0,0 +1,272 @@
/*
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 was renamed from ElasticInferenceServiceAuthorizationHandlerTests


package org.elasticsearch.xpack.inference.services.elastic.authorization;

import org.apache.logging.log4j.Logger;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just review this as a totally new file. Ignore the previous code.

@jonathan-buttner jonathan-buttner marked this pull request as ready for review February 27, 2025 21:26
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

* @param waitTime the max time to wait
* @throws IllegalStateException if the wait time is exceeded or the call receives an {@link InterruptedException}
*/
public void waitForAuthorizationToComplete(TimeValue waitTime) {
Copy link
Member

Choose a reason for hiding this comment

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

This isn't called anywhere other than tests, 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.

Yeah correct, I'll make it package private

this.threadPool = Objects.requireNonNull(threadPool);
logger = LogManager.getLogger(ElasticInferenceServiceAuthorizationHandler.class);
configuration = new AtomicReference<>(
new ElasticInferenceService.Configuration(authorizedContent.get().taskTypesAndModels.getAuthorizedTaskTypes())
Copy link
Member

Choose a reason for hiding this comment

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

Won't this always return and set an empty set? If so, I see it's already in the previous iteration, maybe it's something we fix after this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At this point it'll always be an empty set, but when we get an authorization response back it updates it:

https://github.com/elastic/elasticsearch/pull/123639/files#diff-c37e92ab207cd0222cb473c4e45b5af53a479972c4bf7b885c0303fa99d0dba7R264

@jonathan-buttner jonathan-buttner merged commit a88d645 into elastic:main Mar 3, 2025
17 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.0 Commit could not be cherrypicked due to conflicts
8.18 Commit could not be cherrypicked due to conflicts
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 123639

jonathan-buttner added a commit to jonathan-buttner/elasticsearch that referenced this pull request Mar 3, 2025
…s instead of only once (elastic#123639)

* Refactoring

* Add internal cluster setting to aid testing

* [CI] Auto commit changes from spotless

* Allowing the auth interval to be configurable via a setting

* Removing unused code

* Adding revocation functionality back

---------

Co-authored-by: elasticsearchmachine <[email protected]>
(cherry picked from commit a88d645)

# Conflicts:
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandlerTests.java
jonathan-buttner added a commit to jonathan-buttner/elasticsearch that referenced this pull request Mar 3, 2025
…s instead of only once (elastic#123639)

* Refactoring

* Add internal cluster setting to aid testing

* [CI] Auto commit changes from spotless

* Allowing the auth interval to be configurable via a setting

* Removing unused code

* Adding revocation functionality back

---------

Co-authored-by: elasticsearchmachine <[email protected]>
(cherry picked from commit a88d645)

# Conflicts:
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java
@jonathan-buttner
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x
9.0
8.18

Questions ?

Please refer to the Backport tool documentation

jonathan-buttner added a commit to jonathan-buttner/elasticsearch that referenced this pull request Mar 3, 2025
…s instead of only once (elastic#123639)

* Refactoring

* Add internal cluster setting to aid testing

* [CI] Auto commit changes from spotless

* Allowing the auth interval to be configurable via a setting

* Removing unused code

* Adding revocation functionality back

---------

Co-authored-by: elasticsearchmachine <[email protected]>
(cherry picked from commit a88d645)

# Conflicts:
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandlerTests.java
elasticsearchmachine pushed a commit that referenced this pull request Mar 4, 2025
…ic basis instead of only once (#123639) (#123920)

* [ML] Improve EIS authorization to perform requests on a periodic basis instead of only once (#123639)

* Refactoring

* Add internal cluster setting to aid testing

* [CI] Auto commit changes from spotless

* Allowing the auth interval to be configurable via a setting

* Removing unused code

* Adding revocation functionality back

---------

Co-authored-by: elasticsearchmachine <[email protected]>
(cherry picked from commit a88d645)

# Conflicts:
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandlerTests.java

* Fixing tests
elasticsearchmachine pushed a commit that referenced this pull request Mar 4, 2025
…c basis instead of only once (#123639) (#123918)

* [ML] Improve EIS authorization to perform requests on a periodic basis instead of only once (#123639)

* Refactoring

* Add internal cluster setting to aid testing

* [CI] Auto commit changes from spotless

* Allowing the auth interval to be configurable via a setting

* Removing unused code

* Adding revocation functionality back

---------

Co-authored-by: elasticsearchmachine <[email protected]>
(cherry picked from commit a88d645)

# Conflicts:
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java

* Fixing tests

* Fixing task type any test
elasticsearchmachine pushed a commit that referenced this pull request Mar 4, 2025
…c basis instead of only once (#123639) (#123916)

* [ML] Improve EIS authorization to perform requests on a periodic basis instead of only once (#123639)

* Refactoring

* Add internal cluster setting to aid testing

* [CI] Auto commit changes from spotless

* Allowing the auth interval to be configurable via a setting

* Removing unused code

* Adding revocation functionality back

---------

Co-authored-by: elasticsearchmachine <[email protected]>
(cherry picked from commit a88d645)

# Conflicts:
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/ElasticInferenceService.java
#	x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandler.java
#	x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/services/elastic/authorization/ElasticInferenceServiceAuthorizationHandlerTests.java

* Removing getFirst calls
georgewallace pushed a commit to georgewallace/elasticsearch that referenced this pull request Mar 11, 2025
…s instead of only once (elastic#123639)

* Refactoring

* Add internal cluster setting to aid testing

* [CI] Auto commit changes from spotless

* Allowing the auth interval to be configurable via a setting

* Removing unused code

* Adding revocation functionality back

---------

Co-authored-by: elasticsearchmachine <[email protected]>
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 backport pending Feature:GenAI Features around GenAI :ml Machine learning >non-issue Team:ML Meta label for the ML team v8.18.0 v8.18.1 v8.19.0 v9.0.0 v9.0.1 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants