Skip to content

Extract sshd connections and sessions into their own files and structs

Nick Thomas requested to merge 511-extract-session into main

I want to add some guards against panicking in gitlab-sshd. Right now, a panic anywhere south of handleConn can take down the whole server, affecting unrelated connections. I also want to add some tests to make sure that the anti-panic code does what I want.

To do that, I need to be able to inject some code that will panic at runtime. Since that would be a bug, it's impossible to use acceptance tests to exercise it. I need to be able to inject the panicking code.

To be able to inject code, it needs to be refactored significantly. This MR introduces an injection point at handleConn, where I intend to put the recover() call. This also disentangles a number of data dependencies, which is a nice side-benefit. I stop here because I don't want to introduce behaviour changes alongside such a large diff 😬 . Once merged, I'll add the recover() and a test to internal/ssh/sshd_test.go that calls handleConn with a handler that just panics, and make sure it doesn't bubble up.

Part of #511 (closed)

Edited by Nick Thomas

Merge request reports