feat(sessions-pipeline): search preflight hook and OpenSearch URL auto-correction

Merged
KH
3d ago
+2149-31

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-upgrade Job per OpenSearch workload: <release>-search-preflight-indexer and -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" like databaseGuard, so --no-hooks drops them and charts.sh allows them.
  • The same checks also render as helm test Pods (searchPreflight.helmTest). These are self-contained, with the script inline, so helm test --filter name=<pod> works. Read a failed one with kubectl logs <release>-search-preflight-indexer-test.
  • The reader runs its own sessionReadApi.probeRuntime (node images); the indexer runs Bun.
  • searchPreflight.eksRegion sets the printed association's --region (the cluster's region when OpenSearch is elsewhere).
  • An invalid URL (bad port, non-string) is a FAIL config line; mixed-case hosts are checked; a reader search over zero shards (no index yet) is WARN, not PASS.
  • diagnose-install.py --create-pod-identity (used by configure-rds.sh with POD_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.sh opts 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 --install that 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=false removes it. warnOnly=true reports without blocking.
  • Nothing is written to OpenSearch. _mget and _search are reads. A _bulk probe is sent only after _mget answered for the existing index; it is an update without upsert of an id that does not exist. After a denied _mget, bulk is SKIP (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/_bulk through unchecked; the local proof showed this. The preflight therefore prints WARN indexer index ... not proven yet and passes, and helm test checks 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, _mget docs[], bulk items[] with per-item results, search hits. HTML, {} or another shape is FAIL. Bulk items are judged one by one: document_missing/not_found pass; a per-item security_exception or another error fails.

3. Same logic as the laptop tools.

  • Messages, the create-pod-identity-association line and the relayhistory_indexer / relayhistory_reader bodies match scripts/support/diagnose-install.py (--only search, --only pod-identity) and terraform/modules/aws/search/README.md. test_chart.py::AgreesWithDiagnose keeps 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.sh now prints the preflight lines from its helm test step.

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>)

CheckFailureFix printed
credentialsNo 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)
credentialsIRSA onlysame line (the services sign only with Pod Identity)
credentialsagent refused (http 4xx)role trust must allow pods.eks.amazonaws.com sts:AssumeRole + sts:TagSession
credentialsagent unreachableinstall/check the eks-pod-identity-agent DaemonSet
identitySTS rejected the credentials (FAIL); STS unreachable (WARN only, since the workloads never call STS)recreate the association / optional STS endpoint
networkTCP timeout: "a security group (or NetworkPolicy) drops it"allow inbound TCP 443 on the domain's SG from the cluster/node SG
networkDNS / refusedcheck the URL; a VPC endpoint resolves only inside its VPC
tlscertificate does not name the host / other TLS erroruse the endpoint the certificate covers
health / mget / bulk / search403 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 request403 domain access policyallow es:ESHttp* for the role
any signed requestSigV4 scope/regionset the region (site.region)
any signed request2xx that is not OpenSearch (HTML, {})the URL must be the domain endpoint, not a proxy/dashboards URL
healthcluster redcheck domain health

Test matrix and where it ran

WhatWhereResult
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, skipMac (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 READMEMac (helm 4.1.1)PASS
scripts/ci/charts.sh static sessions-pipeline session-read-api agent-relay (hook ban, determinism, kubeconform)MacPASS, 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-bumpMacPASS
ci/sessions-pipeline-s3-ledger/test_chart.py::test_sweeper_image_overrideMac1 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 badlinuyc (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 testlinuycagrees 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-outlinuyc (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.ts podIdentityCredentials, 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-install uses helm install --no-hooks, so the preflight runs there only through helm test (documented).
  • On a fresh install _mget/_bulk permissions are provable only after the bootstrap Job creates the index. That case is WARN, and helm test (run by configure-rds.sh) proves it.

🤖 Generated with Claude Code