Skip to content

Commit 206a688

Browse files
authored
Merge pull request #29 from cobaltcore-dev/fix-ssh-port-forwarding
add option to disable ssh port forwarding
2 parents eea92d5 + 7a516b9 commit 206a688

3 files changed

Lines changed: 140 additions & 21 deletions

File tree

modules/testing/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,42 @@ drwxr-xr-x 2 cinder cinder 4.0K Feb 24 08:16 .
103103
drwxr-xr-x 6 cinder cinder 4.0K Feb 24 08:09 ..
104104
-rw------- 1 cinder cinder 268 Feb 24 08:16 volume-64159e0c-18bb-449f-b1e0-86f198b170e4
105105
```
106+
107+
## Port Forwarding
108+
109+
* Port forwarding is enabled by default for `controllerVM` and `storageVM` and disabled for `computeVM`.
110+
* If multiple computeVMs are used, a separate port must be assigned to each node; otherwise, collisions will occur.
111+
112+
### Default ssh port forwards
113+
114+
* controllerVM: `2022`
115+
* storageVM: `2122`
116+
* computeVM: `n/a`
117+
118+
### Change default ports
119+
120+
```nix
121+
122+
pkgs.nixosTest {
123+
124+
nodes.controllerVM =
125+
{ ... }:
126+
{
127+
openstack-testing.sshHostPort = 2044; # default was: 2022
128+
};
129+
130+
nodes.computeVM =
131+
{ ... }:
132+
{
133+
openstack-testing.enable = true; # enable / disable all port forwardings
134+
openstack-testing.sshHostPort = 3022;
135+
};
136+
137+
nodes.computeVM2 =
138+
{ ... }:
139+
{
140+
openstack-testing.enable = true; # enable / disable all port forwardings
141+
openstack-testing.sshHostPort = 3122;
142+
};
143+
}
144+
```

modules/testing/default.nix

Lines changed: 95 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,68 @@ let
5454
};
5555
};
5656

57-
portForwarding =
57+
portForwardingStorage =
58+
{ config, lib, ... }:
59+
with lib;
60+
let
61+
cfg = config.openstack-testing;
62+
in
63+
{
64+
options.openstack-testing = {
65+
enable = mkEnableOption "Enable port forwarding." // {
66+
default = true;
67+
};
68+
sshHostPort = mkOption {
69+
default = 2122;
70+
type = types.port;
71+
description = ''
72+
Host port to make the ssh server available.
73+
'';
74+
};
75+
};
76+
config = mkIf cfg.enable {
77+
virtualisation.forwardPorts = [
78+
{
79+
from = "host";
80+
host.port = cfg.sshHostPort;
81+
guest.port = 22;
82+
}
83+
];
84+
};
85+
};
86+
87+
portForwardingCompute =
88+
{ config, lib, ... }:
89+
with lib;
90+
let
91+
cfg = config.openstack-testing;
92+
in
93+
{
94+
options.openstack-testing = {
95+
enable = mkEnableOption "Enable port forwarding." // {
96+
# If multiple nodes are used, a separate port must be assigned to each node; otherwise, collisions will occur.
97+
# We disable ssh port forwarding for compute nodes as default.
98+
default = false;
99+
};
100+
sshHostPort = mkOption {
101+
type = types.port;
102+
description = ''
103+
Host port to make the ssh server available.
104+
'';
105+
};
106+
};
107+
config = mkIf cfg.enable {
108+
virtualisation.forwardPorts = [
109+
{
110+
from = "host";
111+
host.port = cfg.sshHostPort;
112+
guest.port = 22;
113+
}
114+
];
115+
};
116+
};
117+
118+
portForwardingController =
58119
{ config, lib, ... }:
59120
with lib;
60121
let
@@ -92,6 +153,13 @@ let
92153
the configuration of the dashboard.
93154
'';
94155
};
156+
sshHostPort = mkOption {
157+
default = 2022;
158+
type = types.port;
159+
description = ''
160+
Host port to make the ssh server available.
161+
'';
162+
};
95163
};
96164
config = mkIf cfg.enable {
97165
virtualisation.forwardPorts = [
@@ -110,6 +178,11 @@ let
110178
host.port = cfg.vncProxyHostPort;
111179
guest.port = 6080;
112180
}
181+
{
182+
from = "host";
183+
host.port = cfg.sshHostPort;
184+
guest.port = 22;
185+
}
113186
];
114187
};
115188
};
@@ -129,9 +202,13 @@ in
129202
{
130203
imports = [
131204
common
132-
portForwarding
205+
portForwardingController
133206
];
134207

208+
# this is an example how to enable / disable all port forwardings or change port numbers
209+
# openstack-testing.enable = true;
210+
# openstack-testing.sshHostPort = 1122;
211+
135212
virtualisation = {
136213
cores = 4;
137214
memorySize = 6144;
@@ -144,14 +221,6 @@ in
144221
vlan = 2;
145222
};
146223
};
147-
# enable ssh access
148-
forwardPorts = [
149-
{
150-
from = "host";
151-
host.port = 1122;
152-
guest.port = 22;
153-
}
154-
];
155224
};
156225

157226
systemd.services.openstack-create-vm = {
@@ -232,7 +301,14 @@ in
232301
testCompute =
233302
{ ... }:
234303
{
235-
imports = [ common ];
304+
imports = [
305+
common
306+
portForwardingCompute
307+
];
308+
309+
# this is an example how to enable / disable all port forwardings or change port numbers
310+
# openstack-testing.enable = true; # enable / disable all port forwardings
311+
# openstack-testing.sshHostPort = 3022;
236312

237313
virtualisation = {
238314
memorySize = 4096;
@@ -271,14 +347,20 @@ in
271347
};
272348
};
273349
};
274-
275350
};
276351

277352
testStorage =
278353
{ ... }:
279354
{
280355

281-
imports = [ common ];
356+
imports = [
357+
common
358+
portForwardingStorage
359+
];
360+
361+
# this is an example how to enable / disable all port forwardings or change port numbers
362+
# openstack-testing.enable = true; # enable / disable all port forwardings
363+
# openstack-testing.sshHostPort = 2022;
282364

283365
virtualisation = {
284366
memorySize = 4096;
@@ -296,14 +378,6 @@ in
296378
vlan = 2;
297379
};
298380
};
299-
# enable ssh access
300-
forwardPorts = [
301-
{
302-
from = "host";
303-
host.port = 2022;
304-
guest.port = 22;
305-
}
306-
];
307381
};
308382

309383
systemd.network = {

tests/openstack-live-migration.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ pkgs.nixosTest {
133133
(novaConfigForIp "10.0.0.39")
134134
];
135135

136+
openstack-testing.enable = true; # enable / disable all port forwardings
137+
openstack-testing.sshHostPort = 3022;
138+
136139
networking.extraHosts = ''
137140
10.0.0.40 computeVM2 computeVM2.local
138141
'';
@@ -156,6 +159,9 @@ pkgs.nixosTest {
156159
(novaConfigForIp "10.0.0.40")
157160
];
158161

162+
openstack-testing.enable = true; # enable / disable all port forwardings
163+
openstack-testing.sshHostPort = 3122;
164+
159165
networking.extraHosts = ''
160166
10.0.0.39 computeVM computeVM.local
161167
'';

0 commit comments

Comments
 (0)