Categorygithub.com/USTC-vlab/sshmux
modulepackage
0.0.9
Repository: https://github.com/ustc-vlab/sshmux.git
Documentation: pkg.go.dev

# README

sshmux

sshmux is a new, simple implementation of SSH reverse proxy. sshmux was initially developed for Vlab, while we'd like to expand its usage to cover more scenarios.

Build, Run and Test

sshmux requires a Go 1.21+ toolchain to build. You can use go build or make to get the sshmux binary directly in the directory.

You can run the built binary with ./sshmux. Note that you'll need to provide a valid configuration file as described here.

You can perform unit tests with go test or make test. Enable verbose logging with go test -v.

Config

sshmux requires a JSON configuration file to start up. By default it will look at /etc/sshmux/config.json, but you can also specify a custom configuration by passing -c path/to/config.json in the command line arguments. An example file is provided.

The table below shows the available options for sshmux:

KeyTypeDescriptionRequiredExample
addressstringTCP host and port that sshmux will listen on.true"0.0.0.0:8022"
host-keys[]stringPaths to SSH host key files with which sshmux identifies itself.true["/sshmux/ssh_host_ed25519_key"]
apistringHTTP address that sshmux shall interact with.true"http://127.0.0.1:5000/ssh"
tokenstringToken used to authenticate with the API endpoint.true"long-and-random-token"
bannerstringSSH banner to send to downstream.false"Welcome to Vlab\n"
loggerstringUDP host and port that sshmux send log messages to.false"127.0.0.1:5556"
proxy-protocol-allowed-cidrs[]stringCIDRs from which PROXY protocol is allowed.false["127.0.0.22/32"]

Advanced Config

The table below shows extra options for sshmux, mainly for authentication with Vlab backends:

KeyTypeDescriptionExample
recovery-tokenstringToken used to authenticate with the recovery backend. Defaults to token."long-and-random-token"
recovery-serverstringSSH host and port of the recovery server."172.30.0.101:2222"
recovery-username[]stringUsernames dedicated to the recovery server.["recovery", "console"]
all-username-nopasswordboolIf set to true, no users will be asked for UNIX password.true
username-nopassword[]stringUsernames that won't be asked for UNIX password.["vlab", "ubuntu", "root"]
invalid-username[]stringUsernames that are known to be invalid.["user"]
invalid-username-messagestringMessage to display when the requested username is invalid."Invalid username %s."

All of these options can be omitted, if the corresponding feature is not intended to be used.

API server

sshmux requires an API server to perform authentication and authorization for a user.

The API accepts JSON input with the following keys:

KeyTypeDescription
auth_typestringThe authentication type. Always set to "key" at the moment.
usernamestringVlab username. Omitted if the user is authenticating with public key.
passwordstringVlab password. Omitted if the user is authenticating with public key.
public_key_typestringSSH public key type. Omitted if the user is authenticating with username and password.
public_key_datastringBase64-encoded SSH public key payload. Omitted if the user is authenticating with username and password.
unix_usernamestringUNIX username the user is requesting access to.
tokenstringToken used to authenticate the sshmux instance.

The API responds with JSON output with the following keys:

KeyTypeDescription
statusstringThe authentication status. Should be "ok" if the user is authorized.
addressstringTCP host and port of the downstream SSH server the user is requesting for.
private_keystringSSH private key to authenticate for the downstream.
certstringThe certificate associated with the SSH private key.
vmidintegerID of the requested VM. Only used for recovery access.
proxy_protocolintegerPROXY protocol version to use for the downstream. Should be 1, 2 or omitted (which disables PROXY protocol).

Note that if the user is not authorized, the API server should return a status other than "ok", and other keys can be safely ommitted.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author