nassh

package module
v0.0.0-...-7e6dead Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2019 License: MIT Imports: 19 Imported by: 1

README

nassh-relay

Build Status godoc

Basic implementation of the nassh relay protocol in Go. This can be used for relaying SSH sessions in the ChromeOS SSH app, but worth noting is that it doesn't contain any SSH specific code - it could be used to relay any TCP connections.

This repository doesn't contain any usable client/server implementations, it's just a library. An example bastion that uses OpenID Connect for auth can be found in https://github.com/lstoll/ssh-bastion.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoginSessionID

func LoginSessionID(ctx context.Context) (string, bool)

LoginSessionID returns the identifier of the login session from the given context

func RemoteAddr

func RemoteAddr(ctx context.Context) (string, bool)

RemoteAddr returns the remote address of the caller

func SSHSessionID

func SSHSessionID(ctx context.Context) (string, bool)

SSHSessionID returns the identifier of the relay session

func UserID

func UserID(ctx context.Context) (string, bool)

UserID returns the unique user identity from the given context

Types

type Relay

type Relay struct {
	// Logger to output information to. If not set, it will be initialized to a
	// null logger.
	Logger logrus.FieldLogger
	// Dialer is called to establish the connection to the backend. If not set,
	// the host:port is dialed with a default net.Dialer
	Dialer func(ctx context.Context, add string) (io.ReadWriteCloser, error)

	// HTTPSession is a HTTP session store. It is used to track state across
	// calls. It should be resistent to tampering, to ensure sessions are not
	// spoofed. If not set, it will be initialized to a new cookie store with a
	// random secret on first use.
	HTTPSession sessions.Store
	// contains filtered or unexported fields
}

Relay is a server implementation of the nassh relay protocol.

Example
// Bare minimum server
r := Relay{}

m := http.NewServeMux()

// cookie is the URL the client calls first
m.HandleFunc("/cookie", func(w http.ResponseWriter, req *http.Request) {
	// this is where you'd handle your authentication flow.

	// Assuming auth is done, this is the last step to continue the SSH
	// process.
	userID := "User from auth flow"
	authSessID := "unique ID to track this login flow"

	ext := req.URL.Query().Get("ext")
	path := req.URL.Query().Get("path")
	version := req.URL.Query().Get("version")
	method := req.URL.Query().Get("method")

	r.StartSession(w, req, userID, authSessID, ext, path, version, method)
})

m.HandleFunc("/proxy", r.ProxyHandler)
m.HandleFunc("/connect", r.ConnectHandler)
Output:

func (*Relay) StartSession

func (r *Relay) StartSession(w http.ResponseWriter, req *http.Request, userID, loginSessID, ext, path, version, method string)

StartSession should be called at the end of the authentication flow that was initialized by a call to /cookie . userID corresponds to a unique identifier for the user, for tracking. loginSessID can track the auth session in use, for referencing later on. The values of ext, path, version, and method should correspond to the query values for the original /cookie call. It should be provided an unused ResponseWriter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL