Skip to content

Commit

Permalink
packages/nixos: add IMDS setup script
Browse files Browse the repository at this point in the history
Azure needs special care for enabling IMDS within Peerpods. This adds a script to setup IMDS through Proxy ARP (from Peerpods upstream, see https://github.com/confidential-containers/cloud-api-adaptor/blob/main/src/cloud-api-adaptor/podvm/files/usr/local/bin/setup-nat-for-imds.sh), so that all requests to the IMDS from within the pod are routed through an interface that is peered to the Pod VM. Verified to work in 2 distinct Azure peer pods.
  • Loading branch information
msanft committed Nov 11, 2024
1 parent 8da19c0 commit f48bf81
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
19 changes: 19 additions & 0 deletions packages/by-name/cloud-api-adaptor/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
libvirt,
writeShellApplication,
gnugrep,
iproute2,
iptables,
sysctl,
gawk,
runCommand,

# List of supported cloud providers
Expand Down Expand Up @@ -86,6 +90,21 @@ buildGoModule rec {
"SC2153"
];
};

setup-nat-for-imds = writeShellApplication {
name = "setup-nat-for-imds";
runtimeInputs = [
iproute2
iptables
sysctl
gawk
];
text = builtins.readFile "${cloud-api-adaptor.src}/src/cloud-api-adaptor/podvm/files/usr/local/bin/setup-nat-for-imds.sh";
meta = {
mainProgram = "peerpod-imds-nat";
homepage = "https://github.com/confidential-containers/cloud-api-adaptor/blob/main/src/cloud-api-adaptor/podvm/files/usr/local/bin/setup-nat-for-imds.sh";
};
};
};

meta = {
Expand Down
21 changes: 17 additions & 4 deletions packages/nixos/azure.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ in

services.udev.extraRules = azure-storage-rules;
systemd.services.azure-readiness-report = {
wantedBy = [
"basic.target"
"multi-user.target"
];
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
description = "Azure Readiness Report";
Expand All @@ -85,5 +82,21 @@ in
ExecStart = "${lib.getExe pkgs.azure-no-agent}";
};
};

systemd.services.setup-nat-for-imds = {
wantedBy = [ "multi-user.target" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
description = "Setup NAT for IMDS";
serviceConfig = {
Type = "oneshot";
RemainAfterExit = "yes";
# TODO: Find out why just ordering this after network-online.target
# isn't sufficient. (Errors with saying that the network is unreachable)
Restart = "on-failure";
RestartSec = "5s";
ExecStart = "${lib.getExe pkgs.cloud-api-adaptor.setup-nat-for-imds}";
};
};
};
}

0 comments on commit f48bf81

Please sign in to comment.