Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opensearch logs #284

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c9339a8
Add variable to enable CW Logs
Oct 1, 2024
fd6640f
Add support for OpenSearch logs
Oct 1, 2024
8e18cdc
Add OpenSearch install example
Oct 2, 2024
f91ecb9
Add eks opensearch monitoring example
Oct 2, 2024
91627fd
Add outputs and instructions to allow fluentbit writing to opensearch
Oct 2, 2024
5e2fd2f
Document opensearch inputs
Oct 2, 2024
89f085c
Add OpenSearch related information to README files
Oct 2, 2024
66a1ddb
Improve opensearch domain example readme
Oct 2, 2024
44c8e28
Merge branch 'main' into opensearch-logs
bonclay7 Oct 14, 2024
1fb4528
Rename oso example
Oct 2, 2024
cc85b4c
Simplify variables
Nov 22, 2024
6d1fc0e
Update SSL configuration
Nov 22, 2024
cdcb997
Update SSL configuration
Nov 22, 2024
fee6280
Fix username variable
Nov 22, 2024
7f97d83
Optional exposing proxy instance
Nov 22, 2024
bf32ba8
Add expose_proxy doc to README
Nov 22, 2024
7a3af5c
Add expose_proxy doc to README
Nov 22, 2024
9c17d2b
Use launch templates for reverse proxy
Nov 22, 2024
ab41c4c
Fix naming
Nov 23, 2024
4cdfd0b
Add OpenSearch example doc
Nov 23, 2024
a3e2bfb
Merge branch 'main' into opensearch-logs
pelgrim Nov 23, 2024
5ff020d
Include steps to grant Grafana access to OpenSearch
Nov 23, 2024
e9cf8d4
Disable OpenSearch dashboards waiting for gitops repo update
Nov 23, 2024
6421278
Remove credentials from example
Nov 23, 2024
d073157
Remove duplicated instructions for FluentBit
Nov 23, 2024
bd04dd0
Link to OpenSearch instructions
Nov 23, 2024
ecead1c
Fix flux repository release version
Nov 23, 2024
c3ca531
Fix opensearch credentials defaults
Nov 23, 2024
25ff83c
Fix indentation in Grafana OpenSearch policy
Nov 23, 2024
c97d8a9
Run pre-commit
bonclay7 Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .tflint.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugin "aws" {
}

config {
module = true
call_module_type = true
force = false
}

Expand Down
140 changes: 140 additions & 0 deletions docs/helpers/amazon-opensearch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Creating a new Amazon OpenSearch Domain

This example creates an Amazon OpenSearch Domain within a VPC,
including an EC2 proxy instance to grant access to the domain Dashboards page
from outside of the VPC. It serves the purpose of demonstrating a minimal OpenSearch
domain that will receive observability signals using AWS Distro for FluentBit or
AWS Distro for OpenTelemetry. Mind that a production deployment of Amazon OpenSearch would
require elements that are not present in this example.

## Prerequisites

!!! note
Make sure to complete the [prerequisites section](https://aws-observability.github.io/terraform-aws-observability-accelerator/concepts/#prerequisites) before proceeding.
This example is designed to be deployed at the same VPC of the EKS cluster that will be observed. It expects the private and public subnets to have a `Name` tag, with any value that includes either `private` or `public`.

## Setup

### 1. Download sources and initialize Terraform

```
git clone https://github.com/aws-observability/terraform-aws-observability-accelerator.git
cd terraform-aws-observability-accelerator/examples/managed-grafana-workspace
terraform init
```

### 2. AWS Region

Specify the AWS Region where the resources will be deployed:

```bash
export TF_VAR_aws_region=xxx
```

### 3. VPC ID

Specify the id of the VPC where the resources will be deployed:

```bash
export TF_VAR_vpc_id=xxx
```

## Deploy

Simply run this command to deploy the example

```bash
terraform apply
```

## Accessing OpenSearch Dashboards

Get reverse proxy instance public DNS name:

```bash
aws ec2 describe-instances --filter Name=tag:"aws:autoscaling:groupName",Values="reverse_proxy" \
--output json --query 'Reservations[0].Instances[0].PublicDnsName' --region <region> --no-cli-pager
```

Retrieve OpenSearch Dashboards access credentials:

```bash
# Master user name
aws ssm get-parameter --with-decryption --output json --no-cli-pager \
--query "Parameter.Value" --name /terraform-accelerator/opensearch/master-user-name

# Master user password
aws ssm get-parameter --with-decryption --output json --no-cli-pager \
--query "Parameter.Value" --name /terraform-accelerator/opensearch/master-user-password
```

Access the URL from Public DNS name and open OpenSearch Dashboards using the retrieved credentials.

## Granting access to FluentBit

To allow FluentBit to ingest logs into the Amazon OpenSearch domain, follow the instructions bellow.

Get FluentBit Role ARN:

```bash
SA=$(
kubectl -n aws-for-fluent-bit get daemonset aws-for-fluent-bit -o json |
jq -r .spec.template.spec.serviceAccount)
kubectl -n aws-for-fluent-bit get sa $SA -o json |
jq -r .metadata.annotations.'"eks.amazonaws.com/role-arn"'
```

Add FluentBut Role ARN as a backend role in OpenSearch:

1. Access OpenSearch Dashboards. In the left menu, select **Security**.
2. In Security, select **Roles**.
3. In Roles, select **all access**.
4. In All access, select the tab **Mapped Users**, and them **Manage mapping**.
5. In Backend roles, click in **Add another backend role**. In the empty field, enter the FluentBit Role ARN retrieved before.

## Granting access to Amazon Managed Grafana

To allow Amazon Managed Grafana to access Amazon OpenSearch domain datasource, follow the instructions bellow.

1. Connect the workspace to the VPC following [these instructions](https://docs.aws.amazon.com/grafana/latest/userguide/AMG-configure-vpc.html).
2. Add access to OpenSearch datasources by following [these instructions](https://docs.aws.amazon.com/grafana/latest/userguide/ES-adding-AWS-config.html).
3. Include the policy for listing OpenSearch collections:
```bash
GRAFANA_WORKSPACE_ID=<grafana workspace id>
GRAFANA_ROLE_ARN=$(
aws grafana describe-workspace --workspace-id $GRAFANA_WORKSPACE_ID \
--output json --no-cli-pager | jq -r .workspace.workspaceRoleArn)
GRAFANA_ROLE=$(echo $GRAFANA_ROLE_ARN | cut -d/ -f3)
cat <<EOF > policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"aoss:ListCollections"
],
"Resource": "*"
}
]
}
EOF

aws iam put-role-policy --role-name $GRAFANA_ROLE \
--policy-name OpenSearchCollections --policy-document file://policy.json
```

4. Enable the OpenSearch plugin by following [these instructions](https://docs.aws.amazon.com/grafana/latest/userguide/aws-datasources-plugin.html).
5. Access OpenSearch Dashboards. In the left menu, select **Security**.
6. In Security, select **Roles**.
7. In Roles, select **all access**.
8. In All access, select the tab **Mapped Users**, and them **Manage mapping**.
9. In Backend roles, click in **Add another backend role**. In the empty field, enter the Grafana Role ARN retrieved before.

## Cleanup

To clean up your environment, destroy the Terraform example by running

```sh
terraform destroy
```
81 changes: 81 additions & 0 deletions examples/amazon-opensearch-domain/ec2.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
data "aws_ami" "reverse_proxy" {
most_recent = true
owners = ["amazon"]

filter {
name = "name"
values = ["al2023-ami-2023.*-kernel-6.1-x86_64"]
}

filter {
name = "root-device-type"
values = ["ebs"]
}

filter {
name = "virtualization-type"
values = ["hvm"]
}
}

resource "aws_security_group" "reverse_proxy" {
name = "reverse_proxy"
description = "Allow TLS inbound traffic and all outbound traffic"
vpc_id = var.vpc_id

tags = {
Name = "reverse_proxy"
}
}

resource "aws_vpc_security_group_ingress_rule" "reverse_proxy_ipv4" {
security_group_id = aws_security_group.reverse_proxy.id
cidr_ipv4 = local.reverse_proxy_client_ip
from_port = 443
ip_protocol = "tcp"
to_port = 443
}

resource "aws_vpc_security_group_egress_rule" "allow_all_traffic_ipv4" {
security_group_id = aws_security_group.reverse_proxy.id
cidr_ipv4 = "0.0.0.0/0"
ip_protocol = "-1" # semantically equivalent to all ports
}

resource "aws_launch_template" "reverse_proxy" {
name = "reverse_proxy"
image_id = data.aws_ami.reverse_proxy.id
instance_type = "t2.medium"
network_interfaces {
associate_public_ip_address = var.expose_proxy
security_groups = [aws_security_group.reverse_proxy.id]
}
user_data = base64encode(templatefile("${path.module}/user_data.sh", { os_domain = module.opensearch.domain_endpoint }))
metadata_options {
http_tokens = "required"
}
block_device_mappings {
device_name = "/dev/xvda"
ebs {
encrypted = true
}
}
lifecycle {
create_before_destroy = true
}
}

resource "aws_autoscaling_group" "reverse_proxy" {
name = aws_launch_template.reverse_proxy.name
max_size = 1
min_size = 0
desired_capacity = 1
launch_template {
id = aws_launch_template.reverse_proxy.id
version = "$Latest"
}
vpc_zone_identifier = [local.public_subnet_id]
lifecycle {
create_before_destroy = true
}
}
11 changes: 11 additions & 0 deletions examples/amazon-opensearch-domain/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
resource "random_password" "opensearch_master_password" {
length = 16
special = true
override_special = "!#$%&*()-_=+[]{}<>:?"
}

locals {
opensearch_master_user_name = var.master_user_name
opensearch_master_user_password = var.master_user_password == "" ? random_password.opensearch_master_password.result : var.master_user_password
availability_zone = var.availability_zone == "" ? "${var.aws_region}a" : var.availability_zone
}
Loading
Loading