File tree Expand file tree Collapse file tree 4 files changed +73
-4
lines changed Expand file tree Collapse file tree 4 files changed +73
-4
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,35 @@ using:
6363Once the connection is established, you can enter commands in the socat terminal
6464where socat is running.
6565
66+ ## SSH Access for test machines {#sec-nixos-test-ssh-access}
67+
68+ An SSH-based backdoor to log into machines can be enabled with
69+
70+ ``` nix
71+ {
72+ name = "…";
73+ nodes.machines = { /* … */ };
74+ sshBackdoor.enable = true;
75+ }
76+ ```
77+
78+ This creates a [ vsock socket] ( https://man7.org/linux/man-pages/man7/vsock.7.html )
79+ for each VM to log in with SSH. This configures root login with an empty password.
80+
81+ When the VMs get started interactively with the test-driver, it's possible to
82+ connect to ` machine ` with
83+
84+ ```
85+ $ ssh vsock/3 -o User=root
86+ ```
87+
88+ The socket numbers correspond to the node number of the test VM, but start
89+ at three instead of one because that's the lowest possible
90+ vsock number.
91+
92+ On non-NixOS systems you'll probably need to enable
93+ the SSH config from {manpage}` systemd-ssh-proxy(1) ` yourself.
94+
6695## Port forwarding to NixOS test VMs {#sec-nixos-test-port-forwarding}
6796
6897If your test has only a single VM, you may use e.g.
Original file line number Diff line number Diff line change 18171817 "sec-test-options-reference" : [
18181818 " index.html#sec-test-options-reference"
18191819 ],
1820+ "test-opt-sshBackdoor.enable" : [
1821+ " index.html#test-opt-sshBackdoor.enable"
1822+ ],
18201823 "test-opt-defaults" : [
18211824 " index.html#test-opt-defaults"
18221825 ],
19041907 "sec-nixos-test-shell-access" : [
19051908 " index.html#sec-nixos-test-shell-access"
19061909 ],
1910+ "sec-nixos-test-ssh-access" : [
1911+ " index.html#sec-nixos-test-ssh-access"
1912+ ],
19071913 "sec-nixos-test-port-forwarding" : [
19081914 " index.html#sec-nixos-test-port-forwarding"
19091915 ],
Original file line number Diff line number Diff line change 1313 mapAttrs
1414 mkDefault
1515 mkIf
16+ mkMerge
1617 mkOption
1718 mkForce
1819 optional
7778{
7879
7980 options = {
81+ sshBackdoor = {
82+ enable = mkOption {
83+ default = false ;
84+ type = types . bool ;
85+ description = "Whether to turn on the vsock-based SSH backdoor for all VMs." ;
86+ } ;
87+ } ;
88+
8089 node . type = mkOption {
8190 type = types . raw ;
8291 default = baseOS . type ;
172181
173182 passthru . nodes = config . nodesCompat ;
174183
175- defaults = mkIf config . node . pkgsReadOnly {
176- nixpkgs . pkgs = config . node . pkgs ;
177- imports = [ ../../modules/misc/nixpkgs/read-only.nix ] ;
178- } ;
184+ defaults = mkMerge [
185+ ( mkIf config . node . pkgsReadOnly {
186+ nixpkgs . pkgs = config . node . pkgs ;
187+ imports = [ ../../modules/misc/nixpkgs/read-only.nix ] ;
188+ } )
189+ ( mkIf config . sshBackdoor . enable {
190+ testing . sshBackdoor . enable = true ;
191+ } )
192+ ] ;
179193
180194 } ;
181195}
Original file line number Diff line number Diff line change 8787 machine.switch_root() to leave stage 1 and proceed to stage 2
8888 '' ;
8989
90+ sshBackdoor = {
91+ enable = mkEnableOption "vsock-based ssh backdoor for the VM" ;
92+ } ;
93+
9094 } ;
9195
9296 config = {
100104 }
101105 ] ;
102106
107+ services . openssh = mkIf config . testing . sshBackdoor . enable {
108+ enable = true ;
109+ settings = {
110+ PermitRootLogin = "yes" ;
111+ PermitEmptyPasswords = "yes" ;
112+ } ;
113+ } ;
114+
115+ security . pam . services . sshd = mkIf config . testing . sshBackdoor . enable {
116+ allowNullPassword = true ;
117+ } ;
118+
103119 systemd . services . backdoor = lib . mkMerge [
104120 backdoorService
105121 {
175191 # we avoid defining attributes if not possible.
176192 # TODO: refactor such that test-instrumentation can import qemu-vm
177193 package = lib . mkDefault pkgs . qemu_test ;
194+
195+ options = mkIf config . testing . sshBackdoor . enable [
196+ "-device vhost-vsock-pci,guest-cid=${ toString ( config . virtualisation . test . nodeNumber + 2 ) } "
197+ ] ;
178198 } ;
179199 } ;
180200
You can’t perform that action at this time.
0 commit comments