Skip to content

Commit 6b0dfc1

Browse files
salman1993claude
andauthored
feat(search): sign OpenSearch requests with AWS SigV4 (#9947)
## Summary The relay's OpenSearch client could only use HTTP basic auth. Amazon OpenSearch Serverless accepts only requests signed with AWS SigV4, and managed Amazon OpenSearch Service domains can require them, so the relay could not index into either. This PR adds optional SigV4 signing. It is off by default; basic auth and unauthenticated clusters work as before. | Variable | Meaning | | --- | --- | | `BUZZ_OPENSEARCH_AWS_SIGV4_SERVICE` | Turns signing on and names the signing service: `aoss` for a Serverless collection, `es` for a managed domain. Unset means no signing. | | `BUZZ_OPENSEARCH_AWS_REGION` | Region to sign for. Defaults to `AWS_REGION`, then `AWS_DEFAULT_REGION`. | The relay refuses to start when signing is set without a region, together with basic auth, without `BUZZ_OPENSEARCH_URL`, or with a service other than `es` or `aoss`. - **Credentials** come from the AWS default chain: environment variables, the shared profile, a web identity token, then the container or instance role. No keys are added to the relay's own settings. - **Refresh** (`aws_credentials.rs`): the `opensearch` crate asks its credentials provider on every request, and the AWS default chain does not cache. Used directly, every search and bulk write would call the token service or the instance metadata endpoint. The relay keeps one set of credentials and reloads it five minutes before it expires (every 15 minutes for credentials without an expiry). Each load builds the AWS provider anew, because a kept one never rereads the shared profile; a key rotated there is picked up at the next load. Concurrent requests share one load, whether it succeeds or fails: the next load starts at least 30 s after the last one ended, and requests in between use the valid set or fail at once. A first load is bounded at 30 s. A reload while the current set is still valid is bounded at 5 s, and if it fails the current set stays in use. - **Logging:** a failed credential load logs only the kind of error, because the causes can carry what a `credential_process` helper printed. The AWS SDK logs the full cause itself under `aws_config` at warn level, which the relay's default log filter leaves out; the deployment doc says how to turn it on and what it can contain. Credentials are never logged, and the config's `Debug` output shows only the service and region. - **Dependencies:** enables the `opensearch` crate's `aws-auth` feature and adds `aws-config` for the credential chain. ### Worth knowing - The region is not read from the shared AWS profile file, only from the variables above. - Right after a Serverless collection became active, the first signed request got HTTP 401 once; the same run passed 45 s later. The indexer already retries such failures. - A Serverless collection does not support `_refresh`, which only the tests' `SearchIndex::refresh` uses. ### Related issue N/A. Closest existing work: #9838 (the OpenSearch index this client writes to) and #9862. No duplicate found. ### Testing - Unit tests: startup validation of the new settings; credentials are loaded once, survive a failed reload, a failed first load is not repeated per request, requests waiting on a stalled load share its one failure, and a key rotated in a shared profile file is picked up. - Local, unauthenticated OpenSearch 2.19.3: the `postgres_opensearch_search` suite, plus index create, bulk write, search, bulk delete and index delete through `SearchIndex`. - Verified against an Amazon OpenSearch Serverless collection through `SearchIndex` with `aoss` signing and credentials from a shared profile: alias check, index create, bulk write of documents with `community:event_id` ids, search (3 hits), bulk delete of one document, search (2 hits), index delete. On the same collection an unsigned client got HTTP 403 for search and bulk write, and a client signing for `es` got HTTP 403. - The relay binary refuses to start with signing and no region, and with signing plus basic auth. - Not run: a managed domain (`es` signing), and the web identity, container and instance role credential sources. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Salman Mohammed <smohammed@squareup.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
1 parent cb4a83a commit 6b0dfc1

12 files changed

Lines changed: 941 additions & 2 deletions

File tree

‎.env.example‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ BUZZ_PUSH_GATEWAY_DELIVERY_URL=https://push.buzz.xyz/v1/deliveries/apns
187187
# BUZZ_OPENSEARCH_URL=http://localhost:9200
188188
# BUZZ_OPENSEARCH_USERNAME=
189189
# BUZZ_OPENSEARCH_PASSWORD=
190+
# BUZZ_OPENSEARCH_AWS_SIGV4_SERVICE=aoss
191+
# BUZZ_OPENSEARCH_AWS_REGION=us-east-1
190192
# BUZZ_OPENSEARCH_PREVIEW=true
191193
# BUZZ_SEARCH_INDEXER_WORKERS=1
192194

0 commit comments

Comments
 (0)