Skip to content

Commit

Permalink
fix: Add a file watcher for Azure client cert auth
Browse files Browse the repository at this point in the history
Add a file watcher, utilizing fsnotify, to monitor the Azure client
certificate authentication. If the file changes, the pod will need to be
 restarted since Azure SDK doesn't support hotloading a new certificate
 yet.

Signed-off-by: Bryan Cox <[email protected]>
  • Loading branch information
bryan-cox authored and k8s-infra-cherrypick-robot committed Nov 14, 2024
1 parent 75c52f9 commit cd48da6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/Azure/go-autorest/autorest v0.11.29
github.com/Azure/go-autorest/autorest/mocks v0.4.2
github.com/container-storage-interface/spec v1.9.0
github.com/fsnotify/fsnotify v1.8.0
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
github.com/kubernetes-csi/csi-lib-utils v0.17.0
Expand Down Expand Up @@ -80,7 +81,6 @@ require (
github.com/distribution/reference v0.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand Down
1 change: 1 addition & 0 deletions pkg/azureutils/azure_disk_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func GetCloudProviderFromClient(ctx context.Context, kubeClient clientset.Interf
if len(config.AADClientCertPath) > 0 {
// Watch the certificate for changes; if the certificate changes, the pod will be restarted
err = filewatcher.WatchFileForChanges(config.AADClientCertPath)
klog.Warningf("Failed to watch certificate file for changes: %v", err)
}
if err = az.InitializeCloudFromConfig(ctx, config, fromSecret, false); err != nil {
klog.Warningf("InitializeCloudFromConfig failed with error: %v", err)
Expand Down
16 changes: 16 additions & 0 deletions pkg/filewatcher/filewatcher.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
Copyright 2024 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package filewatcher

import (
Expand Down

0 comments on commit cd48da6

Please sign in to comment.