Add health checks for Docker services, ACME environment readiness validation, and Certbot unit tests
- Introduced health checks to Docker Compose files for better service reliability. - Added ACME environment readiness validation to ensure proper configuration for Certbot. - Implemented unit tests for Certbot's `check_acme_environment_ready` method to cover edge cases. - Improved E2E tests with startup wait adjustments and dynamic certificate issuance verification. - Enhanced Kubernetes test cleanup with forced resource deletion for faster termination.
This commit is contained in:
parent
045dd3817e
commit
4df8666a2b
18 changed files with 303 additions and 28 deletions
|
|
@ -458,6 +458,46 @@ class Certbot:
|
|||
else:
|
||||
return ""
|
||||
|
||||
@staticmethod
|
||||
def check_acme_environment_ready(email, acme_server):
|
||||
"""
|
||||
Check if ACME environment is ready for certificate operations.
|
||||
|
||||
Args:
|
||||
email: EASYHAPROXY_CERTBOT_EMAIL value
|
||||
acme_server: Processed ACME server string from set_acme_server()
|
||||
|
||||
Returns:
|
||||
tuple: (is_ready: bool, error_message: str)
|
||||
"""
|
||||
# Check 1: Email configured
|
||||
if not email or email == "":
|
||||
return False, "ACME email not configured (EASYHAPROXY_CERTBOT_EMAIL)"
|
||||
|
||||
# Check 2: ACME server configured
|
||||
if not acme_server or acme_server == "":
|
||||
return False, "ACME server not configured (EASYHAPROXY_CERTBOT_SERVER)"
|
||||
|
||||
# Check 3: ACME server reachability (if URL provided)
|
||||
if "--server " in acme_server:
|
||||
server_url = acme_server.replace("--server ", "")
|
||||
try:
|
||||
# Use 10s timeout, respect REQUESTS_CA_BUNDLE for Pebble CA
|
||||
response = requests.get(server_url, timeout=10, verify=os.getenv("REQUESTS_CA_BUNDLE", True))
|
||||
if response.status_code != 200:
|
||||
return False, f"ACME server {server_url} returned HTTP {response.status_code}"
|
||||
|
||||
# Validate ACME directory structure (RFC 8555)
|
||||
data = response.json()
|
||||
if "newAccount" not in data:
|
||||
return False, f"ACME server {server_url} returned invalid ACME directory"
|
||||
except requests.exceptions.RequestException as e:
|
||||
return False, f"ACME server {server_url} not reachable: {str(e)}"
|
||||
except Exception as e:
|
||||
return False, f"ACME server validation failed: {str(e)}"
|
||||
|
||||
return True, ""
|
||||
|
||||
def check_certificates(self, hosts):
|
||||
if self.email == "" or len(hosts) == 0:
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -35,6 +35,15 @@ def start():
|
|||
|
||||
certbot = Certbot(Consts.certs_certbot)
|
||||
|
||||
# Check ACME environment readiness if Certbot is configured
|
||||
if certbot.email != "":
|
||||
is_ready, error_msg = Certbot.check_acme_environment_ready(certbot.email, certbot.acme_server)
|
||||
if not is_ready:
|
||||
logger_easyhaproxy.warning(f"ACME environment not ready: {error_msg}")
|
||||
logger_easyhaproxy.warning("Certificate auto-renewal may fail. Verify ACME server configuration.")
|
||||
else:
|
||||
logger_easyhaproxy.info("ACME environment validated and ready")
|
||||
|
||||
while True:
|
||||
if old_haproxy is not None:
|
||||
old_haproxy.kill()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue