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

Signoz alert manager setup for SMTP #41

Merged
merged 33 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f6670a8
Set up SMTP settings with test email
BryanFauble Oct 9, 2024
e01bc24
Try wrapping port as string
BryanFauble Oct 9, 2024
bb98de7
Correct port
BryanFauble Oct 9, 2024
7879aa4
Set temporary data
BryanFauble Oct 9, 2024
1f483c0
Adding SES tf configuration
BryanFauble Oct 25, 2024
74ce072
Move module import
BryanFauble Oct 25, 2024
4df7140
Remove comma
BryanFauble Oct 25, 2024
a602155
Remvoe tag ref
BryanFauble Oct 25, 2024
d1aa349
Comment out import for now
BryanFauble Oct 25, 2024
f571fb0
Add imports back
BryanFauble Oct 25, 2024
0c528fd
Create smtp user and pass
BryanFauble Oct 25, 2024
5e1ca66
Pass along smtp user and password
BryanFauble Oct 25, 2024
229693b
Move to local
BryanFauble Oct 25, 2024
1762ba2
Correct var
BryanFauble Oct 25, 2024
80aa670
figure out what is empty string
BryanFauble Oct 25, 2024
27e3067
Correct passing along user id
BryanFauble Oct 25, 2024
2e28ad4
remove output
BryanFauble Oct 25, 2024
3e2295d
Check content of var
BryanFauble Oct 25, 2024
0a6dbb5
Correct ref
BryanFauble Oct 25, 2024
622e3d6
Correct variable passing
BryanFauble Oct 25, 2024
63aa1cd
Remove reading secret manager
BryanFauble Oct 25, 2024
77b002c
Correct to use STARTTLS port
BryanFauble Oct 25, 2024
d2d976c
Correct boolean/string
BryanFauble Oct 25, 2024
da51b70
Add to readme for aws ses
BryanFauble Oct 25, 2024
3ea4803
Update documentation on directory structure
BryanFauble Oct 25, 2024
b8c21e1
Remove self from SES
BryanFauble Oct 25, 2024
71699e9
Merge branch 'ibcdpe-1095-cluster-ingress-signoz' into signoz-alert-m…
BryanFauble Oct 30, 2024
b63caf2
[IBCDPE-1111] upgrade airflow (#42)
BryanFauble Oct 31, 2024
8586b1d
Point to updated config value for airflow regex deserialization (#43)
BryanFauble Oct 31, 2024
e77153e
Merge branch 'main' into signoz-alert-manager
BryanFauble Nov 4, 2024
9d18e49
Remove the need for email domains to be set
BryanFauble Nov 5, 2024
d616dc7
Move token lifecycle to 1.25 days from 1 day
BryanFauble Nov 5, 2024
556a4ba
[IBCDPE-1095] Signoz move to lets encrypt (#45)
BryanFauble Nov 5, 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
41 changes: 33 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@ This repo is used to deploy an EKS cluster to AWS. CI/CD is managed through Spac
│ └── policies: Rego policies that can be attached to 0..* spacelift stacks
├── dev: Development/sandbox environment
│ ├── spacelift: Terraform scripts to manage spacelift resources
│ │ └── dpe-sandbox: Spacelift specific resources to manage the CI/CD pipeline
│ │ └── dpe-k8s/dpe-sandbox: Spacelift specific resources to manage the CI/CD pipeline
│ └── stacks: The deployable cloud resources
│ ├── dpe-auth0: Stack used to provision and setup auth0 IDP (Identity Provider) settings
│ ├── dpe-sandbox-k8s: K8s + supporting AWS resources
│ └── dpe-sandbox-k8s-deployments: Resources deployed inside of a K8s cluster
└── modules: Templatized collections of terraform resources that are used in a stack
├── apache-airflow: K8s deployment for apache airflow
│ └── templates: Resources used during deployment of airflow
├── argo-cd: K8s deployment for Argo CD, a declarative, GitOps continuous delivery tool for Kubernetes.
│ └── templates: Resources used during deployment of this helm chart
├── trivy-operator: K8s deployment for trivy, along with a few supporting charts for security scanning
│ └── templates: Resources used during deployment of these helm charts
├── victoria-metrics: K8s deployment for victoria metrics, a promethus like tool for cluster metric collection
│ └── templates: Resources used during deployment of these helm charts
├── cert-manager: Handles provisioning TLS certificates for the cluster
── envoy-gateway: API Gateway for the cluster securing and providing secure traffic into the cluster
├── postgres-cloud-native: Used to provision a postgres instance
── postgres-cloud-native-operator: Operator that manages the lifecycle of postgres instances on the cluster
├── demo-network-policies: K8s deployment for a demo showcasing how to use network policies
├── demo-pod-level-security-groups-strict: K8s deployment for a demo showcasing how to use pod level security groups in strict mode
├── sage-aws-eks: Sage specific EKS cluster for AWS
├── sage-aws-eks-addons: Sets up additional resources that need to be installed post creation of the EKS cluster
├── sage-aws-k8s-node-autoscaler: K8s node autoscaler using spotinst ocean
└── sage-aws-vpc: Sage specific VPC for AWS
├── sage-aws-ses: AWS SES (Simple email service) setup
├── sage-aws-vpc: Sage specific VPC for AWS
├── signoz: SigNoz provides APM, logs, traces, metrics, exceptions, & alerts in a single tool
├── trivy-operator: K8s deployment for trivy, along with a few supporting charts for security scanning
│ └── templates: Resources used during deployment of these helm charts
├── victoria-metrics: K8s deployment for victoria metrics, a promethus like tool for cluster metric collection
│ └── templates: Resources used during deployment of these helm charts
```

This root `main.tf` contains all the "Things" that are going to be deployed.
Expand Down Expand Up @@ -283,10 +291,27 @@ This document describes the abbreviated process below:
"iam:*PolicyVersion",
"iam:*OpenIDConnectProvider",
"iam:*InstanceProfile",
"iam:ListPolicyVersions"
"iam:ListPolicyVersions",
"iam:ListGroupsForUser",
"iam:ListAttachedUserPolicies"
],
"Resource": "*"
}
},
{
"Effect": "Allow",
"Action": [
"iam:CreateUser",
"iam:AttachUserPolicy",
"iam:ListPolicies",
"iam:TagUser",
"iam:GetUser",
"iam:DeleteUser",
"iam:CreateAccessKey",
"iam:ListAccessKeys",
"iam:DeleteAccessKeys"
],
"Resource": "arn:aws:iam::{{AWS ACCOUNT ID}}:user/smtp_user"
}
]
}
```
Expand Down
9 changes: 9 additions & 0 deletions deployments/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ module "dpe-sandbox-spacelift-development" {
enable_cluster_ingress = true
enable_otel_ingress = true
ssl_hostname = "a09a38cc5a8d6497ea69c6bf6318701b-1974793757.us-east-1.elb.amazonaws.com"

auth0_jwks_uri = "https://dev-sage-dpe.us.auth0.com/.well-known/jwks.json"

ses_email_identities = ["aws-dpe-dev@sagebase.org"]
ses_email_domains = ["sagebase.org"]
# Defines the email address that will be used as the sender of the email alerts
smtp_from = "aws-dpe-dev@sagebase.org"
}

module "dpe-sandbox-spacelift-production" {
Expand Down Expand Up @@ -115,4 +121,7 @@ module "dpe-sandbox-spacelift-production" {
enable_otel_ingress = false
ssl_hostname = ""
auth0_jwks_uri = ""

ses_email_identities = []
ses_email_domains = []
}
5 changes: 5 additions & 0 deletions deployments/spacelift/dpe-k8s/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ locals {
private_subnet_cidrs_eks_worker_nodes = var.private_subnet_cidrs_eks_worker_nodes
azs_eks_control_plane = var.azs_eks_control_plane
azs_eks_worker_nodes = var.azs_eks_worker_nodes
ses_email_identities = var.ses_email_identities
ses_email_domains = var.ses_email_domains
}

k8s_stack_deployments_variables = {
Expand All @@ -25,6 +27,7 @@ locals {
enable_otel_ingress = var.enable_otel_ingress
ssl_hostname = var.ssl_hostname
auth0_jwks_uri = var.auth0_jwks_uri
smtp_from = var.smtp_from
}

auth0_stack_variables = {
Expand All @@ -39,6 +42,8 @@ locals {
private_subnet_ids_eks_worker_nodes = "TF_VAR_private_subnet_ids_eks_worker_nodes"
node_security_group_id = "TF_VAR_node_security_group_id"
pod_to_node_dns_sg_id = "TF_VAR_pod_to_node_dns_sg_id"
smtp_user = "TF_VAR_smtp_user"
smtp_password = "TF_VAR_smtp_password"
}
}

Expand Down
31 changes: 30 additions & 1 deletion deployments/spacelift/dpe-k8s/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,33 @@ variable "auth0_clients" {
description = string
app_type = string
}))
}
}

variable "ses_email_identities" {
type = list(string)
description = "List of email identities to be added to SES"
}

variable "ses_email_domains" {
type = list(string)
description = "List of email domains to be added to SES"
}


variable "smtp_user" {
description = "The SMTP user. Required if smtp_user, smtp_password, and smtp_from are set"
type = string
default = ""
}

variable "smtp_password" {
description = "The SMTP password. Required if smtp_user, smtp_password, and smtp_from are set"
type = string
default = ""
}

variable "smtp_from" {
description = "The SMTP from address. Required if smtp_user, smtp_password, and smtp_from are set"
type = string
default = ""
}
3 changes: 3 additions & 0 deletions deployments/stacks/dpe-k8s-deployments/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ module "signoz" {
gateway_namespace = "envoy-gateway"
cluster_name = var.cluster_name
auth0_jwks_uri = var.auth0_jwks_uri
smtp_password = var.smtp_password
smtp_user = var.smtp_user
smtp_from = var.smtp_from
}

module "envoy-gateway" {
Expand Down
23 changes: 23 additions & 0 deletions deployments/stacks/dpe-k8s-deployments/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,26 @@ variable "auth0_jwks_uri" {
description = "The JWKS URI for Auth0"
type = string
}

variable "auth0_domain" {
description = "Auth0 domain"
type = string
}

variable "smtp_user" {
description = "The SMTP user. Required if smtp_user, smtp_password, and smtp_from are set"
type = string
default = ""
}

variable "smtp_password" {
description = "The SMTP password. Required if smtp_user, smtp_password, and smtp_from are set"
type = string
default = ""
}

variable "smtp_from" {
description = "The SMTP from address. Required if smtp_user, smtp_password, and smtp_from are set"
type = string
default = ""
}
7 changes: 7 additions & 0 deletions deployments/stacks/dpe-k8s/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,10 @@ module "sage-aws-eks" {
private_subnet_ids_eks_control_plane = module.sage-aws-vpc.private_subnet_ids_eks_control_plane
private_subnet_ids_eks_worker_nodes = module.sage-aws-vpc.private_subnet_ids_eks_worker_nodes
}

module "sage-aws-ses" {
source = "../../../modules/sage-aws-ses"

email_identities = var.ses_email_identities
email_domains = var.ses_email_domains
}
9 changes: 9 additions & 0 deletions deployments/stacks/dpe-k8s/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,12 @@ output "region" {
output "cluster_name" {
value = module.sage-aws-eks.cluster_name
}

output "smtp_user" {
value = module.sage-aws-ses.smtp_user
}

output "smtp_password" {
sensitive = true
value = module.sage-aws-ses.smtp_password
}
10 changes: 10 additions & 0 deletions deployments/stacks/dpe-k8s/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ variable "azs_eks_worker_nodes" {
type = list(string)
description = "Availability Zones for the EKS worker nodes"
}

variable "ses_email_identities" {
type = list(string)
description = "List of email identities to be added to SES"
}

variable "ses_email_domains" {
type = list(string)
description = "List of email domains to be added to SES"
}
32 changes: 32 additions & 0 deletions modules/sage-aws-ses/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Purpose
This module is used to set up SES (Simple email service) in AWS.

By setting a few variables we are able to create a number of Email addresses and Domains
to AWS SES. The variables to be set are:

- `email_identities`, example: `["example@sagebase.org"]`
- `email_domains`, example `["sagebase.org"]`

# Manual steps required
After running this module a number of manual steps are required as they are external
processes that need to happen:

## Verify Email address
1) Navigate to Amazon SES in the web console
2) Navigate to `identities`
3) Choose the Identity to verify
4) Send a test email and click the link recieved to verify the email

Optional: Send a test email after verifying to confirm you may recieve emails


## Verify Sending domain
This is required for each AWS account where AWS SES is going to be set up.

Reading: <https://docs.aws.amazon.com/ses/latest/dg/creating-identities.html#just-verify-domain-proc>

1) Navigate to Amazon SES in the web console
2) Navigate to `identities`
3) Choose the Domain to verify
4) Download the DKIM under `Publish DNS records` and create an IT ticket to add the records
5) Example IT ticket for reference: <https://sagebionetworks.jira.com/browse/IT-3965>
6 changes: 6 additions & 0 deletions modules/sage-aws-ses/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
data "aws_iam_policy_document" "ses_sender" {
statement {
actions = ["ses:SendRawEmail"]
resources = ["*"]
}
}
28 changes: 28 additions & 0 deletions modules/sage-aws-ses/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
resource "aws_ses_email_identity" "identities" {
for_each = { for identity in var.email_identities : identity => identity }
email = each.value
}

resource "aws_ses_domain_identity" "identities" {
for_each = { for identity in var.email_domains : identity => identity }
domain = each.value
}

resource "aws_iam_user" "smtp_user" {
name = "smtp_user"
}

resource "aws_iam_access_key" "smtp_user" {
user = aws_iam_user.smtp_user.name
}

resource "aws_iam_policy" "ses_sender" {
name = "ses_sender"
description = "Allows sending of e-mails via Simple Email Service"
policy = data.aws_iam_policy_document.ses_sender.json
}

resource "aws_iam_user_policy_attachment" "test-attach" {
user = aws_iam_user.smtp_user.name
policy_arn = aws_iam_policy.ses_sender.arn
}
9 changes: 9 additions & 0 deletions modules/sage-aws-ses/ouputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

output "smtp_user" {
value = aws_iam_access_key.smtp_user.id
}

output "smtp_password" {
sensitive = true
value = aws_iam_access_key.smtp_user.ses_smtp_password_v4
}
17 changes: 17 additions & 0 deletions modules/sage-aws-ses/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "email_identities" {
type = list(string)
description = "List of email identities to be added to SES"
}

variable "email_domains" {
type = list(string)
description = "List of email domains to be added to SES"
}

variable "tags" {
description = "AWS Resource Tags"
type = map(string)
default = {
"CostCenter" = "No Program / 000000"
}
}
8 changes: 8 additions & 0 deletions modules/sage-aws-ses/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
8 changes: 8 additions & 0 deletions modules/signoz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ A number of items are needed:
- Set up ingress to the cluster/collector to send data to: https://sagebionetworks.jira.com/browse/IBCDPE-1095
- Set up accounts and access to the service decleratively


## Setting up SMTP for alertmanager
Alertmanager is an additional tool that is deployed to the kubernetes cluster that
handles forwarding an alert out to 1 or more streams that will receive the alert.
Alert manager is set to to send emails through AWS SES (Simple Email Service) set up
by the `modules/sage-aws-ses` terraform scripts. See that module for more information
about the setup of AWS SES.

## Accessing signoz (Internet)

#### Sending data into signoz (From internet)
Expand Down
18 changes: 17 additions & 1 deletion modules/signoz/main.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
locals {
alertmanager_enabled = var.smtp_from != "" && var.smtp_user != "" && var.smtp_password != ""
}

resource "kubernetes_namespace" "signoz" {
metadata {
Expand All @@ -7,7 +10,7 @@ resource "kubernetes_namespace" "signoz" {

resource "kubectl_manifest" "signoz-deployment" {
depends_on = [kubernetes_namespace.signoz]

yaml_body = <<YAML
apiVersion: argoproj.io/v1alpha1
kind: Application
Expand All @@ -31,6 +34,19 @@ spec:
parameters:
- name: "clickhouse.password"
value: ${random_password.clickhouse-admin-password.result}
%{if local.alertmanager_enabled}
- name: "alertmanager.enabled"
value: "true"
- name: "alertmanager.additionalEnvs.ALERTMANAGER_SMTP_FROM"
value: ${var.smtp_from}
- name: "alertmanager.additionalEnvs.ALERTMANAGER_SMTP_AUTH_USERNAME"
value: ${var.smtp_user}
- name: "alertmanager.additionalEnvs.ALERTMANAGER_SMTP_AUTH_PASSWORD"
value: ${var.smtp_password}
%{else}
- name: "alertmanager.enabled"
value: "false"
%{endif}
valueFiles:
- $values/modules/signoz/templates/values.yaml
- repoURL: 'https://github.com/Sage-Bionetworks-Workflows/eks-stack.git'
Expand Down
Loading