1
0
Fork 0
This commit is contained in:
Joao Gilberto 2022-11-09 18:27:22 -03:00
parent 5c491f749a
commit 79819aeacb
6 changed files with 41 additions and 20 deletions

View file

@ -1,10 +1,11 @@
# Docker environment variables
| Environment Variable | Description | Default |
|-------------------------------|-------------------------------------------------------------------------------------------------|------------------|
|---------------------------------|-------------------------------------------------------------------------------------------------|------------------|
| EASYHAPROXY_DISCOVER | How the services will be discovered to create `haproxy.cfg`: `static`, `docker`, `swarm` or `kubernetes` | **required** |
| EASYHAPROXY_LABEL_PREFIX | (Optional) The key will search for matching resources. | `easyhaproxy` |
| EASYHAPROXY_LETSENCRYPT_EMAIL | (Optional) The email will be used to request the certificate to Letsencrypt | *empty* |
| EASYHAPROXY_LETSENCRYPT_STAGING | (Optional) If true, will try to connect to the Letsencrypt test server | false |
| EASYHAPROXY_SSL_MODE | (Optional) `strict` supports only the most recent TLS version; `default` good SSL integration with recent browsers; `loose` supports all old SSL protocols for old browsers (not recommended). | `default`|
| EASYHAPROXY_REFRESH_CONF | (Optional) Check configuration every N seconds. | 10 |
| EASYHAPROXY_LOG_LEVEL | (Optional) The log level for EasyHAproxy messages. Available: TRACE,DEBUG,INFO,WARN,ERROR,FATAL | DEBUG |

View file

@ -49,7 +49,7 @@ class HaproxyConfigGenerator:
def __init__(self, mapping):
self.mapping = mapping
self.mapping.setdefault("ssl_mode", 'default')
self.mapping.setdefault("letsencrypt", {"email": ""})
self.mapping.setdefault("letsencrypt", {"email": "", "staging": False})
self.mapping["ssl_mode"] = self.mapping["ssl_mode"].lower()
self.label = DockerLabelHandler(mapping['lookup_label'] if 'lookup_label' in mapping else "easyhaproxy")
self.letsencrypt_hosts = []

View file

@ -174,9 +174,10 @@ class DaemonizeHAProxy:
class Certbot:
def __init__(self, certs, email):
def __init__(self, certs, email, staging):
self.certs = certs
self.email = email
self.staging = staging
def check_certificates(self, hosts):
if self.email == "" or len(hosts) == 0:
@ -201,7 +202,7 @@ class Certbot:
Functions.log(Functions.CERTBOT_LOG, Functions.DEBUG, "Renew certificate for %s" % (host))
renew_certs.append(host_arg)
certbot_certonly = ('/usr/bin/certbot certonly '
certbot_certonly = ('/usr/bin/certbot certonly {staging}'
' --standalone'
' --preferred-challenges http'
' --http-01-port 2080'
@ -210,7 +211,9 @@ class Certbot:
' --no-eff-email'
' --non-interactive'
' --max-log-backups=0'
' %s --email %s' % (' '.join(request_certs), self.email)
' {certs} --email {email}'.format(certs = ' '.join(request_certs),
email = self.email,
staging = '--staging' if self.staging else '')
)
ret_reload = False

View file

@ -22,7 +22,7 @@ def start():
haproxy.haproxy("start")
haproxy.sleep()
certbot = Certbot(Consts.certs_letsencrypt, os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL"))
certbot = Certbot(Consts.certs_letsencrypt, os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL"), os.getenv("EASYHAPROXY_LETSENCRYPT_STAGING", "false").lower() in ["true", "1", "yes"])
while True:
if old_haproxy is not None:

View file

@ -27,7 +27,8 @@ class ContainerEnv:
env_vars["lookup_label"] = os.getenv("EASYHAPROXY_LABEL_PREFIX") if os.getenv("EASYHAPROXY_LABEL_PREFIX") else "easyhaproxy"
if (os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL")):
env_vars["letsencrypt"] = {
"email": os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL")
"email": os.getenv("EASYHAPROXY_LETSENCRYPT_EMAIL"),
"staging": os.getenv("EASYHAPROXY_LETSENCRYPT_STAGING", "false").lower() in ["true", "1", "yes"]
}
return env_vars

View file

@ -95,8 +95,24 @@ def test_container_env_stats_password():
"lookup_label": "easyhaproxy",
"letsencrypt": {
"email": "acme@example.org",
"staging": False
}
} == ContainerEnv.read()
finally:
os.environ['EASYHAPROXY_LETSENCRYPT_EMAIL'] = ''
def test_container_env_letsencrypt():
os.environ['EASYHAPROXY_LETSENCRYPT_EMAIL'] = 'acme@example.org'
os.environ['EASYHAPROXY_LETSENCRYPT_STAGING'] = 'true'
try:
assert {
"customerrors": False,
"ssl_mode": "default",
"lookup_label": "easyhaproxy",
"letsencrypt": {
"email": "acme@example.org",
"staging": True
}
} == ContainerEnv.read()
finally:
os.environ['EASYHAPROXY_LETSENCRYPT_EMAIL'] = ''