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

fix: Vulnerabilities in Istio Gateway Secret Rotation #2075

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import (
machineryutilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/kubernetes"
k8sclientscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/workqueue"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
Expand Down Expand Up @@ -204,21 +203,15 @@ func setupManager(flagVar *flags.FlagVar, cacheOptions cache.Options, scheme *ma
go cleanupStoredVersions(flagVar.DropCrdStoredVersionMap, mgr, setupLog)
go scheduleMetricsCleanup(kymaMetrics, flagVar.MetricsCleanupIntervalInMinutes, mgr, setupLog)

go setupIstioGatewaySecretRotation(config, kcpClient, setupLog)
go gatewaysecret.NewGatewaySecretHandler(kcpClient).
StartRootCertificateWatch(kubernetes.NewForConfigOrDie(config), setupLog)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to reviewer: Checkmarx was complaining about potential race conditions on config and kcpClient. With this change, we keep using config and kcpClient in the current thread, and only then branch of to the go routine.


if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
setupLog.Error(err, "problem running manager")
os.Exit(runtimeProblemExitCode)
}
}

func setupIstioGatewaySecretRotation(config *rest.Config, kcpClient *remote.ConfigAndClient, setupLog logr.Logger) {
kcpClientset := kubernetes.NewForConfigOrDie(config)
gatewaySecretHandler := gatewaysecret.NewGatewaySecretHandler(kcpClient)

gatewaySecretHandler.StartRootCertificateWatch(kcpClientset, setupLog)
}

func addHealthChecks(mgr manager.Manager, setupLog logr.Logger) {
// +kubebuilder:scaffold:builder
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gatewaysecret/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (gsh *GatewaySecretHandler) StartRootCertificateWatch(clientset *kubernetes
})
if err != nil {
log.Error(err, "unable to start watching root certificate")
panic(err)
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to reviewer: Checkmarx was complaining that the panic is not properly handled. Since this is a go routine, I think the panic would anyway just abort the startup of the watch. Therefore we can also just return here since the error is logged and the go routine will "gracefully" stop.

Copy link
Contributor

@LeelaChacha LeelaChacha Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The startup of the watch is vital to the function of the istio gateway secret - the secret that allows TLS for SKR webhook communication. I believe that not being able to set up that secret is an extreme situation (highly unlikely though), and the runtime should stop the execution. If panic is not suitable in this case. I would suggest exiting with a bootstrap error code like so

}

WatchEvents(ctx, secretWatch.ResultChan(), gsh.manageGatewaySecret, log)
Expand Down
Loading