-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [NODE-1530] Allow local network to access metrics through firew…
…all (#2703)
- Loading branch information
Showing
8 changed files
with
113 additions
and
1 deletion.
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 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
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
18 changes: 18 additions & 0 deletions
18
ic-os/components/networking/nftables/hostos/setup-nftables.service
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,18 @@ | ||
[Unit] | ||
Description=Generate Firewall Configuration | ||
# We must wait for IC bootstrap to complete: It writes various | ||
# state files and may also be needed to obtain network config. | ||
After=bootstrap-ic-node.service | ||
Wants=bootstrap-ic-node.service | ||
# We must also wait for storage permission fixup to have finished. | ||
After=setup-permissions.service | ||
Wants=setup-permissions.service | ||
Before=nftables.service | ||
Wants=nftables.service | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/opt/ic/bin/setup-nftables.sh -n /boot/config/config.ini -i /opt/ic/share/nftables.template -o /run/ic-node/nftables-ruleset/nftables.conf | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
70 changes: 70 additions & 0 deletions
70
ic-os/components/networking/nftables/hostos/setup-nftables.sh
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,70 @@ | ||
#!/bin/bash | ||
|
||
# Substitute correct configuration parameters into nftables.conf. | ||
|
||
function usage() { | ||
cat <<EOF | ||
Usage: | ||
setup-nftables -n config.ini -i nftables.template -o nftables.conf | ||
Generate nftables config from template file. | ||
-n config.ini: network configuration description file | ||
-i infile: input ic.json5.template file | ||
-o outfile: output ic.json5 file | ||
EOF | ||
} | ||
|
||
# XXX: the following function is duplicate with generate-network-config.sh | ||
# -- consolidate | ||
# | ||
# Read the network config variables from file. The file must be of the form | ||
# "key=value" for each line with a specific set of keys permissible (see | ||
# code below). | ||
# | ||
# Arguments: | ||
# - $1: Name of the file to be read. | ||
function read_network_variables() { | ||
# Read limited set of keys. Be extra-careful quoting values as it could | ||
# otherwise lead to executing arbitrary shell code! | ||
while IFS="=" read -r key value; do | ||
case "$key" in | ||
"ipv6_prefix") ipv6_prefix="${value}" ;; | ||
esac | ||
done <"$1" | ||
} | ||
|
||
while getopts "n:i:o:" OPT; do | ||
case "${OPT}" in | ||
n) | ||
NETWORK_CONFIG_FILE="${OPTARG}" | ||
;; | ||
i) | ||
IN_FILE="${OPTARG}" | ||
;; | ||
o) | ||
OUT_FILE="${OPTARG}" | ||
;; | ||
*) | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
if [ "${IN_FILE}" == "" -o "${OUT_FILE}" == "" ]; then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
# TODO: This should be pulled from the system, in case of configuration via RA. | ||
if [ "${NETWORK_CONFIG_FILE}" != "" -a -e "${NETWORK_CONFIG_FILE}" ]; then | ||
read_network_variables "${NETWORK_CONFIG_FILE}" | ||
fi | ||
|
||
IPV6_PREFIX="${ipv6_prefix:+${ipv6_prefix}::/64}" # Add suffix to prefix if found | ||
IPV6_PREFIX="${IPV6_PREFIX:-::1/128}" # Default to loopback for easy templating | ||
|
||
mkdir -p /run/ic-node/nftables-ruleset/ | ||
sed -e "s@{{ ipv6_prefix }}@${IPV6_PREFIX}@" \ | ||
"${IN_FILE}" >"${OUT_FILE}" |
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