From 0e1b31b8de2c7e68eca4160a132360d560d16ab8 Mon Sep 17 00:00:00 2001 From: suguanYang Date: Tue, 1 Dec 2026 07:43:50 -0700 Subject: [PATCH] Let the OpenSearch worker clear its delete-by-query scrolls Build cleanup runs _delete_by_query, which opens a scroll and clears it when the delete finishes. The worker role granted indices:data/read/scroll but not indices:data/read/scroll/clear, so every clear was denied and each scroll stayed open for its 5-minute keep-alive. Once the hourly maintenance sweep had opened 500 scrolls, the node rejected every later delete and the worker request timed out after 30 seconds. Grant both scroll actions at cluster and index level, as OpenSearch requires, and add a role-check test for a worker role that cannot clear scrolls. Co-Authored-By: Claude Opus 5.5 --- deploy/opensearch/README.md | 10 +++++--- deploy/opensearch/operations.py | 12 +++++++--- deploy/opensearch/tests/test_operations.py | 28 +++++++++++++++++++--- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/deploy/opensearch/README.md b/deploy/opensearch/README.md index 32a4d787d..00dd33c57 100644 --- a/deploy/opensearch/README.md +++ b/deploy/opensearch/README.md @@ -486,9 +486,13 @@ certificate, then run It lists every rendered action that a live API or worker role does not grant and exits 1 until none are missing. Both roles write: the API publishes builds when it retries indexing and writes a manifest when it archives a document, and -the worker's build cleanup scrolls, bulk-deletes and refreshes. A missing action -shows up only as HTTP 403 on that path, for example retrieval returning 503 or -retired builds that are never collected. +the worker's build cleanup scrolls, bulk-deletes, refreshes and clears its +scroll. A missing action shows up only as HTTP 403 on that path, for example +retrieval returning 503 or retired builds that are never collected. A missing +`indices:data/read/scroll/clear` is quieter: OpenSearch logs the denial and +keeps each cleanup's scroll open for its 5-minute keep-alive. Once 500 scrolls +are open on the node (`search.max_open_scroll_context`), every later delete is +rejected and the worker request times out. Each environment caps its open namespace indexes with `KNOWHERE_OPENSEARCH_OPEN_INDEX_LIMIT` and closes idle ones from diff --git a/deploy/opensearch/operations.py b/deploy/opensearch/operations.py index bfa5f4d63..2a7f69537 100644 --- a/deploy/opensearch/operations.py +++ b/deploy/opensearch/operations.py @@ -338,8 +338,14 @@ def _renderApplicationRoles(indexPrefix: str) -> dict[str, dict[str, list]]: "indices:admin/create", "indices:admin/open", "indices:admin/close*", "indices:data/write/bulk*", "indices:data/write/index", "indices:data/read/count", ] - # Build cleanup runs _delete_by_query?refresh=true, which scrolls, bulk-deletes and then refreshes. - cleanup: list[str] = ["indices:data/write/delete/byquery", "indices:data/write/delete", "indices:admin/refresh"] + # Build cleanup runs _delete_by_query?refresh=true, which scrolls, bulk-deletes, refreshes and + # then clears its scroll. Scroll actions must be granted at both cluster and index level. A + # denied clear leaves each scroll open for its 5-minute keep-alive, and the node's 500 open + # scroll limit then rejects later deletes. + scroll: list[str] = ["indices:data/read/scroll", "indices:data/read/scroll/clear"] + cleanup: list[str] = [ + "indices:data/write/delete/byquery", "indices:data/write/delete", "indices:admin/refresh", *scroll, + ] # Namespace indexes use a 48-character fingerprint. Keep their actions off the manifest index. namespacePattern: str = f"/{indexPrefix}-[a-f0-9]{{48}}/" manifestIndex: str = f"{indexPrefix}-published-manifests" @@ -353,7 +359,7 @@ def _renderApplicationRoles(indexPrefix: str) -> dict[str, dict[str, list]]: {"index_patterns": [manifestIndex], "allowed_actions": manifestActions}, {"index_patterns": [deploymentProbe], "allowed_actions": [_SEARCH]}, ]}, - "knowhere_worker": {"cluster_permissions": [*applicationCluster, "indices:data/read/scroll"], "index_permissions": [ + "knowhere_worker": {"cluster_permissions": [*applicationCluster, *scroll], "index_permissions": [ {"index_patterns": [namespacePattern], "allowed_actions": [*_INDEX_READ, *publication, *cleanup]}, {"index_patterns": [manifestIndex], "allowed_actions": [*manifestActions, "indices:data/write/delete"]}, {"index_patterns": [deploymentProbe], "allowed_actions": [_SEARCH]}, diff --git a/deploy/opensearch/tests/test_operations.py b/deploy/opensearch/tests/test_operations.py index 6bf9a4d97..884e16717 100644 --- a/deploy/opensearch/tests/test_operations.py +++ b/deploy/opensearch/tests/test_operations.py @@ -142,11 +142,12 @@ def test_preserves_namespace_publication_and_deployment_probe_search(roleName: s "cluster:monitor/main", "cluster:monitor/state", "cluster:monitor/health", "indices:data/write/bulk", } if roleName == "knowhere_worker": - # Build cleanup is _delete_by_query?refresh=true: scroll, bulk delete, then refresh. + # Build cleanup is _delete_by_query?refresh=true: scroll, bulk delete, refresh, then clear the scroll. expectedNamespaceActions |= { "indices:data/write/delete/byquery", "indices:data/write/delete", "indices:admin/refresh", + "indices:data/read/scroll", "indices:data/read/scroll/clear", } - expectedClusterActions.add("indices:data/read/scroll") + expectedClusterActions |= {"indices:data/read/scroll", "indices:data/read/scroll/clear"} assert getIndexActions(role, f"{prefix}-{namespaceSuffix}") == expectedNamespaceActions assert getIndexActions(role, f"{prefix}-deployment-probe") == {"indices:data/read/search*"} @@ -192,6 +193,25 @@ def test_application_role_check_detects_missing_close_shard_action(roleName: str ] +def test_application_role_check_detects_worker_unable_to_clear_scrolls() -> None: + # Without this action every build cleanup leaks its scroll until the node's open scroll limit rejects deletes. + operations: type = loadOperations() + prefix: str = "knowhere-staging-lexical-v1" + bundle: dict[str, object] = operations.renderBundle({**createManifest(), "index_prefix": prefix}) + roles: dict[str, _Role] = cast(dict[str, _Role], bundle["roles.yml"]) + worker: _Role = roles["knowhere_worker"] + worker["cluster_permissions"] = [ + action for action in worker["cluster_permissions"] if action != "indices:data/read/scroll/clear" + ] + + result: dict[str, object] = operations.checkApplicationRoles(roles, indexPrefix=prefix, rolePrefix="knowhere_") + + assert result["passed"] is False + assert cast(dict[str, list[str]], result["missing"])["knowhere_worker"] == [ + "cluster indices:data/read/scroll/clear", + ] + + def test_application_role_check_reports_the_read_only_production_api_role() -> None: operations: type = loadOperations() prefix: str = "knowhere-prod-lexical-v1" @@ -224,7 +244,9 @@ def test_application_role_check_reports_the_read_only_production_api_role() -> N f"{manifest} indices:data/write/index", ], "knowhere_prod_worker": [ - f"{namespace} indices:admin/close*", f"{manifest} indices:data/read/get", + "cluster indices:data/read/scroll/clear", + f"{namespace} indices:admin/close*", f"{namespace} indices:data/read/scroll", + f"{namespace} indices:data/read/scroll/clear", f"{manifest} indices:data/read/get", ], }