Merge pull request #9302 from dominikbraun/#9297-reason-for-missing-config-permissions
Return ExHostPermission for insufficient config file permissionspull/9314/head
commit
183bdb2354
|
@ -157,9 +157,14 @@ func runStart(cmd *cobra.Command, args []string) {
|
||||||
out.WarningT("Profile name '{{.name}}' is not valid", out.V{"name": ClusterFlagValue()})
|
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.")
|
exit.Message(reason.Usage, "Only alphanumeric and dashes '-' are permitted. Minimum 1 character, starting with alphanumeric.")
|
||||||
}
|
}
|
||||||
|
|
||||||
existing, err := config.Load(ClusterFlagValue())
|
existing, err := config.Load(ClusterFlagValue())
|
||||||
if err != nil && !config.IsNotExist(err) {
|
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 {
|
if existing != nil {
|
||||||
|
|
|
@ -80,6 +80,24 @@ func IsNotExist(err error) bool {
|
||||||
return false
|
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
|
// MinikubeConfig represents minikube config
|
||||||
type MinikubeConfig map[string]interface{}
|
type MinikubeConfig map[string]interface{}
|
||||||
|
|
||||||
|
@ -184,6 +202,9 @@ func (c *simpleConfigLoader) LoadConfigFromFile(profileName string, miniHome ...
|
||||||
|
|
||||||
data, err := ioutil.ReadFile(path)
|
data, err := ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if os.IsPermission(err) {
|
||||||
|
return nil, &ErrPermissionDenied{err.Error()}
|
||||||
|
}
|
||||||
return nil, errors.Wrap(err, "read")
|
return nil, errors.Wrap(err, "read")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,12 +202,7 @@ var hostIssues = []match{
|
||||||
GOOS: []string{"linux"},
|
GOOS: []string{"linux"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Kind: Kind{
|
Kind: HostHomePermission,
|
||||||
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},
|
|
||||||
},
|
|
||||||
Regexp: re(`/.minikube/.*: permission denied`),
|
Regexp: re(`/.minikube/.*: permission denied`),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,10 +188,17 @@ var (
|
||||||
|
|
||||||
RsrcInsufficientStorage = Kind{ID: "RSRC_INSUFFICIENT_STORAGE", ExitCode: ExInsufficientStorage, Style: style.UnmetRequirement}
|
RsrcInsufficientStorage = Kind{ID: "RSRC_INSUFFICIENT_STORAGE", ExitCode: ExInsufficientStorage, Style: style.UnmetRequirement}
|
||||||
|
|
||||||
HostHomeMkdir = Kind{ID: "HOST_HOME_MKDIR", ExitCode: ExHostPermission}
|
HostHomeMkdir = Kind{ID: "HOST_HOME_MKDIR", ExitCode: ExHostPermission}
|
||||||
HostHomeChown = Kind{ID: "HOST_HOME_CHOWN", ExitCode: ExHostPermission}
|
HostHomeChown = Kind{ID: "HOST_HOME_CHOWN", ExitCode: ExHostPermission}
|
||||||
HostBrowser = Kind{ID: "HOST_BROWSER", ExitCode: ExHostError}
|
HostBrowser = Kind{ID: "HOST_BROWSER", ExitCode: ExHostError}
|
||||||
HostConfigLoad = Kind{ID: "HOST_CONFIG_LOAD", ExitCode: ExHostConfig}
|
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}
|
HostCurrentUser = Kind{ID: "HOST_CURRENT_USER", ExitCode: ExHostConfig}
|
||||||
HostDelCache = Kind{ID: "HOST_DEL_CACHE", ExitCode: ExHostError}
|
HostDelCache = Kind{ID: "HOST_DEL_CACHE", ExitCode: ExHostError}
|
||||||
HostKillMountProc = Kind{ID: "HOST_KILL_MOUNT_PROC", ExitCode: ExHostError}
|
HostKillMountProc = Kind{ID: "HOST_KILL_MOUNT_PROC", ExitCode: ExHostError}
|
||||||
|
|
Loading…
Reference in New Issue