Skip to content

Commit 7b83d98

Browse files
Merge pull request #4224 from Monokaix/release-1.11
[Cherry-pick v1.11] fix security related issues
2 parents 60e8191 + fba23c8 commit 7b83d98

39 files changed

+77
-19
lines changed

cmd/agent/app/app.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"k8s.io/controller-manager/pkg/clientbuilder"
3333
"k8s.io/klog/v2"
3434

35+
"volcano.sh/apis/pkg/apis/helpers"
3536
"volcano.sh/volcano/cmd/agent/app/options"
3637
"volcano.sh/volcano/pkg/agent/healthcheck"
3738
"volcano.sh/volcano/pkg/agent/utils"
@@ -81,8 +82,11 @@ func RunServer(checker healthcheck.HealthChecker, address string, port int) {
8182
mux.HandleFunc("/healthz", checker.HealthCheck)
8283
mux.Handle("/metrics", promhttp.Handler())
8384
s := &http.Server{
84-
Addr: net.JoinHostPort(address, strconv.Itoa(port)),
85-
Handler: mux,
85+
Addr: net.JoinHostPort(address, strconv.Itoa(port)),
86+
Handler: mux,
87+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
88+
ReadTimeout: helpers.DefaultReadTimeout,
89+
WriteTimeout: helpers.DefaultWriteTimeout,
8690
}
8791
if err := s.ListenAndServe(); err != nil {
8892
klog.Fatalf("failed to start health check server: %v", err)

cmd/controller-manager/app/server.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,17 @@ func Run(opt *options.ServerOption) error {
5858

5959
if opt.EnableMetrics {
6060
go func() {
61-
http.Handle("/metrics", commonutil.PromHandler())
62-
klog.Fatalf("Prometheus Http Server failed %s", http.ListenAndServe(opt.ListenAddress, nil))
61+
mux := http.NewServeMux()
62+
mux.Handle("/metrics", commonutil.PromHandler())
63+
64+
server := &http.Server{
65+
Addr: opt.ListenAddress,
66+
Handler: mux,
67+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
68+
ReadTimeout: helpers.DefaultReadTimeout,
69+
WriteTimeout: helpers.DefaultWriteTimeout,
70+
}
71+
klog.Fatalf("Prometheus Http Server failed: %s", server.ListenAndServe())
6372
}()
6473
}
6574

cmd/scheduler/app/options/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type ServerOption struct {
6767
DefaultQueue string
6868
PrintVersion bool
6969
EnableMetrics bool
70+
EnablePprof bool
7071
ListenAddress string
7172
EnablePriorityClass bool
7273
EnableCSIStorage bool
@@ -141,6 +142,7 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) {
141142
"Enable tracking of available storage capacity that CSI drivers provide; it is false by default")
142143
fs.BoolVar(&s.EnableHealthz, "enable-healthz", false, "Enable the health check; it is false by default")
143144
fs.BoolVar(&s.EnableMetrics, "enable-metrics", false, "Enable the metrics function; it is false by default")
145+
fs.BoolVar(&s.EnablePprof, "enable-pprof", false, "Enable the pprof endpoint; it is false by default")
144146
fs.StringSliceVar(&s.NodeSelector, "node-selector", nil, "volcano only work with the labeled node, like: --node-selector=volcano.sh/role:train --node-selector=volcano.sh/role:serving")
145147
fs.BoolVar(&s.EnableCacheDumper, "cache-dumper", true, "Enable the cache dumper, it's true by default")
146148
fs.StringVar(&s.CacheDumpFileDir, "cache-dump-dir", "/tmp", "The target dir where the json file put at when dump cache info to json file")

cmd/scheduler/app/server.go

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
"context"
2121
"fmt"
2222
"net/http"
23+
"net/http/pprof"
2324
"os"
2425

2526
"volcano.sh/apis/pkg/apis/helpers"
26-
2727
"volcano.sh/volcano/cmd/scheduler/app/options"
2828
"volcano.sh/volcano/pkg/kube"
2929
"volcano.sh/volcano/pkg/scheduler"
@@ -69,11 +69,8 @@ func Run(opt *options.ServerOption) error {
6969
panic(err)
7070
}
7171

72-
if opt.EnableMetrics {
73-
go func() {
74-
http.Handle("/metrics", commonutil.PromHandler())
75-
klog.Fatalf("Prometheus Http Server failed %s", http.ListenAndServe(opt.ListenAddress, nil))
76-
}()
72+
if opt.EnableMetrics || opt.EnablePprof {
73+
go startMetricsServer(opt)
7774
}
7875

7976
if opt.EnableHealthz {
@@ -142,3 +139,31 @@ func Run(opt *options.ServerOption) error {
142139
})
143140
return fmt.Errorf("lost lease")
144141
}
142+
143+
func startMetricsServer(opt *options.ServerOption) {
144+
mux := http.NewServeMux()
145+
146+
if opt.EnableMetrics {
147+
mux.Handle("/metrics", commonutil.PromHandler())
148+
}
149+
150+
if opt.EnablePprof {
151+
mux.HandleFunc("/debug/pprof/", pprof.Index)
152+
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
153+
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
154+
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
155+
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
156+
}
157+
158+
server := &http.Server{
159+
Addr: opt.ListenAddress,
160+
Handler: mux,
161+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
162+
ReadTimeout: helpers.DefaultReadTimeout,
163+
WriteTimeout: helpers.DefaultWriteTimeout,
164+
}
165+
166+
if err := server.ListenAndServe(); err != nil {
167+
klog.Errorf("start metrics/pprof http server failed: %v", err)
168+
}
169+
}

cmd/scheduler/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import (
2929
componentbaseoptions "k8s.io/component-base/config/options"
3030
"k8s.io/klog/v2"
3131

32-
// init pprof server
33-
_ "net/http/pprof"
34-
3532
"volcano.sh/volcano/cmd/scheduler/app"
3633
"volcano.sh/volcano/cmd/scheduler/app/options"
3734
commonutil "volcano.sh/volcano/pkg/util"

cmd/webhook-manager/app/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,11 @@ func Run(config *options.Config) error {
108108
}
109109

110110
server := &http.Server{
111-
Addr: config.ListenAddress + ":" + strconv.Itoa(config.Port),
112-
TLSConfig: configTLS(config, restConfig),
111+
Addr: config.ListenAddress + ":" + strconv.Itoa(config.Port),
112+
TLSConfig: configTLS(config, restConfig),
113+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
114+
ReadTimeout: helpers.DefaultReadTimeout,
115+
WriteTimeout: helpers.DefaultWriteTimeout,
113116
}
114117
go func() {
115118
err = server.ListenAndServeTLS("", "")

docs/design/jobflow/README.md

100755100644
File mode changed.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
sigs.k8s.io/controller-runtime v0.13.0
4747
sigs.k8s.io/yaml v1.4.0
4848
stathat.com/c/consistent v1.0.0
49-
volcano.sh/apis v1.11.1
49+
volcano.sh/apis v1.11.2
5050
)
5151

5252
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,5 +510,5 @@ sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
510510
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
511511
stathat.com/c/consistent v1.0.0 h1:ezyc51EGcRPJUxfHGSgJjWzJdj3NiMU9pNfLNGiXV0c=
512512
stathat.com/c/consistent v1.0.0/go.mod h1:QkzMWzcbB+yQBL2AttO6sgsQS/JSTapcDISJalmCDS0=
513-
volcano.sh/apis v1.11.1 h1:BuewlHccLIJVJmVcBF32KewXJmtwpCjx4d7fxVxG900=
514-
volcano.sh/apis v1.11.1/go.mod h1:FOdmG++9+8lgENJ9XXDh+O3Jcb9YVRnlMSpgIh3NSVI=
513+
volcano.sh/apis v1.11.2 h1:Vz8NzP0af8vyxRccrEUt6/FikD5eeEOnCZRolVzZvK8=
514+
volcano.sh/apis v1.11.2/go.mod h1:FOdmG++9+8lgENJ9XXDh+O3Jcb9YVRnlMSpgIh3NSVI=

installer/helm/chart/volcano/templates/scheduler.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ spec:
185185
{{- if .Values.custom.scheduler_metrics_enable }}
186186
- --enable-metrics=true
187187
{{- end }}
188+
{{- if .Values.custom.scheduler_pprof_enable }}
189+
- --enable-pprof=true
190+
{{- end }}
188191
- --leader-elect={{ .Values.custom.leader_elect_enable }}
189192
{{- if .Values.custom.leader_elect_enable }}
190193
- --leader-elect-resource-namespace={{ .Release.Namespace }}

0 commit comments

Comments
 (0)