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

feat: Cover deprecated rbac.authorization.k8s.io/v1beta1 - RBAC resources #160

Merged
merged 3 commits into from
Jun 11, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions fixtures/clusterrole-v1beta1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: pod-reader
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["get", "watch", "list"]
12 changes: 12 additions & 0 deletions fixtures/clusterrolebinding-v1beta1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: read-pods
subjects:
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: pod-reader
apiGroup: rbac.authorization.k8s.io
9 changes: 9 additions & 0 deletions fixtures/role-v1beta1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["pods"]
verbs: ["get", "watch", "list"]
13 changes: 13 additions & 0 deletions fixtures/rolebinding-v1beta1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
name: read-pods
namespace: default
subjects:
- kind: User
name: jane
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
4 changes: 4 additions & 0 deletions pkg/collector/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (c *ClusterCollector) Get() ([]map[string]interface{}, error) {
schema.GroupVersionResource{Group: "storage.k8s.io", Version: "v1", Resource: "storageclasses"},
schema.GroupVersionResource{Group: "storage.k8s.io", Version: "v1", Resource: "volumeattachments"},
schema.GroupVersionResource{Group: "scheduling.k8s.io/v1", Version: "v1", Resource: "priorityclasses"},
schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterroles"},
schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "clusterrolebindings"},
schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "roles"},
schema.GroupVersionResource{Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "rolebindings"},
}
gvrs = append(gvrs, c.additionalResources...)

Expand Down
20 changes: 20 additions & 0 deletions pkg/rules/rego/deprecated-1-22.rego
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ deprecated_api(kind, api_version) = api {
"new": "storage.k8s.io/v1",
"since": "1.13",
},
"ClusterRole": {
"old": ["rbac.authorization.k8s.io/v1beta1"],
"new": "rbac.authorization.k8s.io/v1",
"since": "1.8",
},
"ClusterRoleBinding": {
"old": ["rbac.authorization.k8s.io/v1beta1"],
"new": "rbac.authorization.k8s.io/v1",
"since": "1.8",
},
"Role": {
"old": ["rbac.authorization.k8s.io/v1beta1"],
"new": "rbac.authorization.k8s.io/v1",
"since": "1.8",
},
"RoleBinding": {
"old": ["rbac.authorization.k8s.io/v1beta1"],
"new": "rbac.authorization.k8s.io/v1",
"since": "1.8",
},
}

deprecated_apis[kind].old[_] == api_version
Expand Down
6 changes: 5 additions & 1 deletion test/rules_122_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import (
"github.com/doitintl/kube-no-trouble/pkg/collector"
)

func TestRego116(t *testing.T) {
func TestRego122(t *testing.T) {
testCases := []struct {
name string
manifests []string
expectedKinds []string // kinds of objects
}{
{"ClusterRole", []string{"../fixtures/clusterrole-v1beta1.yaml"}, []string{"ClusterRole"}},
{"ClusterRoleBinding", []string{"../fixtures/clusterrolebinding-v1beta1.yaml"}, []string{"ClusterRoleBinding"}},
{"CSIDriver", []string{"../fixtures/csidriver-v1beta1.yaml"}, []string{"CSIDriver"}},
{"CSINode", []string{"../fixtures/csinode-v1beta1.yaml"}, []string{"CSINode"}},
{"Role", []string{"../fixtures/role-v1beta1.yaml"}, []string{"Role"}},
{"RoleBinding", []string{"../fixtures/rolebinding-v1beta1.yaml"}, []string{"RoleBinding"}},
{"StorageClass", []string{"../fixtures/storageclass-v1beta1.yaml"}, []string{"StorageClass"}},
{"VolumeAttachment", []string{"../fixtures/volumeattachment-v1beta1.yaml"}, []string{"VolumeAttachment"}},
{"PriorityClass", []string{"../fixtures/priorityclass-v1beta1.yaml"}, []string{"PriorityClass"}},
Expand Down