public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge
@ 2024-09-18 12:06 Gabriel Goller
  2024-09-18 12:06 ` [pbs-devel] [PATCH v2] schema: add regex for dns domains with wildcard Gabriel Goller
  2024-09-19 10:52 ` [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge Christian Ebner
  0 siblings, 2 replies; 5+ messages in thread
From: Gabriel Goller @ 2024-09-18 12:06 UTC (permalink / raw)
  To: pbs-devel

As already mentioned in our docs [0], wildcard domains are only
supported when the dns-challenge is used. If the dns-challenge is not
used, throw an error.

[0]: https://pbs.proxmox.com/docs/sysadmin.html#wildcard-certificates

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---

v2, thanks @Christian:
 - fixed configuration matching with wildcard
 - adjusted error message

 src/api2/node/certificates.rs | 18 +++++++++++++++---
 src/config/node.rs            | 10 ++++++++++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/api2/node/certificates.rs b/src/api2/node/certificates.rs
index 61ef910e47a7..4b2952feb8bd 100644
--- a/src/api2/node/certificates.rs
+++ b/src/api2/node/certificates.rs
@@ -294,10 +294,22 @@ async fn order_certificate(
         },
     )?;
 
-    let get_domain_config = |domain: &str| {
+    let get_domain_config = |domain: &str, wildcard: bool| {
         domains
             .iter()
-            .find(|d| d.domain == domain)
+            .find(|d| {
+                if !wildcard {
+                    // fast-path, no matching required
+                    d.domain == domain
+                } else {
+                    // https://community.letsencrypt.org/t/acme-v2-production-environment-wildcards/55578
+                    // DNS names in certificates may only have a single wildcard character, and it must
+                    // be the entire leftmost DNS label, f.e. *.example.com
+                    d.domain
+                        .strip_prefix("*.")
+                        .map_or(false, |stripped| domain == stripped)
+                }
+            })
             .ok_or_else(|| format_err!("no config for domain '{}'", domain))
     };
 
@@ -339,7 +351,7 @@ async fn order_certificate(
         }
 
         info!("The validation for {domain} is pending");
-        let domain_config: &AcmeDomain = get_domain_config(&domain)?;
+        let domain_config: &AcmeDomain = get_domain_config(&domain, auth.wildcard)?;
         let plugin_id = domain_config.plugin.as_deref().unwrap_or("standalone");
         let mut plugin_cfg = crate::acme::get_acme_plugin(&plugins, plugin_id)?
             .ok_or_else(|| format_err!("plugin '{plugin_id}' for domain '{domain}' not found!"))?;
diff --git a/src/config/node.rs b/src/config/node.rs
index 937beb3a125c..59faf3576b8a 100644
--- a/src/config/node.rs
+++ b/src/config/node.rs
@@ -272,6 +272,16 @@ impl NodeConfig {
             if !domains.insert(domain.domain.to_lowercase()) {
                 bail!("duplicate domain '{}' in ACME config", domain.domain);
             }
+            if domain.domain.contains('*')
+                && domain.plugin.map_or(true, |value| {
+                    value.as_str() == "" || value.as_str() == "standalone"
+                })
+            {
+                bail!(
+                    "wildcard domains like '{}' are not usable with the HTTP challenge type",
+                    domain.domain
+                );
+            }
         }
         let mut dummy_acceptor = SslAcceptor::mozilla_intermediate_v5(SslMethod::tls()).unwrap();
         if let Some(ciphers) = self.ciphers_tls_1_3.as_deref() {
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [pbs-devel] [PATCH v2] schema: add regex for dns domains with wildcard
  2024-09-18 12:06 [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge Gabriel Goller
@ 2024-09-18 12:06 ` Gabriel Goller
  2024-09-19 10:52 ` [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge Christian Ebner
  1 sibling, 0 replies; 5+ messages in thread
From: Gabriel Goller @ 2024-09-18 12:06 UTC (permalink / raw)
  To: pbs-devel

Support dns domains with wildcards, f.e. '*.proxmox.com'. This is useful
when adding ACME-domains.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---

v2: nothing changed 

 proxmox-schema/src/api_types.rs | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/proxmox-schema/src/api_types.rs b/proxmox-schema/src/api_types.rs
index fed46257cef2..2e49936e800b 100644
--- a/proxmox-schema/src/api_types.rs
+++ b/proxmox-schema/src/api_types.rs
@@ -53,9 +53,15 @@ pub const SAFE_ID_REGEX_STR: &str = r"(?:[A-Za-z0-9_][A-Za-z0-9._\-]*)";
 #[rustfmt::skip]
 pub const DNS_LABEL_STR: &str = r"(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
 
+#[rustfmt::skip]
+pub const DNS_LABEL_WILDCARD_STR: &str = r"(?:[a-zA-Z0-9\*](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
+
 #[rustfmt::skip]
 pub const DNS_NAME_STR: &str = concatcp!(r"(?:(?:", DNS_LABEL_STR, r"\.)*", DNS_LABEL_STR, ")");
 
+#[rustfmt::skip]
+pub const DNS_NAME_WILDCARD_STR: &str = concatcp!(r"(?:(?:", DNS_LABEL_WILDCARD_STR, r"\.)*", DNS_LABEL_WILDCARD_STR, ")");
+
 #[rustfmt::skip]
 pub const DNS_ALIAS_LABEL_STR: &str = r"(?:[a-zA-Z0-9_](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)";
 
@@ -99,7 +105,7 @@ const_regex! {
     pub MULTI_LINE_COMMENT_REGEX = r"(?m)^([[:^cntrl:]]*)$";
 
     pub HOSTNAME_REGEX = r"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?)$";
-    pub DNS_NAME_REGEX = concatcp!(r"^", DNS_NAME_STR, r"$");
+    pub DNS_NAME_REGEX = concatcp!(r"^", DNS_NAME_WILDCARD_STR, r"$");
     pub DNS_ALIAS_REGEX = concatcp!(r"^", DNS_ALIAS_NAME_STR, r"$");
     pub DNS_NAME_OR_IP_REGEX = concatcp!(r"^(?:", DNS_NAME_STR, "|",  IPRE_STR, r")$");
     pub HOST_PORT_REGEX = concatcp!(r"^(?:", DNS_NAME_STR, "|", IPRE_BRACKET_STR, "):", PORT_REGEX_STR ,"$");
-- 
2.39.5



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge
  2024-09-18 12:06 [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge Gabriel Goller
  2024-09-18 12:06 ` [pbs-devel] [PATCH v2] schema: add regex for dns domains with wildcard Gabriel Goller
@ 2024-09-19 10:52 ` Christian Ebner
  2024-09-19 13:07   ` Christian Ebner
  1 sibling, 1 reply; 5+ messages in thread
From: Christian Ebner @ 2024-09-19 10:52 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Gabriel Goller

Tested again with version 2 of the patches, this does now work as 
expected (although the dns challenge for the wildcard certificate failed 
for me, but that is because of the zone limit set on the api token I guess).

This still misses the fixes trailer for the bugtracker issue though.

Otherwise, consider:

Tested-by: Christian Ebner <c.ebner@proxmox.com>
Reviewed-by: Christian Ebner <c.ebner@proxmox.com>



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge
  2024-09-19 10:52 ` [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge Christian Ebner
@ 2024-09-19 13:07   ` Christian Ebner
  2024-09-19 13:29     ` Christian Ebner
  0 siblings, 1 reply; 5+ messages in thread
From: Christian Ebner @ 2024-09-19 13:07 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Gabriel Goller

Just tested again, with an DNS api token which has full zone access, but 
still get a `failed - status: Invalid` so something might still not be 
right here. The TXT record is published with name 
`_acme-challenge.*.domain.tld` when trying for `*.domain.tld` so that 
should be fine?


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge
  2024-09-19 13:07   ` Christian Ebner
@ 2024-09-19 13:29     ` Christian Ebner
  0 siblings, 0 replies; 5+ messages in thread
From: Christian Ebner @ 2024-09-19 13:29 UTC (permalink / raw)
  To: Proxmox Backup Server development discussion, Gabriel Goller

On 9/19/24 15:07, Christian Ebner wrote:
> Just tested again, with an DNS api token which has full zone access, but 
> still get a `failed - status: Invalid` so something might still not be 
> right here. The TXT record is published with name 
> `_acme-challenge.*.domain.tld` when trying for `*.domain.tld` so that 
> should be fine?

No, it should be named `_acme-challenge.domain.tld` according to the 
article [0] linked to by [1] so that is why it does not get validated.

[0] 
https://www.eff.org/deeplinks/2018/02/technical-deep-dive-securing-automation-acme-dns-challenge-validation
[1] https://letsencrypt.org/docs/challenge-types/#dns-01-challenge


_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-09-19 13:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-18 12:06 [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge Gabriel Goller
2024-09-18 12:06 ` [pbs-devel] [PATCH v2] schema: add regex for dns domains with wildcard Gabriel Goller
2024-09-19 10:52 ` [pbs-devel] [PATCH proxmox-backup v2] config: check if acme domain with wildcard uses dns challenge Christian Ebner
2024-09-19 13:07   ` Christian Ebner
2024-09-19 13:29     ` Christian Ebner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal