Validate public_key_algorithms when the server starts

What does this MR do and why?

An unsupported entry in public_key_algorithms was only caught by x/crypto's NewServerConn, once per incoming connection. gitlab-sshd started, reported healthy, and then refused every SSH connection with unsupported public key authentication algorithm, so a typo survived a successful gitlab-ctl reconfigure and only showed up later as a Git-over-SSH outage.

This MR checks each configured algorithm against ssh.SupportedAlgorithms().PublicKeyAuths and ssh.InsecureAlgorithms().PublicKeyAuths (the same two sets NewServerConn consults) when the server config is built in newServerConfig, and refuses to start with an error that names the offending value. Two tests cover a rejected typo and an accepted list that mixes a current and an insecure-but-accepted algorithm.

References

Differences

Before: With public_key_algorithms: ["rsa-sha2-999"], gitlab-sshd starts and every connection fails.

After: gitlab-sshd exits at startup with unsupported public key authentication algorithm in public_key_algorithms: "rsa-sha2-999".

How to set up and validate locally

  1. Add an invalid entry to sshd.public_key_algorithms in config.yml.
  2. Start gitlab-sshd; it fails immediately with the message above instead of accepting connections it will then reject.
  3. go test ./internal/sshd/ -run TestNewServerConfig.
Edited by Jeston Singh

Merge request reports

Loading
Loading