From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B7C477DF86 for ; Tue, 9 Nov 2021 17:59:04 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 422551159B for ; Tue, 9 Nov 2021 17:59:04 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 29115114D5 for ; Tue, 9 Nov 2021 17:59:01 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 21AFB46059 for ; Tue, 9 Nov 2021 17:54:34 +0100 (CET) From: Stoiko Ivanov To: pbs-devel@lists.proxmox.com Date: Tue, 9 Nov 2021 16:54:22 +0000 Message-Id: <20211109165422.311089-9-s.ivanov@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211109165422.311089-1-s.ivanov@proxmox.com> References: <20211109165422.311089-1-s.ivanov@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.335 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [acme.rs, node.rs, lib.rs, plugin.rs, certificates.rs] Subject: [pbs-devel] [PATCH proxmox-backup 6/6] acme: add support for wildcard certificates X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Nov 2021 16:59:04 -0000 following the implementation in PMG in: * verifying that a acmedomain with wildcard is not using the standalone validation * the initial '*.' is stripped when searching for the proper domain config and when running the validation plugin Signed-off-by: Stoiko Ivanov --- pbs-api-types/src/lib.rs | 5 +++++ src/acme/plugin.rs | 2 +- src/api2/node/certificates.rs | 2 +- src/api2/types/acme.rs | 4 ++-- src/config/node.rs | 9 +++++++++ 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pbs-api-types/src/lib.rs b/pbs-api-types/src/lib.rs index 96ac657b..73a84ca6 100644 --- a/pbs-api-types/src/lib.rs +++ b/pbs-api-types/src/lib.rs @@ -82,6 +82,7 @@ pub use zfs::*; mod local_macros { macro_rules! DNS_LABEL { () => (r"(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)") } macro_rules! DNS_NAME { () => (concat!(r"(?:(?:", DNS_LABEL!() , r"\.)*", DNS_LABEL!(), ")")) } + macro_rules! DNS_NAME_OR_WILDCARD { () => (concat!(r"(?:\*\.)?(?:(?:", DNS_LABEL!() , r"\.)*", DNS_LABEL!(), ")")) } macro_rules! CIDR_V4_REGEX_STR { () => (concat!(r"(?:", IPV4RE!(), r"/\d{1,2})$")) } macro_rules! CIDR_V6_REGEX_STR { () => (concat!(r"(?:", IPV6RE!(), r"/\d{1,3})$")) } macro_rules! DNS_ALIAS_LABEL { () => (r"(?:[a-zA-Z0-9_](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)") } @@ -99,6 +100,7 @@ const_regex! { pub CIDR_REGEX = concat!(r"^(?:", CIDR_V4_REGEX_STR!(), "|", CIDR_V6_REGEX_STR!(), r")$"); pub HOSTNAME_REGEX = r"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)$"; pub DNS_NAME_REGEX = concat!(r"^", DNS_NAME!(), r"$"); + pub DNS_NAME_OR_WILDCARD_REGEX = concat!(r"^", DNS_NAME_OR_WILDCARD!(), r"$"); pub DNS_ALIAS_REGEX = concat!(r"^", DNS_ALIAS_NAME!(), r"$"); pub DNS_NAME_OR_IP_REGEX = concat!(r"^(?:", DNS_NAME!(), "|", IPRE!(), r")$"); @@ -177,6 +179,9 @@ pub const HOSTNAME_SCHEMA: Schema = StringSchema::new("Hostname (as defined in R pub const DNS_NAME_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&DNS_NAME_REGEX); +pub const DNS_NAME_OR_WILDCARD_FORMAT: ApiStringFormat = + ApiStringFormat::Pattern(&DNS_NAME_OR_WILDCARD_REGEX); + pub const DNS_NAME_OR_IP_FORMAT: ApiStringFormat = ApiStringFormat::Pattern(&DNS_NAME_OR_IP_REGEX); diff --git a/src/acme/plugin.rs b/src/acme/plugin.rs index d31c2b8f..4dedb69b 100644 --- a/src/acme/plugin.rs +++ b/src/acme/plugin.rs @@ -145,7 +145,7 @@ impl DnsPlugin { PROXMOX_ACME_SH_PATH, action, &self.core.api, - domain.alias.as_deref().unwrap_or(&domain.domain), + domain.alias.as_deref().unwrap_or(&domain.domain.trim_start_matches("*.")), ]); // We could use 1 socketpair, but tokio wraps them all in `File` internally causing `close` diff --git a/src/api2/node/certificates.rs b/src/api2/node/certificates.rs index 4d26b29f..f6a7c2d3 100644 --- a/src/api2/node/certificates.rs +++ b/src/api2/node/certificates.rs @@ -299,7 +299,7 @@ async fn order_certificate( let get_domain_config = |domain: &str| { domains .iter() - .find(|d| d.domain == domain) + .find(|d| d.domain.trim_start_matches("*.") == domain) .ok_or_else(|| format_err!("no config for domain '{}'", domain)) }; diff --git a/src/api2/types/acme.rs b/src/api2/types/acme.rs index 21e953bb..7b9de74a 100644 --- a/src/api2/types/acme.rs +++ b/src/api2/types/acme.rs @@ -4,12 +4,12 @@ use serde_json::Value; use proxmox_schema::{api, ApiType, Schema, StringSchema, ApiStringFormat}; use pbs_api_types::{ - DNS_ALIAS_FORMAT, DNS_NAME_FORMAT, PROXMOX_SAFE_ID_FORMAT, + DNS_ALIAS_FORMAT, DNS_NAME_OR_WILDCARD_FORMAT, PROXMOX_SAFE_ID_FORMAT, }; #[api( properties: { - "domain": { format: &DNS_NAME_FORMAT }, + "domain": { format: &DNS_NAME_OR_WILDCARD_FORMAT }, "alias": { optional: true, format: &DNS_ALIAS_FORMAT, diff --git a/src/config/node.rs b/src/config/node.rs index 93444216..fb9b1105 100644 --- a/src/config/node.rs +++ b/src/config/node.rs @@ -163,6 +163,15 @@ impl NodeConfig { if !domains.insert(domain.domain.to_lowercase()) { bail!("duplicate domain '{}' in ACME config", domain.domain); } + if domain.domain.starts_with("*.") { + let plugin = domain.plugin.as_deref().unwrap_or("standalone"); + if plugin == "standalone" { + bail!( + "wildcard domain '{}' needs a dns-01 plugin for validation!", + domain.domain + ); + } + } } Ok(()) -- 2.30.2