-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add psk distribution for key sharing between VM and host (#30)
- add psk distribution for vm - add psk distribution for host - add ip and user name for nmLuncher - add shared storage for ssh keys to use with nmLauncher Signed-off-by: Ivan Kuznetsov <[email protected]>
- Loading branch information
Showing
6 changed files
with
134 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ | |
nmLauncher = final.writeShellScriptBin "nmLauncher" '' | ||
export DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/ssh_session_dbus.sock | ||
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/tmp/ssh_system_dbus.sock | ||
${final.openssh}/bin/ssh-keygen -R 192.168.100.1 | ||
netvmip=''${1:-192.168.101.1} | ||
netvmuser=''${2:-ghaf} | ||
${final.openssh}/bin/ssh-keygen -R $netvmip | ||
${final.openssh}/bin/ssh -M -S /tmp/ssh_control_socket \ | ||
-f -N -q [email protected] \ | ||
-f -N -q $netvmuser@$netvmip \ | ||
-i /run/ssh-keys/id_ed25519 \ | ||
-o StrictHostKeyChecking=no \ | ||
-o StreamLocalBindUnlink=yes \ | ||
|
@@ -15,6 +17,6 @@ | |
-L /tmp/ssh_system_dbus.sock:/run/dbus/system_bus_socket | ||
${final.networkmanagerapplet}/bin/nm-connection-editor | ||
# Use the control socket to close the ssh tunnel. | ||
${final.openssh}/bin/ssh -q -S /tmp/ssh_control_socket -O exit [email protected] | ||
${final.openssh}/bin/ssh -q -S /tmp/ssh_control_socket -O exit $netvmuser@$netvmip | ||
''; | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ lib, pkgs, config, ... }: | ||
with lib; | ||
let | ||
cfg = config.services.fmo-psk-distribution-service-host; | ||
in { | ||
options.services.fmo-psk-distribution-service-host = { | ||
enable = mkEnableOption "fmo-psk-distribution-service-host"; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
### host part ### | ||
systemd.services."psk-ssh-keygen" = let | ||
keygenScript = pkgs.writeShellScriptBin "psk-ssh-keygen" '' | ||
set -xeuo pipefail | ||
mkdir -p /run/ssh-keys | ||
echo -en "\n\n\n" | ${pkgs.openssh}/bin/ssh-keygen -t ed25519 -f /run/ssh-keys/id_ed25519 -C "" | ||
chown ghaf:ghaf /run/ssh-keys/* | ||
chmod 600 /run/ssh-keys/* | ||
cp /run/ssh-keys/id_ed25519.pub /run/ssh-public-key/id_ed25519.pub | ||
chmod 644 /run/ssh-public-key/id_ed25519.pub | ||
''; | ||
in { | ||
enable = true; | ||
description = "Generate SSH keys for Waypipe"; | ||
path = [keygenScript]; | ||
wantedBy = ["multi-user.target"]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
StandardOutput = "journal"; | ||
StandardError = "journal"; | ||
ExecStart = "${keygenScript}/bin/psk-ssh-keygen"; | ||
}; | ||
}; | ||
|
||
# This directory needs to be created before any of the microvms start. | ||
systemd.services."create-ssh-public-key-directory" = let | ||
script = pkgs.writeShellScriptBin "create-ssh-public-key-directory" '' | ||
mkdir -pv /run/ssh-public-key | ||
chown -v microvm /run/ssh-public-key | ||
''; | ||
in { | ||
enable = true; | ||
description = "Create shared directory on host"; | ||
path = []; | ||
wantedBy = ["microvms.target"]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
RemainAfterExit = true; | ||
StandardOutput = "journal"; | ||
StandardError = "journal"; | ||
ExecStart = "${script}/bin/create-ssh-public-key-directory"; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ lib, pkgs, config, ... }: | ||
with lib; | ||
let | ||
cfg = config.services.fmo-psk-distribution-service-vm; | ||
in { | ||
options.services.fmo-psk-distribution-service-vm = { | ||
enable = mkEnableOption "fmo-psk-distribution-service-vm"; | ||
|
||
ipaddress-path = mkOption { | ||
type = types.str; | ||
description = "Path to ipaddress file for dynamic use"; | ||
default = ""; | ||
}; | ||
|
||
ipaddress = mkOption { | ||
type = types.str; | ||
description = "Static IP address to use instead for dynamic from file"; | ||
default = ""; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
### vm part ### | ||
# SSH is very picky about the file permissions and ownership and will | ||
# accept neither direct path inside /nix/store or symlink that points | ||
# there. Therefore we copy the file to /etc/ssh/get-auth-keys (by | ||
# setting mode), instead of symlinking it. | ||
environment.etc."ssh/get-auth-keys" = { | ||
source = let | ||
script = pkgs.writeShellScriptBin "get-auth-keys" '' | ||
[[ "$1" != "ghaf" ]] && exit 0 | ||
${pkgs.coreutils}/bin/cat /run/ssh-public-key/id_ed25519.pub | ||
''; | ||
in "${script}/bin/get-auth-keys"; | ||
mode = "0555"; | ||
}; | ||
services.openssh = { | ||
authorizedKeysCommand = "/etc/ssh/get-auth-keys"; | ||
authorizedKeysCommandUser = "nobody"; | ||
}; | ||
}; | ||
} |