https://github.com/ev2900/opensearch_sigv4_iam_auth
Authenticate with OpenSearch via. IAM Sigv4
https://github.com/ev2900/opensearch_sigv4_iam_auth
authentication aws iam opensearch opensearch-examples sigv4
Last synced: 2 months ago
JSON representation
Authenticate with OpenSearch via. IAM Sigv4
- Host: GitHub
- URL: https://github.com/ev2900/opensearch_sigv4_iam_auth
- Owner: ev2900
- Created: 2022-12-19T19:43:48.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2026-03-02T18:19:36.000Z (4 months ago)
- Last Synced: 2026-03-02T21:59:56.367Z (4 months ago)
- Topics: authentication, aws, iam, opensearch, opensearch-examples, sigv4
- Language: Python
- Homepage:
- Size: 210 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# OpenSearch SIGv4 IAM Auth

OpenSearch supports multiple authentication types. The simplest is basic authentication, IAM authentication can also be used. To use IAM authentication requests need to be signed with a Sigv4 authentication header.
The following repository demonstrates how map and IAM user to an OpenSearch role, then how to use the IAM user to make requests to the OpenSearch domain.
Follow the instructions below to walk through an example
1. Run the CloudFormation stack below
[](https://console.aws.amazon.com/cloudformation/home#/stacks/new?stackName=open-sigv4&templateURL=https://sharkech-public.s3.amazonaws.com/misc-public/opensearch_Sigv4.yaml)
The resources created by the CloudFormation stack are documented in the architecture below

2. Navigate to the to the [opensearch-user on the IAM console](https://us-east-1.console.aws.amazon.com/iam/home#/users/opensearch-user?section=security_credentials) and create an access key
3. Create a AWS CLI profile to store the access key Id and secret access key ```aws configure --profile os-profile```
4. Log into OpenSearch dashboard, map the ARN of the IAM user to an OpenSearch role

5. Update and run python script. There are two python scripts you can run. Both do the same thing but use different python libraries. The [opensearchpy_Sigv4.py](https://github.com/ev2900/OpenSearch_Sigv4_IAM_Auth/blob/main/opensearchpy_Sigv4.py) script uses the [opensearch-py](https://opensearch-project.github.io/opensearch-py/) python library to make requests. The [requests_Sigv4.py](https://github.com/ev2900/OpenSearch_Sigv4_IAM_Auth/blob/main/requests_Sigv4.py) uses the more generic [requests](https://pypi.org/project/requests/) library to make requests to OpenSearch.
Update the *host* and *region* variables in the [opensearchpy_Sigv4.py](https://github.com/ev2900/OpenSearch_Sigv4_IAM_Auth/blob/main/opensearchpy_Sigv4.py) python script.
Update the *host*, *path* and *region* variables in the [requests_Sigv4.py](https://github.com/ev2900/OpenSearch_Sigv4_IAM_Auth/blob/main/requests_Sigv4.py) python script.
Then save and run the script(s)