Skip to content

Commit

Permalink
Merge pull request #4 from darkrain42/tailscale-ssh
Browse files Browse the repository at this point in the history
tailscale ssh support
  • Loading branch information
darkrain42 authored May 17, 2024
2 parents 72e478c + 78abaa6 commit 669f1e2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 14 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# tailscale-initramfs

Run the [tailscale](https://tailscale.com) client in a Debian or Ubuntu
initramfs, to provide access to the Linux system prior to unlocking an encrypted
root filesystem. For instance, when combined with
initramfs, to provide access to the Linux system prior to unlocking an
encrypted root filesystem. When combined with [tailscale
ssh](https://tailscale.com/kb/1193/tailscale-ssh) or
[dropbear-initramfs](https://packages.debian.org/stable/dropbear-initramfs),
allows remote unlocking of an encrypted root filesystem from other systems in
the tailnet.
Expand All @@ -12,7 +13,8 @@ key](https://tailscale.com/kb/1085/auth-keys/) to log into your tailnet. Assign
an [ACL
tag](https://tailscale.com/kb/1068/acl-tags/#generate-an-auth-key-with-an-acl-tag
) to that auth key to lock down what access the pre-boot environment can have to
the rest of the tailnet.
the rest of the tailnet, i.e. to disallow all outbound access from the
initramfs, and only permit inbound connections.

## Install

Expand Down Expand Up @@ -46,3 +48,9 @@ update-initramfs -c -k all
the initramfs will show up as the existing device on the tailnet, but means
the private key material is stored in the initramfs (which is commonly
unencrypted).

* [tailscale-initramfs by Lugoues](https://github.com/Lugoues/tailscale-initramfs)

Similar to this package, but registers the initrd as a tailscale device when
you configure the package. The initrd device will be present in the tailnet
all the time.
21 changes: 16 additions & 5 deletions config/config
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
# --authkey, so can also be file:/path/to/secret (the file will be copied into
# the initramfs).
#
# Note that the config (and any key) is stored in the initramfs, which is
# often outside of a cryptroot.
# - https://tailscale.com/kb/1068/acl-tags/#generate-an-auth-key-with-an-acl-tag
# - https://tailscale.com/kb/1111/ephemeral-nodes/
#
# Note: The authkey (like this config file) is stored in the initramfs. If
# you're using disk encryption (LUKS), the initramfs is stored *unencrypted* in
# the boot partition.
#
TAILSCALE_AUTHKEY=

#
Expand All @@ -35,8 +37,17 @@ TAILSCALE_AUTHKEY=
#TAILSCALED_OPTIONS=

#
# Set to any non-empty string to log out of tailscale before passing out of
# the initramfs. This is ineffective if some other package in the initramfs
# Set to any non-empty string to disable tailscale SSH
# - https://tailscale.com/kb/1193/tailscale-ssh
# Default: none
#
#TAILSCALE_DISABLE_SSH=

#
# Set to any non-empty string to log out of tailscale before exiting out of
# the initramfs and continuing to boot the system.
#
# This is ineffective if some other package in the initramfs
# (dropbear-initramfs) brings down the external interfaces. See IFDOWN in
# dropbear-initramfs's config.
# Default: none
Expand All @@ -50,7 +61,7 @@ TAILSCALE_AUTHKEY=
#
# Tailscale will eventually fall back to bootstrapping DNS itself, but there's
# no reason to rely on that (adds a slight delay). Tailscale's fallback is
# also problematic in some corner cases in some versions (see
# also problematic in some corner cases in some older versions (see
# https://github.com/tailscale/tailscale/issues/6110).
#
#FALLBACK_DNS_SERVERS=
Expand Down
2 changes: 2 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ tailscale-initramfs (0.4) UNRELEASED; urgency=medium

* Copy the iptables userspace modules into the initramfs, so that tailscale
is able to update iptables rules.
* Add Tailscale SSH support (allow tailscale to run its SSH server in the
initramfs).

-- Paul Aurich <[email protected]> Thu, 16 May 2024 19:20:32 -0700

Expand Down
4 changes: 2 additions & 2 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ execute_after_dh_fixperms:
chmod 600 debian/tailscale-initramfs/etc/tailscale/initramfs/config

override_dh_builddeb:
# Workaround for building on Ubuntu and installing on Debian (Ubuntu uses
# zstd). https://bugs.debian.org/892664
# Workaround for building on Ubuntu and installing on Debian prior to
# Bookworm (Ubuntu uses zstd). https://bugs.debian.org/892664
dh_builddeb -- -Zxz
15 changes: 15 additions & 0 deletions hooks/tailscale
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ manual_add_modules tun
copy_file config /etc/ssl/certs/ca-certificates.crt
copy_file config /etc/hostname /etc/tailscale/initramfs/hostname

if [ -z "${TAILSCALE_DISABLE_SSH:-}" ]; then
copy_exec /usr/bin/getent bin

# Create root user/group for 'tailscale ssh', if another hook (i.e. dropbear) hasn't
if ! grep -sq '^root:' "$DESTDIR/etc/passwd"; then
home="$(mktemp --directory -- "$DESTDIR/root-XXXXXXXXXX")"
chmod 0700 -- "$home"
echo "root:x:0:0:root:${home#"$DESTDIR"}:/bin/sh" >> "$DESTDIR/etc/passwd"
fi

if ! grep -sq '^root:' "$DESTDIR/etc/group"; then
echo "root:x:0:" >> "$DESTDIR/etc/group"
fi
fi

if [ -e /etc/tailscale/initramfs/config ]; then
cp -pt "$DESTDIR/etc/tailscale/initramfs" /etc/tailscale/initramfs/config
. /etc/tailscale/initramfs/config
Expand Down
12 changes: 8 additions & 4 deletions scripts/init-premount/tailscale
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ run_tailscale()
{
log_begin_msg "Starting tailscale"

local options="--state=/var/lib/tailscale/tailscaled.state --socket=/run/tailscale/tailscaled.sock"
local client_options=""
if [ -z "${TAILSCALE_DISABLE_SSH:-}" ]; then
client_options="$client_options --ssh"
fi
local daemon_options="--state=/var/lib/tailscale/tailscaled.state --socket=/run/tailscale/tailscaled.sock"

# FIXME: This races with dropbear-initramfs bringing up the network
# asynchronously
Expand All @@ -101,13 +105,13 @@ run_tailscale()

# A little race-y to start the client before the daemon, but the client
# will attempt to connect to the socket for a while.
# https://github.com/tailscale/tailscale/blob/8cf1af8a0703c36256fc58e98ddb63b8907848f1/safesocket/safesocket.go#L119-L122
/bin/tailscale --socket=/run/tailscale/tailscaled.sock up --authkey="${TAILSCALE_AUTHKEY}" --hostname="${TAILSCALE_HOSTNAME}" $TAILSCALE_OPTIONS &
# https://github.com/tailscale/tailscale/blob/0cce456ee5bf45b555521109ff525ef81adb9650/safesocket/safesocket.go#L35-L65
/bin/tailscale --socket=/run/tailscale/tailscaled.sock up --authkey="${TAILSCALE_AUTHKEY}" --hostname="${TAILSCALE_HOSTNAME}" $client_options ${TAILSCALE_OPTIONS-} &

if [ "${debug:-}" != y ]; then
exec 2>/run/initramfs/tailscale.log
fi
exec /sbin/tailscaled $options $TAILSCALED_OPTIONS
exec /sbin/tailscaled $daemon_options ${TAILSCALED_OPTIONS-}
}

[ "$BOOT" = nfs ] && configure_networking
Expand Down

0 comments on commit 669f1e2

Please sign in to comment.