Merge pull request #9302 from dominikbraun/#9297-reason-for-missing-config-permissions

Return ExHostPermission for insufficient config file permissions
pull/9314/head
Medya Ghazizadeh 2020-09-23 14:20:41 -05:00 committed by GitHub
commit 183bdb2354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 11 deletions

View File

@ -157,9 +157,14 @@ func runStart(cmd *cobra.Command, args []string) {
out.WarningT("Profile name '{{.name}}' is not valid", out.V{"name": ClusterFlagValue()})
exit.Message(reason.Usage, "Only alphanumeric and dashes '-' are permitted. Minimum 1 character, starting with alphanumeric.")
}
existing, err := config.Load(ClusterFlagValue())
if err != nil && !config.IsNotExist(err) {
exit.Message(reason.HostConfigLoad, "Unable to load config: {{.error}}", out.V{"error": err})
kind := reason.HostConfigLoad
if config.IsPermissionDenied(err) {
kind = reason.HostHomePermission
}
exit.Message(kind, "Unable to load config: {{.error}}", out.V{"error": err})
}
if existing != nil {

View File

@ -80,6 +80,24 @@ func IsNotExist(err error) bool {
return false
}
// ErrPermissionDenied is the error returned when the config cannot be read
// due to insufficient permissions
type ErrPermissionDenied struct {
s string
}
func (e *ErrPermissionDenied) Error() string {
return e.s
}
// IsPermissionDenied returns whether the error is a ErrPermissionDenied instance
func IsPermissionDenied(err error) bool {
if _, ok := err.(*ErrPermissionDenied); ok {
return true
}
return false
}
// MinikubeConfig represents minikube config
type MinikubeConfig map[string]interface{}
@ -184,6 +202,9 @@ func (c *simpleConfigLoader) LoadConfigFromFile(profileName string, miniHome ...
data, err := ioutil.ReadFile(path)
if err != nil {
if os.IsPermission(err) {
return nil, &ErrPermissionDenied{err.Error()}
}
return nil, errors.Wrap(err, "read")
}

View File

@ -202,12 +202,7 @@ var hostIssues = []match{
GOOS: []string{"linux"},
},
{
Kind: Kind{
ID: "HOST_HOME_PERMISSION",
ExitCode: ExGuestPermission,
Advice: "Your user lacks permissions to the minikube profile directory. Run: 'sudo chown -R $USER $HOME/.minikube; chmod -R u+wrx $HOME/.minikube' to fix",
Issues: []int{9165},
},
Kind: HostHomePermission,
Regexp: re(`/.minikube/.*: permission denied`),
},
}

View File

@ -192,6 +192,13 @@ var (
HostHomeChown = Kind{ID: "HOST_HOME_CHOWN", ExitCode: ExHostPermission}
HostBrowser = Kind{ID: "HOST_BROWSER", ExitCode: ExHostError}
HostConfigLoad = Kind{ID: "HOST_CONFIG_LOAD", ExitCode: ExHostConfig}
HostHomePermission = Kind{
ID: "HOST_HOME_PERMISSION",
ExitCode: ExHostPermission,
Advice: "Your user lacks permissions to the minikube profile directory. Run: 'sudo chown -R $USER $HOME/.minikube; chmod -R u+wrx $HOME/.minikube' to fix",
Issues: []int{9165},
}
HostCurrentUser = Kind{ID: "HOST_CURRENT_USER", ExitCode: ExHostConfig}
HostDelCache = Kind{ID: "HOST_DEL_CACHE", ExitCode: ExHostError}
HostKillMountProc = Kind{ID: "HOST_KILL_MOUNT_PROC", ExitCode: ExHostError}