Skip to content

Commit 20cf788

Browse files
Merge pull request #4236 from Monokaix/release-1.9
[Cherry-pick v1.9] fix security related issues
2 parents e29c9af + 534331b commit 20cf788

35 files changed

+57
-12
lines changed

cmd/scheduler/app/options/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type ServerOption struct {
6262
DefaultQueue string
6363
PrintVersion bool
6464
EnableMetrics bool
65+
EnablePprof bool
6566
ListenAddress string
6667
EnablePriorityClass bool
6768
EnableCSIStorage bool
@@ -138,6 +139,7 @@ func (s *ServerOption) AddFlags(fs *pflag.FlagSet) {
138139
"Enable tracking of available storage capacity that CSI drivers provide; it is false by default")
139140
fs.BoolVar(&s.EnableHealthz, "enable-healthz", false, "Enable the health check; it is false by default")
140141
fs.BoolVar(&s.EnableMetrics, "enable-metrics", false, "Enable the metrics function; it is false by default")
142+
fs.BoolVar(&s.EnablePprof, "enable-pprof", false, "Enable the pprof endpoint; it is false by default")
141143
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")
142144
fs.BoolVar(&s.EnableCacheDumper, "cache-dumper", true, "Enable the cache dumper, it's true by default")
143145
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,11 +20,11 @@ import (
2020
"context"
2121
"fmt"
2222
"net/http"
23+
"net/http/pprof"
2324
"os"
2425
"time"
2526

2627
"volcano.sh/apis/pkg/apis/helpers"
27-
2828
"volcano.sh/volcano/cmd/scheduler/app/options"
2929
"volcano.sh/volcano/pkg/kube"
3030
"volcano.sh/volcano/pkg/scheduler"
@@ -85,11 +85,8 @@ func Run(opt *options.ServerOption) error {
8585
panic(err)
8686
}
8787

88-
if opt.EnableMetrics {
89-
go func() {
90-
http.Handle("/metrics", promHandler())
91-
klog.Fatalf("Prometheus Http Server failed %s", http.ListenAndServe(opt.ListenAddress, nil))
92-
}()
88+
if opt.EnableMetrics || opt.EnablePprof {
89+
go startMetricsServer(opt)
9390
}
9491

9592
if opt.EnableHealthz {
@@ -160,3 +157,31 @@ func promHandler() http.Handler {
160157
prometheus.DefaultRegisterer.Unregister(collectors.NewGoCollector())
161158
return promhttp.InstrumentMetricHandler(prometheus.DefaultRegisterer, promhttp.HandlerFor(prometheus.Gatherers{prometheus.DefaultGatherer, legacyregistry.DefaultGatherer}, promhttp.HandlerOpts{}))
162159
}
160+
161+
func startMetricsServer(opt *options.ServerOption) {
162+
mux := http.NewServeMux()
163+
164+
if opt.EnableMetrics {
165+
mux.Handle("/metrics", promHandler())
166+
}
167+
168+
if opt.EnablePprof {
169+
mux.HandleFunc("/debug/pprof/", pprof.Index)
170+
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
171+
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
172+
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
173+
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
174+
}
175+
176+
server := &http.Server{
177+
Addr: opt.ListenAddress,
178+
Handler: mux,
179+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
180+
ReadTimeout: helpers.DefaultReadTimeout,
181+
WriteTimeout: helpers.DefaultWriteTimeout,
182+
}
183+
184+
if err := server.ListenAndServe(); err != nil {
185+
klog.Errorf("start metrics/pprof http server failed: %v", err)
186+
}
187+
}

cmd/scheduler/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import (
2121
"runtime"
2222
"time"
2323

24-
// init pprof server
25-
_ "net/http/pprof"
26-
2724
"github.com/spf13/pflag"
2825
_ "go.uber.org/automaxprocs"
2926

cmd/webhook-manager/app/server.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,11 @@ func Run(config *options.Config) error {
102102
signal.Notify(stopChannel, syscall.SIGTERM, syscall.SIGINT)
103103

104104
server := &http.Server{
105-
Addr: config.ListenAddress + ":" + strconv.Itoa(config.Port),
106-
TLSConfig: configTLS(config, restConfig),
105+
Addr: config.ListenAddress + ":" + strconv.Itoa(config.Port),
106+
TLSConfig: configTLS(config, restConfig),
107+
ReadHeaderTimeout: helpers.DefaultReadHeaderTimeout,
108+
ReadTimeout: helpers.DefaultReadTimeout,
109+
WriteTimeout: helpers.DefaultWriteTimeout,
107110
}
108111
go func() {
109112
err = server.ListenAndServeTLS("", "")

docs/design/jobflow/README.md

100755100644
File mode changed.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ spec:
155155
- --scheduler-conf=/volcano.scheduler/{{base .Values.basic.scheduler_config_file}}
156156
- --enable-healthz=true
157157
- --enable-metrics=true
158+
{{- if .Values.custom.scheduler_pprof_enable }}
159+
- --enable-pprof=true
160+
{{- end }}
158161
- --leader-elect={{ .Values.custom.leader_elect_enable }}
159162
{{- if .Values.custom.leader_elect_enable }}
160163
- --lock-object-namespace={{ .Release.Namespace }}

installer/helm/chart/volcano/values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ custom:
1717
controller_replicas: 1
1818
scheduler_enable: true
1919
scheduler_replicas: 1
20+
scheduler_pprof_enable: false
2021
leader_elect_enable: false
2122
enabled_admissions: "/jobs/mutate,/jobs/validate,/podgroups/mutate,/pods/validate,/pods/mutate,/queues/mutate,/queues/validate"
2223

pkg/controllers/jobflow/constant.go

100755100644
File mode changed.

pkg/controllers/jobflow/jobflow_controller.go

100755100644
File mode changed.

pkg/controllers/jobflow/jobflow_controller_action.go

100755100644
File mode changed.

0 commit comments

Comments
 (0)