Skip to content

Commit 2141040

Browse files
Frapschenliu-cong
authored andcommitted
Adding a flag to control whether auth is added to the EPP metrics server (kubernetes-sigs#1639)
* Adding a flag to control whether auth is added to the EPP metrics server * Update cmd/epp/runner/runner.go Co-authored-by: Cong Liu <[email protected]> * update * apply review's suggestion * apply reviewer's suggestion * rollback interval * update * update README.md * revert gke * update --------- Co-authored-by: Cong Liu <[email protected]>
1 parent 216c8a2 commit 2141040

File tree

7 files changed

+78
-55
lines changed

7 files changed

+78
-55
lines changed

cmd/epp/runner/runner.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
healthPb "google.golang.org/grpc/health/grpc_health_v1"
3838
"k8s.io/apimachinery/pkg/runtime/schema"
3939
"k8s.io/apimachinery/pkg/types"
40+
"k8s.io/client-go/rest"
4041
ctrl "sigs.k8s.io/controller-runtime"
4142
"sigs.k8s.io/controller-runtime/pkg/log"
4243
"sigs.k8s.io/controller-runtime/pkg/log/zap"
@@ -94,17 +95,18 @@ var flowControlConfig = flowcontrol.Config{
9495
}
9596

9697
var (
97-
grpcPort = flag.Int("grpc-port", runserver.DefaultGrpcPort, "The gRPC port used for communicating with Envoy proxy")
98-
grpcHealthPort = flag.Int("grpc-health-port", runserver.DefaultGrpcHealthPort, "The port used for gRPC liveness and readiness probes")
99-
metricsPort = flag.Int("metrics-port", runserver.DefaultMetricsPort, "The metrics port")
100-
enablePprof = flag.Bool("enable-pprof", runserver.DefaultEnablePprof, "Enables pprof handlers. Defaults to true. Set to false to disable pprof handlers.")
101-
poolName = flag.String("pool-name", runserver.DefaultPoolName, "Name of the InferencePool this Endpoint Picker is associated with.")
102-
poolGroup = flag.String("pool-group", runserver.DefaultPoolGroup, "group of the InferencePool this Endpoint Picker is associated with.")
103-
poolNamespace = flag.String("pool-namespace", "", "Namespace of the InferencePool this Endpoint Picker is associated with.")
104-
logVerbosity = flag.Int("v", logging.DEFAULT, "number for the log level verbosity")
105-
secureServing = flag.Bool("secure-serving", runserver.DefaultSecureServing, "Enables secure serving. Defaults to true.")
106-
healthChecking = flag.Bool("health-checking", runserver.DefaultHealthChecking, "Enables health checking")
107-
certPath = flag.String("cert-path", runserver.DefaultCertPath, "The path to the certificate for secure serving. The certificate and private key files "+
98+
grpcPort = flag.Int("grpc-port", runserver.DefaultGrpcPort, "The gRPC port used for communicating with Envoy proxy")
99+
grpcHealthPort = flag.Int("grpc-health-port", runserver.DefaultGrpcHealthPort, "The port used for gRPC liveness and readiness probes")
100+
metricsPort = flag.Int("metrics-port", runserver.DefaultMetricsPort, "The metrics port")
101+
metricsEndpointAuth = flag.Bool("metrics-endpoint-auth", true, "Enables authentication and authorization of the metrics endpoint")
102+
enablePprof = flag.Bool("enable-pprof", runserver.DefaultEnablePprof, "Enables pprof handlers. Defaults to true. Set to false to disable pprof handlers.")
103+
poolName = flag.String("pool-name", runserver.DefaultPoolName, "Name of the InferencePool this Endpoint Picker is associated with.")
104+
poolGroup = flag.String("pool-group", runserver.DefaultPoolGroup, "group of the InferencePool this Endpoint Picker is associated with.")
105+
poolNamespace = flag.String("pool-namespace", "", "Namespace of the InferencePool this Endpoint Picker is associated with.")
106+
logVerbosity = flag.Int("v", logging.DEFAULT, "number for the log level verbosity")
107+
secureServing = flag.Bool("secure-serving", runserver.DefaultSecureServing, "Enables secure serving. Defaults to true.")
108+
healthChecking = flag.Bool("health-checking", runserver.DefaultHealthChecking, "Enables health checking")
109+
certPath = flag.String("cert-path", runserver.DefaultCertPath, "The path to the certificate for secure serving. The certificate and private key files "+
108110
"are assumed to be named tls.crt and tls.key, respectively. If not set, and secureServing is enabled, "+
109111
"then a self-signed certificate is used.")
110112
// metric flags
@@ -218,8 +220,14 @@ func (r *Runner) Run(ctx context.Context) error {
218220
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/metrics/server
219221
// - https://book.kubebuilder.io/reference/metrics.html
220222
metricsServerOptions := metricsserver.Options{
221-
BindAddress: fmt.Sprintf(":%d", *metricsPort),
222-
FilterProvider: filters.WithAuthenticationAndAuthorization,
223+
BindAddress: fmt.Sprintf(":%d", *metricsPort),
224+
FilterProvider: func() func(c *rest.Config, httpClient *http.Client) (metricsserver.Filter, error) {
225+
if *metricsEndpointAuth {
226+
return filters.WithAuthenticationAndAuthorization
227+
}
228+
229+
return nil
230+
}(),
223231
}
224232

225233
// Determine pool namespace: if --pool-namespace is non-empty, use it; else NAMESPACE env var; else default

0 commit comments

Comments
 (0)