Skip to content

Commit

Permalink
Audit rbac, avoid global (*) permissions
Browse files Browse the repository at this point in the history
There are some permissions which are logically not needed,
and some others where we can just reduce the verb set allowed.

Signed-off-by: Alex Kalenyuk <akalenyu@redhat.com>
  • Loading branch information
akalenyu committed Aug 24, 2023
1 parent cc8dbc3 commit 376f0f0
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 54 deletions.
3 changes: 1 addition & 2 deletions pkg/operator/resources/cluster/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func getAPIServerClusterPolicyRules() []rbacv1.PolicyRule {
"datasources",
},
Verbs: []string{
"list",
"get",
},
},
Expand All @@ -159,7 +158,7 @@ func getAPIServerClusterPolicyRules() []rbacv1.PolicyRule {
"cdis/finalizers",
},
Verbs: []string{
"*",
"update",
},
},
}
Expand Down
34 changes: 8 additions & 26 deletions pkg/operator/resources/cluster/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,16 @@ func getControllerClusterPolicyRules() []rbacv1.PolicyRule {
"snapshot.storage.k8s.io",
},
Resources: []string{
"*",
"volumesnapshots",
"volumesnapshotclasses",
"volumesnapshotcontents",
},
Verbs: []string{
"*",
"get",
"list",
"watch",
"create",
"delete",
},
},
{
Expand Down Expand Up @@ -211,30 +217,6 @@ func getControllerClusterPolicyRules() []rbacv1.PolicyRule {
"create",
},
},
{
APIGroups: []string{
"batch",
},
Resources: []string{
"cronjobs",
},
Verbs: []string{
"list",
"watch",
},
},
{
APIGroups: []string{
"batch",
},
Resources: []string{
"jobs",
},
Verbs: []string{
"list",
"watch",
},
},
{
APIGroups: []string{
"kubevirt.io",
Expand Down
5 changes: 4 additions & 1 deletion pkg/operator/resources/namespaced/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ func createAPIServerRole() *rbacv1.Role {
"configmaps",
},
Verbs: []string{
"*",
"get",
"list",
"watch",
"create",
},
},
}
Expand Down
13 changes: 11 additions & 2 deletions pkg/operator/resources/namespaced/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ func createControllerRole() *rbacv1.Role {
"configmaps",
},
Verbs: []string{
"*",
"get",
"list",
"watch",
"create",
"update",
"delete",
},
},
{
Expand Down Expand Up @@ -113,6 +118,8 @@ func createControllerRole() *rbacv1.Role {
Verbs: []string{
"create",
"delete",
"list",
"watch",
},
},
{
Expand All @@ -123,7 +130,9 @@ func createControllerRole() *rbacv1.Role {
"leases",
},
Verbs: []string{
"*",
"get",
"create",
"update",
},
},
{
Expand Down
73 changes: 50 additions & 23 deletions pkg/operator/resources/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ func getClusterPolicyRules() []rbacv1.PolicyRule {
"clusterroles",
},
Verbs: []string{
"*",
"get",
"list",
"watch",
"create",
"update",
"delete",
},
},
{
Expand All @@ -74,31 +79,21 @@ func getClusterPolicyRules() []rbacv1.PolicyRule {
},
{
APIGroups: []string{
"",
"apiextensions.k8s.io",
},
Resources: []string{
"pods",
"services",
"customresourcedefinitions",
"customresourcedefinitions/status",
},
Verbs: []string{
"get",
"list",
"watch",
"create",
"update",
"delete",
},
},
{
APIGroups: []string{
"apiextensions.k8s.io",
},
Resources: []string{
"customresourcedefinitions",
"customresourcedefinitions/status",
},
Verbs: []string{
"*",
},
},
{
APIGroups: []string{
"cdi.kubevirt.io",
Expand All @@ -120,7 +115,12 @@ func getClusterPolicyRules() []rbacv1.PolicyRule {
"mutatingwebhookconfigurations",
},
Verbs: []string{
"*",
"get",
"list",
"watch",
"create",
"update",
"delete",
},
},
{
Expand All @@ -131,7 +131,12 @@ func getClusterPolicyRules() []rbacv1.PolicyRule {
"apiservices",
},
Verbs: []string{
"*",
"get",
"list",
"watch",
"create",
"update",
"delete",
},
},
}
Expand Down Expand Up @@ -165,7 +170,12 @@ func getNamespacedPolicyRules() []rbacv1.PolicyRule {
"roles",
},
Verbs: []string{
"*",
"get",
"list",
"watch",
"create",
"update",
"delete",
},
},
{
Expand All @@ -180,7 +190,13 @@ func getNamespacedPolicyRules() []rbacv1.PolicyRule {
"services",
},
Verbs: []string{
"*",
"get",
"list",
"watch",
"create",
"update",
"patch",
"delete",
},
},
{
Expand All @@ -192,7 +208,12 @@ func getNamespacedPolicyRules() []rbacv1.PolicyRule {
"deployments/finalizers",
},
Verbs: []string{
"*",
"get",
"list",
"watch",
"create",
"update",
"delete",
},
},
{
Expand All @@ -204,7 +225,11 @@ func getNamespacedPolicyRules() []rbacv1.PolicyRule {
"routes/custom-host",
},
Verbs: []string{
"*",
"get",
"list",
"watch",
"create",
"update",
},
},
{
Expand Down Expand Up @@ -246,7 +271,9 @@ func getNamespacedPolicyRules() []rbacv1.PolicyRule {
"leases",
},
Verbs: []string{
"*",
"get",
"create",
"update",
},
},
}
Expand Down

0 comments on commit 376f0f0

Please sign in to comment.