ssh-bridge 1.1.0: fleet relay per brief - persistent /data/home/bridge (bash), git+openssh-client pkgs, busybox crond with /data/crontabs spool, accept-dns=true, MaxSessions 20, no ForceCommand
This commit is contained in:
1 parent
83be6c6309
commit
685b3542e9
5 files changed
+58
-56
No files matched your search
@@ -1,12 +1,12 @@
|
||||
FROM alpine:3.22
|
||||
|
||||
RUN apk add --no-cache openssh tailscale
|
||||
RUN apk add --no-cache openssh openssh-client tailscale bash git
|
||||
|
||||
# Low-privilege login account, key-only. ash shell so interactive jump
|
||||
# sessions (ssh bridge@... then ssh onward) work; -D leaves shadow "!"
|
||||
# (locked) which OpenSSH rejects even for pubkey auth, so unlock it.
|
||||
# Password auth stays off in sshd_config, so an empty password field is inert.
|
||||
RUN adduser -D -H -s /bin/ash bridge && passwd -u bridge
|
||||
# Low-privilege login account, key-only. bash shell for interactive jumps and
|
||||
# fleet scripts; home lives on /data so it survives add-on updates/restarts.
|
||||
# -D leaves shadow "!" (locked) which OpenSSH rejects even for pubkey auth,
|
||||
# so unlock it; password auth stays off in sshd_config, empty field is inert.
|
||||
RUN adduser -D -s /bin/bash -h /data/home/bridge bridge && passwd -u bridge
|
||||
|
||||
COPY sshd_config /etc/ssh/sshd_config
|
||||
COPY run.sh /run.sh
|
||||
|
||||
+32
-43
@@ -1,67 +1,56 @@
|
||||
# ssh-bridge — contained SSH→Tailscale jump host as a Home Assistant local add-on
|
||||
# ssh-bridge — contained SSH→Tailscale fleet relay as a Home Assistant 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:2223 (LAN/WAN), then jumps to tailnet hosts or opens a SOCKS proxy
|
||||
(`ssh -N -D 1080 bridge@...`) exactly like the old NAS VM did.
|
||||
What this is: one Alpine container running tailscaled + sshd + crond. 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 laptops SSH to
|
||||
`ev46.halfast.com:22403` (router → Yellow:2223), then jump to tailnet hosts,
|
||||
run SOCKS (`ssh -D`), ProxyJump (`ssh -W`), cron fleet supervision, and
|
||||
git-over-ssh (`~/fleet.git`).
|
||||
|
||||
## Roles
|
||||
1. Jump host: sshd (key-only, user `bridge`), host port 2223, container 2222.
|
||||
Host key pinned at /data/ssh/ssh_host_ed25519_key — never regenerate;
|
||||
clients pin its fingerprint.
|
||||
2. Tailnet DNS: `tailscale up --accept-dns=true` (MagicDNS for tailnet names;
|
||||
internet + *.local.hass.io forwarded to HAOS DNS).
|
||||
3. Supervisor: persistent home /data/home/bridge (bash), busybox crond with
|
||||
crontabs spooled in /data/crontabs (survives updates).
|
||||
4. Git host: git installed (git-upload-pack/git-receive-pack on PATH),
|
||||
no ForceCommand — non-interactive `ssh host cmd` works.
|
||||
|
||||
## Files
|
||||
- config.yaml add-on manifest (NET_ADMIN + /dev/net/tun only; port 2223 on host, 2222 in-container)
|
||||
- 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
|
||||
- config.yaml add-on manifest (NET_ADMIN + /dev/net/tun only; ports)
|
||||
- Dockerfile alpine + openssh + tailscale + bash + git
|
||||
- sshd_config key-only, AllowUsers bridge, MaxSessions 20, forwarding on
|
||||
- run.sh persistent dirs -> tailscaled -> tailscale up -> crond -> sshd
|
||||
|
||||
## One-time setup (user-driven)
|
||||
1. Source of truth: `hermes/ha-addons` (public, root `repository.yaml` manifest).
|
||||
Already registered on the Yellow as repo `087e3765` "Halfast HA Add-ons";
|
||||
this add-on installs from there. (A reference copy also lives in murphy/ha.)
|
||||
2. Create `/share/ssh-bridge/` on the HA host (Samba share or File editor):
|
||||
- `authorized_keys` your laptop public keys, one per line
|
||||
- `authorized_keys` your laptop public keys, one per line, file must
|
||||
end with a newline (append-safe)
|
||||
- `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)
|
||||
3. Start the add-on. First start registers the node `ssh-bridge`.
|
||||
4. Router: forward new WAN port (e.g. 2222) → Yellow LAN IP:2223.
|
||||
4. Router: forward WAN port 22403 → Yellow LAN IP:2223.
|
||||
Keep the NAS VM bridge running until the new one is proven, then retire it.
|
||||
5. 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. Key-only ash user for jump sessions.
|
||||
|
||||
## 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.
|
||||
- No password auth, no root login. Key-only bash user for jump sessions.
|
||||
|
||||
## 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.
|
||||
- `--accept-dns=true` makes tailnet MagicDNS the container resolver; non-tailnet
|
||||
queries forward to HAOS DNS (covers github.com and *.local.hass.io).
|
||||
- Reusable authkey in /share means HAOS/add-on restarts re-join without UI
|
||||
interaction and keep the same tailnet identity (untagged, user-owned).
|
||||
- Everything persistent is under /data: host key, tailscale state, bridge home,
|
||||
crontabs. Add-on updates rebuild the image but keep /data.
|
||||
@@ -1,7 +1,7 @@
|
||||
name: "SSH Bridge (Tailscale)"
|
||||
version: "1.0.4"
|
||||
version: "1.1.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."
|
||||
description: "Contained tailscale+sshd fleet relay: jump host, SOCKS, tailnet DNS, persistent home, crond, git-over-ssh. Runs in its own network namespace; Home Assistant and the host itself do NOT join the tailnet."
|
||||
url: "https://git.halfast.com/hermes/ha-addons"
|
||||
arch:
|
||||
- aarch64
|
||||
|
||||
+15
-4
@@ -1,8 +1,10 @@
|
||||
#!/bin/ash
|
||||
set -e
|
||||
|
||||
# Persistent state lives in the add-on's /data (survives restarts/HAOS updates).
|
||||
mkdir -p /data/ssh
|
||||
# Everything persistent lives under /data (survives restarts and updates).
|
||||
mkdir -p /data/ssh /data/home/bridge /data/crontabs
|
||||
chown bridge:bridge /data/home/bridge /data/crontabs
|
||||
chmod 700 /data/home/bridge
|
||||
|
||||
# --- tailscaled (real TUN inside this container's netns; host never joins tailnet)
|
||||
tailscaled \
|
||||
@@ -20,13 +22,16 @@ until [ -e /var/run/tailscale/tailscaled.sock ]; do
|
||||
done
|
||||
|
||||
# Auth key is a file in /share (never shown in the add-on options UI).
|
||||
# --accept-dns=true: MagicDNS for tailnet names; non-tailnet names (internet
|
||||
# and *.local.hass.io) are forwarded to the container's upstream resolver,
|
||||
# which is HAOS DNS.
|
||||
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 \
|
||||
--accept-dns=true \
|
||||
${tailscale_extra_args} \
|
||||
--reset
|
||||
unset AUTHKEY
|
||||
@@ -34,7 +39,13 @@ else
|
||||
echo "WARN: /share/ssh-bridge/tailscale_authkey missing; tailscale node not registered"
|
||||
fi
|
||||
|
||||
# --- sshd host key (generated once, kept in /data)
|
||||
# --- busybox crond with a persistent crontab spool (user-owned crontabs,
|
||||
# e.g. bridge's fleet supervise entry). -b daemonizes; logs to /data.
|
||||
ln -sfn /data/crontabs /var/spool/cron/crontabs
|
||||
crond -b -l 6 -L /data/cron.log
|
||||
|
||||
# --- sshd host key (generated once, kept in /data; never regenerate —
|
||||
# client hosts pin this fingerprint)
|
||||
if [ ! -f /data/ssh/ssh_host_ed25519_key ]; then
|
||||
ssh-keygen -q -t ed25519 -N "" -f /data/ssh/ssh_host_ed25519_key
|
||||
fi
|
||||
|
||||
@@ -15,12 +15,14 @@ PubkeyAuthentication yes
|
||||
AllowUsers bridge
|
||||
AuthorizedKeysFile /share/ssh-bridge/authorized_keys
|
||||
|
||||
# Required for -D (SOCKS) and -L jumps; everything else off
|
||||
# Required for -D (SOCKS), -W (ProxyJump) and git-over-ssh; everything else off.
|
||||
# No ForceCommand: non-interactive 'ssh host cmd' must work (git push/pull).
|
||||
AllowTcpForwarding yes
|
||||
AllowAgentForwarding no
|
||||
PermitTunnel no
|
||||
X11Forwarding no
|
||||
GatewayPorts no
|
||||
MaxSessions 20
|
||||
|
||||
# Housekeeping
|
||||
ClientAliveInterval 60
|
||||
|
||||
Reference in new issue
Block a user