Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't mask errors with RBAC message #2236

Merged
merged 1 commit into from Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion cmd/kots/cli/admin-console-upgrade.go
Expand Up @@ -96,9 +96,11 @@ func AdminConsoleUpgradeCmd() *cobra.Command {
log := logger.NewCLILogger()
if !v.GetBool("skip-rbac-check") && v.GetBool("ensure-rbac") {
err := CheckRBAC()
if err != nil {
if err == RBACError {
log.Errorf("Current user has insufficient privileges to upgrade Admin Console.\nFor more information, please visit https://kots.io/vendor/packaging/rbac\nTo bypass this check, use the --skip-rbac-check flag")
return errors.New("insufficient privileges")
} else if err != nil {
return errors.Wrap(err, "failed to check RBAC")
}
}

Expand Down
10 changes: 8 additions & 2 deletions cmd/kots/cli/install.go
Expand Up @@ -82,9 +82,11 @@ func InstallCmd() *cobra.Command {

if !v.GetBool("skip-rbac-check") && v.GetBool("ensure-rbac") {
err := CheckRBAC()
if err != nil {
if err == RBACError {
log.Errorf("Current user has insufficient privileges to install Admin Console.\nFor more information, please visit https://kots.io/vendor/packaging/rbac\nTo bypass this check, use the --skip-rbac-check flag")
return errors.New("insufficient privileges")
} else if err != nil {
return errors.Wrap(err, "failed to check RBAC")
}
}

Expand Down Expand Up @@ -676,6 +678,10 @@ func getHttpProxyEnv(v *viper.Viper) map[string]string {

}

var (
RBACError = errors.New("attempting to grant RBAC permissions not currently held")
)

func CheckRBAC() error {
clientConfig, err := k8sutil.GetClusterConfig()
if err != nil {
Expand Down Expand Up @@ -708,7 +714,7 @@ func CheckRBAC() error {
}

if !resp.Status.Allowed {
return errors.New("attempting to grant RBAC permissions not currently held")
return RBACError
}
return nil
}