AWS OpenSearch Service Domain
This page shows how to write Terraform and CloudFormation for OpenSearch Service Domain and write them securely.
aws_elasticsearch_domain (Terraform)
The Domain in OpenSearch Service can be configured in Terraform with the resource name aws_elasticsearch_domain. The following sections describe 3 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_elasticsearch_domain" "noncompliant_missing_options" { # Noncompliant
domain_name = "sensitive_domain"
}
resource "aws_elasticsearch_domain" "noncompliant_enabled_false" {
domain_name = "sensitive_domain"
resource "aws_elasticsearch_domain" "domain1" { # Noncompliant {{Make sure that using unencrypted Elasticsearch domains is safe here.}}
}
resource "aws_elasticsearch_domain" "domain2" {
# ^^^^^^^^^^^^^^^^^^^^^^^^^^> {{Related domain}}
encrypt_at_rest { # Noncompliant {{Make sure that using unencrypted Elasticsearch domains is safe here.}}
resource "aws_elasticsearch_domain" "elastic-no_domain_endpoint_options" {
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
domain_name = "api.example.com"
}
resource "aws_elasticsearch_domain" "elastic_no_policy" {
Security Best Practices for aws_elasticsearch_domain
There are 5 settings in aws_elasticsearch_domain that should be taken care of for security reasons. The following section explain an overview and example code.
Ensure Amazon Elasticsearch Service domain uses modern TLS protocols
It's better to adopt TLS v1.2+ to avoid using outdated TLS protocols.
Ensure Amazon Elasticsearch Service domain uses HTTPS
It is better to enforce the use of HTTPS for the domain. HTTP connections could be vulnerable to meet-in-the-middle (MITM) attacks.
Ensure to enable at rest encryption of Amazon Elasticsearch Service domain
It is better to enable at rest encryption of Amazon Elasticsearch Service domain. Encryption reduces the risk of data leakage.
Ensure to enable domain logging of Elasticsearch
It is better to enable domain logging of Elasticsearch. Amazon. These logs are useful for troubleshooting availability issues and meeting compliance requirements.
Ensure to enable in-transit encryption of Amazon Elasticsearch Service domain
It is better to enforce the use of encrypted connections among nodes. The in-transit data could be vulnerable to meet-in-the-middle (MITM) attacks.
Parameters
-
access_policiesoptional computed - string -
advanced_optionsoptional computed - map from string to string -
arnoptional computed - string -
domain_idoptional computed - string -
domain_namerequired - string -
elasticsearch_versionoptional - string -
endpointoptional computed - string -
idoptional computed - string -
kibana_endpointoptional computed - string -
tagsoptional - map from string to string -
advanced_security_optionslist block-
enabledrequired - bool -
internal_user_database_enabledoptional - bool -
master_user_optionslist block-
master_user_arnoptional - string -
master_user_nameoptional - string -
master_user_passwordoptional - string
-
-
-
cluster_configlist block-
dedicated_master_countoptional - number -
dedicated_master_enabledoptional - bool -
dedicated_master_typeoptional - string -
instance_countoptional - number -
instance_typeoptional - string -
warm_countoptional - number -
warm_enabledoptional - bool -
warm_typeoptional - string -
zone_awareness_enabledoptional - bool -
zone_awareness_configlist block-
availability_zone_countoptional - number
-
-
-
cognito_optionslist block-
enabledoptional - bool -
identity_pool_idrequired - string -
role_arnrequired - string -
user_pool_idrequired - string
-
-
domain_endpoint_optionslist block-
custom_endpointoptional - string -
custom_endpoint_certificate_arnoptional - string -
custom_endpoint_enabledoptional - bool -
enforce_httpsoptional - bool -
tls_security_policyoptional computed - string
-
-
ebs_optionslist block-
ebs_enabledrequired - bool -
iopsoptional - number -
volume_sizeoptional - number -
volume_typeoptional computed - string
-
-
encrypt_at_restlist block-
enabledrequired - bool -
kms_key_idoptional computed - string
-
-
log_publishing_optionsset block-
cloudwatch_log_group_arnrequired - string -
enabledoptional - bool -
log_typerequired - string
-
-
node_to_node_encryptionlist block-
enabledrequired - bool
-
-
snapshot_optionslist block-
automated_snapshot_start_hourrequired - number
-
-
timeoutssingle block-
updateoptional - string
-
-
vpc_optionslist block-
availability_zonesoptional computed - set of string -
security_group_idsoptional - set of string -
subnet_idsoptional - set of string -
vpc_idoptional computed - string
-
Explanation in Terraform Registry
Manages an AWS Elasticsearch Domain.
AWS::Elasticsearch::Domain (CloudFormation)
The Domain in Elasticsearch can be configured in CloudFormation with the resource name AWS::Elasticsearch::Domain. The following sections describe 9 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: AWS::Elasticsearch::Domain
Properties:
ElasticsearchVersion: '6.3'
DomainName: transactions-search-${self:provider.stage}
ElasticsearchClusterConfig:
DedicatedMasterEnabled: false
Type: AWS::Elasticsearch::Domain
Properties:
DomainName: ${self:provider.environment.ELASTIC_SEARCH_DOMAIN}
EBSOptions:
EBSEnabled: true
VolumeType: gp2
Type: AWS::Elasticsearch::Domain
Properties:
DomainName: kinesis-domain
EBSOptions:
EBSEnabled: true
VolumeSize: 10
# Type: 'AWS::Elasticsearch::Domain'
# AccessPolicies: Json
# Version: "2012-10-17"
# Statement:
# -
# Effect: "Allow"
Type: AWS::Elasticsearch::Domain
Properties:
DomainName: austin-traffic-${self:provider.stage}
ElasticsearchVersion: 7.1
ElasticsearchClusterConfig:
DedicatedMasterEnabled: false
"rule": "$.Resources.*[?(@.Type == 'AWS::Elasticsearch::Domain')].Properties.VPCOptions any null or ($.Resources.*[?(@.Type == 'AWS::Elasticsearch::Domain')].Properties.VPCOptions exists and $.Resources.*[?(@.Type == 'AWS::Elasticsearch::Domain')].Properties.VPCOptions.SubnetIds any null)",
"id": "3b745764-1d47-4adf-a023-18b95dcd713e",
"enabled": true,
"recommendation": {
"name": "Recommended solution having Elastic Cluster inside a VPC.",
"description": "It is recommended to have Elastic Cluster inside a VPC. Please make sure that \"VPCOptions\" block exists and it has \"subnetIds\" defined.",
"Type": "AWS::Elasticsearch::Domain",
"Properties": {
"DomainName": "myDomain"
}
},
"ESDomain2": {
"Type": "AWS::Elasticsearch::Domain",
"Properties": {
"DomainName": "nameddomain"
}
},
"ElasticsearchDomainWithName2": {
"resourceType" : "AWS::Elasticsearch::Domain",
"properties" : [ {
"propertyName" : "AccessPolicies",
"propertyType" : "JsonObject",
"required" : false
}, {
Parameters
-
AccessPoliciesoptional - Json -
AdvancedOptionsoptional - Map -
AdvancedSecurityOptionsoptional - AdvancedSecurityOptionsInput -
CognitoOptionsoptional - CognitoOptions -
DomainEndpointOptionsoptional - DomainEndpointOptions -
DomainNameoptional - String -
EBSOptionsoptional - EBSOptions -
ElasticsearchClusterConfigoptional - ElasticsearchClusterConfig -
ElasticsearchVersionoptional - String -
EncryptionAtRestOptionsoptional - EncryptionAtRestOptions -
LogPublishingOptionsoptional - Map of LogPublishingOption -
NodeToNodeEncryptionOptionsoptional - NodeToNodeEncryptionOptions -
SnapshotOptionsoptional - SnapshotOptions -
Tagsoptional - List of Tag -
VPCOptionsoptional - VPCOptions
Explanation in CloudFormation Registry
The AWS::Elasticsearch::Domain resource creates an Amazon OpenSearch Service (successor to Amazon Elasticsearch Service) domain.
Important The
AWS::Elasticsearch::Domainresource is being replaced by the AWS::OpenSearchService::Domain resource. While the legacy Elasticsearch resource and options are still supported, we recommend modifying your existing Cloudformation templates to use the new OpenSearch Service resource, which supports both OpenSearch and Elasticsearch. For more information about the service rename, see New resource types in the Amazon OpenSearch Service Developer Guide.
Frequently asked questions
What is AWS OpenSearch Service Domain?
AWS OpenSearch Service Domain is a resource for OpenSearch Service of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS OpenSearch Service Domain?
For Terraform, the SonarSource/sonar-iac, SonarSource/sonar-iac and SonarSource/sonar-iac source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the paulovsm/expense-tracker, first-line-outsourcing/tools and AndrewAKG/serverless-kinesis-to-elasticsearch-typescript source code examples are useful. See the CloudFormation Example section for further details.