Skip to content

Commit 5b2d4df

Browse files
committed
Add secret file and fix smarthost and restore
1 parent de9fb79 commit 5b2d4df

File tree

22 files changed

+389
-302
lines changed

22 files changed

+389
-302
lines changed

build-images.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ buildah config --entrypoint=/ \
3939
--label="org.nethserver.authorizations=traefik@node:routeadm" \
4040
--label="org.nethserver.tcp-ports-demand=1" \
4141
--label="org.nethserver.rootfull=0" \
42+
--label="org.nethserver.min-core=3.12.4-0" \
4243
--label="org.nethserver.images=docker.io/library/postgres:16.11 docker.io/n8nio/n8n:2.0.2 docker.io/n8nio/runners:2.0.2" \
4344
--label="org.nethserver.tcp-ports-demand=1" \
4445
"${container}"
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 os
9+
import sys
10+
import json
11+
import agent
12+
import urllib.request
13+
import urllib.error
14+
import ssl
15+
16+
agent.set_weight(os.path.basename(__file__), 0) # Validation step, no task progress at all
17+
18+
# retrieve json data
19+
data = json.load(sys.stdin)
20+
21+
# Setup default values
22+
host = data["host"]
23+
# do not test if it is the same host
24+
oldHost = os.environ.get('TRAEFIK_HOST','')
25+
26+
if host != oldHost and agent.http_route_in_use(domain=host):
27+
agent.set_status('validation-failed')
28+
json.dump([{'field':'host','parameter':'host','value':host,'error':'domain_already_used_in_traefik'}],fp=sys.stdout)
29+
sys.exit(2)

imageroot/actions/configure-module/20configure

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,30 @@
77
import os
88
import json
99
import sys
10-
# agent is a NethServer library which provides function to communicate with the agent
1110
import agent
1211

12+
# Try to parse the stdin as JSON.
13+
# If parsing fails, output everything to stderr
1314
data = json.load(sys.stdin)
1415

1516
# Setup default values
16-
17-
# n8n CSRF settings
18-
host = data.get("host", "")
19-
n8n_URL = "https://"+host
20-
21-
# Db Config
22-
23-
POSTGRES_DB = data.get("POSTGRES_DB","n8n")
24-
POSTGRES_USER = data.get("POSTGRES_USER","n8n")
25-
POSTGRES_PASSWORD = data.get("POSTGRES_PASSWORD","N@8ni0p$$")
26-
POSTGRES_NON_ROOT_USER = data.get("POSTGRES_NON_ROOT_USER","n8n")
27-
POSTGRES_NON_ROOT_PASSWORD = data.get("POSTGRES_NON_ROOT_PASSWORD","N@8ni0p$$")
28-
29-
db_config = {
30-
"POSTGRES_ROOT_HOST": "localhost",
31-
"POSTGRES_DATABASE": POSTGRES_DB,
32-
"POSTGRES_USER": POSTGRES_USER,
33-
"POSTGRES_PASSWORD": POSTGRES_PASSWORD,
34-
"POSTGRES_NON_ROOT_USER": POSTGRES_NON_ROOT_USER,
35-
"POSTGRES_NON_ROOT_PASSWORD": POSTGRES_NON_ROOT_PASSWORD,
36-
17+
host = data["host"]
18+
h2hs = data.get("http2https", True)
19+
20+
# Configure Traefik route for API
21+
set_route_data = {
22+
'instance': os.environ['MODULE_ID'],
23+
'url': 'http://127.0.0.1:' + os.environ["TCP_PORT"],
24+
'host': host,
25+
'http2https': h2hs,
26+
'lets_encrypt_check': True,
27+
'lets_encrypt_cleanup': True,
3728
}
38-
agent.write_envfile('database.env', db_config)
29+
if 'lets_encrypt' in data:
30+
set_route_data['lets_encrypt'] = data['lets_encrypt']
31+
32+
agent.set_route(set_route_data)
3933

40-
# Set N8N_HOST
41-
agent.set_env("N8N_HOST", host)
34+
# Setup Traefik
35+
agent.set_env("TRAEFIK_HOST", host)
36+
agent.set_env("TRAEFIK_HTTP2HTTPS", h2hs)
Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1 @@
1-
#!/usr/bin/env python3
2-
3-
import os
4-
import sys
5-
import json
6-
import agent
7-
import agent.tasks
8-
9-
# Try to parse the stdin as JSON.
10-
# If parsing fails, output everything to stderr
11-
data = json.load(sys.stdin)
12-
13-
14-
# Setup default values
15-
host = data.get("host", "")
16-
h2hs = data.get("http2https", True)
17-
le = data.get("lets_encrypt", True)
18-
19-
# Talk with agent using file descriptor.
20-
# Setup configuration from user input.
21-
agent.set_env("TRAEFIK_HOST", host)
22-
agent.set_env("TRAEFIK_HTTP2HTTPS", h2hs)
23-
agent.set_env("TRAEFIK_LETS_ENCRYPT", le)
24-
25-
# Make sure everything is saved inside the environment file
26-
# just before starting systemd unit
27-
agent.dump_env()
28-
29-
# Find default traefik instance for current node
30-
default_traefik_id = agent.resolve_agent_id('traefik@node')
31-
if default_traefik_id is None:
32-
sys.exit(2)
33-
34-
# Configure traefik virtual host
35-
response = agent.tasks.run(
36-
agent_id=default_traefik_id,
37-
action='set-route',
38-
data={
39-
'instance': os.environ['MODULE_ID'],
40-
'url': f'http://127.0.0.1:{os.environ["TCP_PORT"]}',
41-
'host': host,
42-
'lets_encrypt': le,
43-
'http2https': h2hs,
44-
},
45-
)
46-
47-
# Check if traefik configuration has been successfull
48-
agent.assert_exp(response['exit_code'] == 0)
1+
# Placeholder, see bug NethServer/dev#7058

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"title": "configure n8n settings",
44
"$id": "http://nethserver.org/json-schema/task/input/n8n/configure-module",
5-
"description": "Condifure n8n settings",
5+
"description": "Configure n8n settings",
66
"examples": [
77
{
88
"host": "n8n.domain.org",
@@ -18,17 +18,18 @@
1818
"host": {
1919
"type": "string",
2020
"description": "Host name for the application, like 'n8n.domain.org'",
21-
"format": "idn-hostname"
21+
"format": "hostname",
22+
"pattern": "\\."
2223
},
23-
"lets_encrypt": {
24+
"lets_encrypt": {
2425
"type": "boolean",
2526
"title": "Let's Encrypt certificate",
2627
"description": "Request a valid Let's Encrypt certificate."
2728
},
28-
"http2https": {
29+
"http2https": {
2930
"type": "boolean",
3031
"title": "HTTP to HTTPS redirection",
3132
"description": "Redirect all the HTTP requests to HTTPS"
3233
}
33-
}
34-
}
34+
}
35+
}

imageroot/actions/create-module/20configure

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1 @@
1-
#!/usr/bin/env python3
2-
3-
#
4-
# Copyright (C) 2023 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-
)
33-
34-
# Check if traefik configuration has been successfull
35-
agent.assert_exp(response['exit_code'] == 0)
1+
# Placeholder, see bug NethServer/dev#7058

imageroot/actions/get-configuration/20read

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ config = {}
1515
# Read current configuration from Redis
1616
config["host"] = os.getenv("TRAEFIK_HOST","")
1717
config["http2https"] = os.getenv("TRAEFIK_HTTP2HTTPS") == "True"
18-
config["lets_encrypt"] = os.getenv("TRAEFIK_LETS_ENCRYPT") == "True"
18+
config["lets_encrypt"] = agent.get_route(os.environ['MODULE_ID']).get('lets_encrypt', False)
1919

20-
if not config:
21-
print("Error: JSON output is empty.")
22-
else:
23-
json.dump(config, fp=sys.stdout, indent=2)
20+
json.dump(config, fp=sys.stdout)

imageroot/actions/get-configuration/validate-output.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@
1212
],
1313
"type": "object",
1414
"required": [
15-
"host"
15+
"host",
16+
"http2https",
17+
"lets_encrypt"
1618
],
1719
"properties": {
1820
"host": {
1921
"type": "string",
2022
"description": "Host name for the application, like 'n8n.domain.org'",
2123
"format": "idn-hostname"
2224
},
23-
"lets_encrypt": {
25+
"lets_encrypt": {
2426
"type": "boolean",
2527
"title": "Let's Encrypt certificate",
2628
"description": "Request a valid Let's Encrypt certificate."
2729
},
28-
"http2https": {
30+
"http2https": {
2931
"type": "boolean",
3032
"title": "HTTP to HTTPS redirection",
3133
"description": "Redirect all the HTTP requests to HTTPS"
3234
}
33-
}
3435
}
36+
}

imageroot/actions/restore-module/06copyenv

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ request = json.load(sys.stdin)
2929
original_environment = request['environment']
3030

3131
for evar in [
32-
"TRAEFIK_HOST",
32+
"TRAEFIK_HOST",
3333
"TRAEFIK_HTTP2HTTPS",
34-
"TRAEFIK_LETS_ENCRYPT",
3534
]:
36-
agent.set_env(evar, original_environment[evar])
35+
agent.set_env(evar, original_environment[evar])

0 commit comments

Comments
 (0)