SpitfireLoad Testing & APMWhat's new

SQL: SSH tunnel

When a database can be reached only through an SSH server (a bastion, jump host), PostgreSQL, MySQL / MariaDB, SQL Server and Oracle connections can use an SSH tunnel. You then use existing SSH access instead of opening the database port in the firewall. The controller (connection test, statistics and schema reads) and, during a run, every runner reach the database through an SSH client of their own:

  • one SSH connection is opened per runner and connection, and that runner's whole connection pool shares it; it is reconnected if it drops;
  • the database's host name is resolved on the SSH server's side (e.g. db.internal as the bastion sees it).

Who can set it up

Only installation admins add, change or remove the tunnel. Other admins see, in the SSH tunnel section, only the existing target (or None) and the note Only an installation admin can set up or change the SSH tunnel.; the API returns 403 ssh_install_admin_only to them. Workspace admins can still edit the rest of the connection.

Step by step

SSH tunnel sectionSSH tunnel section

  1. In the Connections group of All integrations In Spitfire: /admin/integrations#connections edit the SQL connection or create a new one.

  2. In the SSH tunnel section switch on Connect through an SSH server.

  3. Enter SSH host (e.g. bastion.example.com), SSH port (default 22) and SSH user.

  4. Authentication:

    • key: Generate key pair creates an ed25519 key; the private key never leaves Spitfire and the screen shows a ready authorized_keys line locked to Host / Port (deleted after a day if never saved). Or choose My own key and paste the whole key into Private key (PEM); if it has a passphrase, enter Key passphrase.
    • password: enter SSH password.

    These fields are encrypted with SPITFIRE_SECRET_KEY and never returned by the API.

  5. Click Fetch host key. Spitfire connects to the SSH server, reads the host key and disconnects without logging in. The key type and the SHA256:… fingerprint appear.

    Host key fingerprint confirmationHost key fingerprint confirmation

  6. Get the fingerprints on the SSH server (or from its administrator) and compare with the line of the same type:

    bash
    for f in /etc/ssh/ssh_host_*_key.pub; do ssh-keygen -lf "$f"; done
  7. If the values are exactly the same, click The fingerprints match: trust this key. If you already know the fingerprint, you can also type it into Host key or SHA256 fingerprint as SHA256:… or ssh-ed25519 AAAA….

  8. In Host, write the database's name as the bastion sees it (e.g. db.internal or 10.0.3.15). The most common mistake is writing the outside name the controller sees.

  9. Press Test. The result comes layer by layer: SSH connection, host key, authentication, forwarding permission, database login. When all pass, Save; the connection's row shows user@bastion:22 under the target.

Warning

Never trust a fingerprint without comparing it. Someone in between (a man-in-the-middle) could present their own key, and all traffic, including your database password, would go to them.

Host key verification

The host key is always verified; it cannot be turned off. With an empty field the save is refused: the SSH server's host key or its SHA256 fingerprint is required (fetch it and confirm). If the server later presents a different key, the connection is refused before anything is sent: ssh: the server's host key does not match the confirmed one. If the key really changed, repeat steps 5-7. Tunnel opens, drops and closes are logged with the connection's name; no secret is written.

Removing the tunnel

Edit the connection, switch off Connect through an SSH server and save. The SSH secrets (private key, passwords) are removed too. Only installation admins can do this.

Common problems

Symptom Cause / fix
Fetch host key gets connection refused or a timeout Wrong host/port, or the controller cannot reach the bastion. Try nc -vz bastion 22 from the controller; for runs the runners must reach the bastion too
ssh: the server's host key does not match the confirmed one Ask the server's administrator whether the key changed. If it did, trust the new fingerprint again; if not, do not continue
ssh: handshake failed: unable to authenticate Wrong user, key or password; or the public key is not in ~/.ssh/authorized_keys of the user on the bastion
ssh: the private key is encrypted; enter its passphrase Enter Key passphrase and save
ssh: private key: … The key was pasted incompletely; paste all of it with the -----BEGIN …----- and -----END …----- lines
ssh tunnel to db.internal:5432: … The Host name does not resolve on the bastion, the bastion cannot reach the database port, or AllowTcpForwarding is off in sshd_config. Try nc -vz db.internal 5432 on the bastion

For a tunnel user without a shell, locked to one target, our recommendation: Preparing PostgreSQL.