ssh: add trailing newline to key strings if missing (#5716)

OpenSSH requires a trailing newline for private keys, which is easy to
accidentally omit when configuring private keys as strings inline via
copy/paste. This adds the missing newline if it is not present. Private
keys read from files still require the trailing newline.
This commit is contained in:
Joe Kralicky 2025-07-10 13:54:24 -04:00 committed by GitHub
parent e5e9e4c14a
commit 651a7e061f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,7 @@ package envoyconfig
import ( import (
"fmt" "fmt"
"net/url" "net/url"
"strings"
xds_core_v3 "github.com/cncf/xds/go/xds/core/v3" xds_core_v3 "github.com/cncf/xds/go/xds/core/v3"
xds_matcher_v3 "github.com/cncf/xds/go/xds/type/matcher/v3" xds_matcher_v3 "github.com/cncf/xds/go/xds/type/matcher/v3"
@ -52,6 +53,9 @@ func buildSSHListener(cfg *config.Config) (*envoy_config_listener_v3.Listener, e
} }
if cfg.Options.SSHHostKeys != nil { if cfg.Options.SSHHostKeys != nil {
for _, key := range *cfg.Options.SSHHostKeys { for _, key := range *cfg.Options.SSHHostKeys {
if !strings.HasSuffix(key, "\n") {
key += "\n"
}
hostKeyDataSources = append(hostKeyDataSources, &envoy_config_core_v3.DataSource{ hostKeyDataSources = append(hostKeyDataSources, &envoy_config_core_v3.DataSource{
Specifier: &envoy_config_core_v3.DataSource_InlineString{ Specifier: &envoy_config_core_v3.DataSource_InlineString{
InlineString: key, InlineString: key,
@ -67,9 +71,13 @@ func buildSSHListener(cfg *config.Config) (*envoy_config_listener_v3.Listener, e
}, },
} }
} else if cfg.Options.SSHUserCAKey != "" { } else if cfg.Options.SSHUserCAKey != "" {
key := cfg.Options.SSHUserCAKey
if !strings.HasSuffix(key, "\n") {
key += "\n"
}
userCaKeyDataSource = &envoy_config_core_v3.DataSource{ userCaKeyDataSource = &envoy_config_core_v3.DataSource{
Specifier: &envoy_config_core_v3.DataSource_InlineString{ Specifier: &envoy_config_core_v3.DataSource_InlineString{
InlineString: cfg.Options.SSHUserCAKey, InlineString: key,
}, },
} }
} }