Skip to content

Commit a901e69

Browse files
authored
feat: refactor Traefik route configuration and update lets_encrypt handling #121
NethServer/dev#7669
1 parent d940508 commit a901e69

File tree

8 files changed

+377
-146
lines changed

8 files changed

+377
-146
lines changed

build-images.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ buildah add "${container}" ui/dist /ui
7575
# Setup the entrypoint, ask to reserve one TCP port with the label and set a rootless container
7676
buildah config --entrypoint=/ \
7777
--label="org.nethserver.authorizations=traefik@any:routeadm node:tunadm,portsadm" \
78-
--label="org.nethserver.min-core=3.1.0" \
78+
--label="org.nethserver.min-core=3.12.4-0" \
7979
--label="org.nethserver.tcp-ports-demand=11" \
8080
--label="org.nethserver.images=ghcr.io/nethserver/nethsecurity-vpn:$controller_version ghcr.io/nethserver/nethsecurity-api:$controller_version ghcr.io/nethserver/nethsecurity-ui:$controller_version ghcr.io/nethserver/nethsecurity-proxy:$controller_version $promtail_image $loki_image $prometheus_image $grafana_image ghcr.io/nethserver/webssh:${IMAGETAG:-latest} $timescale_image" \
8181
"${container}"

imageroot/actions/configure-module/20configure

Lines changed: 72 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -28,72 +28,78 @@ for path in ['loki_path', 'prometheus_path', 'webssh_path']:
2828
config[path] = f'/{uuid.uuid4()}'
2929

3030
# Configure Traefik to route requests to the nethsec-controller service
31-
response = agent.tasks.run(
32-
agent_id=agent.resolve_agent_id('traefik@node'),
33-
action='set-route',
34-
data={
35-
'instance': os.environ['MODULE_ID'],
36-
'url': f'http://127.0.0.1:{ports[3]}',
37-
'http2https': True,
38-
'lets_encrypt': request["lets_encrypt"],
39-
'host': request["host"],
40-
},
41-
)
42-
agent.assert_exp(response['exit_code'] == 0)
43-
response = agent.tasks.run(
44-
agent_id=agent.resolve_agent_id('traefik@node'),
45-
action='set-route',
46-
data={
47-
'instance': os.environ['MODULE_ID'] + '_grafana',
48-
'url': f'http://127.0.0.1:{ports[8]}',
49-
'http2https': True,
50-
'lets_encrypt': request["lets_encrypt"],
51-
'host': request["host"],
52-
'path': '/grafana'
53-
},
54-
)
55-
agent.assert_exp(response['exit_code'] == 0)
56-
response = agent.tasks.run(
57-
agent_id=agent.resolve_agent_id('traefik@node'),
58-
action='set-route',
59-
data={
60-
'instance': os.environ['MODULE_ID'] + '_loki',
61-
'url': f'http://127.0.0.1:{ports[5]}',
62-
'http2https': True,
63-
'lets_encrypt': request["lets_encrypt"],
64-
'host': request["host"],
65-
'path': config['loki_path']
66-
},
67-
)
68-
agent.assert_exp(response['exit_code'] == 0)
69-
response = agent.tasks.run(
70-
agent_id=agent.resolve_agent_id('traefik@node'),
71-
action='set-route',
72-
data={
73-
'instance': os.environ['MODULE_ID'] + '_prometheus',
74-
'url': f'http://127.0.0.1:{ports[7]}',
75-
'http2https': True,
76-
'lets_encrypt': request["lets_encrypt"],
77-
'host': request["host"],
78-
'path': config['prometheus_path']
79-
},
80-
)
81-
agent.assert_exp(response['exit_code'] == 0)
82-
83-
response = agent.tasks.run(
84-
agent_id=agent.resolve_agent_id('traefik@node'),
85-
action='set-route',
86-
data={
87-
'instance': os.environ['MODULE_ID'] + '_webssh',
88-
'url': f'http://127.0.0.1:{ports[9]}',
89-
'http2https': True,
90-
'lets_encrypt': request["lets_encrypt"],
91-
'host': request["host"],
92-
'path': config['webssh_path'],
93-
'strip_prefix': True
94-
},
95-
)
96-
agent.assert_exp(response['exit_code'] == 0)
31+
set_route_data = {
32+
'instance': os.environ['MODULE_ID'],
33+
'url': f'http://127.0.0.1:{ports[3]}',
34+
'http2https': True,
35+
'host': request["host"],
36+
'lets_encrypt_check': True,
37+
'lets_encrypt_cleanup': True,
38+
}
39+
if 'lets_encrypt' in request:
40+
set_route_data['lets_encrypt'] = request['lets_encrypt']
41+
42+
agent.set_route(set_route_data)
43+
44+
# Configure Traefik to route requests to the grafana service
45+
set_route_data = {
46+
'instance': os.environ['MODULE_ID'] + '_grafana',
47+
'url': f'http://127.0.0.1:{ports[8]}',
48+
'http2https': True,
49+
'host': request["host"],
50+
'path': '/grafana',
51+
'lets_encrypt_check': True,
52+
'lets_encrypt_cleanup': True,
53+
}
54+
if 'lets_encrypt' in request:
55+
set_route_data['lets_encrypt'] = request['lets_encrypt']
56+
57+
agent.set_route(set_route_data)
58+
59+
# Configure Traefik to route requests to the loki service
60+
set_route_data = {
61+
'instance': os.environ['MODULE_ID'] + '_loki',
62+
'url': f'http://127.0.0.1:{ports[5]}',
63+
'http2https': True,
64+
'host': request["host"],
65+
'path': config['loki_path'],
66+
'lets_encrypt_check': True,
67+
'lets_encrypt_cleanup': True,
68+
}
69+
if 'lets_encrypt' in request:
70+
set_route_data['lets_encrypt'] = request['lets_encrypt']
71+
72+
agent.set_route(set_route_data)
73+
74+
# Configure Traefik to route requests to the prometheus service
75+
set_route_data = {
76+
'instance': os.environ['MODULE_ID'] + '_prometheus',
77+
'url': f'http://127.0.0.1:{ports[7]}',
78+
'http2https': True,
79+
'host': request["host"],
80+
'path': config['prometheus_path'],
81+
'lets_encrypt_check': True,
82+
'lets_encrypt_cleanup': True,
83+
}
84+
if 'lets_encrypt' in request:
85+
set_route_data['lets_encrypt'] = request['lets_encrypt']
86+
87+
agent.set_route(set_route_data)
88+
89+
# Configure Traefik to route requests to the webssh service
90+
set_route_data = {
91+
'instance': os.environ['MODULE_ID'] + '_webssh',
92+
'url': f'http://127.0.0.1:{ports[9]}',
93+
'http2https': True,
94+
'lets_encrypt': request["lets_encrypt"],
95+
'host': request["host"],
96+
'path': config['webssh_path'],
97+
'strip_prefix': True,
98+
'lets_encrypt_check': True,
99+
'lets_encrypt_cleanup': True,
100+
}
101+
if 'lets_encrypt' in request:
102+
set_route_data['lets_encrypt'] = request['lets_encrypt']
97103

98104
config["allowed_ips"] = request.get("allowed_ips", [])
99105

imageroot/actions/configure-module/validate-input.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"api_user": "admin",
99
"api_password": "admin",
1010
"host": "controller.nethserver.org",
11-
"lets_encrypt": true,
1211
"ovpn_network": "127.2.10.0",
1312
"ovpn_netmask": "255.255.0.0",
1413
"ovpn_cn": "nethsec",
@@ -19,7 +18,7 @@
1918
}
2019
],
2120
"type": "object",
22-
"required": [ "host", "lets_encrypt", "api_user", "ovpn_network", "ovpn_netmask", "ovpn_cn" ],
21+
"required": [ "host", "api_user", "ovpn_network", "ovpn_netmask", "ovpn_cn" ],
2322
"properties": {
2423
"host": {
2524
"type": "string",

imageroot/actions/get-configuration/20read

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ if os.path.isfile('config.json'):
2323
config['api_password'] = ''
2424
network = agent.read_envfile('network.env')
2525
config['vpn_port'] = network['OVPN_UDP_PORT']
26+
config["lets_encrypt"] = agent.get_route(os.environ['MODULE_ID']).get('lets_encrypt', False)
2627
else:
2728
# Prepare random values for first-configuration
2829
# Pick a newtork inside 172.16.0.0/12 (range 172.16.0.0-172.31.255.255)

imageroot/actions/restore-module/20configure

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ config = {}
1515
# Read current configuration from config file
1616
with open('config.json', 'r') as cf:
1717
config = json.loads(cf.read())
18+
if 'lets_encrypt' in config:
19+
del config['lets_encrypt']
1820

1921
agent.tasks.run(agent_id=os.environ['AGENT_ID'], action='configure-module', data=config)

ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@carbon/icons-vue": "^10.37.0",
1313
"@carbon/vue": "^2.40.0",
14-
"@nethserver/ns8-ui-lib": "^1.3.1",
14+
"@nethserver/ns8-ui-lib": "^1.4.1",
1515
"await-to-js": "^3.0.0",
1616
"axios": "^0.30.0",
1717
"carbon-components": "^10.41.0",

0 commit comments

Comments
 (0)