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

sshd: Extract static proxy policy handler

Instead of interpreting the configuration for every new connection, we
can rely on a closure to simplify the proxy handler path. This is more
similar to how the provided MustStrictWhiteListPolicy works which will
be added in a later commit.
parent 0a8db0d6
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -9,7 +9,7 @@ import (
"sync"
"time"
"github.com/pires/go-proxyproto"
proxyproto "github.com/pires/go-proxyproto"
"golang.org/x/crypto/ssh"
"gitlab.com/gitlab-org/gitlab-shell/v14/client"
Loading
Loading
@@ -97,7 +97,7 @@ func (s *Server) listen(ctx context.Context) error {
if s.Config.Server.ProxyProtocol {
sshListener = &proxyproto.Listener{
Listener: sshListener,
Policy: s.requirePolicy,
Policy: s.requirePolicy(),
ReadHeaderTimeout: time.Duration(s.Config.Server.ProxyHeaderTimeout),
}
Loading
Loading
@@ -200,17 +200,23 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) {
})
}
func (s *Server) requirePolicy(_ net.Addr) (proxyproto.Policy, error) {
func (s *Server) requirePolicy() proxyproto.PolicyFunc {
// 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) {
case "require":
return proxyproto.REQUIRE, nil
return staticProxyPolicy(proxyproto.REQUIRE)
case "ignore":
return proxyproto.IGNORE, nil
return staticProxyPolicy(proxyproto.IGNORE)
case "reject":
return proxyproto.REJECT, nil
return staticProxyPolicy(proxyproto.REJECT)
default:
return proxyproto.USE, nil
return staticProxyPolicy(proxyproto.USE)
}
}
func staticProxyPolicy(policy proxyproto.Policy) proxyproto.PolicyFunc {
return func(_ net.Addr) (proxyproto.Policy, error) {
return policy, nil
}
}
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