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 026975dc authored by James Fargher's avatar James Fargher Committed by James Fargher
Browse files

sshd: Add ProxyAllowed setting to limit PROXY protocol IP addresses

Changelog: added
parent 85830ef0
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -27,6 +27,7 @@ type ServerConfig struct {
Listen string `yaml:"listen,omitempty"`
ProxyProtocol bool `yaml:"proxy_protocol,omitempty"`
ProxyPolicy string `yaml:"proxy_policy,omitempty"`
ProxyAllowed []string `yaml:"proxy_allowed,omitempty"`
WebListen string `yaml:"web_listen,omitempty"`
ConcurrentSessionsLimit int64 `yaml:"concurrent_sessions_limit,omitempty"`
ClientAliveInterval YamlDuration `yaml:"client_alive_interval,omitempty"`
Loading
Loading
Loading
Loading
@@ -201,6 +201,10 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) {
}
func (s *Server) requirePolicy() proxyproto.PolicyFunc {
if len(s.Config.Server.ProxyAllowed) > 0 {
return proxyproto.MustStrictWhiteListPolicy(s.Config.Server.ProxyAllowed)
}
// Set the Policy value based on config
// Values are taken from https://github.com/pires/go-proxyproto/blob/195fedcfbfc1be163f3a0d507fac1709e9d81fed/policy.go#L20
switch strings.ToLower(s.Config.Server.ProxyPolicy) {
Loading
Loading
Loading
Loading
@@ -50,7 +50,7 @@ func TestListenAndServe(t *testing.T) {
verifyStatus(t, s, StatusClosed)
}
func TestListenAndServeRejectsPlainConnectionsWhenProxyProtocolEnabled(t *testing.T) {
func TestListenAndServe_proxyProtocolEnabled(t *testing.T) {
target, err := net.ResolveTCPAddr("tcp", serverUrl)
require.NoError(t, err)
Loading
Loading
@@ -70,10 +70,11 @@ func TestListenAndServeRejectsPlainConnectionsWhenProxyProtocolEnabled(t *testin
}()
testCases := []struct {
desc string
proxyPolicy string
header *proxyproto.Header
isRejected bool
desc string
proxyPolicy string
proxyAllowed []string
header *proxyproto.Header
isRejected bool
}{
{
desc: "USE (default) without a header",
Loading
Loading
@@ -123,11 +124,65 @@ func TestListenAndServeRejectsPlainConnectionsWhenProxyProtocolEnabled(t *testin
header: header,
isRejected: false,
},
{
desc: "Allow-listed IP with a header",
proxyAllowed: []string{"127.0.0.1"},
header: header,
isRejected: false,
},
{
desc: "Allow-listed IP without a header",
proxyAllowed: []string{"127.0.0.1"},
header: nil,
isRejected: false,
},
{
desc: "Allow-listed range with a header",
proxyAllowed: []string{"127.0.0.0/24"},
header: header,
isRejected: false,
},
{
desc: "Allow-listed range without a header",
proxyAllowed: []string{"127.0.0.0/24"},
header: nil,
isRejected: false,
},
{
desc: "Not allow-listed IP with a header",
proxyAllowed: []string{"192.168.1.1"},
header: header,
isRejected: true,
},
{
desc: "Not allow-listed IP without a header",
proxyAllowed: []string{"192.168.1.1"},
header: nil,
isRejected: false,
},
{
desc: "Not allow-listed range with a header",
proxyAllowed: []string{"192.168.1.0/24"},
header: header,
isRejected: true,
},
{
desc: "Not allow-listed range without a header",
proxyAllowed: []string{"192.168.1.0/24"},
header: nil,
isRejected: false,
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
setupServerWithConfig(t, &config.Config{Server: config.ServerConfig{ProxyProtocol: true, ProxyPolicy: tc.proxyPolicy}})
setupServerWithConfig(t, &config.Config{
Server: config.ServerConfig{
ProxyProtocol: true,
ProxyPolicy: tc.proxyPolicy,
ProxyAllowed: tc.proxyAllowed,
},
})
conn, err := net.DialTCP("tcp", nil, target)
require.NoError(t, err)
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