dify icon indicating copy to clipboard operation
dify copied to clipboard

feat: add AWS Managed IAM auth for OpenSearch vector DB

Open lan666as opened this issue 8 months ago • 0 comments

Summary

This PR introduces support for connecting to AWS Managed OpenSearch clusters and OpenSearch Serverless (AOSS) using AWS Identity and Access Management (IAM) authentication.

This implementation leverages the AWS SigV4 signing process provided by the opensearch-py library (Urllib3AWSV4SignerAuth), allowing users to configure OpenSearch vector databases without relying on basic username/password authentication, and instead use AWS IAM roles and policies for secure access.

Key changes include:

  • Addition of new configuration options: OPENSEARCH_AUTH_METHOD, OPENSEARCH_AWS_REGION, and OPENSEARCH_AWS_SERVICE.
  • Integration of AWS SigV4 authentication logic in the OpenSearch client initialization.
  • Specific handling for AWS OpenSearch Serverless (AOSS) when adding documents, as it does not support user-provided document IDs during bulk indexing.
  • Updates to environment variable examples (.env.example) and docker-compose.yaml.
  • Addition of a test case for the new AWS IAM authentication method.

Closes #14886 Closes #14849

Implemented based on the official guide: https://github.com/opensearch-project/opensearch-py/blob/main/guides/auth.md

Screenshots

image image image

Checklist

  • [ ] This change requires a documentation update, included: Dify Document
  • [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [ ] I've updated the documentation accordingly.
  • [x] I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

lan666as avatar Apr 28 '25 06:04 lan666as