diff --git a/docs/deployment.md b/docs/deployment.md index cca03d5..719df52 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -1051,6 +1051,21 @@ credential and archive operations. The separate legacy SSH transports for those operations are unavailable on a scoped receiver. Local mail delivery and IMAP keep using their existing configuration. +#### Refresh an existing managed DKIM record + +Upgrade the panels linked to a mail node before upgrading the mail node. +The updated panel accepts public keys from older mail nodes and publishes +the managed RSA key in SubjectPublicKeyInfo format. The existing private +key and selector stay in use. + +Open **Mail DNS check** for a managed mail domain and select +**Refresh mail DNS setup**. If Coulobre publishes the zone and manages its +mail records, it replaces the previous encoding when the public key +matches. A different key at the same selector requires operator review. +For third-party DNS, copy the updated DKIM TXT value to the DNS provider. +Check the authoritative answer, allow cached records to expire, and +verify that a newly delivered message passes DKIM. + ### Use SHA-2 for new managed database logins On a MariaDB build with `auth_mysql_sha2`, you can provision new managed diff --git a/pyproject.toml b/pyproject.toml index 4e64eb3..4c73d7d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "coulobre-panel" -version = "1.0.0rc3" +version = "1.0.0rc4" description = "A web hosting control panel for hosting providers and resellers." readme = "README.md" requires-python = ">=3.12" diff --git a/src/coulobre/hosting/domain_policies.py b/src/coulobre/hosting/domain_policies.py index 5a936cb..7d87953 100644 --- a/src/coulobre/hosting/domain_policies.py +++ b/src/coulobre/hosting/domain_policies.py @@ -7,7 +7,29 @@ def policy_for(account, domain): policy = DomainServicePolicy.objects.filter( account=account, domain=domain ).first() - return policy or DomainServicePolicy(account=account, domain=domain) + if policy is not None: + return policy + return DomainServicePolicy( + account=account, + domain=domain, + mail_managed=( + domain == account.primary_domain + or account.mail_domains.filter(domain=domain).exists() + ), + ) + + +def managed_mail_domains(account): + domains = {account.primary_domain} + domains.update(account.mail_domains.values_list("domain", flat=True)) + for domain, enabled in account.domainservicepolicy_set.values_list( + "domain", "mail_managed" + ): + if enabled: + domains.add(domain) + else: + domains.discard(domain) + return sorted(domains) def require_managed(account, domain, field): diff --git a/src/coulobre/hosting/domain_services.py b/src/coulobre/hosting/domain_services.py index 3104c1a..fcb6ada 100644 --- a/src/coulobre/hosting/domain_services.py +++ b/src/coulobre/hosting/domain_services.py @@ -1,4 +1,5 @@ from django import forms +from django.conf import settings from django.contrib import messages from django.core.exceptions import PermissionDenied, ValidationError from django.db import transaction @@ -14,15 +15,17 @@ from .access import customer_for_user from .account_setup import website_records from .dns_defaults import zone_defaults from .dns_forms import zone_record_rows -from .domain_policies import policy_for +from .domain_policies import managed_mail_domains, policy_for from .independent_websites import account_websites from .installation_features import panel_feature_allowed from .models import DomainServicePolicy, HostingAccount from .resource_requests import lock_hosting_account, require_open_account +from .service_credentials import CredentialKind, show_credential_action from .sftp import site_is_active DNS_PUBLISHING = "LOCAL_DNS_PUBLISHING" MAIL_PROVISIONING = "LOCAL_MAILBOX_PROVISIONING" +MAIL_PAGES = {"email", "forwarders", "replies", "spam"} class DomainServicesForm(forms.Form): @@ -111,14 +114,30 @@ def domain_workspace(request, pk, page): account = get_object_or_404( HostingAccount, pk=pk, customer=customer, retired_at__isnull=True ) - domains = allowed_domains(account) + if page == "dns": + domains = list( + account.dns_zones.order_by("domain").values_list( + "domain", flat=True + ) + ) + elif page in MAIL_PAGES: + domains = sorted( + set(managed_mail_domains(account)) & set(allowed_domains(account)) + ) + else: + domains = allowed_domains(account) + + default = account.primary_domain + if domains and default not in domains: + default = domains[0] + selection = request.GET.get("domain") try: - domain = canonical_domain( - request.GET.get("domain", account.primary_domain) + domain = ( + canonical_domain(selection) if selection is not None else default ) except ValueError as error: raise Http404 from error - if domain not in domains: + if selection is not None and domain not in domains: raise Http404 policy = policy_for(account, domain) initial = { @@ -167,7 +186,7 @@ def domain_workspace(request, pk, page): ) mail_domain = ( account.mail_domains.filter(domain=domain).first() - if page in {"dns", "email", "forwarders", "replies", "spam"} + if page == "dns" or page in MAIL_PAGES else None ) titles = { @@ -184,6 +203,9 @@ def domain_workspace(request, pk, page): from .roundcube import roundcube_available defaults = zone_defaults() if page == "dns" else None + show_mailbox_credentials = show_credential_action( + request, CredentialKind.MAILBOX + ) return render( request, "hosting/domain_workspace.html", @@ -205,14 +227,18 @@ def domain_workspace(request, pk, page): ) if page == "dns" and not policy.dns_managed else (), - "zone_defaults": defaults, "mail_domain": mail_domain, "mail_enabled": panel_feature_allowed( "LOCAL_MAILBOX_PROVISIONING" ), "can_edit_routing": mail_policy_available("routing"), "can_edit_mailbox": mail_policy_available("vacation"), - "roundcube_enabled": roundcube_available(request), + "show_mailbox_credentials": show_mailbox_credentials, + "roundcube_enabled": ( + show_mailbox_credentials and roundcube_available(request) + ), + "mail_imap_host": settings.MAIL_IMAP_HOST, + "mail_submission_host": settings.MAIL_SUBMISSION_HOST, "mailboxes": mail_domain.mailboxes.select_related("provisioning") if mail_domain else (), diff --git a/src/coulobre/hosting/mail_dns_setup.py b/src/coulobre/hosting/mail_dns_setup.py index 8da6102..d0ef8f7 100644 --- a/src/coulobre/hosting/mail_dns_setup.py +++ b/src/coulobre/hosting/mail_dns_setup.py @@ -12,7 +12,12 @@ from coulobre.dns_node import ( TxtRecord, dns_name, ) -from coulobre.mail_dns import MANAGED_DKIM_SELECTOR, matches_version +from coulobre.mail_dns import ( + MANAGED_DKIM_SELECTOR, + matches_version, + normalize_rsa_dkim_record, + same_rsa_dkim_key, +) from .dns_publication import queue_zone_snapshot from .models import HostingDnsZone, HostingMailDomain, MailboxProvisioning @@ -53,7 +58,8 @@ def mail_dns_proposal(domain, public_key): if public_key: records.append( TxtRecord( - f"{MANAGED_DKIM_SELECTOR}._domainkey.{domain}", public_key + f"{MANAGED_DKIM_SELECTOR}._domainkey.{domain}", + normalize_rsa_dkim_record(public_key), ) ) return addresses, mx, tuple(records) @@ -104,7 +110,7 @@ def sync_mail_dns(mail_domain, *, public_key=None): if current is None or account.retired_at is not None: return if public_key is not None: - current.dkim_record = public_key + current.dkim_record = normalize_rsa_dkim_record(public_key) current.dns_sync_requested = True current.save(update_fields=["dkim_record", "dns_sync_requested"]) if not current.dns_sync_requested or account.services_suspended: @@ -173,15 +179,23 @@ def publish_mail_records(zone, domain, public_key): existing = spec.txt_records new_txt = [] + replacements = {} problem = "" for record in txt: version = record.text.split(" ")[0].rstrip(";") at_owner = tuple(item for item in existing if item.name == record.name) if version == "v=DKIM1": if at_owner and at_owner != (record,): - raise ValueError( - "The Coulobre DKIM selector already has a record." - ) + if len(at_owner) != 1 or not same_rsa_dkim_key( + at_owner[0].text, record.text + ): + raise ValueError( + "The Coulobre DKIM selector already has a record." + ) + previous = at_owner[0] + converted = normalize_rsa_dkim_record(previous.text) + if converted != previous.text: + replacements[previous] = replace(previous, text=converted) else: at_owner = tuple( item @@ -207,7 +221,9 @@ def publish_mail_records(zone, domain, public_key): spec.nameservers, (*spec.addresses, *spec.mx_records, *existing, *spec.extra_records), ) - changed = bool(additions or not current_mx or new_txt or alias) + changed = bool( + additions or not current_mx or new_txt or replacements or alias + ) if publication and publication.finished_at is None: if changed: raise MailDnsPublicationPendingError @@ -219,7 +235,10 @@ def publish_mail_records(zone, domain, public_key): serial=(spec.serial + 1) % (MAX_SOA_SERIAL + 1), addresses=spec.addresses + additions, mx_records=spec.mx_records + (mx if not current_mx else ()), - txt_records=spec.txt_records + tuple(new_txt), + txt_records=tuple( + replacements.get(record, record) for record in existing + ) + + tuple(new_txt), extra_records=spec.extra_records + ((alias,) if alias else ()), ) manifest = spec.manifest() diff --git a/src/coulobre/hosting/node_client.py b/src/coulobre/hosting/node_client.py index c7f26c6..167bd72 100644 --- a/src/coulobre/hosting/node_client.py +++ b/src/coulobre/hosting/node_client.py @@ -13,7 +13,7 @@ from coulobre.account_restore_request import ( RESTORE_TIMEOUT_SECONDS, ) from coulobre.linked_updates import ROLES, UNIT_DIR, read_probe -from coulobre.mail_dns import dkim_key +from coulobre.mail_dns import dkim_key, normalize_rsa_dkim_record from coulobre.mail_node import MailboxQuotaUpdate, MailboxSigningRequest from coulobre.node_probe import PROBE_BYTES, parse_status_probe from coulobre.php_pool_settings import PhpPoolSettings @@ -180,7 +180,7 @@ def provision_signing_mailbox(mailbox): or dkim_key(public)[0] != "ok" ): raise ValueError("The mail node returned an invalid DKIM public key.") - return public + return normalize_rsa_dkim_record(public) def update_local_mailbox_quota(mailbox): diff --git a/src/coulobre/hosting/service_credentials.py b/src/coulobre/hosting/service_credentials.py index e8bb723..9a1db24 100644 --- a/src/coulobre/hosting/service_credentials.py +++ b/src/coulobre/hosting/service_credentials.py @@ -103,6 +103,14 @@ def can_rotate_credentials(user, kind): ) +def show_credential_action(request, kind): + return ( + getattr(request, "impersonation", None) is None + and enabled_credential_access(request, kind) + and can_reveal_credentials(request.user, kind) + ) + + @transaction.atomic @sensitive_variables() def verify_credential_access( diff --git a/src/coulobre/hosting/static/hosting/dns-record-editor.js b/src/coulobre/hosting/static/hosting/dns-record-editor.js index 5a59453..67c137d 100644 --- a/src/coulobre/hosting/static/hosting/dns-record-editor.js +++ b/src/coulobre/hosting/static/hosting/dns-record-editor.js @@ -39,6 +39,8 @@ function appendRecord(record) { priority.required = usesPriority; priority.disabled = !usesPriority; value.required = type.value !== "TXT"; + value.rows = type.value === "TXT" ? 4 : 1; + value.classList.toggle("dns-txt-value", type.value === "TXT"); valueLabel.textContent = valueLabels[type.value]; }; type.addEventListener("change", updateFields); diff --git a/src/coulobre/hosting/static/hosting/panel.css b/src/coulobre/hosting/static/hosting/panel.css index e27f72a..4738634 100644 --- a/src/coulobre/hosting/static/hosting/panel.css +++ b/src/coulobre/hosting/static/hosting/panel.css @@ -1043,9 +1043,9 @@ dd { } .dns-edit-row { - display: flex; - flex-wrap: wrap; - align-items: end; + display: grid; + grid-template-columns: minmax(0, 30%) 5rem minmax(0, 1fr) auto; + align-items: start; gap: 0.5rem; min-width: 0; margin: 0; @@ -1054,12 +1054,44 @@ dd { border-radius: 0.5rem; } -.dns-edit-row label { flex: 1 1 8rem; margin: 0; } +.dns-edit-row label { min-width: 0; margin: 0; } .dns-edit-row label[hidden] { display: none; } -.dns-edit-row label:has(select, input[type="number"]) { flex: 0 1 6rem; } -.dns-edit-row label:has(textarea) { flex: 2 1 12rem; } -.dns-edit-row textarea { display: block; min-height: 2.45rem; resize: vertical; } -.dns-record-table code { white-space: pre-wrap; overflow-wrap: anywhere; } +.dns-edit-row > button { margin-top: 1.4em; } +.dns-edit-value { + display: flex; + gap: 0.5rem; +} +.dns-edit-value > label { flex: 1; } +.dns-edit-value > [data-priority-label] { flex: 0 0 5rem; } +.dns-edit-row textarea { + display: block; + min-height: 2.45rem; + overflow-wrap: anywhere; + resize: vertical; +} +.dns-edit-row .dns-txt-value { field-sizing: content; min-height: 5rem; } + +.dns-record-table { table-layout: fixed; } +.dns-record-table .dns-record-name { width: 30%; } +.dns-record-table .dns-record-type { width: 5rem; } +.dns-record-table th, .dns-record-table code { overflow-wrap: anywhere; } +.dns-record-table code { white-space: pre-wrap; } + +.usage-table code, .usage-table th, .usage-error-log { + overflow-wrap: anywhere; +} + +.usage-error-log { + padding: 0 1.2rem 1rem; + white-space: pre-wrap; +} + +@media (max-width: 720px) { + .dns-edit-row { grid-template-columns: minmax(0, 1fr) 5rem; } + .dns-edit-value { grid-column: 1 / -1; } + .dns-edit-row > button { margin-top: 0; justify-self: start; } + .dns-record-table .dns-record-type { width: 3.5rem; } +} .reseller-editor fieldset { min-width: 0; diff --git a/src/coulobre/hosting/templates/hosting/dns_record_editor.html b/src/coulobre/hosting/templates/hosting/dns_record_editor.html index 0a5362f..f134600 100644 --- a/src/coulobre/hosting/templates/hosting/dns_record_editor.html +++ b/src/coulobre/hosting/templates/hosting/dns_record_editor.html @@ -11,8 +11,10 @@ - - +
| Name | Type | Value |
|---|---|---|
| {{ record.name }} | {{ record.type }} | {{ record.value }} |
| {{ record.name }} | {{ record.type }} | {{ record.value }} |
| Name | Type | Value |
|---|---|---|
| {{ record.name }} | {{ record.type }} | {{ record.value }} |
This domain has no saved Coulobre DNS zone.
{% endif %} {% if not policy.dns_managed %} @@ -28,8 +28,8 @@{{ record.name }} {{ record.record_type }} {{ record.address }}Check MX, SPF, DKIM and DMARC records
{% endif %} - {% elif zone_defaults.nameservers %} -Mailbox passwords cannot be viewed in this panel. Use your full email address as your username.
+ {% if mail_imap_host or mail_submission_host %} +Last checked {{ snapshot.observed_at }}
{% if snapshot.report.error %} -{{ snapshot.report.error }}
+{{ snapshot.report.error }}
{% else %} -{{ line }}{% empty %}No entries.
{% endfor %} -{{ line }}{% empty %}No entries.
{% endfor %} +| Time (UTC) | Method | Status | Path | Size |
|---|---|---|---|---|
| {{ entry.time|utc|date:"j M Y, H:i:s" }} | {{ entry.method }} | {{ entry.status }} | {{ entry.path }} | {{ entry.bytes|filesizeformat }} |
{{ entry.raw }} | ||||
No entries.
{% endif %} +{% for line in snapshot.report.error_lines %}{{ line }}{% if not forloop.last %}
+{% endif %}{% endfor %}{% else %}No entries.
{% endif %} {% endif %} {% else %} -No measurement yet.
+No measurement yet.
{% endif %}No active websites.
{% endfor %} {% if mailboxes is not None %} -No mailboxes.
{% endfor %} -| Mailbox | Storage used | Limit |
|---|---|---|
| {{ mailbox }} | {% if mailbox.usage_bytes is not None %}{{ mailbox.usage_bytes|filesizeformat }}{% else %}Unavailable{% endif %} | {{ mailbox.quota_mib|default_if_none:"Unlimited" }}{% if mailbox.quota_mib %} MiB{% endif %} |
No mailboxes.
{% endif %}