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

chore(tf): create password for read-only SQL user on staging #1658

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions tf/env/local/secrets-sql.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ resource "kubernetes_secret" "sql-secrets-init-passwords" {
"SQL_INIT_PASSWORD_API" = base64encode(random_password.sql-passwords["api"].result)
"SQL_INIT_PASSWORD_MW" = base64encode(random_password.sql-passwords["mediawiki-db-manager"].result)
"SQL_INIT_PASSWORD_BACKUPS" = base64encode(random_password.sql-passwords["backup-manager"].result)
"SQL_INIT_OBSERVER" = base64encode(random_password.sql-passwords["observer"].result)
}

}
Expand Down
1 change: 1 addition & 0 deletions tf/env/local/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ variable "sql-passwords" {
"api",
"mediawiki-db-manager",
"backup-manager",
"observer"
]
}

Expand Down
3 changes: 2 additions & 1 deletion tf/env/staging/kubernetes-secrets.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module "wbaas2-k8s-secrets" {
source = "git::ssh://[email protected]/wmde/wbaas-deploy//tf//modules/k8s-secrets?ref=tf-module-k8s-secrets-3"
source = "../../modules-next/k8s-secrets"
providers = {
kubernetes = kubernetes.wbaas-2
}
Expand All @@ -12,6 +12,7 @@ module "wbaas2-k8s-secrets" {
sql_password_api = random_password.sql-passwords["staging-api"].result
sql_password_mediawiki_db_manager = random_password.sql-passwords["staging-mediawiki-db-manager"].result
sql_password_backup_manager = random_password.sql-passwords["staging-backup-manager"].result
sql_password_observer = random_password.sql-passwords["staging-observer"].result
redis_password = random_password.redis-password.result
recaptcha_v3_site_key = var.recaptcha_v3_site_key
recaptcha_v3_secret = var.recaptcha_v3_secret
Expand Down
1 change: 1 addition & 0 deletions tf/env/staging/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ variable "sql-passwords" {
"staging-api",
"staging-mediawiki-db-manager",
"staging-backup-manager",
"staging-observer"
]
}

Expand Down
189 changes: 189 additions & 0 deletions tf/modules-next/k8s-secrets/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
resource "kubernetes_secret" "smtp-credentials" {
for_each = toset(var.mediawiki_secret_namespaces)
metadata {
name = "smtp-credentials"
namespace = each.value
}

data = {
"username" = var.smtp_username
"password" = var.smtp_password
}
}

moved {
from = kubernetes_secret.smtp-credentials
to = kubernetes_secret.smtp-credentials["default"]
}

# Deprecated per https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_service_account_key#example-usage-save-key-in-kubernetes-secret---deprecated
# but will do for now...
resource "kubernetes_secret" "api-serviceaccount" {
metadata {
name = "api-serviceaccount"
}
data = {
"key.json" = base64decode(var.google_service_account_key_api)
}
}

# Deprecated per https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_service_account_key#example-usage-save-key-in-kubernetes-secret---deprecated
# but will do for now...
resource "kubernetes_secret" "clouddns-dns01-solver-svc-acct" {
metadata {
name = "clouddns-dns01-solver-svc-acct"
namespace = "cert-manager"
}
data = {
"key.json" = base64decode(var.google_service_account_key_dns)
}
}

# Used by the sql service for initial setup
resource "kubernetes_secret" "sql-secrets-passwords" {
for_each = toset(var.mediawiki_secret_namespaces)
metadata {
name = "sql-secrets-passwords"
# TODO default? or staging?
namespace = each.value
}

binary_data = {
"mariadb-root-password" = base64encode(var.sql_password_root)
"mariadb-replication-password" = base64encode(var.sql_password_replication)
}
}

moved {
from = kubernetes_secret.sql-secrets-passwords
to = kubernetes_secret.sql-secrets-passwords["default"]
}

# Used by the init script on sql services for user and permissions setup
resource "kubernetes_secret" "sql-secrets-init-passwords" {
for_each = toset(var.mediawiki_secret_namespaces)
metadata {
name = "sql-secrets-init-passwords"
# TODO default? or staging?
namespace = each.value
}

binary_data = {
"SQL_INIT_PASSWORD_API" = base64encode(var.sql_password_api)
"SQL_INIT_PASSWORD_MW" = base64encode(var.sql_password_mediawiki_db_manager)
"SQL_INIT_PASSWORD_BACKUPS" = base64encode(var.sql_password_backup_manager)
"SQL_INIT_OBSERVER" = base64encode(var.sql_password_observer)
}

}

moved {
from = kubernetes_secret.sql-secrets-init-passwords
to = kubernetes_secret.sql-secrets-init-passwords["default"]
}

# Used by the sql service for initial setup
resource "kubernetes_secret" "redis-password" {
for_each = toset(var.mediawiki_secret_namespaces)
metadata {
name = "redis-password"
# Default NS for staging?
namespace = each.value
}

data = {
"password" = var.redis_password
}

}

moved {
from = kubernetes_secret.redis-password
to = kubernetes_secret.redis-password["default"]
}

resource "kubernetes_secret" "recaptcha-v3-secrets" {
for_each = toset(var.mediawiki_secret_namespaces)
metadata {
name = "recaptcha-v3-secrets"
namespace = each.value
}

data = {
"site_key" = var.recaptcha_v3_site_key,
"secret_key" = var.recaptcha_v3_secret
}
}

moved {
from = kubernetes_secret.recaptcha-v3-secrets
to = kubernetes_secret.recaptcha-v3-secrets["default"]
}

resource "kubernetes_secret" "recaptcha-v2-secrets" {
for_each = toset(var.mediawiki_secret_namespaces)
metadata {
name = "recaptcha-v2-secrets"
namespace = each.value
}

data = {
"site_key" = var.recaptcha_v2_site_key,
"secret_key" = var.recaptcha_v2_secret
}
}

moved {
from = kubernetes_secret.recaptcha-v2-secrets
to = kubernetes_secret.recaptcha-v2-secrets["default"]
}

resource "kubernetes_secret" "api-passport-keys" {
for_each = toset(var.mediawiki_secret_namespaces)
metadata {
name = "api-passport-keys"
# TODO assuming default is staging
namespace = each.value
}

binary_data = {
"oauth-public.key" = base64encode(var.api_passport_public_key)
"oauth-private.key" = base64encode(var.api_passport_private_key)
}

}

moved {
from = kubernetes_secret.api-passport-keys
to = kubernetes_secret.api-passport-keys["default"]
}

resource "kubernetes_secret" "api-app-secrets" {
for_each = toset(var.mediawiki_secret_namespaces)
metadata {
name = "api-app-secrets"
namespace = each.value
}

data = {
"api-app-key" = var.api_app_key
"api-app-jwt-secret" = var.api_app_jwt_secret
}
}

moved {
from = kubernetes_secret.api-app-secrets
to = kubernetes_secret.api-app-secrets["default"]
}

# Used by the wbaas-backup pod/job
resource "kubernetes_secret" "backup-openssl-key" {
metadata {
name = "backup-openssl-key"
namespace = "default"
}

data = {
"key" = var.logical_backup_openssl_secret
}
}
8 changes: 8 additions & 0 deletions tf/modules-next/k8s-secrets/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.5.0"
}
}
}
116 changes: 116 additions & 0 deletions tf/modules-next/k8s-secrets/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
variable "smtp_username" {
type = string
description = "Username for SMTP server"
}

variable "smtp_password" {
type = string
description = "Password for SMTP server"
sensitive = true
}

variable "google_service_account_key_api" {
type = string
description = "google service account key for use in the api application"
sensitive = true
}

variable "google_service_account_key_dns" {
type = string
description = "google service account key for use by cert-manager to alter DNS records"
sensitive = true
}

variable "sql_password_root" {
type = string
description = "SQL root password for staging cluster"
sensitive = true
}
variable "sql_password_replication" {
type = string
description = "SQL replication password for staging cluster"
sensitive = true
}

variable "sql_password_api" {
type = string
description = "SQL platform api password for staging cluster"
sensitive = true
}

variable "sql_password_mediawiki_db_manager" {
type = string
description = "SQL mediawiki db manager password for staging cluster"
sensitive = true
}

variable "sql_password_backup_manager" {
type = string
sensitive = true
}

variable "sql_password_observer" {
type = string
sensitive = true
}

variable "redis_password" {
type = string
description = "redis password for staging cluster"
sensitive = true
}

variable "recaptcha_v3_site_key" {
type = string
description = "recaptcha_v3_site_key for the environment"
}
variable "recaptcha_v3_secret" {
type = string
description = "recaptcha_v3_secret for the environment"
sensitive = true
}
variable "recaptcha_v2_site_key" {
type = string
description = "recaptcha_v2_site_key for the environment"
}
variable "recaptcha_v2_secret" {
type = string
description = "recaptcha_v2_secret for the environment"
sensitive = true
}

variable "api_passport_public_key" {
type = string
description = "Laravel Passport OAuth Public Key for staging cluster"
}

variable "api_passport_private_key" {
type = string
description = "Laravel Passport OAuth Private Key for staging cluster"
sensitive = true
}

variable "api_app_key" {
type = string
description = "Laravel API App Key"
sensitive = true
}

variable "api_app_jwt_secret" {
type = string
description = "Laravel API App JWT Secret"
sensitive = true
}

variable "logical_backup_openssl_secret" {
type = string
description = "Key to encrypt backup tarballs"
sensitive = true
}

variable "mediawiki_secret_namespaces" {
type = list(string)
description = "The namespaces to make mediawiki secrets available in"
sensitive = false
default = ["default"]
}