Skip to content

Conversation

@jonathan-buttner
Copy link
Contributor

@jonathan-buttner jonathan-buttner commented May 22, 2025

When we added the proxy action it caused a bug because we moved the InferenceAction.Request to an internal action instead of monitor(here). There are a few places where we're using the InferenceAction.Request directly. In these situations we need to execute the client using the INFERENCE_ORIGIN to indicate that we're acting as the internal user. Otherwise we'd get an error when a read only user (with only monitor_inference privileges) attempts to make inference requests.

Reproducing the issue

The issue can be reproduced like the following:

PUT _inference/rerank/coherererank
{
    "service": "cohere",
    "service_settings": {
        "api_key": "api_key",
        "model_id": "rerank-v3.5"
    }
}

PUT jon/_doc/1?pretty
{
    "title": "The Terminator",
    "overview": "A cyborg is sent back in time to kill Sarah Connor."
}

PUT jon/_doc/2?pretty
{
    "title": "Terminator 2: Judgment Day",
    "overview": "A cyborg is sent back in time to protect John Connor."
}
PUT jon/_doc/3?pretty
{
    "title": "Terminator Genisys",
    "overview": "A cyborg is sent back in time to protect Sarah Connor."
}

GET jon/_search <-- This should result in a permissions error
{
    "_source": [
        "title"
    ],
    "retriever": {
        "text_similarity_reranker": {
            "retriever": {
                "standard": {
                    "query": {
                        "multi_match": {
                            "fields": [
                                "title",
                                "overview"
                            ],
                            "query": "terminator arnold"
                        }
                    }
                }
            },
            "field": "title",
            "inference_text": "terminator arnold",
            "inference_id": "coherererank"
        }
    }
}

POST /_query?format=txt <--- this should also fail
{
    "query": "FROM jon | KEEP title, overview | SORT title DESC | LIMIT 10 | RERANK \"terminator arnold\" ON title WITH coherererank"
}

Error

{
    "error": {
        "root_cause": [
            {
                "type": "status_exception",
                "reason": "[text_similarity_reranker] search failed - retrievers '[standard]' returned errors. All failures are attached as suppressed exceptions.",
                "suppressed": [
                    {
                        "type": "search_phase_execution_exception",
                        "reason": "Computing updated ranks for results failed",
                        "phase": "rank-feature",
                        "grouped": true,
                        "failed_shards": []
                    }
                ]
            }
        ],
        "type": "status_exception",
        "reason": "[text_similarity_reranker] search failed - retrievers '[standard]' returned errors. All failures are attached as suppressed exceptions.",
        "suppressed": [
            {
                "type": "search_phase_execution_exception",
                "reason": "Computing updated ranks for results failed",
                "phase": "rank-feature",
                "grouped": true,
                "failed_shards": [],
                "caused_by": {
                    "type": "security_exception",
                    "reason": "action [cluster:internal/xpack/inference] is unauthorized for user [test_read_user] with effective roles [test_read], this action is granted by the cluster privileges [manage,all]"
                }
            }
        ]
    },
    "status": 403
}

Testing that it works correctly

To ensure the fix works we can do the following

Create a role with only monitor_inference

POST _security/role/test_read?pretty
{
    "cluster": ["monitor_inference"],
    "indices": [
      {
        "names": [
          "jon*"
        ],
        "privileges": [
          "read"
        ],
        "allow_restricted_indices": false
      }
    ]
}

Create a user that uses the role

POST _security/user/test_read_user?pretty
{
    "password": "password",
    "roles": [
      "test_read"
    ]
}

Perform the request with the test_read_user

GET jon/_search
{
    "_source": [
        "title"
    ],
    "retriever": {
        "text_similarity_reranker": {
            "retriever": {
                "standard": {
                    "query": {
                        "multi_match": {
                            "fields": [
                                "title",
                                "overview"
                            ],
                            "query": "terminator arnold"
                        }
                    }
                }
            },
            "field": "title",
            "inference_text": "terminator arnold",
            "inference_id": "coherererank"
        }
    }
}
POST /_query?format=txt
{
    "query": "FROM jon | KEEP title, overview | SORT title DESC | LIMIT 10 | RERANK \"terminator arnold\" ON title WITH coherererank"
}

@jonathan-buttner jonathan-buttner added >bug :ml Machine learning Team:ML Meta label for the ML team auto-backport Automatically create backport pull requests when merged v8.19.0 v9.1.0 v9.0.3 v8.18.3 labels May 22, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @jonathan-buttner, I've created a changelog YAML for you.

@jonathan-buttner jonathan-buttner marked this pull request as ready for review May 22, 2025 18:16
@elasticsearchmachine
Copy link
Collaborator

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

@jonathan-buttner jonathan-buttner merged commit 19e18a9 into elastic:main May 22, 2025
18 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.19 Commit could not be cherrypicked due to conflicts
9.0 Commit could not be cherrypicked due to conflicts
8.18 Commit could not be cherrypicked due to conflicts

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

jonathan-buttner added a commit to jonathan-buttner/elasticsearch that referenced this pull request May 22, 2025
* Using correct origin for inference action

* Update docs/changelog/128327.yaml

* [CI] Auto commit changes from spotless

---------

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

# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/inference/InferenceRunner.java
jonathan-buttner added a commit to jonathan-buttner/elasticsearch that referenced this pull request May 22, 2025
* Using correct origin for inference action

* Update docs/changelog/128327.yaml

* [CI] Auto commit changes from spotless

---------

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

# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/inference/InferenceRunner.java
@jonathan-buttner
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
9.0
8.19
8.18

Questions ?

Please refer to the Backport tool documentation

jonathan-buttner added a commit to jonathan-buttner/elasticsearch that referenced this pull request May 22, 2025
* Using correct origin for inference action

* Update docs/changelog/128327.yaml

* [CI] Auto commit changes from spotless

---------

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

# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/inference/InferenceRunner.java
elasticsearchmachine pushed a commit that referenced this pull request May 22, 2025
* Using correct origin for inference action

* Update docs/changelog/128327.yaml

* [CI] Auto commit changes from spotless

---------

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

# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/inference/InferenceRunner.java
elasticsearchmachine pushed a commit that referenced this pull request May 22, 2025
* Using correct origin for inference action

* Update docs/changelog/128327.yaml

* [CI] Auto commit changes from spotless

---------

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

# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/inference/InferenceRunner.java
elasticsearchmachine pushed a commit that referenced this pull request May 22, 2025
* Using correct origin for inference action

* Update docs/changelog/128327.yaml

* [CI] Auto commit changes from spotless

---------

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

# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/inference/InferenceRunner.java
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 >bug :ml Machine learning Team:ML Meta label for the ML team v8.18.3 v8.19.0 v9.0.3 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Performing rerank inference requests with monitor_inference fails with authorization error

3 participants