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

sshd: Return error when proxy policy is misconfigured

MustStrictWhiteListPolicy panics when configured incorrectly. So here we
use the error returning version instead.
parent 95e4909e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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),
}
Loading
Loading
@@ -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
}
}
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