Skip to content

Commit 5499639

Browse files
authored
fix(azure): security hardening for Azure modules (#385)
* fix(azure): critical security vulnerabilities in Azure SQL modules - Restrict Azure PostgreSQL firewall from 0.0.0.0-255.255.255.255 to Azure services only (0.0.0.0-0.0.0.0) - Restrict Azure MySQL firewall from 0.0.0.0-255.255.255.255 to Azure services only (0.0.0.0-0.0.0.0) - Change enable_ssl default to true for Azure PostgreSQL - Add enable_ssl variable to Azure MySQL with default true - Make MySQL require_secure_transport conditional on enable_ssl variable instead of always OFF * fix(azure): cert-manager race condition and overly permissive RBAC - Add depends_on to kubectl_manifest resources to prevent cert-manager webhook race condition during cluster provisioning - Downgrade zop-system ClusterRoleBinding from cluster-admin to edit for principle of least privilege * Enable SSL for Grafana PostgreSQL connection on Azure
1 parent 922c9dd commit 5499639

8 files changed

Lines changed: 21 additions & 10 deletions

File tree

k8s/azure/aks/cert-manager.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ resource "helm_release" "cert_manager" {
7070
}
7171

7272
resource "kubectl_manifest" "cluster_wildcard_issuer" {
73-
yaml_body = local.cluster_wildcard_issuer
73+
yaml_body = local.cluster_wildcard_issuer
74+
depends_on = [helm_release.cert_manager]
7475
}
7576

7677
resource "kubectl_manifest" "cluster_wildcard_certificate" {
77-
yaml_body = local.cluster_wildcard_certificate
78+
yaml_body = local.cluster_wildcard_certificate
79+
depends_on = [kubectl_manifest.cluster_wildcard_issuer]
7880
}
7981

8082
resource "kubernetes_secret_v1" "certificate_replicator" {

k8s/azure/aks/grafana.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ locals {
2222
GRAFANA_DB_HOST = try(local.grafana_enable && var.observability_config.grafana.persistence.type == "db" ? module.grafana_db[0].db_url : "", "")
2323
GRAFANA_DB_PASSWORD = try(local.grafana_enable && var.observability_config.grafana.persistence.type == "db" ? module.grafana_db[0].db_password : "", "")
2424
GRAFANA_DB_USER = try(local.grafana_enable && var.observability_config.grafana.persistence.type == "db" ? module.grafana_db[0].db_admin_user : "", "")
25+
GRAFANA_DB_SSL_MODE = try(local.grafana_enable && var.observability_config.grafana.persistence.type == "db" ? "require" : "disable", "disable")
2526
GRAFANA_MIN_REPLICA = try(var.observability_config.grafana.min_replica != null ? var.observability_config.grafana.min_replica : 1, 1)
2627
GRAFANA_MAX_REPLICA = try(var.observability_config.grafana.max_replica != null ? var.observability_config.grafana.max_replica : 10, 10)
2728
GRAFANA_REQUEST_MEMORY = try(var.observability_config.grafana.request_memory != null ? var.observability_config.grafana.request_memory : "100Mi", "100Mi")

k8s/azure/aks/templates/grafana-values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ grafana.ini:
1919
host: ${GRAFANA_DB_HOST}
2020
user: ${GRAFANA_DB_USER}
2121
password: ${GRAFANA_DB_PASSWORD}
22+
ssl_mode: ${GRAFANA_DB_SSL_MODE}
2223
%{~ endif ~}
2324
server:
2425
root_url: https://${GRAFANA_HOST}

sql/azure-mysql/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ resource "azurerm_mysql_flexible_database" "mysql_db" {
6565
}
6666

6767
resource "azurerm_mysql_flexible_server_configuration" "mysql_parameter_group" {
68+
count = var.enable_ssl == false ? 1 : 0
6869
name = "require_secure_transport"
6970
resource_group_name = var.resource_group_name
7071
server_name = azurerm_mysql_flexible_server.mysql_server.name
@@ -77,7 +78,7 @@ resource "azurerm_mysql_flexible_server_firewall_rule" "mysql_firewall" {
7778
resource_group_name = var.resource_group_name
7879
server_name = azurerm_mysql_flexible_server.mysql_server.name
7980
start_ip_address = "0.0.0.0"
80-
end_ip_address = "255.255.255.255"
81+
end_ip_address = "0.0.0.0"
8182
}
8283

8384
resource "azurerm_mysql_flexible_server" "mysql_read_replica" {

sql/azure-mysql/vars.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ variable "io_scaling_enabled" {
133133
default = false
134134
}
135135

136+
variable "enable_ssl" {
137+
description = "Whether SSL should be enabled or not based on user requirement"
138+
type = bool
139+
default = true
140+
}
141+
136142
variable "multi_ds" {
137143
description = "Whether to create multiple databases in the same instance"
138144
type = bool

sql/azure-postgres/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ resource "azurerm_postgresql_flexible_server_configuration" "ssl_parameter_group
7171
}
7272

7373
resource "azurerm_postgresql_flexible_server_firewall_rule" "postgres_firewall" {
74-
count = local.vnet_enabled ? 0 : 1
75-
name = "${var.cluster_name}-${var.namespace}-postgres-firewall"
76-
server_id = azurerm_postgresql_flexible_server.postgres_server.id
77-
start_ip_address = "0.0.0.0"
78-
end_ip_address = "255.255.255.255"
74+
count = local.vnet_enabled ? 0 : 1
75+
name = "${var.cluster_name}-${var.namespace}-postgres-firewall"
76+
server_id = azurerm_postgresql_flexible_server.postgres_server.id
77+
start_ip_address = "0.0.0.0"
78+
end_ip_address = "0.0.0.0"
7979
}
8080

8181
resource "azurerm_postgresql_flexible_server" "postgresql_replica_server" {

sql/azure-postgres/vars.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ variable "zone" {
101101
variable "enable_ssl" {
102102
description = "Whether SSL should be enabled or not based on user requirement"
103103
type = bool
104-
default = false
104+
default = true
105105
}
106106

107107
variable "storage_mb" {

zop-system/azure/permissions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ resource "kubernetes_cluster_role_binding" "zop_cluster_role_binding_cluster_adm
150150
role_ref {
151151
api_group = "rbac.authorization.k8s.io"
152152
kind = "ClusterRole"
153-
name = "cluster-admin"
153+
name = "edit"
154154
}
155155
subject {
156156
kind = "ServiceAccount"

0 commit comments

Comments
 (0)