AWS Introduction
AWS Pricing
AWS Threats
AWS Misconfigurations
- Getting Started with AWS Audit
- Permissions required for Misconfigurations Detection
- API Gateway Audit
- Cloudformation Audit
- CloudFront Audit
- CloudTrail Audit
- Cloudwatch Audit
- DynamoDB Audit
- EC2 Audit
- Elastic Search Audit
- ELB Audit
- IAM Audit
- KMS Audit
- Kubernetes Audit
- Lambda Audit
- RDS Audit
- Redshift Audit
- Route53 Audit
- S3 Audit
- Security Groups Audit
- SES Audit
- SNS Audit
- IAM Deep Dive
- App Sync Audit
- Code Build Audit
- Open Search Audit
- Shield Audit
- SQS Audit
Unrestricted Elasticsearch Access Should Not Be Allowed
More Info:
No security group should allow unrestricted inbound access to TCP port 9200 (Elasticsearch).
Risk Level
Medium
Address
Security
Compliance Standards
CBP, AWSWAF
Triage and Remediation
Remediation
To remediate the issue of unrestricted Elasticsearch access in AWS, you can follow the below steps:
- Login to the AWS console and navigate to the Elasticsearch service.
- Select the Elasticsearch domain that needs to be remediated.
- Click on the “Modify access” button under the “Actions” dropdown.
- In the “Configure access” section, select the option “Limit access to specific IP addresses or VPCs”.
- Enter the IP addresses or CIDR blocks that should be allowed to access the Elasticsearch domain.
- Click on the “Submit” button to save the changes.
After completing these steps, the Elasticsearch domain will only be accessible from the specified IP addresses or VPCs, and unrestricted access will be restricted.
To remediate unrestricted Elasticsearch access in AWS using AWS CLI, follow these steps:
-
Open the AWS CLI and run the following command to list all Elasticsearch domains in your account:
aws es list-domain-names
-
Identify the Elasticsearch domain that has unrestricted access.
-
Run the following command to update the Elasticsearch domain’s access policy to restrict access:
aws es update-elasticsearch-domain-config --domain-name <domain-name> --advanced-security-options 'Enabled=true,InternalUserDatabaseEnabled=true,MasterUserOptions={MasterUserName=<master-username>,MasterUserPassword=<master-password>}'
Replace
<domain-name>
with the name of the Elasticsearch domain and<master-username>
and<master-password>
with the credentials for the Elasticsearch master user. -
Verify that access to the Elasticsearch domain is now restricted by running the following command:
aws es describe-elasticsearch-domain-config --domain-name <domain-name>
This command should return the updated access policy for the Elasticsearch domain.
-
Ensure that you have a backup of the Elasticsearch domain before making any changes to it.
To remediate unrestricted Elasticsearch access in AWS using Python, you can follow these steps:
- Install the AWS SDK for Python (Boto3) using the following command:
pip install boto3
- Create an AWS Identity and Access Management (IAM) client using the following code snippet:
import boto3
# Create IAM client
iam = boto3.client('iam')
- Create an Elasticsearch service client using the following code snippet:
import boto3
# Create Elasticsearch service client
es = boto3.client('es')
- Use the Elasticsearch service client to retrieve the Elasticsearch domain policies using the following code snippet:
import boto3
# Create Elasticsearch service client
es = boto3.client('es')
# Retrieve Elasticsearch domain policies
response = es.describe_elasticsearch_domain_config(
DomainName='your-domain-name'
)
# Extract the Elasticsearch domain policies
policies = response['DomainConfig']['AccessPolicies']
- Check if the Elasticsearch domain policies allow unrestricted access using the following code snippet:
import json
# Check if Elasticsearch domain policies allow unrestricted access
if '{"Effect":"Allow","Principal":"*","Action":"es:*","Resource":"arn:aws:es:*:*:domain/your-domain-name/*"}' in policies:
# Remove the unrestricted access policy
new_policies = json.loads(policies)
new_policies['Statement'].remove({
'Effect': 'Allow',
'Principal': {'*'},
'Action': 'es:*',
'Resource': 'arn:aws:es:*:*:domain/your-domain-name/*'
})
new_policies = json.dumps(new_policies)
else:
# No remediation needed
new_policies = policies
- Use the Elasticsearch service client to update the Elasticsearch domain policies using the following code snippet:
import boto3
# Create Elasticsearch service client
es = boto3.client('es')
# Update Elasticsearch domain policies
response = es.update_elasticsearch_domain_config(
DomainName='your-domain-name',
AccessPolicies=new_policies
)
- Verify that the remediation was successful by checking the Elasticsearch domain policies again using the following code snippet:
import boto3
# Create Elasticsearch service client
es = boto3.client('es')
# Retrieve Elasticsearch domain policies
response = es.describe_elasticsearch_domain_config(
DomainName='your-domain-name'
)
# Extract the Elasticsearch domain policies
policies = response['DomainConfig']['AccessPolicies']
By following these steps, you can remediate unrestricted Elasticsearch access in AWS using Python.