From 20b005be8dce5b9ee4c45d462e6840ab7a8b4c98 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Wed, 4 Nov 2026 17:53:42 -0600 Subject: [PATCH] Keep Hermes Matrix connection and edge certificates configured --- bootstrap/edge/main.tf | 31 ++++++++++++++++++++++++++++++- docs/ai-ops.md | 7 +++++++ docs/templates/ai-ops.md.tmpl | 8 ++++++++ lib/jeannie/pipeline.sh | 2 +- 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/bootstrap/edge/main.tf b/bootstrap/edge/main.tf index 68f25a3..607cae4 100644 --- a/bootstrap/edge/main.tf +++ b/bootstrap/edge/main.tf @@ -25,8 +25,8 @@ locals { jeannie_api_server_name = "api.${var.server_name}" office_server_name = var.office_server_name office_onlyoffice_server_name = var.office_onlyoffice_server_name - server_names = distinct(concat([var.server_name, local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name, local.jeannie_api_server_name, local.office_server_name, local.office_onlyoffice_server_name], var.additional_server_names)) matrix_server_names = var.matrix_enabled ? [var.matrix_server_name, var.element_server_name] : [] + server_names = distinct(concat([var.server_name, local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name, local.jeannie_api_server_name, local.office_server_name, local.office_onlyoffice_server_name], local.matrix_server_names, var.additional_server_names)) main_server_names = [for name in local.server_names : name if !contains([local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name, local.jeannie_api_server_name, local.office_server_name, local.office_onlyoffice_server_name], name) && !contains(local.matrix_server_names, name)] default_conf = templatefile("${path.module}/templates/default.conf.tftpl", { server_name = var.server_name @@ -116,6 +116,9 @@ resource "null_resource" "edge_services" { office_host = var.office_backend_host office_port = tostring(var.office_backend_port) matrix_server_name = var.matrix_server_name + element_server_name = var.element_server_name + matrix_enabled = tostring(var.matrix_enabled) + certificate_sync_revision = "matrix-san-v1" enable_letsencrypt = tostring(var.enable_letsencrypt) letsencrypt_email = var.letsencrypt_email letsencrypt_staging = tostring(var.letsencrypt_staging) @@ -193,6 +196,8 @@ tailscale_auth_key='${var.edge_tailscale_auth_key}' tailscale_tag='${var.edge_tailscale_tag}' server_name="${self.triggers.server_name}" matrix_server_name="${self.triggers.matrix_server_name}" +element_server_name="${self.triggers.element_server_name}" +matrix_enabled="${self.triggers.matrix_enabled}" server_names="${self.triggers.server_names}" certbot_domain_args="${self.triggers.certbot_domain_args}" backend_host="${self.triggers.backend_host}" @@ -339,6 +344,18 @@ deploy_current_certificate() { sudo cp -L "$install_dir/letsencrypt/live/$server_name/privkey.pem" "$install_dir/certs/current.key" sudo chmod 0644 "$install_dir/certs/current.crt" sudo chmod 0600 "$install_dir/certs/current.key" + if [ "$matrix_enabled" = "true" ]; then + if sudo openssl x509 -in "$install_dir/certs/current.crt" -noout -checkend 0 >/dev/null && + sudo openssl x509 -in "$install_dir/certs/current.crt" -noout -checkhost "$matrix_server_name" | grep -Fq 'does match certificate' && + sudo openssl x509 -in "$install_dir/certs/current.crt" -noout -checkhost "$element_server_name" | grep -Fq 'does match certificate'; then + sudo cp -L "$install_dir/certs/current.crt" "$install_dir/certs/matrix.crt" + sudo cp -L "$install_dir/certs/current.key" "$install_dir/certs/matrix.key" + sudo chmod 0644 "$install_dir/certs/matrix.crt" + sudo chmod 0600 "$install_dir/certs/matrix.key" + else + echo "Shared certificate does not cover both Matrix and Element or has expired; retaining existing Matrix certificate." >&2 + fi + fi } letsencrypt_certificate_present() { @@ -377,6 +394,18 @@ if [ -s "$install_dir/letsencrypt/live/$server_name/fullchain.pem" ] && cp -L "$install_dir/letsencrypt/live/$server_name/privkey.pem" "$install_dir/certs/current.key" chmod 0644 "$install_dir/certs/current.crt" chmod 0600 "$install_dir/certs/current.key" + if [ "$matrix_enabled" = "true" ]; then + if openssl x509 -in "$install_dir/certs/current.crt" -noout -checkend 0 >/dev/null && + openssl x509 -in "$install_dir/certs/current.crt" -noout -checkhost "$matrix_server_name" | grep -Fq 'does match certificate' && + openssl x509 -in "$install_dir/certs/current.crt" -noout -checkhost "$element_server_name" | grep -Fq 'does match certificate'; then + cp -L "$install_dir/certs/current.crt" "$install_dir/certs/matrix.crt" + cp -L "$install_dir/certs/current.key" "$install_dir/certs/matrix.key" + chmod 0644 "$install_dir/certs/matrix.crt" + chmod 0600 "$install_dir/certs/matrix.key" + else + echo "Shared certificate does not cover both Matrix and Element or has expired; retaining existing Matrix certificate." >&2 + fi + fi cd "$install_dir" docker compose exec -T nginx-dev nginx -s reload || docker compose restart nginx-dev fi diff --git a/docs/ai-ops.md b/docs/ai-ops.md index 9277a7b..fd0c41b 100644 --- a/docs/ai-ops.md +++ b/docs/ai-ops.md @@ -114,6 +114,13 @@ ran `hermes-connect` is recorded as the plugin's Jeannie source. Runbook lookup requires an existing `./jeannie ai-index`. OmniRoute may use an external model provider, depending on the configured route. +Hermes uses the HTTPS Matrix homeserver URL. The edge requests Matrix and Element +names on its shared Let's Encrypt certificate and copies it to their isolated +files on deployment and renewal only when it is unexpired and covers both names. +Otherwise it retains the existing Matrix certificate and logs a warning. Run +`./jeannie edge apply` to install the updated renewal script. `./jeannie +deploy-hermes` regenerates the Hermes environment and restarts its gateway. + ## AI Evals The repo includes a local eval harness for Jeannie explanations and homelab RAG diff --git a/docs/templates/ai-ops.md.tmpl b/docs/templates/ai-ops.md.tmpl index 6551e9c..297a602 100644 --- a/docs/templates/ai-ops.md.tmpl +++ b/docs/templates/ai-ops.md.tmpl @@ -114,6 +114,14 @@ ran `hermes-connect` is recorded as the plugin's Jeannie source. Runbook lookup requires an existing `./{{ main_script }} ai-index`. OmniRoute may use an external model provider, depending on the configured route. +Hermes uses the HTTPS Matrix homeserver URL. The edge requests Matrix and Element +names on its shared Let's Encrypt certificate and copies it to their isolated +files on deployment and renewal only when it is unexpired and covers both names. +Otherwise it retains the existing Matrix certificate and logs a warning. Run +`./{{ main_script }} edge apply` to install the updated renewal script. +`./{{ main_script }} deploy-hermes` regenerates the Hermes environment and +restarts its gateway. + ## AI Evals The repo includes a local eval harness for Jeannie explanations and homelab RAG diff --git a/lib/jeannie/pipeline.sh b/lib/jeannie/pipeline.sh index 1d489be..544e69e 100644 --- a/lib/jeannie/pipeline.sh +++ b/lib/jeannie/pipeline.sh @@ -6081,7 +6081,7 @@ OPENAI_BASE_URL=${hermes_openai_base_url} OPENAI_API_KEY=${hermes_omniroute_api_key} HERMES_MODEL=${hermes_model} HERMES_CUSTOM_LOCALHOST_${LAB_OMNIROUTE_PORT:-20128}_API_KEY=${hermes_omniroute_api_key} -MATRIX_HOMESERVER=${LAB_MATRIX_SERVER_NAME:-matrix.lab2025.duckdns.org} +MATRIX_HOMESERVER=https://${LAB_MATRIX_SERVER_NAME:-matrix.lab2025.duckdns.org} MATRIX_USER_ID=${HERMES_MATRIX_USER_ID:-@hermes:matrix.lab2025.duckdns.org} MATRIX_PASSWORD=${MATRIX_BOT_PASSWORD:-} MATRIX_ALLOWED_USERS=${HERMES_MATRIX_ALLOWED_USERS:-@jv:matrix.lab2025.duckdns.org}