Skip to content

Commit eff72d8

Browse files
committed
Configure the testing initramfs for SSH access
If run.sh is invoked with -i or SSH_INCLUDE=1 is defined in testing/.config, the wrapper script now does the following: * Creates a dracut configuration file to enable crypt-ssh, listening on port 22 with ~/.ssh/authorized_keys set as the dropbear authentication ACL. * Writes an SSH configuration file allowing ssh $test_environment to transparently connect you to the running ZFSBootMenu instance on port 2222. * Sets 'ip=dhcp rd.neednet' on the ZBM KCL. If the option is not set, a dracut configuration file is written to omit crypt-ssh. The presence or absence of this flag does not control whether or not an initramfs / EFI executable is generated.
1 parent 28bbc2d commit eff72d8

File tree

1 file changed

+55
-45
lines changed

1 file changed

+55
-45
lines changed

testing/run.sh

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Usage: $0 [options]
1616
-s Enable serial console on stdio
1717
-v Set type of qemu display to use
1818
-D Set test directory
19-
-i Write SSH config include
19+
-i Enable dropbear remote access via crypt-ssh
2020
-n Do not reset the controlling terminal after the VM exits
2121
-e Boot the VM with an EFI bundle
2222
EOF
@@ -173,8 +173,58 @@ else
173173
AAPPEND+=("console=${SERDEV}" "console=tty1")
174174
fi
175175

176-
if [ "${#AAPPEND[@]}" -gt 0 ]; then
177-
APPEND="${APPEND} ${AAPPEND[*]}"
176+
SSH_PORT=2222
177+
while true; do
178+
PID="$( lsof -Pi :${SSH_PORT} -sTCP:LISTEN -t )"
179+
if [ -n "${PID}" ] ; then
180+
SSH_PORT=$((SSH_PORT+1))
181+
continue
182+
else
183+
break
184+
fi
185+
done
186+
187+
if ((SSH_INCLUDE)); then
188+
export SSH_CONF_DIR="${HOME}/.ssh/zfsbootmenu.d"
189+
[ -d "${SSH_CONF_DIR}" ] || mkdir "${SSH_CONF_DIR}" && chmod 700 "${SSH_CONF_DIR}"
190+
191+
echo "Creating host records in ${SSH_CONF_DIR}"
192+
193+
# Strip directory components
194+
TESTHOST="${TESTDIR##*/}"
195+
# Make sure the host starts with "test." even if the directory does not
196+
TESTHOST="test.${TESTHOST#test.}"
197+
198+
[ "${TESTHOST}" = "test." ] && TESTHOST=""
199+
200+
export TESTHOST
201+
202+
if [ -n "${TESTHOST}" ]; then
203+
cat << EOF > "${SSH_CONF_DIR}/${TESTHOST}"
204+
Host ${TESTHOST}
205+
HostName localhost
206+
Port ${SSH_PORT}
207+
User root
208+
UserKnownHostsFile /dev/null
209+
StrictHostKeyChecking no
210+
LogLevel error
211+
EOF
212+
fi
213+
214+
cat << EOF > "${TESTDIR}/dracut.conf.d/crypt-ssh.conf"
215+
dropbear_acl="${HOME}/.ssh/authorized_keys"
216+
dropbear_port="22"
217+
add_dracutmodules+=" crypt-ssh "
218+
EOF
219+
220+
AAPPEND+=("ip=dhcp" "rd.neednet")
221+
222+
chmod 0600 "${SSH_CONF_DIR}/${TESTHOST}"
223+
trap cleanup EXIT INT TERM
224+
else
225+
cat << EOF > "${TESTDIR}/dracut.conf.d/crypt-ssh.conf"
226+
omit_dracutmodules+=" crypt-ssh "
227+
EOF
178228
fi
179229

180230
# Creation is required if either kernel or initramfs is missing
@@ -237,48 +287,8 @@ else
237287
BFILES+=( "-initrd" "${INITRD}" )
238288
fi
239289

240-
SSH_PORT=2222
241-
while true; do
242-
PID="$( lsof -Pi :${SSH_PORT} -sTCP:LISTEN -t )"
243-
if [ -n "${PID}" ] ; then
244-
SSH_PORT=$((SSH_PORT+1))
245-
continue
246-
else
247-
break
248-
fi
249-
done
250-
251-
export SSH_CONF_DIR="${HOME}/.ssh/zfsbootmenu.d"
252-
[ -d "${SSH_CONF_DIR}" ] && SSH_INCLUDE=1
253-
254-
if ((SSH_INCLUDE)); then
255-
[ -d "${SSH_CONF_DIR}" ] || mkdir "${SSH_CONF_DIR}" && chmod 700 "${SSH_CONF_DIR}"
256-
257-
echo "Creating host records in ${SSH_CONF_DIR}"
258-
259-
# Strip directory components
260-
TESTHOST="${TESTDIR##*/}"
261-
# Make sure the host starts with "test." even if the directory does not
262-
TESTHOST="test.${TESTHOST#test.}"
263-
264-
[ "${TESTHOST}" = "test." ] && TESTHOST=""
265-
266-
export TESTHOST
267-
268-
if [ -n "${TESTHOST}" ]; then
269-
cat << EOF > "${SSH_CONF_DIR}/${TESTHOST}"
270-
Host ${TESTHOST}
271-
HostName localhost
272-
Port ${SSH_PORT}
273-
User root
274-
UserKnownHostsFile /dev/null
275-
StrictHostKeyChecking no
276-
LogLevel error
277-
EOF
278-
fi
279-
280-
chmod 0600 "${SSH_CONF_DIR}/${TESTHOST}"
281-
trap cleanup EXIT INT TERM
290+
if [ "${#AAPPEND[@]}" -gt 0 ]; then
291+
APPEND="${APPEND} ${AAPPEND[*]}"
282292
fi
283293

284294
# shellcheck disable=SC2086

0 commit comments

Comments
 (0)