fix: delegate permissions to `get, list, watch` `pods/log` resources (#1212)
* fix: delegate permissions to get, list, watch pods/log resources Signed-off-by: Anatolii Bazko <abazko@redhat.com>pull/1228/head
parent
812d34324d
commit
b4511e3cf9
|
|
@ -126,7 +126,7 @@ metadata:
|
|||
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
|
||||
repository: https://github.com/eclipse-che/che-operator
|
||||
support: Eclipse Foundation
|
||||
name: eclipse-che-preview-openshift.v7.40.0-382.next-all-namespaces
|
||||
name: eclipse-che-preview-openshift.v7.40.0-383.next-all-namespaces
|
||||
namespace: placeholder
|
||||
spec:
|
||||
apiservicedefinitions: {}
|
||||
|
|
@ -768,6 +768,14 @@ spec:
|
|||
- consoles
|
||||
verbs:
|
||||
- get
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- pods/log
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- workspace.devfile.io
|
||||
resources:
|
||||
|
|
@ -1450,4 +1458,4 @@ spec:
|
|||
maturity: stable
|
||||
provider:
|
||||
name: Eclipse Foundation
|
||||
version: 7.40.0-382.next-all-namespaces
|
||||
version: 7.40.0-383.next-all-namespaces
|
||||
|
|
|
|||
|
|
@ -133,7 +133,7 @@ metadata:
|
|||
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
|
||||
repository: https://github.com/eclipse-che/che-operator
|
||||
support: Eclipse Foundation
|
||||
name: eclipse-che-preview-kubernetes.v7.40.0-382.next
|
||||
name: eclipse-che-preview-kubernetes.v7.40.0-383.next
|
||||
namespace: placeholder
|
||||
spec:
|
||||
apiservicedefinitions: {}
|
||||
|
|
@ -755,6 +755,14 @@ spec:
|
|||
- kubernetesimagepullers
|
||||
verbs:
|
||||
- '*'
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- pods/log
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- workspace.devfile.io
|
||||
resources:
|
||||
|
|
@ -1417,4 +1425,4 @@ spec:
|
|||
maturity: stable
|
||||
provider:
|
||||
name: Eclipse Foundation
|
||||
version: 7.40.0-382.next
|
||||
version: 7.40.0-383.next
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ metadata:
|
|||
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
|
||||
repository: https://github.com/eclipse-che/che-operator
|
||||
support: Eclipse Foundation
|
||||
name: eclipse-che-preview-openshift.v7.40.0-382.next
|
||||
name: eclipse-che-preview-openshift.v7.40.0-383.next
|
||||
namespace: placeholder
|
||||
spec:
|
||||
apiservicedefinitions: {}
|
||||
|
|
@ -768,6 +768,14 @@ spec:
|
|||
- consoles
|
||||
verbs:
|
||||
- get
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- pods/log
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- workspace.devfile.io
|
||||
resources:
|
||||
|
|
@ -1450,4 +1458,4 @@ spec:
|
|||
maturity: stable
|
||||
provider:
|
||||
name: Eclipse Foundation
|
||||
version: 7.40.0-382.next
|
||||
version: 7.40.0-383.next
|
||||
|
|
|
|||
|
|
@ -365,6 +365,14 @@ rules:
|
|||
- cluster
|
||||
verbs:
|
||||
- get
|
||||
- apiGroups:
|
||||
- ''
|
||||
resources:
|
||||
- pods/log
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
### CHE-OPERATOR ROLES ONLY: END
|
||||
# devworkspace-controller-view-workspaces.ClusterRole.yaml
|
||||
- apiGroups:
|
||||
|
|
|
|||
|
|
@ -799,49 +799,24 @@ func TestShouldDelegatePermissionsForCheWorkspaces(t *testing.T) {
|
|||
t.Fatalf("Error reconciling: %v", err)
|
||||
}
|
||||
|
||||
if !testCase.clusterRole {
|
||||
viewRole := &rbac.Role{}
|
||||
if err := r.client.Get(context.TODO(), types.NamespacedName{Name: deploy.ViewRoleName, Namespace: namespace}, viewRole); err != nil {
|
||||
t.Errorf("role '%s' not found", deploy.ViewRoleName)
|
||||
}
|
||||
viewRoleBinding := &rbac.RoleBinding{}
|
||||
if err := r.client.Get(context.TODO(), types.NamespacedName{Name: ViewRoleBindingName, Namespace: namespace}, viewRoleBinding); err != nil {
|
||||
t.Errorf("rolebinding '%s' not found", ViewRoleBindingName)
|
||||
}
|
||||
manageNamespacesClusterRoleName := fmt.Sprintf(CheNamespaceEditorClusterRoleNameTemplate, namespace)
|
||||
cheManageNamespaceClusterRole := &rbac.ClusterRole{}
|
||||
if err := r.nonCachedClient.Get(context.TODO(), types.NamespacedName{Name: manageNamespacesClusterRoleName}, cheManageNamespaceClusterRole); err != nil {
|
||||
t.Errorf("role '%s' not found", manageNamespacesClusterRoleName)
|
||||
}
|
||||
cheManageNamespaceClusterRoleBinding := &rbac.ClusterRoleBinding{}
|
||||
if err := r.nonCachedClient.Get(context.TODO(), types.NamespacedName{Name: manageNamespacesClusterRoleName}, cheManageNamespaceClusterRoleBinding); err != nil {
|
||||
t.Errorf("rolebinding '%s' not found", manageNamespacesClusterRoleName)
|
||||
}
|
||||
|
||||
execRole := &rbac.Role{}
|
||||
if err := r.client.Get(context.TODO(), types.NamespacedName{Name: deploy.ExecRoleName, Namespace: namespace}, execRole); err != nil {
|
||||
t.Errorf("role '%s' not found", deploy.ExecRoleName)
|
||||
}
|
||||
execRoleBinding := &rbac.RoleBinding{}
|
||||
if err := r.client.Get(context.TODO(), types.NamespacedName{Name: ExecRoleBindingName, Namespace: namespace}, execRoleBinding); err != nil {
|
||||
t.Errorf("rolebinding '%s' not found", ExecRoleBindingName)
|
||||
}
|
||||
|
||||
editRoleBinding := &rbac.RoleBinding{}
|
||||
if err := r.client.Get(context.TODO(), types.NamespacedName{Name: EditRoleBindingName, Namespace: namespace}, editRoleBinding); err != nil {
|
||||
t.Errorf("rolebinding '%s' not found", EditRoleBindingName)
|
||||
}
|
||||
} else {
|
||||
manageNamespacesClusterRoleName := fmt.Sprintf(CheNamespaceEditorClusterRoleNameTemplate, namespace)
|
||||
cheManageNamespaceClusterRole := &rbac.ClusterRole{}
|
||||
if err := r.nonCachedClient.Get(context.TODO(), types.NamespacedName{Name: manageNamespacesClusterRoleName}, cheManageNamespaceClusterRole); err != nil {
|
||||
t.Errorf("role '%s' not found", manageNamespacesClusterRoleName)
|
||||
}
|
||||
cheManageNamespaceClusterRoleBinding := &rbac.ClusterRoleBinding{}
|
||||
if err := r.nonCachedClient.Get(context.TODO(), types.NamespacedName{Name: manageNamespacesClusterRoleName}, cheManageNamespaceClusterRoleBinding); err != nil {
|
||||
t.Errorf("rolebinding '%s' not found", manageNamespacesClusterRoleName)
|
||||
}
|
||||
|
||||
cheWorkspacesClusterRoleName := fmt.Sprintf(CheWorkspacesClusterRoleNameTemplate, namespace)
|
||||
cheWorkspacesClusterRole := &rbac.ClusterRole{}
|
||||
if err := r.nonCachedClient.Get(context.TODO(), types.NamespacedName{Name: cheWorkspacesClusterRoleName}, cheWorkspacesClusterRole); err != nil {
|
||||
t.Errorf("role '%s' not found", cheWorkspacesClusterRole)
|
||||
}
|
||||
cheWorkspacesClusterRoleBinding := &rbac.ClusterRoleBinding{}
|
||||
if err := r.nonCachedClient.Get(context.TODO(), types.NamespacedName{Name: cheWorkspacesClusterRoleName}, cheWorkspacesClusterRoleBinding); err != nil {
|
||||
t.Errorf("rolebinding '%s' not found", cheWorkspacesClusterRole)
|
||||
}
|
||||
cheWorkspacesClusterRoleName := fmt.Sprintf(CheWorkspacesClusterRoleNameTemplate, namespace)
|
||||
cheWorkspacesClusterRole := &rbac.ClusterRole{}
|
||||
if err := r.nonCachedClient.Get(context.TODO(), types.NamespacedName{Name: cheWorkspacesClusterRoleName}, cheWorkspacesClusterRole); err != nil {
|
||||
t.Errorf("role '%s' not found", cheWorkspacesClusterRole)
|
||||
}
|
||||
cheWorkspacesClusterRoleBinding := &rbac.ClusterRoleBinding{}
|
||||
if err := r.nonCachedClient.Get(context.TODO(), types.NamespacedName{Name: cheWorkspacesClusterRoleName}, cheWorkspacesClusterRoleBinding); err != nil {
|
||||
t.Errorf("rolebinding '%s' not found", cheWorkspacesClusterRole)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -253,6 +253,11 @@ func getWorkspacesPolicies() []rbac.PolicyRule {
|
|||
Resources: []string{"pods/exec"},
|
||||
Verbs: []string{"create"},
|
||||
},
|
||||
{
|
||||
APIGroups: []string{""},
|
||||
Resources: []string{"pods/log"},
|
||||
Verbs: []string{"get", "list", "watch"},
|
||||
},
|
||||
{
|
||||
APIGroups: []string{""},
|
||||
Resources: []string{"persistentvolumeclaims", "configmaps"},
|
||||
|
|
|
|||
|
|
@ -365,6 +365,14 @@ rules:
|
|||
- cluster
|
||||
verbs:
|
||||
- get
|
||||
- apiGroups:
|
||||
- ''
|
||||
resources:
|
||||
- pods/log
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
### CHE-OPERATOR ROLES ONLY: END
|
||||
# devworkspace-controller-view-workspaces.ClusterRole.yaml
|
||||
- apiGroups:
|
||||
|
|
|
|||
|
|
@ -18,63 +18,11 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
const (
|
||||
// ViewRoleName role to get k8s object needed for Workspace components(metrics plugin, Che terminals, tasks etc.)
|
||||
ViewRoleName = "view"
|
||||
// ExecRoleName - role name to create Che terminals and tasks in the workspace.
|
||||
ExecRoleName = "exec"
|
||||
)
|
||||
|
||||
var roleDiffOpts = cmp.Options{
|
||||
cmpopts.IgnoreFields(rbac.Role{}, "TypeMeta", "ObjectMeta"),
|
||||
cmpopts.IgnoreFields(rbac.PolicyRule{}, "ResourceNames", "NonResourceURLs"),
|
||||
}
|
||||
|
||||
func SyncExecRoleToCluster(deployContext *DeployContext) (bool, error) {
|
||||
execPolicyRule := []rbac.PolicyRule{
|
||||
{
|
||||
APIGroups: []string{
|
||||
"",
|
||||
},
|
||||
Resources: []string{
|
||||
"pods/exec",
|
||||
},
|
||||
Verbs: []string{
|
||||
"*",
|
||||
},
|
||||
},
|
||||
}
|
||||
return SyncRoleToCluster(deployContext, ExecRoleName, execPolicyRule)
|
||||
}
|
||||
|
||||
func SyncViewRoleToCluster(deployContext *DeployContext) (bool, error) {
|
||||
viewPolicyRule := []rbac.PolicyRule{
|
||||
{
|
||||
APIGroups: []string{
|
||||
"",
|
||||
},
|
||||
Resources: []string{
|
||||
"pods",
|
||||
},
|
||||
Verbs: []string{
|
||||
"list", "get",
|
||||
},
|
||||
},
|
||||
{
|
||||
APIGroups: []string{
|
||||
"metrics.k8s.io",
|
||||
},
|
||||
Resources: []string{
|
||||
"pods",
|
||||
},
|
||||
Verbs: []string{
|
||||
"list", "get", "watch",
|
||||
},
|
||||
},
|
||||
}
|
||||
return SyncRoleToCluster(deployContext, ViewRoleName, viewPolicyRule)
|
||||
}
|
||||
|
||||
func SyncRoleToCluster(
|
||||
deployContext *DeployContext,
|
||||
name string,
|
||||
|
|
|
|||
Loading…
Reference in New Issue