From: Wolfgang Bumiller <w.bumiller@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH api 4/4] check acme cert expiration in pmg-daily
Date: Wed, 17 Mar 2021 11:02:16 +0100 [thread overview]
Message-ID: <20210317100216.8008-5-w.bumiller@proxmox.com> (raw)
In-Reply-To: <20210317100216.8008-1-w.bumiller@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
---
src/bin/pmg-daily | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/src/bin/pmg-daily b/src/bin/pmg-daily
index 8865c94..d454c62 100755
--- a/src/bin/pmg-daily
+++ b/src/bin/pmg-daily
@@ -8,6 +8,7 @@ use strict;
use warnings;
use Time::Local;
+use PVE::Certificate;
use PVE::SafeSyslog;
use PVE::INotify;
use PVE::RESTEnvironment;
@@ -18,6 +19,9 @@ use PMG::ClusterConfig;
use PMG::DBTools;
use PMG::API2::Subscription;
use PMG::API2::APT;
+use PMG::API2::Certificates;
+use PMG::CertHelpers;
+use PMG::NodeConfig;
$SIG{'__WARN__'} = sub {
my $err = $@;
@@ -89,5 +93,37 @@ PMG::Utils::service_cmd('pmg-smtp-filter', 'restart') if $restart_filter;
# run bayes database maintainance
system('sa-learn --force-expire >/dev/null 2>&1');
+eval {
+ my $node_config = PMG::NodeConfig::load_config();
+ my $acme_node_config = PMG::NodeConfig::get_acme_conf($node_config);
+ my $acme_domains = $acme_node_config && $acme_node_config->{domains};
+ if ($acme_domains) {
+ my %typed_domains = map {
+ $_ => PMG::NodeConfig::filter_domains_by_type($acme_domains, $_)
+ } qw(api smtp);
+
+ foreach my $type (qw(api smtp)) {
+ next if !$typed_domains{$type};
+
+ # Guard both certificates separately.
+ eval {
+ my $cert = PMG::CertHelpers::cert_path($type);
+ if (!-e $cert) {
+ syslog ('info', "ACME config found for '$type' certificate, but no custom certificate exists. Skipping ACME renewal until initial certificate has been deployed.");
+ next;
+ }
+
+ if (PVE::Certificate::check_expiry($cert, time() + 30*24*60*60)) {
+ PMG::API2::Certificates->renew_acme_cert({ node => $nodename, type => $type });
+ } else {
+ syslog ('info', "Custom '$type' certificate does not expire soon, skipping ACME renewal.");
+ }
+ };
+ syslog ('err', "Renewing '$type' ACME certificate failed: $@") if $@;
+ }
+ }
+};
+syslog ('err', "Renewing ACME certificate failed: $@") if $@;
+
exit (0);
--
2.20.1
next prev parent reply other threads:[~2021-03-17 10:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-17 10:02 [pmg-devel] [PATCH api 0/4] ACME updates Wolfgang Bumiller
2021-03-17 10:02 ` [pmg-devel] [PATCH api 1/4] add missing use statement Wolfgang Bumiller
2021-03-17 10:02 ` [pmg-devel] [PATCH api 2/4] support forced account deactivation Wolfgang Bumiller
2021-03-17 10:33 ` Thomas Lamprecht
2021-03-17 10:02 ` [pmg-devel] [PATCH api 3/4] add PMG::NodeConfig::filter_domains_by_type helper Wolfgang Bumiller
2021-03-17 10:02 ` Wolfgang Bumiller [this message]
2021-03-17 10:34 ` [pmg-devel] applied-series: [PATCH api 0/4] ACME updates Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210317100216.8008-5-w.bumiller@proxmox.com \
--to=w.bumiller@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox