diff --git a/vm_supervisor/conf.py b/vm_supervisor/conf.py index bfa76e230..4f54dff90 100644 --- a/vm_supervisor/conf.py +++ b/vm_supervisor/conf.py @@ -308,9 +308,6 @@ def setup(self): os.makedirs(self.EXECUTION_LOG_DIRECTORY, exist_ok=True) os.makedirs(self.PERSISTENT_VOLUMES_DIR, exist_ok=True) - if not self.NETWORK_INTERFACE: - self.NETWORK_INTERFACE = get_default_interface() - if self.DNS_NAMESERVERS is None and self.DNS_RESOLUTION: self.DNS_NAMESERVERS = obtain_dns_ips( dns_resolver=self.DNS_RESOLUTION, @@ -334,6 +331,28 @@ def display(self) -> str: f"{attribute:<27} = {value}" for attribute, value in attributes.items() ) + def filter_dns_servers(self, ipv4_only: bool) -> Optional[List[str]]: + """ + Filter Dns (ipv4 + ipv6 or only ipv4) + + Parameter: + ipv4_only (bool) + Return: + Optional[List[str]]: list of dns filtered + + """ + dns_servers = self.DNS_NAMESERVERS + if not dns_servers: + raise ValueError("Invalid configuration: DNS nameservers missing") + + # Apply DNS IPv6 here if user configurations allow it + dns_servers = [ + server + for server in dns_servers + if not ipaddress.ip_address(server).version == 6 or ipv4_only + ] + return dns_servers + class Config: env_prefix = "ALEPH_VM_" case_sensitive = False diff --git a/vm_supervisor/vm/firecracker/program.py b/vm_supervisor/vm/firecracker/program.py index 407a1dcc6..28761e37c 100644 --- a/vm_supervisor/vm/firecracker/program.py +++ b/vm_supervisor/vm/firecracker/program.py @@ -2,6 +2,7 @@ import asyncio import dataclasses +import ipaddress import logging import os.path from asyncio import StreamReader, StreamWriter @@ -377,8 +378,7 @@ async def _setup_configuration( ipv6 = self.get_vm_ipv6() ipv6_gateway = self.get_vm_ipv6_gateway() - if not settings.DNS_NAMESERVERS: - raise ValueError("Invalid configuration: DNS nameservers missing") + dns_servers = settings.filter_dns_servers(ipv4_only=False) # True to Disable Ipv6 Dns runtime_config = self.fvm.runtime_config assert runtime_config @@ -394,7 +394,7 @@ async def _setup_configuration( ipv6=ipv6, route=route, ipv6_gateway=ipv6_gateway, - dns_servers=settings.DNS_NAMESERVERS, + dns_servers=dns_servers, code=code, encoding=self.resources.code_encoding, entrypoint=self.resources.code_entrypoint,