Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Metrics Initialization Behind Feature Gates #1616

Open
camilamacedo86 opened this issue Jan 14, 2025 · 1 comment
Open

Move Metrics Initialization Behind Feature Gates #1616

camilamacedo86 opened this issue Jan 14, 2025 · 1 comment

Comments

@camilamacedo86
Copy link
Contributor

camilamacedo86 commented Jan 14, 2025

The metrics server should be controlled through a feature gate (MetricsEndpoint) to provide flexibility in enabling or disabling it. The following requirements must be met:

  1. If the feature gate is disabled, the MetricsServer in the controller should not be initialized.
  2. If the feature gate is enabled, the metrics server should function as expected.
  3. No changes should be required in the default Kustomize configuration or deployment files to accommodate this functionality.

(Discussed in the meeting on Jan 14)

Acceptance Criteria - TL'DR

  1. Metrics Server Initialization:

    • The metrics server is initialized only when the feature gate is enabled for catalogd and operator-controller
      -
      metricsServerOptions := server.Options{}
      if len(certFile) > 0 && len(keyFile) > 0 {
      setupLog.Info("Starting metrics server with TLS enabled", "addr", metricsAddr, "tls-cert", certFile, "tls-key", keyFile)
      metricsServerOptions.BindAddress = metricsAddr
      metricsServerOptions.SecureServing = true
      metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
      // If the certificate files change, the watcher will reload them.
      var err error
      certWatcher, err = certwatcher.New(certFile, keyFile)
      if err != nil {
      setupLog.Error(err, "Failed to initialize certificate watcher")
      os.Exit(1)
      }
      metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, func(config *tls.Config) {
      config.GetCertificate = certWatcher.GetCertificate
      // If the enable-http2 flag is false (the default), http/2 should be disabled
      // due to its vulnerabilities. More specifically, disabling http/2 will
      // prevent from being vulnerable to the HTTP/2 Stream Cancellation and
      // Rapid Reset CVEs. For more information see:
      // - https://github.com/advisories/GHSA-qppj-fm5r-hxr3
      // - https://github.com/advisories/GHSA-4374-p667-p6c8
      // Besides, those CVEs are solved already; the solution is still insufficient, and we need to mitigate
      // the risks. More info https://github.com/golang/go/issues/63417
      config.NextProtos = []string{"http/1.1"}
      })
      } else {
      // Note that the metrics server is not serving if the BindAddress is set to "0".
      // Therefore, the metrics server is disabled by default. It is only enabled
      // if certFile and keyFile are provided. The intention is not allowing the metrics
      // be served with the default self-signed certificate generated by controller-runtime.
      metricsServerOptions.BindAddress = "0"
      setupLog.Info("WARNING: Metrics Server is disabled. " +
      "Metrics will not be served since the TLS certificate and key file are not provided.")
      }

      -
      metricsServerOptions := metricsserver.Options{}
      if len(certFile) > 0 && len(keyFile) > 0 {
      setupLog.Info("Starting metrics server with TLS enabled", "addr", metricsAddr, "tls-cert", certFile, "tls-key", keyFile)
      metricsServerOptions.BindAddress = metricsAddr
      metricsServerOptions.SecureServing = true
      metricsServerOptions.FilterProvider = filters.WithAuthenticationAndAuthorization
      metricsServerOptions.TLSOpts = append(metricsServerOptions.TLSOpts, tlsOpts)
      } else {
      // Note that the metrics server is not serving if the BindAddress is set to "0".
      // Therefore, the metrics server is disabled by default. It is only enabled
      // if certFile and keyFile are provided. The intention is not allowing the metrics
      // be served with the default self-signed certificate generated by controller-runtime.
      metricsServerOptions.BindAddress = "0"
      setupLog.Info("WARNING: Metrics Server is disabled. " +
      "Metrics will not be served since the TLS certificate and key file are not provided.")
      }
    • If the feature gate is disabled, the server should bind 0 to metricsServerOptions.BindAddress to prevent the controller runtime from starting the server.
  2. Kustomize Configuration:

    • The existing Kustomize configuration should remain unchanged.
  3. Testing:

  1. Default Behavior:

    • (Required to discuss in the channel/PR) The default configuration should continue to enable the metrics server (i.e., the feature gate is enabled by default).
  2. Ensure properly documentation

@camilamacedo86 camilamacedo86 added kind/documentation Categorizes issue or PR as related to documentation. and removed kind/documentation Categorizes issue or PR as related to documentation. labels Jan 14, 2025
@camilamacedo86
Copy link
Contributor Author

c/c @LalatenduMohanty @joelanford ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant