feat(sessions-pipeline): search preflight hook and OpenSearch URL auto-correction
Why
A customer's search indexer crash-looped on EKS after install. Every known cause can be seen before rollout. This PR stops the install with one readable line per cause instead of a CrashLoopBackOff.
What
1. OpenSearch URL auto-correction. A bare host (a VPC endpoint copied without its scheme, optionally with :port or a trailing /) becomes https://<host>. This applies in site.opensearchUrl (umbrella site.yaml, which also corrects the subchart copies in place before deriving), searchIndexer.search.opensearch.url, sessionReadApi.search.opensearch.url (sessions-pipeline), and the standalone session-read-api chart. http://, a path, credentials or a query still fail with the existing message.
2. Search preflight hook (charts/sessions-pipeline/templates/search-preflight.yaml, files/search-preflight.mjs; searchPreflight.*, on by default).
- One
pre-install,pre-upgradeJob per OpenSearch workload:<release>-search-preflight-indexerand-reader. Each runs as that workload's ServiceAccount, with the workload's own pinned image (Bun), pull secrets and scheduling. EKS Pod Identity therefore injects the same credentials. - The hooks carry
agentworkforce.dev/preflight: "true"likedatabaseGuard, so--no-hooksdrops them andcharts.shallows them. - The same checks also render as
helm testPods (searchPreflight.helmTest). These are self-contained, with the script inline, sohelm test --filter name=<pod>works. Read a failed one withkubectl logs <release>-search-preflight-indexer-test. - The reader runs its own
sessionReadApi.probeRuntime(nodeimages); the indexer runs Bun. searchPreflight.eksRegionsets the printed association's--region(the cluster's region when OpenSearch is elsewhere).- An invalid URL (bad port, non-string) is a
FAIL configline; mixed-case hosts are checked; a reader search over zero shards (no index yet) isWARN, not PASS. diagnose-install.py --create-pod-identity(used byconfigure-rds.shwithPOD_IDENTITY_ROLES) now creates named associations before any workload exists, so a fresh configure-rds install passes the preflight.ci/agent-relay/db-guard/kind.shopts out (sessions-pipeline.searchPreflight.enabled=false): kind has no Pod Identity, so the preflight correctly refused that install.- The script is self-contained (
node:builtins only, its own SigV4). It runs under Bun and Node. - Temporary ServiceAccount. When the chart creates the ServiceAccount and none exists yet (
lookup), a hook ServiceAccount of the same name is created for the Job. Helm deletes it when the hook phase ends, before it creates the release's own. A live ServiceAccount is never shadowed or deleted.- On Helm 3, a failed Job leaves the ServiceAccount behind: earlier successful hooks are not cleaned up. It carries the release's ownership metadata, so the next install or upgrade adopts it.
- This covers a fresh install. It also covers the
helm upgrade --installthat retries a failed first install: that retry runs pre-upgrade hooks, and the release ServiceAccount was never created.
- Opt-out and scope. Renders only for an OpenSearch (SigV4, so AWS) backend. Postgres search (GKE
values-gcp*.yaml, AKS, kind) renders nothing.searchPreflight.enabled=falseremoves it.warnOnly=truereports without blocking. - Nothing is written to OpenSearch.
_mgetand_searchare reads. A_bulkprobe is sent only after_mgetanswered for the existing index; it is an update without upsert of an id that does not exist. After a denied_mget, bulk isSKIP(a delete probe there left a deleted-document marker in the proof, so no write probe is sent at all). When the index does not exist yet (fresh install, before the bootstrap Job), OpenSearch lets_mget/_bulkthrough unchecked; the local proof showed this. The preflight therefore printsWARN indexer index ... not proven yetand passes, andhelm testchecks the created index. - 2xx responses must have the expected shape. A 2xx counts only if the response is the probe's OpenSearch answer: health
status,_mgetdocs[], bulkitems[]with per-item results, searchhits. HTML,{}or another shape is FAIL. Bulk items are judged one by one:document_missing/not_foundpass; a per-itemsecurity_exceptionor another error fails.
3. Same logic as the laptop tools.
- Messages, the
create-pod-identity-associationline and therelayhistory_indexer/relayhistory_readerbodies matchscripts/support/diagnose-install.py(--only search,--only pod-identity) andterraform/modules/aws/search/README.md.test_chart.py::AgreesWithDiagnosekeeps them equal. - IRSA-only is reported as such, because the services sign OpenSearch only with Pod Identity (sessions-pipeline
src/shared/opensearch-composition.ts). configure-rds.shnow prints the preflight lines from itshelm teststep.
4. Docs. sessions-pipeline README "Search preflight (OpenSearch)", agent-relay README site table, docs/enterprise-aws-install.md step 4, docs/self-hosted-eks.md helm test table, docs/support/diagnose-install.md.
Versions: session-read-api 0.2.21, sessions-pipeline 0.8.78, agent-relay 0.7.107 (main took agent-relay 0.7.104 to 0.7.106 and sessions-pipeline 0.8.76 and 0.8.77 first; merged main and moved up). This includes the locks and registry entries (opt.sessions-pipeline.search-preflight, and internal_env for the plumbing env vars), plus a regenerated doc and fast-path.
What each check prints on failure (FAIL <role> <check>: <cause> | fix: <fix>)
| Check | Failure | Fix printed |
|---|---|---|
| credentials | No EKS Pod Identity association for ServiceAccount <sa> in <ns> | aws eks create-pod-identity-association --cluster-name <c> --region <r> --namespace <ns> --service-account <sa> --role-arn <ROLE> (filled from eksClusterName / indexerRoleArn when set) |
| credentials | IRSA only | same line (the services sign only with Pod Identity) |
| credentials | agent refused (http 4xx) | role trust must allow pods.eks.amazonaws.com sts:AssumeRole + sts:TagSession |
| credentials | agent unreachable | install/check the eks-pod-identity-agent DaemonSet |
| identity | STS rejected the credentials (FAIL); STS unreachable (WARN only, since the workloads never call STS) | recreate the association / optional STS endpoint |
| network | TCP timeout: "a security group (or NetworkPolicy) drops it" | allow inbound TCP 443 on the domain's SG from the cluster/node SG |
| network | DNS / refused | check the URL; a VPC endpoint resolves only inside its VPC |
| tls | certificate does not name the host / other TLS error | use the endpoint the certificate covers |
| health / mget / bulk / search | 403 FGAC (names the missing permission, e.g. indices:data/read/mget[shard], #572) | PUT _plugins/_security/api/roles/relayhistory_indexer {…} and rolesmapping … {"backend_roles":[role ARN with and without IAM path]} (reader: relayhistory_reader read) |
| any signed request | 403 domain access policy | allow es:ESHttp* for the role |
| any signed request | SigV4 scope/region | set the region (site.region) |
| any signed request | 2xx that is not OpenSearch (HTML, {}) | the URL must be the domain endpoint, not a proxy/dashboards URL |
| health | cluster red | check domain health |
Test matrix and where it ran
| What | Where | Result |
|---|---|---|
node --test ci/sessions-pipeline-search-preflight/preflight.test.mjs: 17 tests (the ES signature pinned to botocore 1.35.99), including the AWS SigV4 test-suite vector (get-vanilla), every message above, HTML/{}/item-level bulk and _mget results, warnOnly, skip | Mac (Node 22) | PASS |
ci/sessions-pipeline-search-preflight/test_chart.py: 15 tests (adds reader runtime, non-string/port/query refusals). URL auto-correction (indexer, reader, standalone read API, site.opensearchUrl, status test), http:// and path still refused, hook on/off per profile (EKS short form, values-eks-rds-native.yaml, values-gcp.yaml, values-gcp-native.yaml, AKS docs/azure-install), opt-out/helmTest/warnOnly switches, --no-hooks drops it, same SA/image as the workload, role bodies equal to diagnose-install.py and the Terraform README | Mac (helm 4.1.1) | PASS |
scripts/ci/charts.sh static sessions-pipeline session-read-api agent-relay (hook ban, determinism, kubeconform) | Mac | PASS, 0 errors |
| test_site_values (updated: bare host now corrected), native_no_relayauth, search_limits/cadence/streaming/staged/bounded_repair, eks_alb_ingress, retained_workloads, install_pack, release_candidate, read_api, operator-session-erase, azure-blob, scrub-engine, native-consumer, component names, diagnose_install, rds-ca, configure-rds-chart-test, registry check, render-fast-path --check, version-bump | Mac | PASS |
ci/sessions-pipeline-s3-ledger/test_chart.py::test_sweeper_image_override | Mac | 1 failure on local helm 4.1.1 (a falsy-digest case in rearm-sweeper.yaml, untouched here); CI (helm 4.3.1) decides |
Real OpenSearch proof ci/sessions-pipeline-search-preflight/opensearch-proof/run.sh: OpenSearch 2.19.1 with the security plugin (FGAC), a botocore SigV4-verifying stand-in for the AWS front end, Pod Identity agent and STS; 16 scenarios. Covers: no association, agent refusal, fresh install (WARN), role not mapped (403 on health/mget/bulk), mapped role without indices:data/read/mget gives a _mget 403 with the #572 fix, then PASS after the documented mapping (Bun and Node), no index write, reader unmapped then mapped, wrong region, cert/host mismatch, DNS, refused, a security group that drops 443 (iptables DROP gives a timeout naming the SG); indices and document counts unchanged; 40/40 signatures verified by botocore, 0 bad | linuyc (Docker) | 17/17 on OpenSearch 2.19.1 and 1.3.20 at 55739cad; botocore verified every signature, 0 bad |
#572 finding: with only the cluster indices:data/read/mget missing (index-level mget* kept), OpenSearch 1.3.20, 2.11.1 and 2.19.1 all allow the indexer's own POST <index>/_mget, so these versions do not reproduce #572 (the customer's AWS domain did). The probe sends the indexer's exact request, and the scenario requires the preflight's verdict to equal the indexer's own request on the version under test | linuyc | agrees on all three |
Hook mechanics ci/sessions-pipeline-search-preflight/kind-hook-proof.sh on kind v1.33 with helm 4.3.1, no uninstall anywhere: fresh install blocked at pre-install with the cause in the Job log and termination message; temporary SA deleted; failed release kept; the helm upgrade --install retry runs a new pre-upgrade Job as the SA; with the cause "fixed" (warnOnly stands in, since kind has no Pod Identity) the retry succeeds and the release owns the real SA; an upgrade with the SA live leaves the SA untouched (same UID); helm test prints the check; opt-out | linuyc (kind) | 27/27 on each of Helm 3.10.3, 3.22.1 and 4.3.1 (Helm 3.10 leaves the temporary SA after a failed hook; it carries the release's ownership metadata and is adopted) |
Not proven here: a run against real AWS (Pod Identity agent, AWS OpenSearch FGAC with IAM backend roles, a real security group). A separate EKS sandbox rehearsal covers that.
Runtime-only / another repo
- The indexer's own startup logs live in sessions-pipeline (
src/shared/locker.tspodIdentityCredentials,src/shared/opensearch-composition.ts,packages/pipeline/src/search-index/opensearch.ts). They are not changed here. Printing the same one-line causes at runtime is a follow-up in that repo. - The upgrader's
--first-installuseshelm install --no-hooks, so the preflight runs there only throughhelm test(documented). - On a fresh install
_mget/_bulkpermissions are provable only after the bootstrap Job creates the index. That case is WARN, andhelm test(run by configure-rds.sh) proves it.
🤖 Generated with Claude Code