mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #44175 from thaJeztah/22.06_backport_fix_g112_slowlorus
[22.06 backport] set ReadHeaderTimeout to address G112: Potential Slowloris Attack (gosec)
This commit is contained in:
commit
7772535e79
4 changed files with 19 additions and 5 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/server/httpstatus"
|
"github.com/docker/docker/api/server/httpstatus"
|
||||||
"github.com/docker/docker/api/server/httputils"
|
"github.com/docker/docker/api/server/httputils"
|
||||||
|
@ -58,7 +59,8 @@ func (s *Server) Accept(addr string, listeners ...net.Listener) {
|
||||||
for _, listener := range listeners {
|
for _, listener := range listeners {
|
||||||
httpServer := &HTTPServer{
|
httpServer := &HTTPServer{
|
||||||
srv: &http.Server{
|
srv: &http.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
|
ReadHeaderTimeout: 5 * time.Minute, // "G112: Potential Slowloris Attack (gosec)"; not a real concern for our use, so setting a long timeout.
|
||||||
},
|
},
|
||||||
l: listener,
|
l: listener,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
metrics "github.com/docker/go-metrics"
|
metrics "github.com/docker/go-metrics"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -24,7 +25,11 @@ func startMetricsServer(addr string) error {
|
||||||
mux.Handle("/metrics", metrics.Handler())
|
mux.Handle("/metrics", metrics.Handler())
|
||||||
go func() {
|
go func() {
|
||||||
logrus.Infof("metrics API listening on %s", l.Addr())
|
logrus.Infof("metrics API listening on %s", l.Addr())
|
||||||
if err := http.Serve(l, mux); err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
|
srv := &http.Server{
|
||||||
|
Handler: mux,
|
||||||
|
ReadHeaderTimeout: 5 * time.Minute, // "G112: Potential Slowloris Attack (gosec)"; not a real concern for our use, so setting a long timeout.
|
||||||
|
}
|
||||||
|
if err := srv.Serve(l); err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
|
||||||
logrus.WithError(err).Error("error serving metrics API")
|
logrus.WithError(err).Error("error serving metrics API")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/pkg/plugingetter"
|
"github.com/docker/docker/pkg/plugingetter"
|
||||||
"github.com/docker/docker/pkg/plugins"
|
"github.com/docker/docker/pkg/plugins"
|
||||||
|
@ -31,7 +32,11 @@ func (daemon *Daemon) listenMetricsSock() (string, error) {
|
||||||
mux.Handle("/metrics", metrics.Handler())
|
mux.Handle("/metrics", metrics.Handler())
|
||||||
go func() {
|
go func() {
|
||||||
logrus.Debugf("metrics API listening on %s", l.Addr())
|
logrus.Debugf("metrics API listening on %s", l.Addr())
|
||||||
if err := http.Serve(l, mux); err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
|
srv := &http.Server{
|
||||||
|
Handler: mux,
|
||||||
|
ReadHeaderTimeout: 5 * time.Minute, // "G112: Potential Slowloris Attack (gosec)"; not a real concern for our use, so setting a long timeout.
|
||||||
|
}
|
||||||
|
if err := srv.Serve(l); err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
|
||||||
logrus.WithError(err).Error("error serving metrics API")
|
logrus.WithError(err).Error("error serving metrics API")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/libnetwork/internal/caller"
|
"github.com/docker/docker/libnetwork/internal/caller"
|
||||||
"github.com/docker/docker/pkg/stack"
|
"github.com/docker/docker/pkg/stack"
|
||||||
|
@ -94,8 +95,9 @@ func (s *Server) EnableDiagnostic(ip string, port int) {
|
||||||
|
|
||||||
logrus.Infof("Starting the diagnostic server listening on %d for commands", port)
|
logrus.Infof("Starting the diagnostic server listening on %d for commands", port)
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: net.JoinHostPort(ip, strconv.Itoa(port)),
|
Addr: net.JoinHostPort(ip, strconv.Itoa(port)),
|
||||||
Handler: s,
|
Handler: s,
|
||||||
|
ReadHeaderTimeout: 5 * time.Minute, // "G112: Potential Slowloris Attack (gosec)"; not a real concern for our use, so setting a long timeout.
|
||||||
}
|
}
|
||||||
s.srv = srv
|
s.srv = srv
|
||||||
s.enable = 1
|
s.enable = 1
|
||||||
|
|
Loading…
Reference in a new issue