Skip to main content
Version: Next

SSH Tunnel Configuration

Many HPC sites give compute nodes no outbound internet access, and many Kubernetes clusters have no publicly reachable ingress. The wstunnel shadow needs both: the workload dials out to an ingress and runs a wstunnel client there. On an air-gapped site it cannot.

The SSH shadow inverts the direction. Instead of the compute node dialing out, the cluster dials in to the site's SSH login node and forwards each exposed port from the compute node the job landed on:

browser → Ingress / Service → shadow pod (ssh -L) → HPC login node → compute node (Jupyter)

The only requirement is outbound SSH from the cluster to the login node. The offloaded pod runs nothing on its side: no wstunnel client, no WireGuard configuration, no pre-exec injection.

info

The SSH shadow replaces wstunnel, not full mesh. It exposes the offloaded pod's ports to the cluster. A workload that needs the other direction, in-cluster object storage or a message bus for example, gets it over the same login node with the reverse tunnel, without WireGuard and without a network namespace. Combining the SSH shadow with full mesh is rejected at startup.


Before you start: what the site has to allow​

The shadow is an ordinary SSH client, so everything it needs is decided by the site's sshd_config files. Which ones depends on ForwardTarget: with login, the default, the shadow's session ends on the login node; with node it passes through the login node and ends on the compute node's own sshd.

Both targets need outbound SSH from the cluster to the login node's port, from the namespaces shadows are created in. Network policies that restrict pod egress have to allow it.

With ForwardTarget: login​

  1. AllowTcpForwarding yes for the account the shadow logs in as. This is the one that catches people out: plenty of HPC sites set AllowTcpForwarding no globally and re-enable it only for a subset of users, often only those who authenticate with MFA. Check it before anything else:

    # from your own machine, with the same key/principal the shadow will use
    ssh -N -L 19999:<login node>:22 <user>@<login node> &
    nc -z 127.0.0.1 19999 && head -c 40 < /dev/tcp/127.0.0.1/19999

    If the site refuses, the shadow still starts and still reports Ready — the failure only shows up when traffic arrives, as a connection reset at the client and this line in kubectl logs <shadow pod> -c ssh-forward:

    channel 1: open failed: administratively prohibited: open failed

    If the site will not allow it, switch to ForwardMode: exec, which relays through a command on the login node instead and needs no forwarding privilege.

  2. A route from the login node to the compute nodes, on the ports the pod exposes. ssh -L resolves and connects to the compute node from the login node, using whatever name the plugin reported. Verify with the name the plugin actually reports (hostname -f on the compute node for the Slurm plugin), not the short name:

    ssh <user>@<login node> "curl -sv http://<compute node fqdn>:<port>/"

With ForwardTarget: node​

  1. A way from the login node to port 22 of the compute node. In portforward mode the shadow uses ssh -W, which is TCP forwarding too, so the login node needs AllowTcpForwarding yes as above. In exec mode it runs nc <node> 22 on the login node instead, which needs no forwarding privilege.

  2. An ssh login to a compute node while the account has a job running there. Slurm sites usually allow it through pam_slurm_adopt. Check it from your own machine, with the key the shadow will use, while one of your jobs runs on the node:

    # portforward mode
    ssh -J <user>@<login node> <user>@<compute node fqdn> hostname
    # exec mode
    ssh -o ProxyCommand="ssh <user>@<login node> nc %h 22" <user>@<compute node fqdn> hostname

    Run it before restricting the key as in A key for the tunnel only. With the restricted key, run it from a host listed in from=; the wrapper then prints tunnel key: refused: hostname, which already proves the key logged in on the node.

  3. Forwarding on the compute node's sshd, in both modes: the forwards are always -L on the node. AllowTcpForwarding for TCP ports and AllowStreamLocalForwarding for socket ports. Both are on in a stock sshd_config, and a login node that refuses forwarding does not mean its compute nodes do. To test TCP forwarding, omit hostname from the relevant command above and insert -N -L 8080:127.0.0.1:8080 before the destination. Keep it running and, from another terminal, connect to local port 8080 while a server listens on the compute node's loopback port 8080. A successful login or local listener alone does not test forwarding permission.

The login node needs no route to the pod's own ports: the last hop happens inside the compute node.

ssh -L carries TCP only. UDP ports on the offloaded pod are skipped, with a warning in the virtual kubelet log, and a pod that exposes only UDP ports gets no shadow unless it asks for the reverse tunnel.


Which shadow does what​

DirectionTriggerWorkload must run
wstunnel (default)cluster → podEnableTunnel + exposed portswstunnel client, dials out
sshcluster → podEnableTunnel + exposed portsnothing
ssh reversepod → clusterSSH.Reverse.Enabled + interlink.eu/reverse-forwardsnothing: the batch script starts a relay and waits for the tunnel
full meshbidirectionalFullMesh: true, every podmesh.sh (slirp4netns + WireGuard)

Security checklist​

The defaults keep existing deployments working unchanged. For a new deployment, or once the site is ready for it:

  1. End the tunnel on the compute node, ForwardTarget: node, so the workload never listens on the network. See Forward modes.
  2. Have the workload listen on a unix socket. Failing that, on 127.0.0.1 with the whole node to itself (--exclusive). Never on 0.0.0.0. See Where the workload listens.
  3. Verify compute node host keys: keep NodeHostKeys: verify, and pin the login node's key in KnownHostsConfigMap. See Compute nodes.
  4. Give the shadow a key for the tunnel only, restricted in authorized_keys, never the plugin's key. See A key for the tunnel only.
  5. Decide on ReplicateCredentials. It is on by default and copies that key into every shadow namespace, where anyone who can read Secrets can use it. See Credential replication.

Configuration​

Virtual Kubelet​

# VirtualKubeletConfig.yaml
Network:
EnableTunnel: true
ShadowMode: ssh
SSH:
LoginHost: login.hpc.example.org
User: alice
KeySecret: hpc-ssh-key
ForwardTarget: node
KnownHostsConfigMap: hpc-known-hosts # login node key, plus node keys or a CA line

EnableTunnel turns shadow pods on for offloaded pods with exposed ports; ShadowMode picks which shadow is rendered. Both are needed. ForwardTarget: node is recommended but not yet the default, see Forward modes. KnownHostsConfigMap holds the host keys the shadow trusts, see Host key verification.

Helm​

virtualNode:
network:
enableTunnel: true
shadowMode: ssh
ssh:
loginHost: login.hpc.example.org
user: alice
keySecret: hpc-ssh-key
forwardTarget: node
knownHostsConfigMap: hpc-known-hosts

Charts that predate forwardTarget and nodeHostKeys ignore them without an error, and the shadow stays on the login target: check that the output of helm template contains ForwardTarget.

See examples/ssh_tunnel.yaml in the chart repository for a complete deployment.

Options​

OptionDefaultDescription
LoginHostnoneSSH login node to forward through (required)
UsernoneLogin name on that node (required)
Port22Login node's SSH port
Imageghcr.io/interlink-hq/interlink/ssh-tunnel:<version>Image the shadow runs. Needs an ssh client, plus kinit for Kerberos
Authpublickeypublickey or kerberos
ForwardTargetloginWhere the ssh session ends: login (the login node connects to the workload over plain TCP) or node (the compute node's own sshd, recommended). See Forward modes
ForwardModeportforwardportforward (sshd forwarding: -L on the login node, or -W on the login node and -L on the compute node) or exec (ssh commands only, no forwarding)
ExecConnectCommandncNetcat run on the login node in exec mode: <command> <node> <port> with the login target, <command> <node> 22 with the node target
KeySecretnoneSecret holding the shadow's private key (publickey). Use a key for the tunnel only, never the plugin's
KeySecretKeyid_ed25519Key inside KeySecret
KeytabSecretnoneSecret holding the keytab (kerberos)
KeytabSecretKeyuser.keytabKey inside KeytabSecret
PrincipalnoneKerberos principal (kerberos)
Krb5ConfigMapnoneConfigMap with a krb5.conf, mounted at /etc/krb5.conf
KnownHostsConfigMapnoneConfigMap with a known_hosts file: the login node's key, plus compute node keys, host patterns or @cert-authority lines
NodeHostKeysverifyHow compute node host keys are checked, with ForwardTarget: node and by the reverse tunnel, except a user-space sshd reached with Reverse.NodeExec: srun: verify or accept-new. See Compute nodes
ReplicateCredentialstrueCopy the credential into each shadow's namespace
NodeWaitTimeout2hHow long the shadow waits for the compute node
ExtraOptions[]Extra ssh options, each passed as -o <option> on every hop, after the shadow's own. ssh keeps the first value it sees, so they add settings but cannot override the shadow's. One exception: GSSAPIDelegateCredentials=yes turns Kerberos delegation back on for the login hop
Reverse.EnabledfalseLet pods ask for a tunnel back into the cluster
Reverse.SshdnodeWhich sshd makes the reverse forwards: node (the compute node's own) or userspace (one the shadow starts in the job, for nodes whose sshd refuses forwarding). See A user-space sshd
Reverse.NodeExecsshHow the shadow reaches port 22 of the compute node: ssh (through the login node, as ForwardMode says) or srun (srun --jobid=<job> --overlap on the login node, a last resort with lower throughput, see Performance). Set here only: pods cannot change it
Reverse.AllowSocksfalseLet pods ask for a SOCKS proxy on the compute node, open to every user of that node. See Endpoints not known in advance
Reverse.SshdPath/usr/sbin/sshdThe sshd binary on the compute node, for Reverse.Sshd: userspace only
Reverse.PythonPathpython3The python3 on the compute node, which runs the relay

Misconfiguration fails at startup, not on the first offloaded pod, so a missing LoginHost or a kerberos block without a Principal is caught immediately.


Forward modes​

Two settings decide how a connection travels from the shadow to the workload.

ForwardTarget says where the shadow's ssh session ends.

  • login (default): on the login node, which then opens a plain TCP connection to <compute node>:<port>. That last leg is not encrypted, and the workload has to listen on an address the login node can reach.
  • node: on the compute node's own sshd, reached through the login node. The login node only relays encrypted traffic, and each forward is opened inside the node, to 127.0.0.1:<port> or to a unix socket, so the workload does not listen on the network at all.

node is the recommended setting. login stays the default so that an upgrade changes nothing for existing deployments; the virtual kubelet says so in one line at startup.

ForwardMode says what the shadow asks of the login node.

  • portforward (default): yes, one ssh -L per exposed port. It is the cheapest option and depends on nothing but the ssh client.
  • exec: no. It is for sites that do not grant forwarding. Each exposed port gets a local listener in the shadow, and every accepted connection is relayed by a netcat run as an ordinary ssh command. The only privileges involved are the ones the shadow already uses to log in.

What each combination needs from the site:

ForwardTargetForwardModeLogin nodeCompute nodeWorkload listens on
loginportforwardTCP forwarding (-L)nothingthe node's address
loginexecruns nc <node> <port>nothingthe node's address
nodeportforwardTCP forwarding (-W <node>:22)TCP or socket forwarding (-L)127.0.0.1 or a socket
nodeexecruns nc <node> 22TCP or socket forwarding (-L)127.0.0.1 or a socket

node with exec needs no forwarding on the login node, only on the compute node's sshd, so it keeps the workload off the network at sites whose login nodes refuse forwarding:

Network:
ShadowMode: "ssh"
SSH:
LoginHost: "login.hpc.example.org"
User: "alice"
KeySecret: "hpc-ssh-key"
ForwardTarget: "node"
ForwardMode: "exec"
ExecConnectCommand: "nc" # ncat, or "nc -q 1" on a netcat that does not half-close

The two modes are interchangeable above the socket: the Service still fronts the same container port, and nothing on either side can tell them apart. The target is what decides where the workload has to listen, see Where the workload listens.

portforwardexec
Connectionsone long-lived sshone ssh channel per TCP connection
Cost per connectionnoneone multiplexed channel open
Failure surfacesat connect timeat connect time

The relays share a single SSH connection, opened as a control master before the listeners start. Without it every connection would pay a full handshake — a notebook UI opens dozens — and the login node would see a session per connection. Because they share one TCP connection they also share its head-of-line blocking, which is fine for a UI and less so for bulk transfer.

Two things to check when picking exec:

  • Which netcat. nc varies. netcat-traditional does not propagate a half-close, so a client that closes its write side can leave the connection hanging; nc -q 1 or ncat avoids it. Set ExecConnectCommand accordingly.
  • Process limits. With ForwardTarget: login, even multiplexed, a netcat runs on the login node per connection. Sites with per-user process caps will notice a busy shadow. With ForwardTarget: node there is one netcat per tunnel, carrying the session to the compute node's sshd.

Authentication​

Public key​

ssh-keygen -t ed25519 -f ./hpc_key -N ''
ssh-copy-id -i ./hpc_key.pub alice@login.hpc.example.org

kubectl create secret generic hpc-ssh-key -n interlink \
--from-file=id_ed25519=./hpc_key
SSH:
Auth: publickey
KeySecret: hpc-ssh-key

A key for the tunnel only​

The shadow's key is copied into every namespace a shadow runs in (see Credential replication), so plan for it to leak. Never reuse the plugin's key, which can submit jobs. Create a key for the tunnel alone and restrict it in the HPC account's ~/.ssh/authorized_keys, which login and compute nodes usually share:

restrict,port-forwarding,from="<cluster egress>,<login nodes>",command="$HOME/.interlink/tunnel-wrapper" ssh-ed25519 AAAA... interlink-tunnel
  • restrict turns off port, agent and X11 forwarding and terminal allocation.
  • port-forwarding turns port forwarding back on, which ForwardTarget: node needs in both modes (the forwards are -L on the compute node), as do ForwardMode: portforward on the login node and the reverse tunnel. Only a deployment with ForwardTarget: login, ForwardMode: exec and no reverse tunnel can drop it: sshd then forwards nothing for this key, but the wrapper's nc lines still relay to any host and port the login node reaches, so from= stays the main limit.
  • from= lists where the key may be used from: the cluster's egress addresses for the login hop, and the login nodes, as the compute nodes see them, for the hop to a compute node. This is the main limit. A key that may forward, or run the wrapper's nc, can reach anything the login node or a compute node reaches, and permitopen has no way to say "any compute node".
  • command= runs the wrapper below in place of any shell or command the client asks for.

~/.interlink/tunnel-wrapper, executable by the account (chmod 700):

#!/bin/sh
# The only commands the interLink tunnel key may run. Forwarding (-W, -L, -R) and
# "ssh -N" open no session and never reach this script.
NC='nc' # the virtual kubelet's ExecConnectCommand
c=${SSH_ORIGINAL_COMMAND:-}
case $c in *'
'*) echo "tunnel key: refused" >&2; exit 1 ;; esac
h="'?[A-Za-z0-9][A-Za-z0-9._:-]*'?"
ok() { printf '%s\n' "$c" | grep -Eqx -- "$1"; }
if ok "$NC $h [0-9]{1,5}" ||
ok 'cat /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts2'; then
exec /bin/sh -c "$c"
fi
echo "tunnel key: refused: $c" >&2
exit 1

It allows the netcat relays of exec mode and the read of the login node's host key list that NodeHostKeys: verify does, and nothing else: no shell, no scp, no job submission. Set NC to the virtual kubelet's ExecConnectCommand. The newline check matters: grep -x matches line by line, so a second line could otherwise ride along. The reverse tunnel needs a few more lines.

As written, h accepts any host, so the relays reach whatever the login node reaches. A site can narrow them by setting h to its node-name pattern, for example h="'?node[0-9]+\.nodes\.example\.org'?".

This works for Auth: publickey only. A keytab is the account's own credential and cannot be restricted this way. It does not work with Reverse.Sshd: userspace either.

Kerberos​

For GSSAPI sites (GSSAPIAuthentication yes on the login node):

kubectl create secret generic hpc-keytab -n interlink \
--from-file=user.keytab=/path/to/user.keytab
SSH:
Auth: kerberos
KeytabSecret: hpc-keytab
Principal: alice@EXAMPLE.ORG
Krb5ConfigMap: krb5-config # if the image's /etc/krb5.conf lacks your realm

The shadow runs kinit in an init container and refreshes the ticket from a sidecar for the life of the tunnel, so long-running notebooks survive ticket expiry.

The ticket is not forwarded to the login node or to compute nodes (GSSAPIDelegateCredentials=no): nothing the shadow runs there needs it. If a site requires it on the login node, add GSSAPIDelegateCredentials=yes to ExtraOptions. The one exception is the reverse tunnel's last-resort carrier, Reverse.NodeExec: srun: srun runs on the login node and needs the ticket there, so the login hop then delegates it. The hop to a compute node never does.

Host key verification​

Kerberos and public keys both prove who the client is. Only the host key proves the server is the one you meant to reach.

Login node​

Without KnownHostsConfigMap the shadow uses StrictHostKeyChecking=accept-new, which trusts whatever key the login node presents on first contact. That is a small MITM window on every new shadow pod. For production, pin the key:

ssh-keyscan login.hpc.example.org > known_hosts
kubectl create configmap hpc-known-hosts -n interlink --from-file=known_hosts
SSH:
KnownHostsConfigMap: hpc-known-hosts

This switches the shadow to StrictHostKeyChecking=yes.

Compute nodes​

With ForwardTarget: node, and for the reverse tunnel whatever the target, the shadow opens a second session, through the login node, to the compute node's own sshd, and checks that node's host key too. The one exception is a user-space sshd reached with Reverse.NodeExec: srun. NodeHostKeys decides how:

  • verify (default): the key must be listed, and ssh runs with StrictHostKeyChecking=yes. At each start the shadow collects the keys it trusts from the KnownHostsConfigMap file and from the login node's /etc/ssh/ssh_known_hosts and ssh_known_hosts2, read over the login connection. Some sites list their nodes there, often as a single @cert-authority line; verify then needs only the login node's key pinned in KnownHostsConfigMap (see below).
  • accept-new: any key is accepted, with a warning in the virtual kubelet and shadow logs. This protects nothing: the shadow starts from an empty list every time, so every start is a first contact.

Verifying the node stops a host that pretends to be it, anywhere on the HPC network, from receiving the tunnel and the traffic in it.

If the login node does not list the nodes, add them to the ConfigMap's known_hosts, next to the login node's key, in one of these forms:

# one key shared by every node
*.nodes.example.org ssh-ed25519 AAAA...
# the CA that signs the nodes' host certificates
@cert-authority *.nodes.example.org ssh-ed25519 AAAA...
# one line per node
node07.nodes.example.org ssh-ed25519 AAAA...

Names are matched against what the plugin reports, hostname -f for the Slurm plugin. To see whether the nodes share a key, scan two of them from the login node and compare the fingerprints:

ssh <user>@<login node> "ssh-keyscan -t ed25519 <node a> <node b> 2>/dev/null" | ssh-keygen -lf -

The same fingerprint twice means one host-pattern line covers every node. Two different ones mean each node has its own key: ask the site for its CA or its list of node keys.

Pin the login node's key as well. Without it the login connection is itself accept-new, and node keys read over it are only as trustworthy as that first contact: an impersonated login node could serve false ones. The virtual kubelet warns at startup in that case.


How the compute node is discovered​

The shadow is created when the pod is, which is long before the batch system has scheduled anything — so at creation time there is no node to forward to yet.

  1. interLink creates a ConfigMap, <shadow>-node, holding two empty keys, compute-node and socket-dir.
  2. The plugin reports the allocated node as PodStatus.NodeName once the job runs, and, if it supports socket ports, the pod's socket directory as PodStatus.SocketDir.
  3. interLink patches both into the ConfigMap. It is mounted, not injected into the pod spec, so kubelet refreshes it in place — restarting the shadow would change its pod IP, which Kubernetes has already been told is the offloaded pod's IP.
  4. The shadow's wait-for-node init container polls the mounted node name, and the socket directory when the pod has socket ports or a reverse tunnel. Then the tunnels start: ssh-forward for exposed ports, ssh-reverse for a reverse tunnel.

While the job is queued the shadow sits in Init:0/1. That is the expected state, not a failure — it reads as "waiting for the allocation" rather than a crash-looping tunnel. After NodeWaitTimeout the init container fails with an explicit message.

If the job is later requeued onto a different host, the plugin reports the new one, interLink republishes it, and the shadow rebuilds its forwarders in place:

compute node changed from node07.hpc.example.org to node11.hpc.example.org, rebuilding the tunnel

With ForwardTarget: node the line is compute node or socket directory changed, rebuilding the tunnel.

The container is not restarted, so the shadow keeps its pod IP — the one Kubernetes has already been told is the offloaded pod's IP. With ForwardTarget: node it also rebuilds when the socket directory changes, and while the node refuses it, for example because a requeued job is not running there yet, it retries every 30 seconds.

warning

This requires a plugin that reports PodStatus.NodeName. A plugin that does not will leave the shadow waiting until the timeout expires. Socket ports also need PodStatus.SocketDir, which the Slurm plugin reports only when its SocketDirRoot is set.

What a plugin may report​

The reported name ends up as an argument to ssh, so interLink accepts only an RFC 1123 hostname or an IP literal and refuses anything else rather than trying to escape it:

Refusing to publish compute node "node07 -oProxyCommand=..." for ns/pod:
not a hostname or IP address. The shadow passes this to ssh, so it is rejected
rather than escaped.

A name carrying whitespace would otherwise split into an extra ssh option, and one carrying a quote or $( would break out of the relay command in exec mode. Plugins should report what the node calls itself — hostname -f for the Slurm plugin — and nothing else.

PodStatus.SocketDir must be an absolute path of at most 92 bytes, so that <dir>/fwd-65535.sock fits the 107-byte limit of a unix socket path. Each component may hold only letters, digits, ., _ and -, and starts with a letter, a digit or _. An invalid directory is logged and published empty, so socket ports keep waiting. Report it only together with NodeName, once the job has created the directory.


Credential replication​

Shadow pods follow the offloaded pod. With interlink.eu/shadow-same-ns: "true" — the usual choice for multi-tenant setups such as Kubeflow notebooks — that means the shadow lands in a per-user namespace, where the SSH credential does not exist.

By default interLink copies the credential Secret, and any Krb5ConfigMap / KnownHostsConfigMap, from its own namespace into the shadow's namespace. The Secret is the shadow's own, KeySecret or KeytabSecret, and nothing else is copied. Since the copy is readable there, make KeySecret a key for the tunnel only.

Copies are marked with interlink.eu/replicated-from, and only objects carrying that annotation are overwritten on a later pass. If an object of the same name is already there and holds something else, pod creation fails rather than replacing it:

refusing to overwrite secret alice/hpc-ssh-key: it already exists, holds different
content and was not created by interLink

That matters with shadow-same-ns, where the target is somebody's own namespace and a name collision would otherwise destroy their Secret. An unmarked copy whose content already matches is adopted instead of refused, so upgrading from a version that predates the marker does not break existing deployments.

warning

Replication makes the credential readable by anyone who can read Secrets in those namespaces. If that is not acceptable, set ReplicateCredentials: false and provision the Secret in each namespace yourself, through a secrets operator or a replication controller.


Where the workload listens​

The tunnel hands each connection to an address on the compute node, and the workload has to listen there. That choice also decides who else on the HPC side can connect:

  • 0.0.0.0: anyone who can reach the node over the network can connect.
  • 127.0.0.1: every user with a job or a login on that node can connect.
  • A socket in a 0700 directory: the kernel checks the permissions on every connect, so only your account gets in.

With ForwardTarget: node, in order of preference:

  1. A unix socket. The workload listens on $INTERLINK_SOCKET_DIR/fwd-<port>.sock and the pod lists the port in interlink.eu/shadow-socket-ports, as in the example below. It needs a plugin that provides a socket directory.
  2. TCP on 127.0.0.1, only when the job has the whole node, so that no other user's job runs there: slurm-job.vk.io/flags: "--exclusive" with the Slurm plugin.
  3. Never 0.0.0.0. The forward does not need it, and it opens the workload to the whole HPC network.

With ForwardTarget: login the login node connects to the node's address, so the workload has to listen on it, which in practice means 0.0.0.0 and the exposure of the first line above. Keep the application's own authentication on, or move to the node target.

The socket directory keeps out other HPC accounts. It does not keep out other jobs of the same account, the node's administrators, or anything in the cluster that can reach the shadow's Service: keep the application's own authentication, and restrict the Service with a NetworkPolicy.

The server behind a forward must run on the batch node, the one the plugin reports as NodeName. A unix socket is reachable only on the host that bound it, so ranks of a multi-node job on other nodes cannot be forwarded: multi-node jobs are out of scope.

The socket directory​

The plugin picks a directory for each pod. The job creates it with mode 0700 when it starts, fails rather than use one it did not create, and removes it when it ends. Every container sees it at the same path, in INTERLINK_SOCKET_DIR.

For the Slurm plugin, set SocketDirRoot in its configuration; each pod gets <SocketDirRoot>/<first 12 hex digits of the pod UID>. The root must be:

  • on a filesystem that both the job and an ssh session on the node see, never node-local /tmp, which some sites make private to each job;
  • at most 79 bytes long, so that the longest socket path, <root>/<12 digits>/fwd-65535.sock, fits the 107-byte limit;
  • owned by the account with mode 0700, never writable by other accounts. Where others can write, they can create a pod's directory first and make its job fail.

Pod configuration​

An offloaded pod that exposes a port gets a shadow. With the node target, a notebook listening on a socket looks like this:

apiVersion: v1
kind: Pod
metadata:
name: notebook
annotations:
# Keep the shadow in this pod's namespace, so it can mount credentials
# replicated here rather than into a separate <ns>-shadow namespace.
interlink.eu/shadow-same-ns: "true"
# Forward 8888 to $INTERLINK_SOCKET_DIR/fwd-8888.sock instead of a TCP port.
interlink.eu/shadow-socket-ports: "8888"
spec:
nodeSelector:
kubernetes.io/hostname: hpc-vk
tolerations:
- key: virtual-node.interlink/no-schedule
operator: Exists
effect: NoSchedule
containers:
- name: jupyter
image: docker://jupyter/scipy-notebook
command:
- sh
- -c
- >-
exec jupyter lab --no-browser
--ServerApp.sock=$INTERLINK_SOCKET_DIR/fwd-8888.sock
--ServerApp.allow_remote_access=True
ports:
- containerPort: 8888
name: notebook

Jupyter Server creates the socket with mode 0600 by default. Keep its token: the socket keeps out other HPC users, but anything in the cluster that reaches the shadow's Service still reaches the notebook. allow_remote_access only turns off Jupyter's check of the Host header: listening on a socket or on loopback, Jupyter otherwise answers 403 to any name but localhost, so to every request through an Ingress or the Service. The token stays on.

Without a socket directory, give the job the whole node and listen on loopback: slurm-job.vk.io/flags: "--exclusive" and --ip=127.0.0.1 --ServerApp.allow_remote_access=True. With ForwardTarget: login the notebook needs --ip=0.0.0.0 instead, with the exposure described in Where the workload listens.

The shadow's Service carries the same ports, so anything that can reach the Service — an Ingress, an Istio VirtualService, kubectl port-forward — reaches the notebook.

interlink.eu/wstunnel-extra-ports works here too, for ports not declared in the container spec.

note

ssh -L forwards TCP only. UDP ports are skipped, with a warning in the virtual kubelet log.


Pod to cluster: the reverse tunnel​

Everything above carries connections from the cluster to the pod. A workload that needs the other direction, an object store, a message bus or the Kubernetes API that only exist inside the cluster, gets it over the same login node. The site switches it on with Network.SSH.Reverse.Enabled: true; the pod lists what it needs:

apiVersion: v1
kind: Pod
metadata:
name: trainer
annotations:
interlink.eu/reverse-forwards: "minio.user.svc.cluster.local:9000 6443:kubernetes.default.svc.cluster.local:443"

The workload then uses the Service name and port as it would in the cluster, http://minio.user.svc.cluster.local:9000 here. The compute node needs no route to the cluster, no WireGuard and no network namespace, so its own interfaces, InfiniBand included, stay visible to the job.

How it works​

job container ──connect name:port──> relay on 127.x.y.z:port (started by the job)
│ checks the caller's user
▼
<socket dir>/rev-<port>.sock (compute node's sshd, -R)
│ carried back over the shadow's ssh session
▼
shadow pod (ssh-reverse) ──dials──> Service inside the cluster
  1. The virtual kubelet prepends a snippet to the pod's slurm-job.vk.io/pre-exec. When the job starts, it launches a small Python relay on the compute node that listens on a loopback address derived from the pod UID (127.x.y.z), one port per forward, for as long as the job runs. It maps the forwarded names to that address in the container's /etc/hosts (through SINGULARITY_BIND and APPTAINER_BIND) and holds the workload until the tunnel is up, for at most ten minutes. The workload itself is unchanged.
  2. The shadow runs a second container, ssh-reverse. Once the compute node and the pod's socket directory are known, it logs in to the compute node's own sshd through the login node, the same way and with the same host key check as ForwardTarget: node, and asks it with ssh -R for one unix socket per forward, rev-<port>.sock in the socket directory. The session runs nothing but a wait that ends when the job removes that directory.
  3. For each connection, the relay checks that it comes from the job's user and hands it to the matching socket. sshd carries it back over the session, and the shadow pod dials the endpoint from inside the cluster.

The tunnel is rebuilt if the job moves to another node, like the forwards. While it is down, the relay keeps its address and closes new connections at once.

What the site has to allow​

The reverse tunnel always ends on the compute node, whatever ForwardTarget says. With the default Reverse.NodeExec: ssh it gets there the way ForwardTarget: node does, so it needs the same: -W or nc <node> 22 on the login node, as ForwardMode says, and an ssh login to a node where the account has a running job. With Reverse.NodeExec: srun it needs squeue and srun --jobid=<job> --overlap on the login node instead and, with Reverse.Sshd: node, a netcat on the compute nodes (ExecConnectCommand) and a login to the node's sshd from 127.0.0.1. On top of that:

  • Remote forwarding to a unix socket on the compute node's sshd, AllowStreamLocalForwarding yes (the default) or remote, in both forward modes. A SOCKS proxy also needs AllowTcpForwarding yes or remote there, and GatewayPorts other than yes, which would bind it on every address of the node.
  • A socket directory from the plugin: SocketDirRoot in the Slurm plugin, see The socket directory. The relay and the sockets live there.
  • python3 on the compute nodes (Reverse.PythonPath), which runs the relay. It is stock on most distributions and needs no root.

Where the compute node's sshd refuses that forwarding, an sshd the shadow starts in the job can take its place, see A user-space sshd.

Annotations​

AnnotationValue
interlink.eu/reverse-forwardsSpace-separated endpoints, each host:port or listen-port:host:port
interlink.eu/reverse-socks-portPort of a SOCKS5 proxy for endpoints not listed; off when unset, refused unless the virtual kubelet sets Reverse.AllowSocks
interlink.eu/reverse-bindThe 127.x.y.z address the relay listens on, instead of the derived one

The relay runs as the job's user, so it cannot bind a port below 1024: give such an endpoint a listen port, 6443:kubernetes.default.svc.cluster.local:443, and the job connects to port 6443. The name resolves to the right address either way. An annotation that does not parse is refused when the pod is created, with the reason in the virtual kubelet log and the pod's events.

The carrier to the compute node and the sshd that makes the forwards are the site's choice, set in the virtual kubelet configuration (Reverse.NodeExec, Reverse.Sshd); a pod cannot change them.

Endpoints not known in advance​

warning

A SOCKS proxy lets every user of the compute node reach, through it, any endpoint the shadow reaches in the cluster. ssh has no unix socket form of it, so it listens on 127.0.0.1 of the node and neither the relay nor the socket directory protects it. It is off unless the virtual kubelet sets Reverse.AllowSocks: true. A site that agreed to a reverse tunnel with fixed endpoints and no proxy has not agreed to this: ask before turning it on.

With AllowSocks, interlink.eu/reverse-socks-port: "1080" adds a SOCKS5 proxy on 127.0.0.1:1080 of the compute node. A program told to use it, ALL_PROXY=socks5h://127.0.0.1:1080 for curl and Python requests, reaches any cluster address by name, resolved inside the cluster at connect time. Declare what you can in interlink.eu/reverse-forwards and keep SOCKS for the rest.

  • Without AllowSocks, a pod that sets the annotation is refused when it is created.
  • With it, the pod gets a ReverseSocksProxy warning event, and the virtual kubelet and the shadow log a warning.
  • Every pod's proxy is on 127.0.0.1, so two pods on one compute node cannot use the same port. If another user already listens on it, the job fails at start. If another pod of the same account does, the job cannot tell, and the shadow's tunnel fails instead, see Troubleshooting.

Who else can use the forwards​

Only the job's user. A port on a loopback address is reachable by every user of the compute node, so the relay accepts a connection only when the connecting socket belongs to the job's user (read from /proc/net/tcp), and the socket behind it is created by sshd with mode 0600 inside the 0700 socket directory. This is always on.

The job holds the relay's address from its start to its end, so nobody else can take it later, not even while the tunnel is being rebuilt. If something already listens there when the job starts, the relay cannot bind and the job fails rather than run with a stranger's listener in its place.

It does not keep out other jobs of the same account, or the node's administrators.

A user-space sshd​

With Reverse.Sshd: userspace the forwards are made by an sshd the shadow starts on the compute node, as the job's user, instead of the node's own. It runs as sshd -i, with an ssh session's stdin and stdout as its transport, so it listens on no port. Its host key and the one client key it accepts are generated for each start. The client's private key never leaves the shadow; the host's private key and the client's public key are written to the socket directory, next to a configuration that allows remote forwarding and nothing else, and go away with it. The relay, the sockets and the owner check are the same as above.

It needs the sshd binary on the node (Reverse.SshdPath), and a key allowed to run any command on the node, or on the login node with Reverse.NodeExec: srun, because the shadow sends the script that prepares it. It does not work with a key for the tunnel only.

With Reverse.NodeExec: srun no session reaches the node's own sshd, so NodeHostKeys does not apply: the shadow checks only the host key it generated, which it sends through the login node.

With a key for the tunnel only​

With the default Reverse.Sshd: node, a key for the tunnel only works. Keep port-forwarding in its authorized_keys line, since -R needs it in both forward modes. In the wrapper, define the directory pattern next to h=, with the plugin's SocketDirRoot in place of /gpfs/projects/example/interlink, its regex metacharacters escaped:

d='/gpfs/projects/example/interlink/[0-9a-f]{12}'

Keep it this narrow: the rm -f line below lets the key delete any rev-*.sock the account owns under a directory d matches.

and insert these lines into its if, before its last condition, the ok 'cat /etc/ssh/ssh_known_hosts ...'; then line:

   ok "rm -f $d/rev-\*\.sock" ||
ok "while \[ -d $d \]( && \[ -S $d/rev-[0-9]{1,5}\.sock \])*; do sleep 10; echo; done" ||
ok "squeue -h --me -t R -n [0-9a-f-]{36} -o '%i %B'" ||
ok "srun --jobid=[0-9]+ --overlap -u -n1 -w [A-Za-z0-9][A-Za-z0-9._-]* --cpus-per-task=1 $NC 127\.0\.0\.1 22" ||

The first two run on the compute node: one clears the sockets a previous session left behind, before the forwards are requested, and the other is the wait that holds the session. The last two are the srun carrier, run on the login node. With it the compute node's sshd sees the session come from 127.0.0.1, so add that address to from=.

Limits​

  • TCP only.
  • The relay and the sockets exist only on the batch node, the one the plugin reports as NodeName, and so does the file that maps the names, as long as TMPDIR is node-local. Ranks of a multi-node job on other nodes then fail instead of reaching anything. With TMPDIR on a shared filesystem they resolve the names to an address with no relay behind it, where another user of their node could listen. Multi-node jobs are out of scope.
  • The tunnel comes up once the shadow has learned the compute node, a status poll or two after the job starts; the pre-exec waits for it.
  • The pre-exec assumes the Slurm plugin with Singularity or Apptainer, as the mesh pre-exec does, and a plugin that reports a socket directory.
  • The sockets, the relay and, with a user-space sshd, its keys and configuration live in the pod's socket directory. The job removes it when it ends, and the tunnel session and the relay end with it.

Performance​

Reverse.NodeExec: srun reaches the compute node with srun --jobid=<job> --overlap -w <batch host> on the login node, running inside the allocation ExecConnectCommand to 127.0.0.1:22 with Reverse.Sshd: node, or the user-space sshd itself with userspace, so the tunnel goes through Slurm's I/O forwarding, which has lower throughput than ssh. It is a last resort, for nodes the login node cannot reach over ssh. Under Kerberos it is also the one case where the login hop delegates the ticket, see Kerberos. The owner-only relay adds no measurable cost.


Troubleshooting​

Shadow stuck in Init:0/1. Normal while the job is queued. If it persists, check that the job is actually running and that the plugin reports the node:

kubectl get configmap <shadow>-node -o jsonpath='{.data.compute-node}'

Empty means no plugin has reported one yet.

waiting for the plugin to report a socket directory in the wait-for-node log. The pod lists socket ports or asks for a reverse tunnel, but the plugin has not reported a socket directory, and one without socket support never will: set SocketDirRoot in the Slurm plugin. After NodeWaitTimeout the init container fails with timed out waiting for a socket directory. What has been reported so far:

kubectl get configmap <shadow>-node -o jsonpath='{.data.socket-dir}'

ssh-forward crash-loops (login target) or repeats the tunnel to <node> is down; retrying in 30s (node target), with a permission error. The credential Secret is missing from the shadow's namespace, or KeySecretKey does not match the key inside it. With ReplicateCredentials: false the Secret must already exist there.

Connection refused or reset through the tunnel. The tunnel reached the compute node but nothing listens where it connects.

  • With ForwardTarget: node that is 127.0.0.1:<port> on the batch node, or $INTERLINK_SOCKET_DIR/fwd-<port>.sock for socket ports. Check that the server listens there and runs on that node. A pod created before SocketDirRoot was set or changed is given a directory its job never created: recreate the pod.
  • With ForwardTarget: login the login node connects to the node's address, which a server on 127.0.0.1 does not listen on. Read Where the workload listens before binding 0.0.0.0, or move to the node target.

Connection reset, and channel N: open failed: administratively prohibited in the ssh-forward log. An sshd refuses port forwarding for this account. With ForwardTarget: login it is the login node's. With node it is either the login node's, refusing -W when the tunnel starts (followed by stdio forwarding failed), or the compute node's, refusing -L when traffic arrives. ForwardMode: exec avoids only the first: the login node then runs nc <node> 22 instead of forwarding, but the forwards stay -L on the compute node. If the compute node refuses, have the site allow it or use ForwardTarget: login.

Host key verification failed. With ForwardTarget: login, KnownHostsConfigMap does not contain the login node's current key. Re-run ssh-keyscan and update the ConfigMap.

With node, and in the ssh-reverse log, it can also be the compute node's key. A line no host key for <node>: ... just before it means nothing in the list matches the node's name: add its key, a host pattern or an @cert-authority line, as in Compute nodes. That line is not printed when the list holds any @cert-authority line, so without it, first check that a line covers the reported name: ssh-keygen -F <node> -f known_hosts, against the ConfigMap's file and the login node's /etc/ssh/ssh_known_hosts. With a CA line, the node's certificate must also list that name as a principal. If both hold, the node presented a key or certificate the list does not accept. That is exactly what the check is for: ask the site whether the node was reinstalled before changing the ConfigMap.

Refusing to publish compute node ... in the virtual kubelet log, and the shadow stays in Init:0/1. The plugin reported something that is not a hostname or an IP address, so it was not passed to ssh. See what a plugin may report; the plugin needs fixing, and the value it produced is quoted in the message.

Pod creation fails with refusing to overwrite secret .... The shadow's namespace already contains a different object under the credential's name. Rename the credential, or set ReplicateCredentials: false and provision it yourself.

interLink: the reverse tunnel did not come up within 600s in the job log. The shadow's ssh-reverse container never got through. In its log each failed attempt ends in the reverse tunnel to <node> is down; retrying in 30s, and the lines before it say why:

  • could not clear <dir> on <node>: the session to the compute node failed. It goes the same way as with ForwardTarget: node, so the lines before it read as in the entries above: a host key the list does not accept, or a login the node refuses.
  • remote port forwarding failed for listen path <dir>/rev-<port>.sock: the compute node's sshd refuses forwarding to a unix socket (AllowStreamLocalForwarding), or the key lacks port-forwarding. Have the site allow it, or set Reverse.Sshd: userspace. For the SOCKS port the line ends in listen port <port>: the setting is AllowTcpForwarding, or something already listens on 127.0.0.1:<port> on that node (ss -ltnp), possibly another pod of the same account. Pick another interlink.eu/reverse-socks-port.
  • could not prepare <dir> on <node>, with Reverse.Sshd: userspace: the session that writes the user-space sshd's files into the socket directory failed (the login to the node, srun, or cd into the directory). A wrong Reverse.SshdPath shows up instead as the inner ssh failing to connect, just before the retry line.
  • no running job named ..., with Reverse.NodeExec: srun: squeue on the login node did not list a running job under the pod's UID.

interLink: the reverse tunnel needs a plugin with SocketDirRoot set in the job log. The plugin gave the job no socket directory. Set SocketDirRoot in the Slurm plugin, see The socket directory.

interLink: the reverse relay stopped, see above in the job log. The relay did not start. relay: cannot listen on 127.x.y.z:<port>: ... just before it means something already listens on the pod's relay address; ss -ltnp on the node shows what. If it belongs to another user, the job failed on purpose rather than run behind it: report it to the site. Without that line, check Reverse.PythonPath.

interLink: another user listens on the SOCKS port in the job log. Another user holds 127.0.0.1:<port> on the compute node. Pick another interlink.eu/reverse-socks-port.

interLink: the SOCKS proxy listens on every address of the node in the job log. The node's sshd sets GatewayPorts yes, so the proxy would be open to other machines, and the job fails rather than run with it. Ask the site for GatewayPorts no or clientspecified for the account, or drop interlink.eu/reverse-socks-port.

Pod creation fails with interlink.eu/reverse-forwards: .... The annotation did not parse; the message names the entry and what is wrong with it.

Pod creation fails with ... does not allow a SOCKS proxy. The pod sets interlink.eu/reverse-socks-port and the virtual kubelet does not set Reverse.AllowSocks. List the endpoints in interlink.eu/reverse-forwards instead, or read Endpoints not known in advance before asking the site.

An nginx wstunnel Deployment appears instead of the SSH shadow. A custom template file is overriding the built-in one. The virtual kubelet prefers Network.WstunnelTemplatePath over its own templates; the Helm chart stops mounting it in ssh mode, but a hand-written config may still point at one.


References​