Skip to content

Commit d7de304

Browse files
Merge pull request #170 from Monokaix/master
[Security] Add http server timeout
2 parents 2d1b261 + 1b58ecf commit d7de304

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

pkg/apis/helpers/helpers.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ import (
4444
schedulerv1beta1 "volcano.sh/apis/pkg/apis/scheduling/v1beta1"
4545
)
4646

47+
const (
48+
// DefaultReadHeaderTimeout defines the default timeout for reading request headers
49+
DefaultReadHeaderTimeout = 5 * time.Second
50+
// DefaultReadTimeout defines the default timeout for reading the entire request
51+
DefaultReadTimeout = 30 * time.Second
52+
// DefaultWriteTimeout defines the default timeout for writing the response
53+
DefaultWriteTimeout = 60 * time.Second
54+
// DefaultMaxHeaderBytes defines the default max size of request headers in bytes
55+
// 1 MB
56+
DefaultMaxHeaderBytes = 1 << 20
57+
)
58+
59+
// JobKind creates job GroupVersionKind.
4760
// JobKind creates job GroupVersionKind.
4861
var JobKind = vcbatch.SchemeGroupVersion.WithKind("Job")
4962

@@ -200,9 +213,12 @@ func StartHealthz(healthzBindAddress, name string, caCertData, certData, certKey
200213
healthz.InstallHandler(pathRecorderMux)
201214

202215
server := &http.Server{
203-
Addr: listener.Addr().String(),
204-
Handler: pathRecorderMux,
205-
MaxHeaderBytes: 1 << 20,
216+
Addr: listener.Addr().String(),
217+
Handler: pathRecorderMux,
218+
MaxHeaderBytes: DefaultMaxHeaderBytes,
219+
ReadHeaderTimeout: DefaultReadHeaderTimeout,
220+
ReadTimeout: DefaultReadTimeout,
221+
WriteTimeout: DefaultWriteTimeout,
206222
}
207223
if len(caCertData) != 0 && len(certData) != 0 && len(certKeyData) != 0 {
208224
certPool := x509.NewCertPool()

0 commit comments

Comments
 (0)