Skip to content

Commit

Permalink
Optional monitoring ports
Browse files Browse the repository at this point in the history
  • Loading branch information
badrogger committed Dec 4, 2024
1 parent 3f9de98 commit f25d4b6
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 154 deletions.
7 changes: 4 additions & 3 deletions node_cli/cli/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,13 @@ def check(network):
run_checks(network)


@node.command(help='Reconfigure iptables rules')
@node.command(help='Reconfigure nftables rules')
@click.option('--monitoring', is_flag=True)
@click.option('--yes', is_flag=True, callback=abort_if_false,
expose_value=False,
prompt='Are you sure you want to reconfigure firewall rules?')
def configure_firewall():
configure_firewall_rules()
def configure_firewall(monitoring):
configure_firewall_rules(enable_monitoring=monitoring)


@node.command(help='Show node version information')
Expand Down
2 changes: 1 addition & 1 deletion node_cli/core/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def docker_compose(self) -> CheckResult:
return self._failed(name=name, info=info)

v_cmd_result = run_cmd(
['docker compose', 'version'],
['docker', 'compose', 'version'],
check_code=False,
separate_stderr=True
)
Expand Down
8 changes: 5 additions & 3 deletions node_cli/core/nftables.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def add_loopback_rule(self, chain) -> None:
else:
logger.info('Loopback rule already exists in chain %s', chain)

def setup_firewall(self) -> None:
def setup_firewall(self, enable_monitoring: bool = False) -> None:
"""Setup firewall rules"""
try:
self.create_table_if_not_exists()
Expand All @@ -306,6 +306,8 @@ def setup_firewall(self) -> None:
self.add_connection_tracking_rule(self.chain)

tcp_ports = [get_ssh_port(), 8080, 443, 53, 3009, 9100]
if enable_monitoring:
tcp_ports.extend([8080, 9100])
for port in tcp_ports:
self.add_rule_if_not_exists(Rule(chain=self.chain, protocol='tcp', port=port))

Expand All @@ -330,7 +332,7 @@ def setup_firewall(self) -> None:
raise NFTablesError(e)


def configure_nftables() -> None:
def configure_nftables(enable_monitoring: bool = False) -> None:
nft_mgr = NFTablesManager()
nft_mgr.setup_firewall()
nft_mgr.setup_firewall(enable_monitoring=enable_monitoring)
logger.info('Firewall setup completed successfully')
Loading

0 comments on commit f25d4b6

Please sign in to comment.