Skip to content

Commit

Permalink
Chore(NODE-1248): Remove ipv4 nameserver propagation and hard-code va…
Browse files Browse the repository at this point in the history
…lues into generate_network_config.rs
  • Loading branch information
andrewbattat committed Jan 25, 2024
1 parent f233f68 commit fba6c0a
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 88 deletions.
2 changes: 0 additions & 2 deletions ic-os/guestos/docs/ConfigStore.adoc
Expand Up @@ -63,8 +63,6 @@ Must be a file of key/value pairs separated by "=" (one per line) with the follo

- *name_servers*: The ipv6 name servers to be used. If multiple servers are needed, separate them with spaces. This key is only meaningful if DHCP or SLAAC is not used.

- *ipv4_name_servers*: The ipv4 name servers to be used. If multiple servers are needed, separate them with spaces. This key is only meaningful if DHCP or SLAAC is not used.

- *hostname*: The hostname, which can be any text in principle but is generally derived from the ID of the physical host (e.g., MAC address).

Note: if this file is not given, the system will fall back to network auto configuration.
Expand Down
1 change: 0 additions & 1 deletion ic-os/guestos/rootfs/opt/ic/bin/generate-replica-config.sh
Expand Up @@ -75,7 +75,6 @@ function read_network_variables() {
"ipv6_address") ipv6_address="${value}" ;;
"ipv6_gateway") ipv6_gateway="${value}" ;;
"name_servers") name_servers="${value}" ;;
"ipv4_name_servers") ipv4_name_servers="${value}" ;;
"ipv4_address") ipv4_address="${value}" ;;
"ipv4_gateway") ipv4_gateway="${value}" ;;
"domain") domain="${value}" ;;
Expand Down
1 change: 0 additions & 1 deletion ic-os/hostos/rootfs/opt/ic/bin/generate-guestos-config.sh
Expand Up @@ -110,7 +110,6 @@ function assemble_config_media() {
cmd+=(--ipv4_gateway "${ipv4_gateway}")
cmd+=(--domain "${domain}")
fi
cmd+=(--ipv4_name_servers "$(/opt/ic/bin/fetch-property.sh --key=.dns.ipv4_name_servers --metric=hostos_ipv4_dns_name_servers --config=${DEPLOYMENT})")
cmd+=(--hostname "guest-$(/opt/ic/bin/fetch-mgmt-mac.sh | sed 's/://g')")
cmd+=(--nns_url "$(/opt/ic/bin/fetch-property.sh --key=.nns.url --metric=hostos_nns_url --config=${DEPLOYMENT})")
if [ -f "/boot/config/node_operator_private_key.pem" ]; then
Expand Down
11 changes: 1 addition & 10 deletions ic-os/scripts/build-bootstrap-config-image.sh
Expand Up @@ -33,11 +33,6 @@ options may be specified:
script, e.g. --ipv6_name_servers "2606:4700:4700::1111
2606:4700:4700::1001").
--ipv4_name_servers servers
ipv4 DNS servers to use. Can be multiple servers separated by space (make
sure to quote the argument string so it appears as a single argument to the
script, e.g. --ipv4_name_servers "1.1.1.1 1.0.0.1").
--ipv4_address a.b.c.d/n
(optional) The IPv4 address to assign. Must include prefix length (e.g.
18.208.190.35/28).
Expand Down Expand Up @@ -131,7 +126,7 @@ function build_ic_bootstrap_tar() {
local OUT_FILE="$1"
shift

local IPV6_ADDRESS IPV6_GATEWAY IPV6_NAME_SERVERS IPV4_NAME_SERVERS DOMAIN HOSTNAME
local IPV6_ADDRESS IPV6_GATEWAY IPV6_NAME_SERVERS DOMAIN HOSTNAME
local IC_CRYPTO IC_REGISTRY_LOCAL_STORE
local NNS_URL NNS_PUBLIC_KEY NODE_OPERATOR_PRIVATE_KEY
local BACKUP_RETENTION_TIME_SECS BACKUP_PURGING_INTERVAL_SECS
Expand All @@ -156,9 +151,6 @@ function build_ic_bootstrap_tar() {
--ipv6_name_servers)
IPV6_NAME_SERVERS="$2"
;;
--ipv4_name_servers)
IPV4_NAME_SERVERS="$2"
;;
--ipv4_address)
IPV4_ADDRESS="$2"
;;
Expand Down Expand Up @@ -234,7 +226,6 @@ function build_ic_bootstrap_tar() {
${IPV6_ADDRESS:+ipv6_address=$IPV6_ADDRESS}
${IPV6_GATEWAY:+ipv6_gateway=$IPV6_GATEWAY}
name_servers=$IPV6_NAME_SERVERS
ipv4_name_servers=$IPV4_NAME_SERVERS
hostname=$HOSTNAME
${IPV4_ADDRESS:+ipv4_address=$IPV4_ADDRESS}
${IPV4_GATEWAY:+ipv4_gateway=$IPV4_GATEWAY}
Expand Down
3 changes: 1 addition & 2 deletions ic-os/setupos/data/deployment.json.template
Expand Up @@ -9,8 +9,7 @@
"url": "NNS_URL"
},
"dns": {
"name_servers": "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844",
"ipv4_name_servers": "1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4"
"name_servers": "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844"
},
"resources": {
"memory": "490"
Expand Down
51 changes: 7 additions & 44 deletions rs/ic_os/guestos_tool/src/generate_network_config.rs
Expand Up @@ -8,17 +8,19 @@ use anyhow::{bail, Context, Result};

use config::config_map_from_path;
use network::interfaces::{get_interface_name as get_valid_interface_name, get_interface_paths};
use network::systemd::{generate_ipv4_nameserver_list, generate_ipv6_nameserver_list};
use network::systemd::generate_ipv6_nameserver_list;
use utils::get_command_stdout;

pub static DEFAULT_GUESTOS_NETWORK_CONFIG_PATH: &str = "/boot/config/network.conf";

const IPV4_NAME_SERVER_NETWORKD_CONTENTS: &str =
"DNS=1.1.1.1\nDNS=1.0.0.1\nDNS=8.8.8.8\nDNS=8.8.4.4\n";

#[derive(Debug)]
struct NetworkInfo {
ipv6_info: Option<IpAddressInfo>,
ipv6_name_servers: Option<String>,
ipv4_info: Option<IpAddressInfo>,
ipv4_name_servers: Option<String>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -169,17 +171,10 @@ fn create_network_info(
.map(generate_ipv6_nameserver_list)
.transpose()?;

let ipv4_name_servers = network_config_variables
.get("ipv4_name_servers")
.map(|ipv4_name_servers| ipv4_name_servers.split_whitespace())
.map(generate_ipv4_nameserver_list)
.transpose()?;

Ok(NetworkInfo {
ipv6_info,
ipv6_name_servers,
ipv4_info,
ipv4_name_servers,
})
}

Expand All @@ -206,10 +201,7 @@ fn generate_networkd_config_contents(
let match_contents = generate_network_config_match_contents(interface_name);
let ipv6_contents = generate_network_config_ipv6_contents(network_info.ipv6_info, disable_dad);
let ipv6_name_servers = generate_network_config_dns_contents(network_info.ipv6_name_servers);
let ipv4_contents = generate_network_config_ipv4_contents(
network_info.ipv4_info,
network_info.ipv4_name_servers,
);
let ipv4_contents = generate_network_config_ipv4_contents(network_info.ipv4_info);

format!(
"{}{}{}\n{}",
Expand Down Expand Up @@ -260,10 +252,7 @@ fn generate_network_config_dns_contents(name_servers: Option<String>) -> String
name_servers.unwrap_or_default()
}

fn generate_network_config_ipv4_contents(
ipv4_info: Option<IpAddressInfo>,
ipv4_name_servers: Option<String>,
) -> String {
fn generate_network_config_ipv4_contents(ipv4_info: Option<IpAddressInfo>) -> String {
ipv4_info
.map(|ipv4_info| {
indoc::formatdoc!(
Expand All @@ -274,7 +263,7 @@ fn generate_network_config_ipv4_contents(
"#,
ipv4_info.address_with_prefix,
ipv4_info.gateway,
ipv4_name_servers.unwrap_or_default()
IPV4_NAME_SERVER_NETWORKD_CONTENTS
)
})
.unwrap_or_default()
Expand Down Expand Up @@ -335,10 +324,6 @@ mod tests {
"2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844"
.to_string(),
);
network_config_variables.insert(
"ipv4_name_servers".to_string(),
"1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4".to_string(),
);

eprintln!("network_config_variables: {:?}", network_config_variables);

Expand All @@ -359,13 +344,6 @@ mod tests {
assert!(result.ipv6_name_servers.is_some());
let ipv6_name_servers = result.ipv6_name_servers.unwrap();
assert_eq!(ipv6_name_servers, "DNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n");

assert!(result.ipv4_name_servers.is_some());
let ipv4_name_servers = result.ipv4_name_servers.unwrap();
assert_eq!(
ipv4_name_servers,
"DNS=1.1.1.1\nDNS=1.0.0.1\nDNS=8.8.8.8\nDNS=8.8.4.4\n"
);
}

#[test]
Expand All @@ -378,10 +356,6 @@ mod tests {
"2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844"
.to_string(),
);
network_config_variables.insert(
"ipv4_name_servers".to_string(),
"1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4".to_string(),
);

eprintln!("network_config_variables: {:?}", network_config_variables);

Expand All @@ -397,13 +371,6 @@ mod tests {
assert!(result.ipv6_name_servers.is_some());
let ipv6_name_servers = result.ipv6_name_servers.unwrap();
assert_eq!(ipv6_name_servers, "DNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n");

assert!(result.ipv4_name_servers.is_some());
let ipv4_name_servers = result.ipv4_name_servers.unwrap();
assert_eq!(
ipv4_name_servers,
"DNS=1.1.1.1\nDNS=1.0.0.1\nDNS=8.8.8.8\nDNS=8.8.4.4\n"
);
}

#[test]
Expand Down Expand Up @@ -517,7 +484,6 @@ mod tests {
ipv6_info: Some(IpAddressInfo::new_ipv6_address("2001:db8::1/64", "2001:db8::1").unwrap()),
ipv6_name_servers: Some("DNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n".to_string()),
ipv4_info: Some(IpAddressInfo::new_ipv4_address("192.168.1.100", "30", "192.168.1.1").unwrap()),
ipv4_name_servers: Some("DNS=1.1.1.1\nDNS=1.0.0.1\nDNS=8.8.8.8\nDNS=8.8.4.4\n".to_string()),
};
let interface_name = "enp65s0f1";

Expand All @@ -533,7 +499,6 @@ mod tests {
ipv6_info: Some(IpAddressInfo::new_ipv6_address("2001:db8::1/64", "2001:db8::1").unwrap()),
ipv6_name_servers: Some("DNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n".to_string()),
ipv4_info: None,
ipv4_name_servers: Some("DNS=1.1.1.1\nDNS=1.0.0.1\nDNS=8.8.8.8\nDNS=8.8.4.4\n".to_string()),
};
let interface_name = "enp65s0f1";

Expand All @@ -549,7 +514,6 @@ mod tests {
ipv6_info: Some(IpAddressInfo::new_ipv6_address("2001:db8::1/64", "2001:db8::1").unwrap()),
ipv6_name_servers: Some("DNS=2606:4700:4700::1111\nDNS=2606:4700:4700::1001\nDNS=2001:4860:4860::8888\nDNS=2001:4860:4860::8844\n".to_string()),
ipv4_info: Some(IpAddressInfo::new_ipv4_address("192.168.1.100", "30", "192.168.1.1").unwrap()),
ipv4_name_servers: Some("DNS=1.1.1.1\nDNS=1.0.0.1\nDNS=8.8.8.8\nDNS=8.8.4.4\n".to_string()),
};
let interface_name = "enp65s0f1";

Expand All @@ -565,7 +529,6 @@ mod tests {
ipv6_info: None,
ipv6_name_servers: None,
ipv4_info: None,
ipv4_name_servers: None,
};
let interface_name = "enp65s0f1";

Expand Down
19 changes: 1 addition & 18 deletions rs/ic_os/network/src/systemd.rs
@@ -1,5 +1,5 @@
use std::fs::{create_dir_all, write};
use std::net::{Ipv4Addr, Ipv6Addr};
use std::net::Ipv6Addr;
use std::path::Path;
use std::process::Command;

Expand Down Expand Up @@ -28,23 +28,6 @@ where
Ok(result)
}

pub fn generate_ipv4_nameserver_list<'a, I>(nameservers: I) -> Result<String>
where
I: IntoIterator<Item = &'a str>,
{
let mut result = String::new();
for nameserver in nameservers {
if nameserver.parse::<Ipv4Addr>().is_err() {
bail!(
"Invalid nameserver found in deployment config: {}",
nameserver
);
}
result.push_str(&format!("DNS={nameserver}\n"));
}
Ok(result)
}

fn generate_network_interface_content(interface_name: &str) -> String {
format!(
"
Expand Down
11 changes: 4 additions & 7 deletions rs/ic_os/utils/src/deployment.rs
Expand Up @@ -33,7 +33,6 @@ pub struct Nns {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
pub struct Dns {
pub name_servers: String,
pub ipv4_name_servers: String,
}

#[serde_as]
Expand Down Expand Up @@ -66,8 +65,7 @@ mod test {
"url": "https://dfinity.org/"
},
"dns": {
"name_servers": "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844",
"ipv4_name_servers": "1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4"
"name_servers": "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844"
},
"resources": {
"memory": "490"
Expand All @@ -79,7 +77,7 @@ mod test {
deployment: Deployment { name: "mainnet".to_string() },
logging: Logging { hosts: "elasticsearch-node-0.mercury.dfinity.systems:443 elasticsearch-node-1.mercury.dfinity.systems:443 elasticsearch-node-2.mercury.dfinity.systems:443 elasticsearch-node-3.mercury.dfinity.systems:443".to_string() },
nns: Nns { url: Url::parse("https://dfinity.org").unwrap() },
dns: Dns { name_servers: "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844".to_string(), ipv4_name_servers: "1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4".to_string()},
dns: Dns { name_servers: "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844".to_string()},
resources: Resources { memory: 490, cpu: None },
}
});
Expand All @@ -95,8 +93,7 @@ mod test {
"url": "https://dfinity.org/"
},
"dns": {
"name_servers": "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844",
"ipv4_name_servers": "1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4"
"name_servers": "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844"
},
"resources": {
"memory": "490",
Expand All @@ -109,7 +106,7 @@ mod test {
deployment: Deployment { name: "mainnet".to_string() },
logging: Logging { hosts: "elasticsearch-node-0.mercury.dfinity.systems:443 elasticsearch-node-1.mercury.dfinity.systems:443 elasticsearch-node-2.mercury.dfinity.systems:443 elasticsearch-node-3.mercury.dfinity.systems:443".to_string() },
nns: Nns { url: Url::parse("https://dfinity.org").unwrap() },
dns: Dns { name_servers: "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844".to_string(), ipv4_name_servers: "1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4".to_string() },
dns: Dns { name_servers: "2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844".to_string()},
resources: Resources { memory: 490, cpu: Some("qemu".to_string()) },
}
});
Expand Down
4 changes: 1 addition & 3 deletions testnet/tools/build-guestos-configs.sh
Expand Up @@ -132,11 +132,10 @@ CONFIG="$(cat ${INPUT})"
VALUES=$(echo ${CONFIG} | jq -r -c '[
.deployment,
(.name_servers | join(" ")),
(.ipv4_name_servers | join(" ")),
(.elasticsearch_hosts | join(" ")),
(.elasticsearch_tags | join(" "))
] | join("\u0001")')
IFS=$'\1' read -r DEPLOYMENT NAME_SERVERS IPV4_NAME_SERVERS ELASTICSEARCH_HOSTS ELASTICSEARCH_TAGS < <(echo $VALUES)
IFS=$'\1' read -r DEPLOYMENT NAME_SERVERS ELASTICSEARCH_HOSTS ELASTICSEARCH_TAGS < <(echo $VALUES)

# Read all the node info out in one swoop
NODES=0
Expand Down Expand Up @@ -325,7 +324,6 @@ function build_bootstrap_images() {
"--nns_url" "${NNS_URL}" \
"--nns_public_key" "${IC_PREP_DIR}/nns_public_key.pem" \
"--ipv6_name_servers" "${NAME_SERVERS}" \
"--ipv4_name_servers" "${IPV4_NAME_SERVERS}" \
"--hostname" "${hostname}" \
"--accounts_ssh_authorized_keys" "${SSH}" \
${ELASTICSEARCH_HOSTS:+"--elasticsearch_hosts"} ${ELASTICSEARCH_HOSTS:+"${ELASTICSEARCH_HOSTS}"} \
Expand Down

0 comments on commit fba6c0a

Please sign in to comment.