feat(mail): enhance mail configuration with getmail and dovecot settings

- Added getmail configuration generation using template files.
- Introduced postfix and dovecot configuration checksums for deployment.
- Created new dovecot configuration file and sieve script for email handling.
- Updated main.tf to utilize local variables for configuration management.
- Removed redundant external password hasher from main.tf.

feat(nginx): improve nginx configuration management

- Centralized nginx configuration into a local variable with checksum.
- Created separate config maps for default website configurations.
- Updated deployment to utilize new configuration structure.

feat(sftpgo): add SFTPGo application deployment

- Introduced SFTPGo with Kubernetes resources including namespace, config maps, and secrets.
- Configured SFTPGo with SMTP settings and AWS credentials.
- Implemented health checks and volume mounts for persistent storage.

refactor(seafile): remove Seafile module

- Deleted Seafile module and associated resources as part of cleanup.
This commit is contained in:
2025-05-05 00:47:36 +02:00
parent 6adbd50c6d
commit e6e85b00f7
60 changed files with 1107 additions and 604 deletions
+40
View File
@@ -51,5 +51,45 @@ locals {
name = kubernetes_secret.relay_mail_credentials.metadata[0].name
}
}
getmail_config = { for job in local.getmail_jobs : "getmailrc_${job.name}" =>
templatefile("${path.module}/resources/getmail/getmailrc.tpl", {
recipient = job.recipient
domain = job.domain
server = job.server
port = job.port
username = job.username
password = job.password
mailbox = job.mailbox
delete_after = job.delete_after
dovecot_lmtp_address = "dovecot-lmtp.mail.svc.cluster.local"
dovecot_lmtp_port = 31024
})
}
postfix_run_config = file("${path.module}/resources/postfix/run.config")
postfix_bcc_map = join("\n", [for account in var.email_accounts : "/([^@]+)@${replace(account.domain, ".", "\\.")}/ $${1}+Sent@${account.domain}"])
postfix_run_config_checksum = sha256(local.postfix_run_config)
postfix_bcc_map_checksum = sha256(local.postfix_bcc_map)
dovecot_config = file("${path.module}/resources/dovecot/dovecot.conf")
dovecot_users = join("\n", [for account in var.email_accounts : "${account.username}:{BLF-CRYPT.HEX}${local.password_hashes[account.username]}:1000:1000::/var/mail/${account.username}::"])
dovecot_sieve = file("${path.module}/resources/dovecot/sieve")
dovecot_config_checksum = sha256(local.dovecot_config)
dovecot_users_checksum = sha256(local.dovecot_users)
dovecot_sieve_checksum = sha256(local.dovecot_sieve)
}
data "external" "password_hasher" {
for_each = { for account in var.email_accounts : account.username => account }
program = ["python3", "${path.module}/lib/bcrypt_hash.py"]
query = {
password = each.value.password
cost = "10"
}
}
+18 -42
View File
@@ -1,13 +1,3 @@
data "external" "password_hasher" {
for_each = { for account in var.email_accounts : account.username => account }
program = ["python3", "${path.module}//lib/bcrypt_hash.py"]
query = {
password = each.value.password
cost = "10"
}
}
resource "kubernetes_namespace" "mail" {
metadata {
annotations = {
@@ -26,7 +16,7 @@ resource "kubernetes_secret" "dovecot_users" {
namespace = kubernetes_namespace.mail.metadata[0].name
}
data = {
"users" = join("\n", [for account in var.email_accounts : "${account.username}:{BLF-CRYPT.HEX}${local.password_hashes[account.username]}:1000:1000::/var/mail/${account.username}::"])
"users" = local.dovecot_users
}
}
@@ -72,18 +62,17 @@ resource "kubernetes_config_map" "postfix_config" {
}
data = {
"run.config" = file("${path.module}/resources/mail/run.config")
"run.config" = local.postfix_run_config
}
}
resource "kubernetes_secret" "bcc_map" {
metadata {
name = "bcc-map"
namespace = kubernetes_namespace.mail.metadata[0].name
}
data = {
"bcc_map" = join("\n", [for account in var.email_accounts : "/([^@]+)@${replace(account.domain, ".", "\\.")}/ $${1}+Sent@${account.domain}"])
"bcc_map" = local.postfix_bcc_map
}
}
@@ -93,21 +82,7 @@ resource "kubernetes_config_map" "getmail_config" {
namespace = kubernetes_namespace.mail.metadata[0].name
}
data = { for job in local.getmail_jobs : "getmailrc_${job.name}" =>
templatefile("${path.module}/resources/mail/getmailrc.tpl", {
recipient = job.recipient
domain = job.domain
server = job.server
port = job.port
username = job.username
password = job.password
mailbox = job.mailbox
delete_after = job.delete_after
dovecot_lmtp_address = "dovecot-lmtp.mail.svc.cluster.local"
dovecot_lmtp_port = 31024
})
}
data = local.getmail_config
}
resource "kubernetes_config_map" "dovecot_config" {
@@ -117,7 +92,7 @@ resource "kubernetes_config_map" "dovecot_config" {
}
data = {
"dovecot.conf" = file("${path.module}/resources/mail/dovecot.conf")
"dovecot.conf" = local.dovecot_config
}
}
@@ -128,7 +103,7 @@ resource "kubernetes_config_map" "dovecot_sieve" {
}
data = {
"sieve" = file("${path.module}/resources/mail/sieve")
"sieve" = local.dovecot_sieve
}
}
@@ -247,6 +222,12 @@ resource "kubernetes_deployment" "dovecot" {
labels = {
app = "dovecot"
}
annotations = {
"checksum/dovecot" = local.dovecot_config_checksum
"checksum/sieve" = local.dovecot_sieve_checksum
# Commented out to avoid unnecessary restarts
# "checksum/users" = local.dovecot_users_checksum
}
}
spec {
service_account_name = kubernetes_service_account.mail_app.metadata[0].name
@@ -337,11 +318,7 @@ resource "kubernetes_deployment" "dovecot" {
}
depends_on = [kubernetes_manifest.mail_certificate, kubernetes_service_account.mail_app]
lifecycle {
ignore_changes = [spec[0].template[0].metadata[0].annotations]
replace_triggered_by = [
kubernetes_config_map.dovecot_config,
kubernetes_config_map.dovecot_sieve,
]
ignore_changes = [spec[0].template[0].metadata[0].annotations["kubectl.kubernetes.io/restartedAt"]]
}
}
@@ -368,6 +345,10 @@ resource "kubernetes_deployment" "postfix" {
labels = {
app = "postfix"
}
annotations = {
"checksum/runconfig" = local.postfix_run_config_checksum
"checksum/bccmap" = local.postfix_bcc_map_checksum
}
}
spec {
service_account_name = kubernetes_service_account.mail_app.metadata[0].name
@@ -460,12 +441,7 @@ resource "kubernetes_deployment" "postfix" {
}
depends_on = [kubernetes_manifest.mail_certificate, kubernetes_service_account.mail_app]
lifecycle {
ignore_changes = [spec[0].template[0].metadata[0].annotations]
replace_triggered_by = [
kubernetes_config_map.postfix_config,
kubernetes_secret.relay_mail_credentials,
kubernetes_secret.bcc_map,
]
ignore_changes = [spec[0].template[0].metadata[0].annotations["kubectl.kubernetes.io/restartedAt"]]
}
}