Repository: kubernetes/dashboard (go)

Issue:
`cani` API endpoint returns `false` and cause frontend to refresh content every 5s
<!-- Please use this template while reporting a bug and provide as much info as possible. Not doing so may result in your bug not being addressed in a timely manner. Thanks!-->

##### Environment
<!-- Describe your setup. Versions of Node.js, Go etc. are needed only from developers. -->
```
Installation method: docker image deployed directly to cluster
Kubernetes version: v1.18.1
Dashboard version: v2.0.0-rc5+0.g646b573
Operating system: macOS
Node.js version ('node --version' output): N/A
Go version ('go version' output): N/A
```

##### Steps to reproduce
<!-- Describe all steps needed to reproduce the issue. It is a good place to use numbered list. -->
1. Go the pod list page in any namespace.
2. Click **show all** button to expand the pod labels.
3. Wait for about 5s.
##### Observed result
<!-- Describe observed result as precisely as possible. -->
1. The row will automatically fold again.
2. If I open dev console and switch to "Network" tab, I can see the dashboard frontend is sending some request every 5s to refresh the content of the pod list.
##### Expected result
<!-- Describe expected result as precisely as possible. -->
1. The row **shouldn't** fold again.
2. The frontend shouldn't make requests every 5s to refresh the pod list.

##### Comments
<!-- If you have any comments or more details, put them here. -->
We did some debugging, and identified the issue to be `GET api/v1/settings/global/cani` returns `allow: false` while it should have been `true`.
We use auth head to login, and I verified my logged-in user does have `get` access to the `kubernetes-dashboard-settings` configmap in `kubernetes-dashboard` namespace (I can access the configmap directly on WebUI).

For now, we are using the workaround of `--disable-settings-authorizer` to artificially make the `cani` endpoint return `true`. And this solves the frontend refreshing issue.

Pull request description:
Fix can-i check for settings configmap
Fixes #5170

Patch:
diff --git a/package-lock.json b/package-lock.json
index 88f2e9d60..b97ee1c8c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -12379,14 +12379,14 @@
       }
     },
     "husky": {
-      "version": "4.2.3",
-      "resolved": "https://registry.npmjs.org/husky/-/husky-4.2.3.tgz",
-      "integrity": "sha512-VxTsSTRwYveKXN4SaH1/FefRJYCtx+wx04sSVcOpD7N2zjoHxa+cEJ07Qg5NmV3HAK+IRKOyNVpi2YBIVccIfQ==",
+      "version": "4.2.5",
+      "resolved": "https://registry.npmjs.org/husky/-/husky-4.2.5.tgz",
+      "integrity": "sha512-SYZ95AjKcX7goYVZtVZF2i6XiZcHknw50iXvY7b0MiGoj5RwdgRQNEHdb+gPDPCXKlzwrybjFjkL6FOj8uRhZQ==",
       "dev": true,
       "requires": {
-        "chalk": "^3.0.0",
+        "chalk": "^4.0.0",
         "ci-info": "^2.0.0",
-        "compare-versions": "^3.5.1",
+        "compare-versions": "^3.6.0",
         "cosmiconfig": "^6.0.0",
         "find-versions": "^3.2.0",
         "opencollective-postinstall": "^2.0.2",
@@ -12407,9 +12407,9 @@
           }
         },
         "chalk": {
-          "version": "3.0.0",
-          "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
-          "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==",
+          "version": "4.0.0",
+          "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.0.0.tgz",
+          "integrity": "sha512-N9oWFcegS0sFr9oh1oz2d7Npos6vNoWW9HvtCg5N1KRFpUhaAhvTv5Y58g880fZaEYSNm3qDz8SU1UrGvp+n7A==",
           "dev": true,
           "requires": {
             "ansi-styles": "^4.1.0",
diff --git a/package.json b/package.json
index 2a6fc6999..915ad37c2 100644
--- a/package.json
+++ b/package.json
@@ -161,7 +161,7 @@
     "gts": "1.1.2",
     "gulp": "4.0.2",
     "gulp-filter": "6.0.0",
-    "husky": "4.2.3",
+    "husky": "4.2.5",
     "jasmine-core": "3.5.0",
     "jasmine-spec-reporter": "4.2.1",
     "js-beautify": "1.10.3",
diff --git a/src/app/backend/client/api/common.go b/src/app/backend/client/api/common.go
index 83e72cebd..cb34a7dfa 100644
--- a/src/app/backend/client/api/common.go
+++ b/src/app/backend/client/api/common.go
@@ -16,19 +16,23 @@ package api
 
 import (
 	"crypto/rand"
+	"fmt"
+	"strings"
 
 	v1 "k8s.io/api/authorization/v1"
 )
 
 // ToSelfSubjectAccessReview creates kubernetes API object based on provided data.
-func ToSelfSubjectAccessReview(namespace, name, resource, verb string) *v1.SelfSubjectAccessReview {
+func ToSelfSubjectAccessReview(namespace, name, resourceKind, verb string) *v1.SelfSubjectAccessReview {
 	return &v1.SelfSubjectAccessReview{
 		Spec: v1.SelfSubjectAccessReviewSpec{
 			ResourceAttributes: &v1.ResourceAttributes{
 				Namespace: namespace,
 				Name:      name,
-				Resource:  resource,
-				Verb:      verb,
+				// Resource kind name must be in a plural lower-case format,
+				Resource: fmt.Sprintf("%ss", strings.ToLower(resourceKind)),
+				// Let's enforce the same lower-case format for verbs
+				Verb: strings.ToLower(verb),
 			},
 		},
 	}


Test patch:
diff --git a/src/app/backend/client/api/common_test.go b/src/app/backend/client/api/common_test.go
index e3c653de5..2cb7f5724 100644
--- a/src/app/backend/client/api/common_test.go
+++ b/src/app/backend/client/api/common_test.go
@@ -18,8 +18,9 @@ import (
 	"reflect"
 	"testing"
 
-	"github.com/kubernetes/dashboard/src/app/backend/client/api"
 	v1 "k8s.io/api/authorization/v1"
+
+	"github.com/kubernetes/dashboard/src/app/backend/client/api"
 )
 
 func TestToSelfSubjectAccessReview(t *testing.T) {
@@ -32,8 +33,8 @@ func TestToSelfSubjectAccessReview(t *testing.T) {
 			ResourceAttributes: &v1.ResourceAttributes{
 				Namespace: ns,
 				Name:      name,
-				Resource:  resourceName,
-				Verb:      verb,
+				Resource:  "deployments",
+				Verb:      "get",
 			},
 		},
 	}