ssh-bridge: contained tailscale+sshd jump host add-on

This commit is contained in:
Hermes Sysadmin committed 2026-11-19 22:50:10 +00:00
1 parent 5df8d11b1e
commit 14081ac81d
5 files changed
+177

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
FROM alpine:3.22
RUN apk add --no-cache openssh tailscale
# Low-privilege login account; nologin shell — sessions exist only to forward.
RUN adduser -D -H -s /sbin/nologin bridge
COPY sshd_config /etc/ssh/sshd_config
COPY run.sh /run.sh
RUN chmod +x /run.sh
ENTRYPOINT ["/run.sh"]
+69
View File
@@ -0,0 +1,69 @@
# ssh-bridge — contained SSH→Tailscale jump host as a Home Assistant local add-on
What this is: one Alpine container running tailscaled + sshd. tailscale0 lives in
the container's own network namespace. The HAOS host and HA core never join the
tailnet and the container has no HA API access. Work laptop SSHes to
yellow:2222 (LAN/WAN), then jumps to tailnet hosts or opens a SOCKS proxy
(`ssh -N -D 1080 bridge@...`) exactly like the old NAS VM did.
## Files
- config.yaml add-on manifest (NET_ADMIN + /dev/net/tun only; port 2222)
- Dockerfile alpine + openssh + tailscale (community repo, in-image default)
- sshd_config key-only, AllowUsers bridge, forwarding on, everything else off
- run.sh tailscaled -> tailscale up (authkey from /share) -> sshd
## One-time setup (user-driven)
1. Put this folder in the murphy/ha repo under `addons/ssh-bridge/`.
2. On the Yellow: Settings → Apps → ⋮ → Add copy repository →
`https://git.halfast.com/murphy/ha` (local add-on repos point at a folder;
if the whole repo is the source, the add-on store scans `addons/`).
Install "SSH Bridge (Tailscale)".
3. Create `/share/ssh-bridge/` on the HA host (Samba share or File editor):
- `authorized_keys` your laptop public keys, one per line
- `tailscale_authkey` a REUSABLE auth key from the Tailscale admin console
(Keys → Generate auth key → reusable, ephemeral OFF,
expiry 90d is fine; pre-authorize the node and add
the tag there if using auto-tags)
4. Start the add-on. First start registers the node `ssh-bridge`.
5. Router: forward new WAN port (e.g. 2222) → Yellow LAN IP:2222.
Keep the NAS VM bridge running until the new one is proven, then retire it.
6. Laptops: update ~/.ssh/config Host entries to the new port/host.
## What it deliberately does NOT do
- No advertise_routes, no exit node → the bridge exposes zero LAN to the tailnet.
- No hassio_api/homeassistant_api → cannot reach HA even from inside the container.
- No password auth, no root login, nologin shell user.
## Tailscale ACL additions (merge into existing policy — review current first!)
Default Tailscale policy is allow-all; if the tailnet already has custom rules,
these must be ADDED, not pasted over. Sketch:
```
// auto-tag the bridge node by hostname
"autoTags": [
{ "match": "name:ssh-bridge", "tag": "tag:ssh-bridge" }
],
"acl": [
// bridge -> SSH jump targets only (tag the hosts, or list them)
{ "action": "accept", "src": ["tag:ssh-bridge"], "dst": ["tag:jump-hosts:22"] },
// bridge -> web UIs for the SOCKS/Chrome path (tag UI services 'web')
{ "action": "accept", "src": ["tag:ssh-bridge"], "dst": ["tag:web:443,80"] },
// no rule grants anything else: deny-by-default catches the rest.
// IMPORTANT: if the existing policy has a catch-all allow (default policy),
// the bridge inherits it — that catch-all must be narrowed for containment.
]
```
Tagging: in the admin console, add `tag:jump-hosts` to the hosts you ssh to and
`tag:web` to Grafana/Gitea/Longhorn-UI/etc. New services get tagged, no policy edits.
## Notes / known edges
- Chrome + SOCKS: QUIC (UDP) bypasses the SOCKS tunnel; sites that prefer QUIC
may fall back to TCP or fail — normal for ssh -D setups, worth knowing.
- `--accept-dns=false` keeps tailnet MagicDNS from hijacking the container's resolver.
- Reusable authkey in /share means HAOS/add-on restarts re-join without UI interaction.
- The add-on rebuilds on install (tiny alpine layer set; fine on the Yellow).
Subsequent HAOS updates keep the built image.
+29
View File
@@ -0,0 +1,29 @@
name: "SSH Bridge (Tailscale)"
version: "1.0.0"
slug: "ssh_bridge"
description: "Contained tailscale+sshd jump host for tailnet access. Runs in its own network namespace; Home Assistant and the host itself do NOT join the tailnet."
url: "https://git.halfast.com/murphy/ha"
arch:
- aarch64
stage: local
boot: auto
# Only what tailscaled needs: NET_ADMIN + tun. No hassio_api, no homeassistant_api,
# no docker_api, no full_access. Cannot touch HA core even if popped.
privileged:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
# authorized_keys + tailscale authkey live in /share/ssh-bridge/ on the HA host
# (manageable via Samba/File editor), mounted read-only. Secrets stay out of the
# add-on options UI.
map:
- share:ro
ports:
2222/tcp: 2222
options:
tailscale_hostname: "ssh-bridge"
tailscale_extra_args: ""
schema:
tailscale_hostname: str
tailscale_extra_args: "str?"
log_level: "select[debug|info|warn|error]?"
+42
View File
@@ -0,0 +1,42 @@
#!/bin/ash
set -e
# Persistent state lives in the add-on's /data (survives restarts/HAOS updates).
mkdir -p /data/ssh
# --- tailscaled (real TUN inside this container's netns; host never joins tailnet)
tailscaled \
--statedir=/data/tailscale \
--tun=tailscale0 \
--loginfoleak=false &
TAILSD=$!
# Wait for the socket before trying to bring the node up.
i=0
until [ -e /data/tailscale/tailscaled.sock ]; do
i=$((i+1)); [ "$i" -gt 30 ] && { echo "tailscaled socket never appeared"; exit 1; }
sleep 1
done
# Auth key is a file in /share (never shown in the add-on options UI).
if [ -r /share/ssh-bridge/tailscale_authkey ]; then
AUTHKEY="$(cat /share/ssh-bridge/tailscale_authkey)"
# shellcheck disable=SC2086
tailscale up \
--authkey="$AUTHKEY" \
--hostname="${tailscale_hostname:-ssh-bridge}" \
--accept-dns=false \
${tailscale_extra_args} \
--reset
unset AUTHKEY
else
echo "WARN: /share/ssh-bridge/tailscale_authkey missing; tailscale node not registered"
fi
# --- sshd host key (generated once, kept in /data)
if [ ! -f /data/ssh/ssh_host_ed25519_key ]; then
ssh-keygen -q -t ed25519 -N "" -f /data/ssh/ssh_host_ed25519_key
fi
# --- sshd in foreground; supervisor restarts the add-on if it dies
exec /usr/sbin/sshd -D -f /etc/ssh/sshd_config -e
+25
View File
@@ -0,0 +1,25 @@
# ssh-bridge sshd — key-only, forward-only jump host.
Port 2222
ListenAddress 0.0.0.0
HostKey /data/ssh/ssh_host_ed25519_key
# Hard limits
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
AllowUsers bridge
AuthorizedKeysFile /share/ssh-bridge/authorized_keys
# Required for -D (SOCKS) and -L jumps; everything else off
AllowTcpForwarding yes
AllowAgentForwarding no
PermitTunnel no
X11Forwarding no
GatewayPorts no
# Housekeeping
ClientAliveInterval 60
ClientAliveCountMax 3
LogLevel INFO