Skip to content

Commit 8b48eb0

Browse files
authored
Enhance Let's Encrypt certificate management and error handling (#157)
NethServer/dev#7669
1 parent 74428ef commit 8b48eb0

File tree

8 files changed

+209
-120
lines changed

8 files changed

+209
-120
lines changed

build-images.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ buildah add "${container}" ui/dist /ui
181181
# Setup the entrypoint, ask to reserve one TCP port with the label and set a rootless container
182182
buildah config --entrypoint=/ \
183183
--label="org.nethserver.authorizations=traefik@node:routeadm mail@any:mailadm cluster:accountconsumer nethvoice@any:pbookreader" \
184+
--label="org.nethserver.min-core=3.12.4-0" \
184185
--label="org.nethserver.tcp-ports-demand=1" \
185186
--label="org.nethserver.rootfull=0" \
186187
--label="org.nethserver.min-from=1.4.4" \
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
3+
#
4+
# Copyright (C) 2025 Nethesis S.r.l.
5+
# SPDX-License-Identifier: GPL-3.0-or-later
6+
#
7+
8+
import json
9+
import sys
10+
import os
11+
import agent
12+
13+
# Try to parse the stdin as JSON.
14+
# If parsing fails, output everything to stderr
15+
data = json.load(sys.stdin)
16+
17+
## Configure set-route
18+
set_route_data = {
19+
'instance': os.environ['MODULE_ID'],
20+
'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"],
21+
'http2https': True,
22+
'host': data["hostname"],
23+
'lets_encrypt_check': True,
24+
'lets_encrypt_cleanup': True,
25+
}
26+
if 'request_https_certificate' in data:
27+
set_route_data['lets_encrypt'] = data['request_https_certificate']
28+
29+
agent.set_route(set_route_data)

imageroot/actions/configure-module/20config

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,6 @@ if not agent_id:
2222
# Connect to redis
2323
rdb = agent.redis_connect()
2424

25-
webtop_request_https_certificate = os.environ["WEBTOP_REQUEST_HTTPS_CERTIFICATE"].lower() in ('true', '1', 't')
26-
if data.get("request_https_certificate") is not None:
27-
if data.get("request_https_certificate") != webtop_request_https_certificate:
28-
webtop_request_https_certificate = data["request_https_certificate"]
29-
agent.set_env("WEBTOP_REQUEST_HTTPS_CERTIFICATE", data["request_https_certificate"])
30-
31-
# Configure Traefik to route WebTop's host requests to the webtop module
32-
response = agent.tasks.run(
33-
agent_id=agent.resolve_agent_id('traefik@node'),
34-
action='set-route',
35-
data={
36-
'instance': os.environ['MODULE_ID'],
37-
'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"],
38-
'http2https': True,
39-
'lets_encrypt': webtop_request_https_certificate,
40-
'host': data["hostname"],
41-
}
42-
)
43-
# Check if traefik configuration has been successfull
44-
agent.assert_exp(response['exit_code'] == 0)
45-
46-
4725
public_url = 'https://' + data["hostname"] + '/webtop'
4826
dav_url = 'https://' + data["hostname"] + '/webtop-dav/server.php'
4927

imageroot/actions/create-module/10env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import agent
99

1010
agent.set_env('WEBTOP_TIMEZONE', '-')
1111
agent.set_env('WEBTOP_LOCALE', 'en_US')
12-
agent.set_env('WEBTOP_REQUEST_HTTPS_CERTIFICATE', 'False')
1312
agent.set_env('WEBDAV_DEBUG', 'False')
1413
agent.set_env('WEBDAV_LOG_LEVEL', 'ERROR')
1514
agent.set_env('Z_PUSH_LOG_LEVEL', 'ERROR')

imageroot/actions/destroy-module/20destroy

100755100644
Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1 @@
1-
#!/usr/bin/env python3
2-
3-
#
4-
# Copyright (C) 2022 Nethesis S.r.l.
5-
# SPDX-License-Identifier: GPL-3.0-or-later
6-
#
7-
8-
# Remove traefik route
9-
10-
import os
11-
import sys
12-
import json
13-
import agent
14-
import agent.tasks
15-
16-
# Try to parse the stdin as JSON.
17-
# If parsing fails, output everything to stderr
18-
data = json.load(sys.stdin)
19-
20-
# Find default traefik instance for current node
21-
default_traefik_id = agent.resolve_agent_id('traefik@node')
22-
if default_traefik_id is None:
23-
sys.exit(2)
24-
25-
# Remove traefik route
26-
response = agent.tasks.run(
27-
agent_id=default_traefik_id,
28-
action='delete-route',
29-
data={
30-
'instance': os.environ['MODULE_ID']
31-
},
32-
)
1+
# Placeholder, see bug NethServer/dev#7058

imageroot/actions/get-configuration/20readconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import json
99
import os
1010
import sys
11+
import agent
1112

1213
config={
1314
"hostname": os.getenv("WEBTOP_HOSTNAME", ""),
14-
"request_https_certificate": os.environ["WEBTOP_REQUEST_HTTPS_CERTIFICATE"].lower() in ('true', '1', 't'),
15+
"request_https_certificate": agent.get_route(os.environ['MODULE_ID']).get('lets_encrypt', False),
1516
"locale": os.environ["WEBTOP_LOCALE"],
1617
"timezone": os.environ["WEBTOP_TIMEZONE"],
1718
"mail_module": os.getenv("MAIL_MODULE", ""),

ui/public/i18n/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"action": {
8787
"get-status": "Get status",
8888
"get-configuration": "Get configuration",
89+
"get-defaults": "Get defaults",
8990
"configure-module": "Configure module",
9091
"get-module-info": "Get module info",
9192
"get-name": "Get name",

0 commit comments

Comments
 (0)