-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs - NethServer/dev#7158 - NethServer/dev#7004 - NethServer/dev#7305 - NethServer/dev#6987 - NethServer/dev#7300 - NethServer/dev#7312
- Loading branch information
Showing
21 changed files
with
337 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
imageroot/actions/get-trusted-proxies/20get_trusted_proxies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import agent | ||
import json | ||
import sys | ||
import os | ||
import conf_helpers | ||
|
||
def main(): | ||
curconf = conf_helpers.parse_yaml_config("traefik.yaml") | ||
try: | ||
proxies = list(set( | ||
curconf['entryPoints']['http']['forwardedHeaders']["trustedIPs"] + | ||
curconf['entryPoints']['https']['forwardedHeaders']["trustedIPs"] | ||
)) | ||
except KeyError: | ||
proxies = [] | ||
response = { | ||
"proxies": proxies, | ||
"depth": int(os.getenv("PROXIES_DEPTH", 0)) | ||
} | ||
json.dump(response, fp=sys.stdout) | ||
|
||
if __name__ == "__main__": | ||
main() |
31 changes: 31 additions & 0 deletions
31
imageroot/actions/get-trusted-proxies/validate-output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "set-trusted-proxies output", | ||
"$id": "http://schema.nethserver.org/traefik/set-trusted-proxies-output.json", | ||
"description": "Get the IP addresses that are trusted as front-end proxies", | ||
"examples": [ | ||
{ | ||
"proxies": [ | ||
"192.168.1.1", | ||
"192.168.1.2" | ||
] | ||
} | ||
], | ||
"type": "object", | ||
"required": [ | ||
"proxies" | ||
], | ||
"additionalProperties": false, | ||
"properties": { | ||
"depth": { | ||
"type":"integer", | ||
"minimum": 0 | ||
}, | ||
"proxies": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
set -e | ||
|
||
shopt -s nullglob | ||
|
||
# Restore HTTP routes created from the UI: | ||
for froute in state-backup/manual_flags/* ; do | ||
route=$(basename "${froute}") | ||
if [[ -f "state-backup/configs/${route}.yml" ]]; then | ||
cp -vfT "state-backup/configs/${route}.yml" "configs/${route}.yml" | ||
touch "manual_flags/${route}" | ||
fi | ||
done | ||
|
||
# Restore uploaded certificates (dynamic config): | ||
find state-backup/configs -type f -name 'cert_*.yml' -0 | \ | ||
xargs -0 -r -- cp -pvt configs/ | ||
|
||
# Restore uploaded certificates (certificates and private keys): | ||
find state-backup/custom_certificates -type f -0 | \ | ||
xargs -0 -r -- cp -pvt custom_certificates/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import json | ||
import sys | ||
import os | ||
import agent | ||
import ipaddress | ||
|
||
def main(): | ||
agent.set_weight(os.path.basename(__file__), 0) # Validation step, no task progress at all | ||
request = json.load(sys.stdin) | ||
if "ip_allowlist" in request: | ||
for ipvalue in request['ip_allowlist']: | ||
# Check if ipvalue is a string representing IPv4, IPv6, or | ||
# CIDR: | ||
try: | ||
if '/' in ipvalue: | ||
# CIDR validation | ||
ipaddress.ip_network(ipvalue, strict=False) | ||
else: | ||
# IP validation | ||
ipaddress.ip_address(ipvalue) | ||
except ValueError: | ||
agent.set_status('validation-failed') | ||
json.dump([{'field':'ip_allowlist','parameter':'ip_allowlist','value': ipvalue,'error':'bad_ip_address'}], fp=sys.stdout) | ||
sys.exit(3) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
imageroot/actions/set-trusted-proxies/20set_trusted_proxies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import agent | ||
import json | ||
import sys | ||
import conf_helpers | ||
import ipaddress | ||
|
||
def main(): | ||
request = json.load(sys.stdin) | ||
validate_request(request) | ||
curconf = conf_helpers.parse_yaml_config("traefik.yaml") | ||
curconf['entryPoints']['http'].setdefault('forwardedHeaders', {"trustedIPs": []}) | ||
curconf['entryPoints']['https'].setdefault('forwardedHeaders', {"trustedIPs": []}) | ||
curconf['entryPoints']['http']['forwardedHeaders']["trustedIPs"] = request['proxies'] | ||
curconf['entryPoints']['https']['forwardedHeaders']["trustedIPs"] = request['proxies'] | ||
conf_helpers.write_yaml_config(curconf, "traefik.yaml") | ||
if len(request['proxies']) > 0: | ||
agent.set_env('PROXIES_DEPTH', str(request.get('depth', 1))) | ||
else: | ||
agent.set_env('PROXIES_DEPTH', '0') | ||
agent.run_helper("systemctl", "--user", "restart", "traefik.service").check_returncode() | ||
|
||
def validate_request(request): | ||
for ipvalue in request['proxies']: | ||
# Check if ipvalue is a string representing IPv4 or IPv6 | ||
try: | ||
# IP validation | ||
ipaddress.ip_address(ipvalue) | ||
except ValueError: | ||
agent.set_status('validation-failed') | ||
json.dump([{'field':'proxies','parameter':'proxies','value': ipvalue,'error':'bad_ip_address'}], fp=sys.stdout) | ||
sys.exit(3) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "set-trusted-proxies input", | ||
"$id": "http://schema.nethserver.org/traefik/set-trusted-proxies-input.json", | ||
"description": "Set the IP addresses that are trusted as front-end proxies", | ||
"examples": [ | ||
{ | ||
"depth": 1, | ||
"proxies": [ | ||
"192.168.1.1", | ||
"192.168.1.2" | ||
] | ||
} | ||
], | ||
"type": "object", | ||
"required": [ | ||
"proxies" | ||
], | ||
"additionalProperties": false, | ||
"properties": { | ||
"depth": { | ||
"type":"integer", | ||
"minimum": 0 | ||
}, | ||
"proxies": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
#!/usr/bin/env sh | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (C) 2023 Nethesis S.r.l. | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
rm -fv backup-custom-routes.json | ||
rm -rf state.backup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
set -e | ||
|
||
rm -rf state-backup | ||
mkdir -vp state-backup | ||
|
||
cp -pvT traefik.yaml state-backup/ | ||
cp -prvT configs state-backup/configs/ | ||
cp -prvT manual_flags state-backup/manual_flags/ | ||
cp -prvT custom_certificates state-backup/custom_certificates/ | ||
cp -prvT acme/ state-backup/acme/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# | ||
# Restic include patterns for Traefik state | ||
# Syntax reference: https://pkg.go.dev/path/filepath#Glob | ||
# Restic --files-from: https://restic.readthedocs.io/en/stable/040_backup.html#including-files | ||
# | ||
state/state-backup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# Copyright (C) 2025 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import os | ||
import re | ||
import yaml | ||
|
||
def write_yaml_config(conf, path): | ||
"""Safely write a configuration file.""" | ||
with open(path + '.tmp', 'w') as fp: | ||
fp.write(yaml.safe_dump(conf, default_flow_style=False, sort_keys=False, allow_unicode=True)) | ||
os.rename(path + '.tmp', path) | ||
|
||
def parse_yaml_config(path): | ||
"""Parse a YAML configuration file.""" | ||
with open(path, 'r') as fp: | ||
conf = yaml.safe_load(fp) | ||
return conf |
Oops, something went wrong.