summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2025-10-02 23:29:13 +0200
committerChristian Breunig <christian@breunig.cc>2025-10-02 23:39:40 +0200
commitae74a511e11b7516a276b9bfa40e2c02cbe182cd (patch)
tree9d8c02a4f039b46841de207f331a17a223d8508b /src
parent008bd2463ee2cba05470768e11d634c2461ea5fa (diff)
downloadvyos-1x-ae74a511e11b7516a276b9bfa40e2c02cbe182cd.tar.gz
vyos-1x-ae74a511e11b7516a276b9bfa40e2c02cbe182cd.zip
pki: T7885: "renew certbot force" now supports setting up ACME from scratch
Assume someone deleted the certbot_config folder, "renew certbot force" alone will not work as there are no configuration files left to know what to renew. Re-run CLI PKI helper to initially request certificates via ACME again. This "should" (famous last words) never be the case - but sometimes the universe has a bad time.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/op_mode/pki.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/op_mode/pki.py b/src/op_mode/pki.py
index 0f144443b..7ee51a1ae 100755
--- a/src/op_mode/pki.py
+++ b/src/op_mode/pki.py
@@ -26,6 +26,7 @@ from cryptography.x509.oid import ExtendedKeyUsageOID
import vyos.opmode
+from vyos.base import Warning
from vyos.config import Config
from vyos.config import config_dict_mangle_acme
from vyos.pki import encode_certificate
@@ -1379,6 +1380,17 @@ def renew_certbot(raw: bool, force: typing.Optional[bool] = False):
certbot_config = directories['certbot']
hook_dir = directories['base']
+ if force and not os.path.isdir(f'{certbot_config}'):
+ # Assume someone deleted the certbot_config folder, renew alone will not
+ # work as there are no configuration files left to know what to renew.
+ # Re-run CLI PKI helper to initially request certificates via ACME
+ # again. This should never be the case - but sometimes the universe has
+ # a bad time
+ Warning(f'Directory "{certbot_config}" missing. Reinitializing PKI ' \
+ 'subsystem...\n\n')
+ vyos_conf_scripts_dir = directories['conf_mode']
+ cmd(f'sudo sg vyattacfg -c {vyos_conf_scripts_dir}/pki.py')
+
tmp = f'/usr/bin/certbot renew --no-random-sleep-on-renew ' \
f'--config-dir "{certbot_config}" ' \
f'--post-hook "{hook_dir}/vyos-certbot-renew-pki.sh"'