Skip to content

Commit 364d48c

Browse files
committed
Add firewall migration from boot
1 parent 1a95aff commit 364d48c

4 files changed

Lines changed: 46 additions & 4 deletions

File tree

node_cli/configs/user.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,12 @@ def validate_user_config(user_config: BaseUserConfig) -> None:
150150
validate_env_type(env_type=user_config.env_type)
151151

152152
if not isinstance(user_config, MirageUserConfig):
153-
validate_alias_or_address(user_config.manager_contracts, ContractType.MANAGER, user_config.endpoint)
153+
validate_alias_or_address(
154+
user_config.manager_contracts, ContractType.MANAGER, user_config.endpoint
155+
)
154156

155157
if isinstance(user_config, (SkaleUserConfig, MirageBootUserConfig)):
156-
validate_alias_or_address(user_config.ima_contracts, ContractType.IMA, endpoint)
158+
validate_alias_or_address(user_config.ima_contracts, ContractType.IMA, user_config.endpoint)
157159

158160

159161
def to_lower_keys(params: Dict[str, str]) -> Dict[str, str]:

node_cli/core/mirage_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def migrate_from_boot(
6161
sync_schains=False,
6262
node_type=NodeType.MIRAGE,
6363
)
64-
migrate_ok = update_mirage_op(env_filepath, env, update_type=MirageUpdateType.INFRA_ONLY)
64+
migrate_ok = update_mirage_op(env_filepath, env, update_type=MirageUpdateType.FROM_BOOT)
6565
alive = is_base_containers_alive(node_type=NodeType.MIRAGE)
6666
if not migrate_ok or not alive:
6767
print_node_cmd_error()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import glob
2+
import logging
3+
import os
4+
from pathlib import Path
5+
6+
from node_cli.utils.helper import run_cmd
7+
8+
logger = logging.getLogger(__name__)
9+
10+
NFT_CHAIN_BASE_PATH = '/etc/nft.conf.d/skale/chains'
11+
NFT_COMMITTEE_SCOPE_CHAIN_PATH = 'mirage-committee.conf'
12+
13+
14+
class NoLegacyNFTChainConfigError(Exception):
15+
pass
16+
17+
18+
def move_chain_to_new_name() -> None:
19+
after_boot_chain_path = glob.glob(os.path.join(NFT_CHAIN_BASE_PATH, '*'))[0]
20+
new_path = os.path.join(NFT_CHAIN_BASE_PATH, NFT_COMMITTEE_SCOPE_CHAIN_PATH)
21+
if Path(after_boot_chain_path).exists():
22+
raise NoLegacyNFTChainConfigError(f'File {after_boot_chain_path} does not exists')
23+
Path(after_boot_chain_path).rename(Path(new_path))
24+
25+
26+
def reload_nft():
27+
run_cmd(['nft', '-f', '/etc/nftables.conf'])
28+
29+
30+
def migrate_nftables_from_boot():
31+
logger.info('Starting nftables migration from boot')
32+
move_chain_to_new_name()
33+
logger.info('Reloading nftables rules')
34+
reload_nft()

node_cli/operations/mirage.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from node_cli.core.host import ensure_btrfs_kernel_module_autoloaded, link_env_file, prepare_host
3131
from node_cli.core.nftables import configure_nftables
3232
from node_cli.core.nginx import generate_nginx_config
33+
from node_cli.migrations.mirage.from_boot import migrate_nftables_from_boot
3334
from node_cli.operations.base import checked_host
3435
from node_cli.operations.common import unpack_backup_archive
3536
from node_cli.operations.config_repo import (
@@ -53,13 +54,15 @@
5354
class MirageUpdateType(Enum):
5455
REGULAR = 'regular'
5556
INFRA_ONLY = 'infra_only'
57+
FROM_BOOT = 'from_boot'
5658

5759

5860
@checked_host
5961
def update_mirage(env_filepath: str, env: dict, update_type: MirageUpdateType) -> bool:
6062
compose_rm(node_type=NodeType.MIRAGE, env=env)
61-
if update_type != MirageUpdateType.INFRA_ONLY:
63+
if update_type in (MirageUpdateType.INFRA_ONLY, MirageUpdateType.FROM_BOOT):
6264
remove_dynamic_containers()
65+
6366
sync_skale_node()
6467
ensure_btrfs_kernel_module_autoloaded()
6568

@@ -87,6 +90,9 @@ def update_mirage(env_filepath: str, env: dict, update_type: MirageUpdateType) -
8790
distro.id(),
8891
distro.version(),
8992
)
93+
94+
if update_type == MirageUpdateType.FROM_BOOT:
95+
migrate_nftables_from_boot()
9096
update_images(env=env, node_type=NodeType.MIRAGE)
9197
compose_up(env=env, node_type=NodeType.MIRAGE)
9298
return True

0 commit comments

Comments
 (0)