@@ -194,9 +194,14 @@ func main() {
194194
195195func mvCNIConf (configDir , configFile , confName string ) error {
196196 cniConfPath := filepath .Join (configDir , confName )
197- if _ , err := os .Stat (cniConfPath ); err == nil {
198- klog .Infof ("CNI config file %q already exists, skipping copying CNI config file" , cniConfPath )
199- return nil
197+ if info , err := os .Stat (cniConfPath ); err == nil {
198+ // File exists, check permissions.
199+ if info .Mode ().Perm () == 0o600 {
200+ klog .Infof ("CNI config file %q already exists with correct permissions, skipping." , cniConfPath )
201+ return nil
202+ }
203+ klog .Infof ("Fixing permission of existing CNI config file %q to 600" , cniConfPath )
204+ return os .Chmod (cniConfPath , 0o600 )
200205 }
201206
202207 data , err := os .ReadFile (configFile ) // #nosec G304
@@ -206,7 +211,7 @@ func mvCNIConf(configDir, configFile, confName string) error {
206211 }
207212
208213 klog .Infof ("Installing cni config file %q to %q" , configFile , cniConfPath )
209- return os .WriteFile (cniConfPath , data , 0o644 ) // #nosec G306
214+ return os .WriteFile (cniConfPath , data , 0o600 ) // #nosec G306
210215}
211216
212217func Retry (attempts , sleep int , f func (configuration * daemon.Configuration ) error , ctrl * daemon.Configuration ) (err error ) {
0 commit comments