github.com/stefanmcshane/helm@v0.0.0-20221213002717-88a4a2c6e77d/cmd/helm/root_unix.go (about)

     1  //go:build !windows
     2  
     3  /*
     4  Copyright The Helm Authors.
     5  
     6  Licensed under the Apache License, Version 2.0 (the "License");
     7  you may not use this file except in compliance with the License.
     8  You may obtain a copy of the License at
     9  
    10      http://www.apache.org/licenses/LICENSE-2.0
    11  
    12  Unless required by applicable law or agreed to in writing, software
    13  distributed under the License is distributed on an "AS IS" BASIS,
    14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15  See the License for the specific language governing permissions and
    16  limitations under the License.
    17  */
    18  
    19  package main
    20  
    21  import (
    22  	"os"
    23  	"os/user"
    24  	"path/filepath"
    25  )
    26  
    27  func checkPerms() {
    28  	// This function MUST NOT FAIL, as it is just a check for a common permissions problem.
    29  	// If for some reason the function hits a stopping condition, it may panic. But only if
    30  	// we can be sure that it is panicking because Helm cannot proceed.
    31  
    32  	kc := settings.KubeConfig
    33  	if kc == "" {
    34  		kc = os.Getenv("KUBECONFIG")
    35  	}
    36  	if kc == "" {
    37  		u, err := user.Current()
    38  		if err != nil {
    39  			// No idea where to find KubeConfig, so return silently. Many helm commands
    40  			// can proceed happily without a KUBECONFIG, so this is not a fatal error.
    41  			return
    42  		}
    43  		kc = filepath.Join(u.HomeDir, ".kube", "config")
    44  	}
    45  	fi, err := os.Stat(kc)
    46  	if err != nil {
    47  		// DO NOT error if no KubeConfig is found. Not all commands require one.
    48  		return
    49  	}
    50  
    51  	perm := fi.Mode().Perm()
    52  	if perm&0040 > 0 {
    53  		warning("Kubernetes configuration file is group-readable. This is insecure. Location: %s", kc)
    54  	}
    55  	if perm&0004 > 0 {
    56  		warning("Kubernetes configuration file is world-readable. This is insecure. Location: %s", kc)
    57  	}
    58  }