Skip to main content

bind

Function bind 

Source
pub fn bind(
    addr: &str,
    jump_hosts: Vec<String>,
    remote_addr: Option<String>,
    sopsfile: &str,
    cmd: Option<String>,
)
Expand description

Binds a local address to a server that forwards incoming TCP connections through a chain of SSH jump hosts to a specified remote address. The server runs in a separate thread.

§Arguments

  • addr - The local address to bind the server to (e.g., “127.0.0.1:8000”).
  • jump_hosts - A vector of SSH jump host addresses (e.g., vec![“jump1.example.com:22”, “jump2.example.com:22”]).
  • remote_addr - The final remote address to forward connections to (e.g., “remote.example.com:80”).
  • sopsfile - The path to a SOPS-encrypted YAML file containing SSH credentials.

§Panics

This function will panic if:

  • The sops command is not found in the system’s PATH.
  • Decrypting the SOPS file fails.
  • Deserializing the decrypted YAML content into credentials fails.
  • Binding to the specified local address fails.

§Example

use std::thread;
use sshbind::bind;

fn main() {
    let addr = "127.0.0.1:8000";
    let jump_hosts = vec!["jump1.example.com:22".to_string(), "jump2.example.com:22".to_string()];
    let remote_addr = "remote.example.com:80";
    let sopsfile = "/path/to/creds.sops.yaml";

    // Start the server in a separate thread
    let server_thread = thread::spawn(move || {
        bind(addr, jump_hosts, remote_addr, sopsfile);
    });

    // Perform other tasks or wait for user input

    // Optionally, join the server thread if you want to wait for its completion
    // server_thread.join().unwrap();
}

Note: Ensure that the sops command-line tool is installed and accessible in the system’s PATH.