summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Fargher <jfargher@gitlab.com>2022-11-08 10:26:04 +1300
committerJames Fargher <proglottis@gmail.com>2022-11-23 19:25:30 +0000
commitded04466b285ed6d6e45fad13e6fd3437238c301 (patch)
tree9ba770320eca983c2787c213882733abed6eb1b0
parent95e4909e47906f516b5c9ea2b786574fec2a8f65 (diff)
downloadgitlab-shell-ded04466b285ed6d6e45fad13e6fd3437238c301.tar.gz
sshd: Return error when proxy policy is misconfigured
MustStrictWhiteListPolicy panics when configured incorrectly. So here we use the error returning version instead.
-rw-r--r--internal/sshd/sshd.go19
1 files changed, 12 insertions, 7 deletions
diff --git a/internal/sshd/sshd.go b/internal/sshd/sshd.go
index c61d527..d20286a 100644
--- a/internal/sshd/sshd.go
+++ b/internal/sshd/sshd.go
@@ -95,9 +95,14 @@ func (s *Server) listen(ctx context.Context) error {
}
if s.Config.Server.ProxyProtocol {
+ policy, err := s.proxyPolicy()
+ if err != nil {
+ return fmt.Errorf("invalid policy configuration: %w", err)
+ }
+
sshListener = &proxyproto.Listener{
Listener: sshListener,
- Policy: s.requirePolicy(),
+ Policy: policy,
ReadHeaderTimeout: time.Duration(s.Config.Server.ProxyHeaderTimeout),
}
@@ -200,22 +205,22 @@ func (s *Server) handleConn(ctx context.Context, nconn net.Conn) {
})
}
-func (s *Server) requirePolicy() proxyproto.PolicyFunc {
+func (s *Server) proxyPolicy() (proxyproto.PolicyFunc, error) {
if len(s.Config.Server.ProxyAllowed) > 0 {
- return proxyproto.MustStrictWhiteListPolicy(s.Config.Server.ProxyAllowed)
+ return proxyproto.StrictWhiteListPolicy(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) {
case "require":
- return staticProxyPolicy(proxyproto.REQUIRE)
+ return staticProxyPolicy(proxyproto.REQUIRE), nil
case "ignore":
- return staticProxyPolicy(proxyproto.IGNORE)
+ return staticProxyPolicy(proxyproto.IGNORE), nil
case "reject":
- return staticProxyPolicy(proxyproto.REJECT)
+ return staticProxyPolicy(proxyproto.REJECT), nil
default:
- return staticProxyPolicy(proxyproto.USE)
+ return staticProxyPolicy(proxyproto.USE), nil
}
}