Skip to content

Commit eeb006a

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 f54bfd7 commit eeb006a

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ install "$scratch_dir/tailscale" /usr/local/bin/tailscale
6464
install "$scratch_dir/tailscaled" /usr/local/sbin/tailscaled
6565
install "$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
6868

6969
if ! command -v iptables >& /dev/null; then
7070
if command -v apt-get >& /dev/null; then

src/tailscale/tailscaled-entrypoint.sh

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,22 @@ 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
33+
mkdir -p /var/log /var/run/tailscale
3434
touch $TAILSCALED_LOG
3535
>$TAILSCALED_LOG 2>&1 \
36-
/usr/local/sbin/tailscaled \
37-
--statedir=/workspaces/.tailscale/ \
38-
--socket=$TAILSCALED_SOCK \
39-
--port=41641 &
36+
/usr/local/sbin/tailscaled &
4037
TAILSCALED_PID=$!
4138
elif command -v sudo > /dev/null; then
4239
if [[ ! -c /dev/net/tun ]]; then
4340
sudo --non-interactive mkdir -p /dev/net
4441
sudo --non-interactive mknod /dev/net/tun c 10 200
4542
fi
4643
check_userspace
47-
sudo --non-interactive mkdir -p /workspaces/.tailscale /var/log
44+
sudo --non-interactive mkdir -p /var/log /var/run/tailscale
4845
sudo --non-interactive touch $TAILSCALED_LOG
4946
>$TAILSCALED_LOG 2>&1 \
5047
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 &
48+
/usr/local/sbin/tailscaled &
5549
TAILSCALED_PID=$!
5650
else
5751
>&2 echo "tailscaled could not start as root."

0 commit comments

Comments
 (0)