Skip to content

Commit 3b2d788

Browse files
committed
tailscale: persist state across container restarts
The state directory is now in the default location inside the container, /var/lib/tailscale and other default parameters for tailscaled are removed. The state directory is now a mount declared in the feature specification, and references `${devcontainerId}` so that the state is local to the particular devcontainer instance. Updates #40
1 parent 7a72aca commit 3b2d788

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ sudo tailscale up --accept-routes
2525
You'll only need to run `tailscale up` once per Codespace.
2626
The Tailscale state will be saved between rebuilds.
2727

28+
## Details
29+
30+
- A mount is added called `tailscale-${devcontainerId}` mapped to
31+
`/var/lib/tailscale` to persist taislcaled state across devcontainer rebuilds,
32+
so a single devcontainer will remain logged in for the devcontainer lifetime.
33+
- The feature requires `CAP_NET_ADMIN` in order to configure certain network
34+
properties for kernel mode tailscale.
35+
- The feature requires kernel tun support in the runtime and `CAP_MKNOD` so that
36+
it can create a tun device node if needed.
37+
- `CAP_NET_RAW` enables the feature to send ICMP.
38+
2839
## Development
2940

3041
A convenient way to develop this feature is to use codespaces, as they start by

src/tailscale/devcontainer-feature.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,12 @@
1313
"default": "latest",
1414
"description": "Version of Tailscale to download"
1515
}
16-
}
16+
},
17+
"mounts": [
18+
{
19+
"source": "tailscale-${devcontainerId}",
20+
"target": "/var/lib/tailscale",
21+
"type": "volume"
22+
}
23+
]
1724
}

src/tailscale/install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ install -D "$scratch_dir/tailscale" /usr/local/bin/tailscale
6464
install -D "$scratch_dir/tailscaled" /usr/local/sbin/tailscaled
6565
install -D "$script_dir/tailscaled-entrypoint.sh" /usr/local/sbin/tailscaled-entrypoint
6666

67-
mkdir -p /var/lib/tailscale /var/run/tailscale
67+
mkdir -p /var/lib/tailscale /var/run/tailscale /var/log
68+
touch /var/log/tailscaled.log
6869

6970
if ! command -v iptables >& /dev/null; then
7071
if command -v apt-get >& /dev/null; then

src/tailscale/tailscaled-entrypoint.sh

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,17 @@ if [[ "$(id -u)" -eq 0 ]]; then
3030
mknod /dev/net/tun c 10 200
3131
fi
3232
check_userspace
33-
mkdir -p /workspaces/.tailscale /var/log
34-
touch $TAILSCALED_LOG
35-
>$TAILSCALED_LOG 2>&1 \
36-
/usr/local/sbin/tailscaled \
37-
--statedir=/workspaces/.tailscale/ \
38-
--socket=$TAILSCALED_SOCK \
39-
--port=41641 &
33+
>$TAILSCALED_LOG 2>&1 /usr/local/sbin/tailscaled &
4034
TAILSCALED_PID=$!
4135
elif command -v sudo > /dev/null; then
4236
if [[ ! -c /dev/net/tun ]]; then
4337
sudo --non-interactive mkdir -p /dev/net
4438
sudo --non-interactive mknod /dev/net/tun c 10 200
4539
fi
4640
check_userspace
47-
sudo --non-interactive mkdir -p /workspaces/.tailscale /var/log
48-
sudo --non-interactive touch $TAILSCALED_LOG
4941
>$TAILSCALED_LOG 2>&1 \
5042
sudo --non-interactive "TS_DEBUG_FIREWALL_MODE=$TS_DEBUG_FIREWALL_MODE" \
51-
/usr/local/sbin/tailscaled \
52-
--statedir=/workspaces/.tailscale/ \
53-
--socket=$TAILSCALED_SOCK \
54-
--port=41641 &
43+
/usr/local/sbin/tailscaled &
5544
TAILSCALED_PID=$!
5645
else
5746
>&2 echo "tailscaled could not start as root."

0 commit comments

Comments
 (0)