Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions deploy/opensearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions deploy/opensearch/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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]},
Expand Down
28 changes: 25 additions & 3 deletions deploy/opensearch/tests/test_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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*"}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
],
}

Expand Down
Loading