Documentation
¶
Overview ¶
Package gitssh serves git clone and fetch (protocol v2, git-upload-pack) and push (git-receive-pack, through package gitpush) over SSH, in process, with golang.org/x/crypto/ssh. A client signs in with a public key a user registered through the admin API; the only things it can do afterwards are run git-upload-pack on a repository it may read and git-receive-pack on one it may push to. There is no shell, no pty, no subsystem, no forwarding of any kind, no other channel.
Index ¶
Constants ¶
const ( MaxAuthTries = 3 MaxPreExec = 16 // channel requests tolerated before the exec MaxEnvValueLen = 256 DefaultHandshake = 10 * time.Second DefaultIdle = 30 * time.Second // from the session channel to its exec )
Bounds on one connection.
const DefaultMaxLifetime = time.Hour
DefaultMaxLifetime is the longest an SSH connection lives.
const MaxCommandLen = 512
MaxCommandLen bounds an exec request's command line.
Variables ¶
var ErrCommand = errors.New("only git-upload-pack and git-receive-pack are available: no shell, no other command")
ErrCommand is returned for any command that is not git-upload-pack or git-receive-pack.
var ErrPush = errors.New("push over SSH is not enabled on this forge; it serves clone and fetch only")
ErrPush is returned for git-receive-pack on a server that has no push engine.
Functions ¶
func ExecService ¶
ExecService returns the service a command line asks for (git-upload-pack or git-receive-pack, compared whole), or "" for anything else.
func LoadHostKey ¶
LoadHostKey reads the server's SSH host key from an OpenSSH private key file that must be a regular file, not a symbolic link, owned by this user and closed to group and others (the check the TLS key gets). The key must be ed25519 and carry no passphrase. It is never generated here: a host key made silently at start would change on every redeploy and teach clients to ignore the warning. Make it once with ssh-keygen -t ed25519 -f <file> with an empty passphrase.
func ParseExec ¶
ParseExec reads the command line git sends: git-upload-pack '<path>' or git-receive-pack '<path>' (the path always single-quoted, gitprotocol-pack). The command name is compared whole; the path must be owner/name and holds no quote, backslash or "!" (what git's own quoting would have to escape), so nothing is ever unquoted or interpreted: there is no shell.
Types ¶
type Authenticator ¶
type Authenticator interface {
AuthenticateSSHKey(ctx context.Context, fingerprint string) (login string, err error)
}
Authenticator maps a key fingerprint to the account that registered it.
type Server ¶
type Server struct {
Auth Authenticator
Repos *gitrepo.Service
// Push serves git-receive-pack; nil refuses every push.
Push *gitpush.Pusher
Sessions *gitrepo.Limiter // keyed by account; Total and PerKey caps
HostKey ssh.Signer
Log *slog.Logger
// RequestTimeout bounds one whole git session (0: gitrepo's default).
RequestTimeout time.Duration
// Handshake bounds the SSH handshake and authentication (0: 10 s).
Handshake time.Duration
// Idle bounds the wait for the exec once a session channel is open (0: 30 s).
Idle time.Duration
// MaxConns and MaxConnsPerHost cap open TCP connections (0: the admin
// listener's caps).
MaxConns, MaxConnsPerHost int
// MaxLifetime ends a connection however active it is (0: 1 hour): an account
// disabled, a key revoked or a collaborator removed is never served for
// longer than this by a connection that authenticated before.
MaxLifetime time.Duration
// contains filtered or unexported fields
}
Server is the SSH git server.
func (*Server) Disconnect ¶
Disconnect closes every live connection of login. DisableUser calls it (see store.Store.OnUserDisabled), so a disabled account's sessions end with it.