As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 444c4ae0 authored by Javiera Tapia's avatar Javiera Tapia
Browse files

Restrict sshd public_key_algorithms

Since https://github.com/golang/crypto/commit/eb61739cd99fb244c7cd188d3c5bae54824e781d
it is now possible to restrict the host_key_algorithms.
This commit allows sshd to restrict them in the server config.
parent 6cb97270
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -98,6 +98,8 @@ sshd:
kex_algorithms: [curve25519-sha256, curve25519-sha256@libssh.org, ecdh-sha2-nistp256, ecdh-sha2-nistp384, ecdh-sha2-nistp521, diffie-hellman-group14-sha256, diffie-hellman-group14-sha1]
# Specified the ciphers allowed
ciphers: [aes128-gcm@openssh.com, chacha20-poly1305@openssh.com, aes256-gcm@openssh.com, aes128-ctr, aes192-ctr,aes256-ctr]
# Specified the available Host Key algorithms
host_key_algorithms: [ssh-rsa, ssh-dss, ecdsa-sha2-nistp256, sk-ecdsa-sha2-nistp256@openssh.com, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521, ssh-ed25519, sk-ssh-ed25519@openssh.com, rsa-sha2-256, rsa-sha2-512]
# SSH host key files.
host_key_files:
- /run/secrets/ssh-hostkeys/ssh_host_rsa_key
Loading
Loading
Loading
Loading
@@ -47,6 +47,7 @@ type ServerConfig struct {
HostCertFiles []string `yaml:"host_cert_files,omitempty"`
MACs []string `yaml:"macs"`
KexAlgorithms []string `yaml:"kex_algorithms"`
HostKeyAlgorithms []string `yaml:"host_key_algorithms"`
Ciphers []string `yaml:"ciphers"`
GSSAPI GSSAPIConfig `yaml:"gssapi,omitempty"`
}
Loading
Loading
Loading
Loading
@@ -36,6 +36,19 @@ var (
"diffie-hellman-group14-sha256",
"diffie-hellman-group14-sha1",
}
supportedHostKeyAlgorithms = []string{
"ssh-rsa",
"ssh-dss",
"ecdsa-sha2-nistp256",
"sk-ecdsa-sha2-nistp256@openssh.com",
"ecdsa-sha2-nistp384",
"ecdsa-sha2-nistp521",
"ssh-ed25519",
"sk-ssh-ed25519@openssh.com",
"rsa-sha2-256",
"rsa-sha2-512",
}
)
type serverConfig struct {
Loading
Loading
@@ -266,6 +279,12 @@ func (s *serverConfig) get(ctx context.Context) *ssh.ServerConfig {
sshCfg.Ciphers = s.cfg.Server.Ciphers
}
if len(s.cfg.Server.HostKeyAlgorithms) > 0 {
sshCfg.PublicKeyAuthAlgorithms = s.cfg.Server.HostKeyAlgorithms
} else {
sshCfg.PublicKeyAuthAlgorithms = supportedHostKeyAlgorithms
}
for _, key := range s.hostKeys {
sshCfg.AddHostKey(key)
}
Loading
Loading
Loading
Loading
@@ -251,6 +251,7 @@ func TestDefaultAlgorithms(t *testing.T) {
require.Equal(t, supportedMACs, sshServerConfig.MACs)
require.Equal(t, supportedKeyExchanges, sshServerConfig.KeyExchanges)
require.Equal(t, supportedHostKeyAlgorithms, sshServerConfig.PublicKeyAuthAlgorithms)
require.Nil(t, sshServerConfig.Ciphers)
sshServerConfig.SetDefaults()
Loading
Loading
@@ -266,6 +267,7 @@ func TestDefaultAlgorithms(t *testing.T) {
"aes192-ctr",
"aes256-ctr",
}
require.Equal(t, sshServerConfig.Ciphers, defaultCiphers)
}
Loading
Loading
@@ -273,13 +275,15 @@ func TestCustomAlgorithms(t *testing.T) {
customMACs := []string{"hmac-sha2-512-etm@openssh.com"}
customKexAlgos := []string{"curve25519-sha256"}
customCiphers := []string{"aes256-gcm@openssh.com"}
customHostAlgos := []string{"rsa-sha2-256"}
srvCfg := &serverConfig{
cfg: &config.Config{
Server: config.ServerConfig{
MACs: customMACs,
KexAlgorithms: customKexAlgos,
Ciphers: customCiphers,
MACs: customMACs,
KexAlgorithms: customKexAlgos,
Ciphers: customCiphers,
HostKeyAlgorithms: customHostAlgos,
},
},
}
Loading
Loading
@@ -288,6 +292,7 @@ func TestCustomAlgorithms(t *testing.T) {
require.Equal(t, customMACs, sshServerConfig.MACs)
require.Equal(t, customKexAlgos, sshServerConfig.KeyExchanges)
require.Equal(t, customCiphers, sshServerConfig.Ciphers)
require.Equal(t, customHostAlgos, sshServerConfig.PublicKeyAuthAlgorithms)
sshServerConfig.SetDefaults()
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment