Add Gitea and Mail modules with configuration and resources
- Created Gitea module with outputs, provider, and variables for deployment. - Implemented Mail module including configuration for Dovecot and Postfix, along with necessary resources such as secrets, config maps, and deployments. - Added Python script for bcrypt password hashing and integrated it into the Mail module. - Defined persistent volumes and claims for Seafile module, along with Nginx configuration for serving content. - Established necessary variables for all modules to ensure flexibility and configurability.
This commit is contained in:
@@ -35,3 +35,47 @@ module "m3uproxy" {
|
||||
wireguard_private_key = var.wireguard_private_key
|
||||
wireguard_public_key = var.wireguard_public_key
|
||||
}
|
||||
|
||||
module "mail" {
|
||||
source = "../modules/mail"
|
||||
|
||||
persistent_folder = local.persistent_folder
|
||||
|
||||
primary_domain = local.primary_domain
|
||||
email_accounts = local.email_accounts
|
||||
|
||||
relay_smtp_host = local.scaleway_smtp_host
|
||||
relay_smtp_port = 465
|
||||
relay_smtp_username = var.scaleway_project_id
|
||||
relay_smtp_password = scaleway_iam_api_key.mail_app_api.secret_key
|
||||
|
||||
fetch_emails_schedule = local.fetch_emails_schedule
|
||||
|
||||
mail_crypt_private_key = var.mail_crypt_private_key
|
||||
mail_crypt_public_key = var.mail_crypt_public_key
|
||||
}
|
||||
|
||||
module "gitea" {
|
||||
source = "../modules/gitea"
|
||||
|
||||
persistent_folder = local.persistent_folder
|
||||
database_folder = local.database_folder
|
||||
|
||||
backup_folder = local.gitea_backup_path
|
||||
backup_retention_days = local.local_backup_retention_days
|
||||
backup_cron_schedule = local.gitea_sql_backup_cron_schedule
|
||||
|
||||
db_password = var.gitea_mysql_password
|
||||
db_root_password = var.mysql_root_password
|
||||
|
||||
tag = local.gitea_version
|
||||
fqdn = local.gitea_fqdn
|
||||
app_name = "A13Labs git repository"
|
||||
|
||||
relay_smtp_host = local.scaleway_smtp_host
|
||||
relay_smtp_port = local.scaleway_smtp_port
|
||||
relay_smtp_username = var.scaleway_project_id
|
||||
relay_smtp_password = scaleway_iam_api_key.mail_app_api.secret_key
|
||||
|
||||
from_email = "gitea@${local.primary_domain}"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
module "mail_backup" {
|
||||
|
||||
source = "../modules/scw_backup_job"
|
||||
|
||||
namespace = module.mail.namespace
|
||||
app_name = module.mail.app_name
|
||||
|
||||
scaleway_organization_id = var.scaleway_organization_id
|
||||
scaleway_project_id = var.scaleway_organization_id
|
||||
access_key = scaleway_iam_api_key.backup_app_api.access_key
|
||||
secret_key = scaleway_iam_api_key.backup_app_api.secret_key
|
||||
bucket_name = scaleway_object_bucket.backup.name
|
||||
|
||||
retention_days = local.local_backup_retention_days
|
||||
cron_schedule = local.mail_files_backup_cron_schedule
|
||||
|
||||
source_folder = module.mail.path
|
||||
target_folder = local.mail_backup_path
|
||||
}
|
||||
|
||||
module "gitea_backup" {
|
||||
source = "../modules/scw_backup_job"
|
||||
|
||||
namespace = module.gitea.namespace
|
||||
app_name = module.gitea.app_name
|
||||
|
||||
scaleway_organization_id = var.scaleway_organization_id
|
||||
scaleway_project_id = var.scaleway_organization_id
|
||||
access_key = scaleway_iam_api_key.backup_app_api.access_key
|
||||
secret_key = scaleway_iam_api_key.backup_app_api.secret_key
|
||||
bucket_name = scaleway_object_bucket.backup.name
|
||||
|
||||
retention_days = local.local_backup_retention_days
|
||||
cron_schedule = local.gitea_files_backup_cron_schedule
|
||||
|
||||
source_folder = module.gitea.path
|
||||
target_folder = local.gitea_backup_path
|
||||
}
|
||||
|
||||
module "nextcloud_backup" {
|
||||
|
||||
source = "../modules/scw_backup_job"
|
||||
|
||||
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
||||
app_name = "nextcloud"
|
||||
|
||||
scaleway_organization_id = var.scaleway_organization_id
|
||||
scaleway_project_id = var.scaleway_organization_id
|
||||
access_key = scaleway_iam_api_key.backup_app_api.access_key
|
||||
secret_key = scaleway_iam_api_key.backup_app_api.secret_key
|
||||
bucket_name = scaleway_object_bucket.backup.name
|
||||
|
||||
retention_days = local.local_backup_retention_days
|
||||
cron_schedule = local.nextcloud_files_backup_cron_schedule
|
||||
|
||||
source_folder = local.nextcloud_path
|
||||
target_folder = local.nextcloud_backup_path
|
||||
}
|
||||
@@ -14,10 +14,8 @@ locals {
|
||||
}
|
||||
}
|
||||
|
||||
gitea_version = "1.23.4"
|
||||
gitea_fqdn = "code.${local.primary_domain}"
|
||||
gitea_sql_backup_cron_schedule = "20 2 * * *"
|
||||
gitea_files_backup_cron_schedule = "30 2 * * *"
|
||||
gitea_version = "1.23.4"
|
||||
gitea_fqdn = "code.${local.primary_domain}"
|
||||
|
||||
nextcloud_version = "30.0.0-apache"
|
||||
nextcloud_fqdn = "cloud.${local.primary_domain}"
|
||||
@@ -51,13 +49,17 @@ locals {
|
||||
rustdesk_fqdn = "rustdesk.${local.primary_domain}"
|
||||
|
||||
# backup
|
||||
local_backup_retention_days = 2
|
||||
cloud_backup_retention_days = 3
|
||||
local_backup_retention_days = 2
|
||||
cloud_backup_retention_days = 3
|
||||
mail_backup_path = "${local.persistent_folder}/backup.mail"
|
||||
gitea_backup_path = "${local.persistent_folder}/backup.gitea"
|
||||
gitea_sql_backup_cron_schedule = "20 2 * * *"
|
||||
gitea_files_backup_cron_schedule = "30 2 * * *"
|
||||
mail_files_backup_cron_schedule = "0 3 * * *"
|
||||
|
||||
# mail settings
|
||||
getmail_version = "v0.0.1-6.19.07"
|
||||
fetch_emails_schedule = "*/2 * * * *"
|
||||
mail_files_backup_cron_schedule = "0 3 * * *"
|
||||
getmail_version = "v0.0.1-6.19.07"
|
||||
fetch_emails_schedule = "*/2 * * * *"
|
||||
|
||||
# email settings
|
||||
scaleway_smtp_host = "smtp.tem.scw.cloud"
|
||||
|
||||
@@ -1,340 +0,0 @@
|
||||
locals {
|
||||
gitea_env_vars = {
|
||||
APP_NAME = "A13Labs git repository"
|
||||
HTTP_PORT = "3000"
|
||||
RUN_MODE = "prod"
|
||||
LFS_START_SERVER = "true"
|
||||
SSH_DOMAIN = local.gitea_fqdn
|
||||
DISABLE_REGISTRATION = true
|
||||
INSTALL_LOCK = "true"
|
||||
DB_TYPE = "mysql"
|
||||
DB_NAME = "gitea"
|
||||
DB_HOST = module.gitea_database.host
|
||||
SSH_LISTEN_PORT = 22
|
||||
GITEA__mailer__ENABLED = true
|
||||
GITEA__mailer__FROM = "gitea@alexpires.me"
|
||||
GITEA__mailer__SMTP_ADDR = local.scaleway_smtp_host
|
||||
GITEA__mailer__SMTP_PORT = local.scaleway_smtp_port
|
||||
GITEA__mailer__PROTOCOL = "smtps"
|
||||
}
|
||||
|
||||
gitea_secrets = {
|
||||
DB_USER = {
|
||||
key = "username"
|
||||
name = module.gitea_database.app_crendentials_name
|
||||
}
|
||||
DB_PASSWD = {
|
||||
key = "password"
|
||||
name = module.gitea_database.app_crendentials_name
|
||||
}
|
||||
GITEA__mailer__USER = {
|
||||
key = "username"
|
||||
name = kubernetes_secret.gitea_mail_credentials.metadata[0].name
|
||||
}
|
||||
GITEA__mailer__PASSWD = {
|
||||
key = "password"
|
||||
name = kubernetes_secret.gitea_mail_credentials.metadata[0].name
|
||||
}
|
||||
}
|
||||
|
||||
gitea_path = "${local.persistent_folder}/gitea"
|
||||
gitea_db_path = "${local.database_folder}/mysql.gitea"
|
||||
gitea_backup_path = "${local.persistent_folder}/backup.gitea"
|
||||
}
|
||||
|
||||
#
|
||||
# Namespace
|
||||
#
|
||||
resource "kubernetes_namespace" "gitea" {
|
||||
metadata {
|
||||
annotations = {
|
||||
name = "gitea"
|
||||
}
|
||||
|
||||
labels = {
|
||||
name = "gitea"
|
||||
}
|
||||
|
||||
name = "gitea"
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# Mail credentials
|
||||
#
|
||||
resource "kubernetes_secret" "gitea_mail_credentials" {
|
||||
metadata {
|
||||
name = "gitea-mail-credentials"
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
}
|
||||
data = {
|
||||
username = var.scaleway_project_id
|
||||
password = scaleway_iam_api_key.mail_app_api.secret_key
|
||||
}
|
||||
type = "Opaque"
|
||||
}
|
||||
|
||||
#
|
||||
# Setup MariaDB database
|
||||
#
|
||||
module "gitea_database" {
|
||||
source = "../modules/k8s_mariadb"
|
||||
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
app_name = "gitea"
|
||||
|
||||
app_password = var.gitea_mysql_password
|
||||
root_password = var.mysql_root_password
|
||||
|
||||
retention_days = local.local_backup_retention_days
|
||||
cron_schedule = local.gitea_sql_backup_cron_schedule
|
||||
|
||||
database_folder = local.gitea_db_path
|
||||
backup_folder = local.gitea_backup_path
|
||||
}
|
||||
|
||||
#
|
||||
# Setup rsync backup job to scaleway bucket
|
||||
#
|
||||
module "gitea_backup" {
|
||||
source = "../modules/scw_backup_job"
|
||||
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
app_name = "gitea"
|
||||
|
||||
scaleway_organization_id = var.scaleway_organization_id
|
||||
scaleway_project_id = var.scaleway_organization_id
|
||||
access_key = scaleway_iam_api_key.backup_app_api.access_key
|
||||
secret_key = scaleway_iam_api_key.backup_app_api.secret_key
|
||||
bucket_name = scaleway_object_bucket.backup.name
|
||||
|
||||
retention_days = local.local_backup_retention_days
|
||||
cron_schedule = local.gitea_files_backup_cron_schedule
|
||||
|
||||
source_folder = local.gitea_path
|
||||
target_folder = local.gitea_backup_path
|
||||
}
|
||||
|
||||
#
|
||||
# Gitea service, ingress, deployment and file backup job
|
||||
#
|
||||
resource "kubernetes_service_account" "gitea_service_account" {
|
||||
|
||||
metadata {
|
||||
name = "gitea-app-sa"
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
}
|
||||
|
||||
automount_service_account_token = false
|
||||
}
|
||||
|
||||
resource "kubernetes_service" "gitea_http" {
|
||||
metadata {
|
||||
name = "http"
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
}
|
||||
spec {
|
||||
port {
|
||||
port = 80
|
||||
target_port = "http"
|
||||
}
|
||||
selector = {
|
||||
app = "gitea"
|
||||
}
|
||||
cluster_ip = "None"
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_ingress_v1" "gitea_ingress" {
|
||||
metadata {
|
||||
name = "gitea-ingress"
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
|
||||
annotations = {
|
||||
"kubernetes.io/ingress.class" = "public"
|
||||
"cert-manager.io/cluster-issuer" = "letsencrypt-prod"
|
||||
"nginx.ingress.kubernetes.io/ssl-redirect" = "true"
|
||||
"nginx.ingress.kubernetes.io/proxy-body-size" = "8m"
|
||||
"nginx.ingress.kubernetes.io/proxy-request-buffering" = "on"
|
||||
"nginx.ingress.kubernetes.io/proxy-buffer-size" = "32k"
|
||||
"nginx.ingress.kubernetes.io/proxy-buffers-number" = "16"
|
||||
}
|
||||
}
|
||||
spec {
|
||||
tls {
|
||||
hosts = [local.gitea_fqdn]
|
||||
secret_name = "gitea-tls"
|
||||
}
|
||||
rule {
|
||||
host = local.gitea_fqdn
|
||||
http {
|
||||
path {
|
||||
backend {
|
||||
service {
|
||||
name = "http"
|
||||
port {
|
||||
number = 80
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_deployment" "gitea" {
|
||||
|
||||
depends_on = [module.gitea_database]
|
||||
|
||||
metadata {
|
||||
name = "gitea-app"
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
}
|
||||
spec {
|
||||
selector {
|
||||
match_labels = {
|
||||
app = "gitea"
|
||||
}
|
||||
}
|
||||
strategy {
|
||||
type = "Recreate"
|
||||
}
|
||||
template {
|
||||
metadata {
|
||||
labels = {
|
||||
app = "gitea"
|
||||
}
|
||||
}
|
||||
spec {
|
||||
service_account_name = kubernetes_service_account.gitea_service_account.metadata[0].name
|
||||
container {
|
||||
name = "gitea"
|
||||
image = "gitea/gitea:${local.gitea_version}"
|
||||
image_pull_policy = "Always"
|
||||
|
||||
resources {
|
||||
requests = {
|
||||
memory = "100Mi"
|
||||
}
|
||||
limits = {
|
||||
memory = "300Mi"
|
||||
}
|
||||
}
|
||||
|
||||
liveness_probe {
|
||||
http_get {
|
||||
path = "/api/healthz"
|
||||
port = "http"
|
||||
}
|
||||
initial_delay_seconds = 200
|
||||
period_seconds = 300
|
||||
success_threshold = 1
|
||||
failure_threshold = 5
|
||||
}
|
||||
|
||||
readiness_probe {
|
||||
tcp_socket {
|
||||
port = "http"
|
||||
}
|
||||
initial_delay_seconds = 5
|
||||
period_seconds = 10
|
||||
success_threshold = 1
|
||||
failure_threshold = 3
|
||||
}
|
||||
|
||||
dynamic "env" {
|
||||
for_each = local.gitea_env_vars
|
||||
content {
|
||||
name = env.key
|
||||
value = env.value
|
||||
}
|
||||
}
|
||||
security_context {
|
||||
allow_privilege_escalation = false
|
||||
}
|
||||
|
||||
dynamic "env" {
|
||||
for_each = local.gitea_secrets
|
||||
content {
|
||||
name = env.key
|
||||
value_from {
|
||||
secret_key_ref {
|
||||
key = env.value.key
|
||||
name = env.value.name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
port {
|
||||
container_port = 3000
|
||||
name = "http"
|
||||
}
|
||||
port {
|
||||
container_port = 22
|
||||
name = "ssh"
|
||||
}
|
||||
|
||||
volume_mount {
|
||||
mount_path = "/data"
|
||||
name = "persistent-storage"
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "persistent-storage"
|
||||
host_path {
|
||||
path = local.gitea_path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_role" "gitea_ssh_access" {
|
||||
metadata {
|
||||
name = "gitea-ssh-access"
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
}
|
||||
rule {
|
||||
api_groups = [""]
|
||||
resources = ["pods", "pods/log"]
|
||||
verbs = ["get", "list"]
|
||||
}
|
||||
rule {
|
||||
api_groups = [""]
|
||||
resources = ["pods/exec"]
|
||||
verbs = ["create"]
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_role_binding" "gitea_ssh_access" {
|
||||
metadata {
|
||||
name = "gitea-ssh-access"
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
}
|
||||
role_ref {
|
||||
api_group = "rbac.authorization.k8s.io"
|
||||
kind = "Role"
|
||||
name = kubernetes_role.gitea_ssh_access.metadata[0].name
|
||||
}
|
||||
subject {
|
||||
kind = "ServiceAccount"
|
||||
name = kubernetes_service_account.gitea_service_account.metadata[0].name
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_secret" "gitea_access_token" {
|
||||
metadata {
|
||||
annotations = {
|
||||
"kubernetes.io/service-account.name" = kubernetes_service_account.gitea_service_account.metadata[0].name
|
||||
}
|
||||
name = "git-token"
|
||||
namespace = kubernetes_namespace.gitea.metadata[0].name
|
||||
}
|
||||
|
||||
type = "kubernetes.io/service-account-token"
|
||||
wait_for_service_account_token = true
|
||||
}
|
||||
@@ -1,634 +0,0 @@
|
||||
locals {
|
||||
mail_path = "${local.persistent_folder}/mail"
|
||||
mailboxes_path = "${local.mail_path}/mailboxes"
|
||||
getmail_path = "${local.mail_path}/getmail"
|
||||
postfix_path = "${local.mail_path}/postfix"
|
||||
mail_backup_path = "${local.persistent_folder}/backup.mail"
|
||||
|
||||
getmail_jobs = flatten([
|
||||
for account in local.email_accounts : [
|
||||
for mailbox in account.mailboxes : {
|
||||
name = "${account.recipient}-${mailbox}"
|
||||
recipient = "${account.recipient}+${mailbox}"
|
||||
domain = account.domain
|
||||
server = account.receive.server
|
||||
port = account.receive.port
|
||||
username = account.username
|
||||
password = account.password
|
||||
mailbox = mailbox
|
||||
delete_after = try(account.delete_after, 30)
|
||||
}
|
||||
]
|
||||
])
|
||||
|
||||
postfix_env_vars = {
|
||||
# Email configuration
|
||||
SMTP_HOST = local.scaleway_smtp_host
|
||||
SMTP_PORT = 465
|
||||
MY_PRIMARY_DOMAIN = local.primary_domain
|
||||
MY_DESTINATION = join(",", [for account in local.email_accounts : account.domain])
|
||||
MY_NETWORKS = "127.0.0.0/8"
|
||||
MAILNAME = "smtp.${local.primary_domain}"
|
||||
DOVECOT_AUTH_ADDRESS = "dovecot-auth.mail.svc.cluster.local"
|
||||
DOVECOT_AUTH_PORT = 31000
|
||||
DOVECOT_LMTP_ADDRESS = "dovecot-lmtp.mail.svc.cluster.local"
|
||||
DOVECOT_LMTP_PORT = 31024
|
||||
LOG_TO_STDOUT = 0
|
||||
}
|
||||
|
||||
password_hashes = {
|
||||
for account in local.email_accounts : account.username => data.external.password_hasher[account.username].result.hex_encoded_bcrypt_hash
|
||||
}
|
||||
|
||||
postfix_secrets = {
|
||||
SMTP_USER = {
|
||||
key = "username"
|
||||
name = kubernetes_secret.relay_mail_credentials.metadata[0].name
|
||||
}
|
||||
|
||||
SMTP_PASSWORD = {
|
||||
key = "password"
|
||||
name = kubernetes_secret.relay_mail_credentials.metadata[0].name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data "external" "password_hasher" {
|
||||
for_each = { for account in local.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 = {
|
||||
name = "mail"
|
||||
}
|
||||
labels = {
|
||||
name = "mail"
|
||||
}
|
||||
name = "mail"
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_secret" "dovecot_users" {
|
||||
metadata {
|
||||
name = "dovecot-users"
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
}
|
||||
data = {
|
||||
"users" = join("\n", [for account in local.email_accounts : "${account.username}:{BLF-CRYPT.HEX}${local.password_hashes[account.username]}:1000:1000::/var/mail/${account.username}::"])
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_secret" "relay_mail_credentials" {
|
||||
metadata {
|
||||
name = "relay-mail-credentials"
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
}
|
||||
data = {
|
||||
username = var.scaleway_project_id
|
||||
password = scaleway_iam_api_key.mail_app_api.secret_key
|
||||
}
|
||||
type = "Opaque"
|
||||
}
|
||||
|
||||
resource "kubernetes_secret" "mail_crypt_certs" {
|
||||
metadata {
|
||||
name = "mail-crypt-certs"
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
}
|
||||
data = {
|
||||
"ecprivkey.pem" = var.mail_crypt_private_key
|
||||
"ecpubkey.pem" = var.mail_crypt_public_key
|
||||
}
|
||||
type = "Opaque"
|
||||
}
|
||||
|
||||
|
||||
resource "kubernetes_service_account" "mail_app" {
|
||||
|
||||
metadata {
|
||||
name = "mail-app-sa"
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
}
|
||||
|
||||
automount_service_account_token = false
|
||||
}
|
||||
|
||||
resource "kubernetes_config_map" "postfix_config" {
|
||||
metadata {
|
||||
name = "postfix-config"
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
}
|
||||
|
||||
data = {
|
||||
"run.config" = file("${path.module}/resources/mail/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 local.email_accounts : "/([^@]+)@${replace(account.domain, ".", "\\.")}/ $${1}+Sent@${account.domain}"])
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_config_map" "getmail_config" {
|
||||
metadata {
|
||||
name = "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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_config_map" "dovecot_config" {
|
||||
metadata {
|
||||
name = "dovecot-config"
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
}
|
||||
|
||||
data = {
|
||||
"dovecot.conf" = file("${path.module}/resources/mail/dovecot.conf")
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_config_map" "dovecot_sieve" {
|
||||
metadata {
|
||||
name = "dovecot-sieve"
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
}
|
||||
|
||||
data = {
|
||||
"sieve" = file("${path.module}/resources/mail/sieve")
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_manifest" "mail_certificate" {
|
||||
manifest = {
|
||||
apiVersion = "cert-manager.io/v1"
|
||||
kind = "Certificate"
|
||||
metadata = {
|
||||
name = "mail-cert"
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
}
|
||||
spec = {
|
||||
secretName = "mail-tls"
|
||||
issuerRef = {
|
||||
name = "letsencrypt-prod"
|
||||
kind = "ClusterIssuer"
|
||||
}
|
||||
commonName = "imap.${local.primary_domain}"
|
||||
dnsNames = flatten([for account in local.email_accounts : ["imap.${account.domain}", "smtp.${account.domain}"]])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module "mail_backup" {
|
||||
|
||||
source = "../modules/scw_backup_job"
|
||||
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
app_name = "mail"
|
||||
|
||||
scaleway_organization_id = var.scaleway_organization_id
|
||||
scaleway_project_id = var.scaleway_organization_id
|
||||
access_key = scaleway_iam_api_key.backup_app_api.access_key
|
||||
secret_key = scaleway_iam_api_key.backup_app_api.secret_key
|
||||
bucket_name = scaleway_object_bucket.backup.name
|
||||
|
||||
retention_days = local.local_backup_retention_days
|
||||
cron_schedule = local.mail_files_backup_cron_schedule
|
||||
|
||||
source_folder = local.mail_path
|
||||
target_folder = local.mail_backup_path
|
||||
}
|
||||
|
||||
resource "kubernetes_cron_job_v1" "fetch_emails" {
|
||||
metadata {
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
name = "fetch-emails"
|
||||
}
|
||||
|
||||
spec {
|
||||
schedule = local.fetch_emails_schedule
|
||||
|
||||
job_template {
|
||||
metadata {
|
||||
name = "fetch-emails"
|
||||
}
|
||||
spec {
|
||||
backoff_limit = 1
|
||||
parallelism = 1
|
||||
completions = 1
|
||||
active_deadline_seconds = 300
|
||||
|
||||
template {
|
||||
metadata {
|
||||
labels = {
|
||||
app = "fetch-emails"
|
||||
}
|
||||
}
|
||||
|
||||
spec {
|
||||
container {
|
||||
name = "getmail"
|
||||
image = "a13labs/getmail6:${local.getmail_version}"
|
||||
args = concat(["--getmaildir", "/var/getmail"], flatten([for job in local.getmail_jobs : ["-r", "/getmail/getmailrc_${job.name}"]]))
|
||||
|
||||
volume_mount {
|
||||
name = "getmail-config"
|
||||
mount_path = "/getmail"
|
||||
read_only = true
|
||||
}
|
||||
|
||||
security_context {
|
||||
run_as_user = 1000
|
||||
run_as_group = 1000
|
||||
}
|
||||
|
||||
volume_mount {
|
||||
name = "getmail-cache"
|
||||
mount_path = "/var/getmail"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
restart_policy = "Never"
|
||||
|
||||
volume {
|
||||
name = "getmail-config"
|
||||
config_map {
|
||||
name = "getmail-config"
|
||||
}
|
||||
}
|
||||
|
||||
volume {
|
||||
name = "getmail-cache"
|
||||
host_path {
|
||||
path = local.getmail_path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_deployment" "dovecot" {
|
||||
metadata {
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
name = "dovecot"
|
||||
labels = {
|
||||
app = "dovecot"
|
||||
}
|
||||
}
|
||||
spec {
|
||||
replicas = 1
|
||||
selector {
|
||||
match_labels = {
|
||||
app = "dovecot"
|
||||
}
|
||||
}
|
||||
strategy {
|
||||
type = "Recreate"
|
||||
}
|
||||
template {
|
||||
metadata {
|
||||
labels = {
|
||||
app = "dovecot"
|
||||
}
|
||||
}
|
||||
spec {
|
||||
service_account_name = kubernetes_service_account.mail_app.metadata[0].name
|
||||
container {
|
||||
name = "dovecot"
|
||||
image = "dovecot/dovecot:latest"
|
||||
port {
|
||||
container_port = 31993
|
||||
host_port = 993
|
||||
}
|
||||
port {
|
||||
container_port = 31024
|
||||
}
|
||||
port {
|
||||
container_port = 31000
|
||||
}
|
||||
volume_mount {
|
||||
name = "email-storage"
|
||||
mount_path = "/var/mail"
|
||||
}
|
||||
volume_mount {
|
||||
name = "users"
|
||||
mount_path = "/etc/dovecot/users"
|
||||
sub_path = "users"
|
||||
read_only = true
|
||||
}
|
||||
volume_mount {
|
||||
name = "dovecot-config"
|
||||
mount_path = "/etc/dovecot/dovecot.conf"
|
||||
sub_path = "dovecot.conf"
|
||||
read_only = true
|
||||
}
|
||||
volume_mount {
|
||||
name = "dovecot-sieve"
|
||||
mount_path = "/etc/dovecot/sieve/default.sieve"
|
||||
sub_path = "sieve"
|
||||
read_only = true
|
||||
}
|
||||
volume_mount {
|
||||
name = "certs"
|
||||
mount_path = "/etc/letsencrypt"
|
||||
read_only = true
|
||||
}
|
||||
volume_mount {
|
||||
name = "mail-crypt-certs"
|
||||
mount_path = "/etc/mail-crypt"
|
||||
read_only = true
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "email-storage"
|
||||
host_path {
|
||||
path = local.mailboxes_path
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "users"
|
||||
secret {
|
||||
secret_name = kubernetes_secret.dovecot_users.metadata[0].name
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "dovecot-config"
|
||||
config_map {
|
||||
name = kubernetes_config_map.dovecot_config.metadata[0].name
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "certs"
|
||||
secret {
|
||||
secret_name = "mail-tls"
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "dovecot-sieve"
|
||||
config_map {
|
||||
name = kubernetes_config_map.dovecot_sieve.metadata[0].name
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "mail-crypt-certs"
|
||||
secret {
|
||||
secret_name = kubernetes_secret.mail_crypt_certs.metadata[0].name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_deployment" "postfix" {
|
||||
metadata {
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
name = "postfix"
|
||||
labels = {
|
||||
app = "postfix"
|
||||
}
|
||||
}
|
||||
spec {
|
||||
replicas = 1
|
||||
selector {
|
||||
match_labels = {
|
||||
app = "postfix"
|
||||
}
|
||||
}
|
||||
strategy {
|
||||
type = "Recreate"
|
||||
}
|
||||
template {
|
||||
metadata {
|
||||
labels = {
|
||||
app = "postfix"
|
||||
}
|
||||
}
|
||||
spec {
|
||||
service_account_name = kubernetes_service_account.mail_app.metadata[0].name
|
||||
container {
|
||||
name = "postfix"
|
||||
image = "tozd/postfix:alpine-316"
|
||||
port {
|
||||
container_port = 465
|
||||
host_port = 465
|
||||
}
|
||||
dynamic "env" {
|
||||
for_each = local.postfix_env_vars
|
||||
content {
|
||||
name = env.key
|
||||
value = env.value
|
||||
}
|
||||
}
|
||||
dynamic "env" {
|
||||
for_each = local.postfix_secrets
|
||||
content {
|
||||
name = env.key
|
||||
value_from {
|
||||
secret_key_ref {
|
||||
key = env.value.key
|
||||
name = env.value.name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
volume_mount {
|
||||
name = "email-storage"
|
||||
mount_path = "/var/spool/postfix"
|
||||
}
|
||||
volume_mount {
|
||||
name = "postfix-run-config"
|
||||
mount_path = "/etc/service/postfix/run.config"
|
||||
sub_path = "run.config"
|
||||
read_only = true
|
||||
}
|
||||
volume_mount {
|
||||
name = "bcc-map"
|
||||
mount_path = "/etc/postfix/bcc_map"
|
||||
sub_path = "bcc_map"
|
||||
read_only = true
|
||||
}
|
||||
volume_mount {
|
||||
name = "certs"
|
||||
mount_path = "/etc/letsencrypt"
|
||||
read_only = true
|
||||
}
|
||||
volume_mount {
|
||||
name = "postfix-logs"
|
||||
mount_path = "/var/log/postfix"
|
||||
read_only = false
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "email-storage"
|
||||
host_path {
|
||||
path = local.postfix_path
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "postfix-run-config"
|
||||
config_map {
|
||||
name = kubernetes_config_map.postfix_config.metadata[0].name
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "bcc-map"
|
||||
secret {
|
||||
secret_name = kubernetes_secret.bcc_map.metadata[0].name
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "certs"
|
||||
secret {
|
||||
secret_name = "mail-tls"
|
||||
}
|
||||
}
|
||||
volume {
|
||||
name = "postfix-logs"
|
||||
host_path {
|
||||
path = "/var/log/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,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resource "kubernetes_service" "dovecot" {
|
||||
metadata {
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
name = "dovecot"
|
||||
}
|
||||
|
||||
spec {
|
||||
selector = {
|
||||
app = "dovecot"
|
||||
}
|
||||
|
||||
port {
|
||||
name = "imap"
|
||||
port = 993
|
||||
target_port = 31993
|
||||
}
|
||||
|
||||
type = "LoadBalancer"
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
metadata[0].annotations
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_service" "dovecot_lmtp" {
|
||||
metadata {
|
||||
name = "dovecot-lmtp"
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
}
|
||||
|
||||
spec {
|
||||
selector = {
|
||||
app = "dovecot"
|
||||
}
|
||||
port {
|
||||
port = 31024
|
||||
}
|
||||
cluster_ip = "None"
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_service" "dovecot_auth" {
|
||||
metadata {
|
||||
name = "dovecot-auth"
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
}
|
||||
|
||||
spec {
|
||||
selector = {
|
||||
app = "dovecot"
|
||||
}
|
||||
port {
|
||||
port = 31000
|
||||
}
|
||||
cluster_ip = "None"
|
||||
}
|
||||
}
|
||||
|
||||
resource "kubernetes_service" "postfix" {
|
||||
metadata {
|
||||
namespace = kubernetes_namespace.mail.metadata[0].name
|
||||
name = "postfix"
|
||||
}
|
||||
|
||||
spec {
|
||||
selector = {
|
||||
app = "postfix"
|
||||
}
|
||||
|
||||
port {
|
||||
name = "smtp"
|
||||
port = 465
|
||||
target_port = 465
|
||||
}
|
||||
|
||||
type = "LoadBalancer"
|
||||
}
|
||||
|
||||
lifecycle {
|
||||
ignore_changes = [
|
||||
metadata[0].annotations
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -169,29 +169,6 @@ module "nextcloud_database" {
|
||||
backup_folder = local.nextcloud_backup_path
|
||||
}
|
||||
|
||||
#
|
||||
# Setup rsync backup job to scaleway bucket
|
||||
#
|
||||
module "nextcloud_backup" {
|
||||
|
||||
source = "../modules/scw_backup_job"
|
||||
|
||||
namespace = kubernetes_namespace.nextcloud.metadata[0].name
|
||||
app_name = "nextcloud"
|
||||
|
||||
scaleway_organization_id = var.scaleway_organization_id
|
||||
scaleway_project_id = var.scaleway_organization_id
|
||||
access_key = scaleway_iam_api_key.backup_app_api.access_key
|
||||
secret_key = scaleway_iam_api_key.backup_app_api.secret_key
|
||||
bucket_name = scaleway_object_bucket.backup.name
|
||||
|
||||
retention_days = local.local_backup_retention_days
|
||||
cron_schedule = local.nextcloud_files_backup_cron_schedule
|
||||
|
||||
source_folder = local.nextcloud_path
|
||||
target_folder = local.nextcloud_backup_path
|
||||
}
|
||||
|
||||
#
|
||||
# Nextcloud service, ingress, deployment and file backup job
|
||||
#
|
||||
|
||||
@@ -1,253 +0,0 @@
|
||||
dovecot_config_version = "2.4.0"
|
||||
dovecot_storage_version = "2.4.0"
|
||||
|
||||
base_dir = /run/dovecot
|
||||
state_dir = /run/dovecot
|
||||
|
||||
protocols = imap lmtp
|
||||
listen = *
|
||||
|
||||
mail_driver=maildir
|
||||
mailbox_list_layout=index
|
||||
mailbox_list_utf8=yes
|
||||
mail_path=~/mail
|
||||
mail_home=/var/mail/%{user|lower}
|
||||
mail_utf8_extensions = yes
|
||||
|
||||
default_internal_user = vmail
|
||||
default_login_user = vmail
|
||||
default_internal_group = vmail
|
||||
|
||||
mail_uid = vmail
|
||||
mail_gid = vmail
|
||||
|
||||
namespace inbox {
|
||||
inbox = yes
|
||||
|
||||
mailbox Drafts {
|
||||
special_use = \Drafts
|
||||
auto = create
|
||||
auto = subscribe
|
||||
}
|
||||
|
||||
mailbox Junk {
|
||||
special_use = \Junk
|
||||
auto = create
|
||||
auto = subscribe
|
||||
}
|
||||
|
||||
mailbox Trash {
|
||||
special_use = \Trash
|
||||
auto = create
|
||||
auto = subscribe
|
||||
}
|
||||
|
||||
mailbox Sent {
|
||||
special_use = \Sent
|
||||
auto = create
|
||||
auto = subscribe
|
||||
}
|
||||
|
||||
mailbox Archive {
|
||||
special_use = \Archive
|
||||
auto = create
|
||||
auto = subscribe
|
||||
}
|
||||
}
|
||||
|
||||
passdb passwd-file {
|
||||
driver = passwd-file
|
||||
passwd_file_path = /etc/dovecot/users
|
||||
}
|
||||
|
||||
ssl_server {
|
||||
cert_file = /etc/letsencrypt/tls.crt
|
||||
key_file = /etc/letsencrypt/tls.key
|
||||
}
|
||||
|
||||
mail_attribute {
|
||||
dict file {
|
||||
path = %{home}/dovecot-attributes
|
||||
}
|
||||
}
|
||||
|
||||
log_path = /dev/stdout
|
||||
|
||||
imap_hibernate_timeout = 5s
|
||||
|
||||
mail_plugins {
|
||||
fts = yes
|
||||
fts_flatcurve = yes
|
||||
mail_log = yes
|
||||
notify = yes
|
||||
}
|
||||
|
||||
mail_log_events = delete undelete expunge save copy mailbox_create mailbox_delete mailbox_rename flag_change
|
||||
|
||||
fts_autoindex = yes
|
||||
fts_autoindex_max_recent_msgs = 999
|
||||
fts_search_add_missing = yes
|
||||
language_filters = normalizer-icu snowball stopwords
|
||||
|
||||
language_tokenizers = generic email-address
|
||||
language_tokenizer_generic_algorithm = simple
|
||||
|
||||
language en {
|
||||
default = yes
|
||||
filters = lowercase snowball english-possessive stopwords
|
||||
}
|
||||
|
||||
fts flatcurve {
|
||||
substring_search = yes
|
||||
}
|
||||
|
||||
protocol imap {
|
||||
mail_plugins {
|
||||
imap_sieve = yes
|
||||
imap_filter_sieve = yes
|
||||
}
|
||||
}
|
||||
|
||||
lmtp_save_to_detail_mailbox = yes
|
||||
recipient_delimiter = +
|
||||
|
||||
protocol lmtp {
|
||||
mail_plugins {
|
||||
sieve = yes
|
||||
}
|
||||
}
|
||||
|
||||
service imap-login {
|
||||
process_min_avail = 1
|
||||
client_limit = 100
|
||||
inet_listener imap {
|
||||
port = 31143
|
||||
}
|
||||
inet_listener imaps {
|
||||
port = 31993
|
||||
ssl = yes
|
||||
}
|
||||
}
|
||||
|
||||
service stats {
|
||||
process_min_avail = 1
|
||||
inet_listener http {
|
||||
port = 9090
|
||||
}
|
||||
}
|
||||
|
||||
auth_mechanisms = plain login
|
||||
|
||||
service auth {
|
||||
inet_listener auth {
|
||||
port = 31000
|
||||
}
|
||||
}
|
||||
|
||||
# LMTP service to store sent emails
|
||||
service lmtp {
|
||||
inet_listener auth {
|
||||
port = 31024
|
||||
}
|
||||
mail_plugins {
|
||||
sieve = yes
|
||||
}
|
||||
}
|
||||
|
||||
event_exporter log {
|
||||
format = json
|
||||
time_format = rfc3339
|
||||
}
|
||||
|
||||
metric auth_success {
|
||||
filter = (event=auth_request_finished AND success=yes)
|
||||
}
|
||||
|
||||
metric auth_failure {
|
||||
filter = (event=auth_request_finished AND NOT success=yes)
|
||||
exporter = log
|
||||
}
|
||||
|
||||
metric imap_command {
|
||||
filter = event=imap_command_finished
|
||||
group_by cmd_name {
|
||||
method discrete {
|
||||
}
|
||||
}
|
||||
group_by tagged_reply_state {
|
||||
method discrete {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
metric smtp_command {
|
||||
filter = event=smtp_server_command_finished and protocol=submission
|
||||
group_by cmd_name {
|
||||
method discrete {
|
||||
}
|
||||
}
|
||||
group_by status_code {
|
||||
method discrete {
|
||||
}
|
||||
}
|
||||
group_by duration {
|
||||
method exponential {
|
||||
base = 10
|
||||
min_magnitude = 1
|
||||
max_magnitude = 5
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
metric lmtp_command {
|
||||
filter = event=smtp_server_command_finished and protocol=lmtp
|
||||
group_by cmd_name {
|
||||
method discrete {
|
||||
}
|
||||
}
|
||||
group_by status_code {
|
||||
method discrete {
|
||||
}
|
||||
}
|
||||
group_by duration {
|
||||
method exponential {
|
||||
base = 10
|
||||
min_magnitude = 1
|
||||
max_magnitude = 5
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
metric mail_delivery {
|
||||
filter = event=mail_delivery_finished
|
||||
group_by duration {
|
||||
method exponential {
|
||||
base = 10
|
||||
min_magnitude = 1
|
||||
max_magnitude = 5
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sieve_script default {
|
||||
path = /etc/dovecot/sieve/default.sieve
|
||||
}
|
||||
|
||||
mail_plugins {
|
||||
mail_crypt = yes
|
||||
}
|
||||
|
||||
crypt_global_private_key main {
|
||||
crypt_private_key_file = /etc/mail-crypt/ecprivkey.pem
|
||||
}
|
||||
crypt_global_public_key_file = /etc/mail-crypt/ecpubkey.pem
|
||||
|
||||
log_path = /dev/stdout
|
||||
info_log_path = /dev/stdout
|
||||
debug_log_path = /dev/stdout
|
||||
|
||||
# Enable verbose logging
|
||||
# auth_verbose = yes
|
||||
# auth_debug = yes
|
||||
# auth_debug_passwords = yes
|
||||
# mail_debug = yes
|
||||
@@ -1,20 +0,0 @@
|
||||
[retriever]
|
||||
type = SimpleIMAPSSLRetriever
|
||||
server = ${server}
|
||||
port = ${port}
|
||||
username = ${username}
|
||||
password = ${password}
|
||||
mailboxes = ('${mailbox}',)
|
||||
|
||||
[destination]
|
||||
type = MDA_lmtp
|
||||
host = ${dovecot_lmtp_address}
|
||||
port = ${dovecot_lmtp_port}
|
||||
override = ${recipient}@${domain}
|
||||
|
||||
[options]
|
||||
read_all = false
|
||||
delete_after = ${delete_after}
|
||||
verbose = 1
|
||||
mark_read = true
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
#!/bin/bash
|
||||
if [ -z "$SMTP_HOST" ]; then
|
||||
echo "SMTP_HOST is required"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$SMTP_PORT" ]; then
|
||||
echo "SMTP_PORT is required"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$SMTP_USER" ]; then
|
||||
echo "SMTP_USER is required"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$SMTP_PASSWORD" ]; then
|
||||
echo "SMTP_PASSWORD is required"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$DOVECOT_AUTH_ADDRESS" ]; then
|
||||
echo "DOVECOT_AUTH_ADDRESS is required"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$DOVECOT_AUTH_PORT" ]; then
|
||||
echo "DOVECOT_AUTH_PORT is required"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
postconf -e "myhostname=$MAILNAME"
|
||||
postconf -e "mydomain=$MY_PRIMARY_DOMAIN"
|
||||
postconf -e "myorigin=$MY_PRIMARY_DOMAIN"
|
||||
postconf -e "smtpd_banner=\$myhostname ESMTP \$mail_name"
|
||||
postconf -e "mydestination=$MY_DESTINATION"
|
||||
|
||||
# Relay configuration
|
||||
postconf -e "relayhost=[$SMTP_HOST]:$SMTP_PORT"
|
||||
postconf -e "smtp_sasl_auth_enable=yes"
|
||||
postconf -e "smtp_sasl_password_maps=static:$SMTP_USER:$SMTP_PASSWORD"
|
||||
postconf -e "smtp_sasl_security_options=noanonymous"
|
||||
postconf -e "smtp_tls_security_level=encrypt"
|
||||
postconf -e "smtp_use_tls=yes"
|
||||
postconf -e "smtp_tls_CAfile=/etc/ssl/certs/ca-certificates.crt"
|
||||
|
||||
# SASL configuration
|
||||
postconf -e "smtpd_sasl_type=dovecot"
|
||||
postconf -e "smtpd_sasl_path=inet:$DOVECOT_AUTH_ADDRESS:$DOVECOT_AUTH_PORT"
|
||||
postconf -e "smtpd_sasl_auth_enable=yes"
|
||||
postconf -e "smtpd_sasl_security_options=noanonymous"
|
||||
postconf -e "smtpd_recipient_restrictions=permit_sasl_authenticated, reject"
|
||||
postconf -e "smtpd_relay_restrictions=permit_sasl_authenticated, reject_unauth_destination"
|
||||
postconf -e "smtpd_sasl_authenticated_header=yes"
|
||||
postconf -e "smtpd_tls_wrappermode=yes"
|
||||
|
||||
# TLS configuration
|
||||
postconf -e "smtpd_tls_cert_file=/etc/letsencrypt/tls.crt"
|
||||
postconf -e "smtpd_tls_key_file=/etc/letsencrypt/tls.key"
|
||||
postconf -e "smtpd_tls_security_level=encrypt"
|
||||
postconf -e "smtp_tls_wrappermode=yes"
|
||||
|
||||
# BCC configuration
|
||||
postconf -e "virtual_transport=lmtp:[$DOVECOT_LMTP_ADDRESS]:$DOVECOT_LMTP_PORT"
|
||||
|
||||
# Other configuration
|
||||
postconf -e "inet_interfaces=all"
|
||||
postconf -e "inet_protocols=ipv4"
|
||||
postconf -e "queue_directory=/var/spool/postfix"
|
||||
postconf -e "compatibility_level=2"
|
||||
|
||||
# Debugging
|
||||
# postconf -e "debug_peer_list=127.0.0.1"
|
||||
# postconf -e "debug_peer_level=3"
|
||||
|
||||
echo "
|
||||
smtps inet n - n - - smtpd
|
||||
-o syslog_name=postfix/smtps
|
||||
-o smtpd_tls_wrappermode=yes
|
||||
-o smtpd_sasl_auth_enable=yes
|
||||
-o smtpd_recipient_restrictions=permit_sasl_authenticated,reject
|
||||
" | sudo tee -a /etc/postfix/master.cf
|
||||
|
||||
/usr/sbin/postfix -c /etc/postfix start
|
||||
/usr/sbin/postfix -c /etc/postfix abort
|
||||
exec "$POSTFIX_PATH" -c /etc/postfix -s
|
||||
@@ -1,5 +0,0 @@
|
||||
require ["fileinto", "envelope"];
|
||||
|
||||
if envelope :is "from" "${user}" {
|
||||
fileinto "Sent";
|
||||
}
|
||||
Reference in New Issue
Block a user