2247d8c3a2
* + endpoint and namespace level authorizations + user namespace authorization API + k8s client setup service account with k8s roles and policies by portainer role * User authorization changes refresh token cache * rbac authorizes k8s requests * CE to EE migrator to include new authorizations * code clean up * comments * * merge in the RestrictDefaultNamespace changes * - remove unnecessary check for default namespace * + updates namespace access policies when generating token * * updates namespace access policies when querying the user namespace endpoint * + k8s rule in rbac.go for endpoint access test + missing k8s cluster rules for different roles * feat(rbac): update kube rbac * feat(rbac): use the authorization directive * feat(rbac): Update namespace access policies when user/team is deleted * refactor(app): use new angular-multi-select capabilities * feat(rbac): fix authorizations * feat(rbac): fix userAccessPolicies update bug * feat(rbac): add W applications authorizations * feat(rbac): add application details W authorizations * feat(rbac): add configurations W autohorizations * feat(rbac): add configuration details W authorizations * feat(rbac): add volumes W authorizations * feat(rbac): add volume details W authorizations * feat(rbac): add componentstatus to portainer-view role and add cluster/node authorizations * fix(rbac): disable application note for non authorized user * fix(rbac): add endpoints list and components status to portainer-basic * fix(rbac): allow user to access default namespace when restrict default namespace isn't activated * fix(rbac): remove default namespace from useraccesspolicies when restrict default namespace isn't activated * fix(rbac): change some things * fix(rbac): allow standard user to access container console * - removed unused parameter * fix(rbac): fix team authorizations Co-authored-by: Maxime Bajeux <max.bajeux@gmail.com> Co-authored-by: xAt0mZ <baron_l@epitech.eu>
36 lines
1.0 KiB
Go
36 lines
1.0 KiB
Go
package cli
|
|
|
|
import (
|
|
portainer "github.com/portainer/portainer/api"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
func defaultSystemNamespaces() map[string]struct{} {
|
|
return map[string]struct{}{
|
|
"kube-system": struct{}{},
|
|
"kube-public": struct{}{},
|
|
"kube-node-lease": struct{}{},
|
|
"portainer": struct{}{},
|
|
}
|
|
}
|
|
|
|
// GetNamespaces gets the namespaces in the current k8s endpoint connection
|
|
func (kcl *KubeClient) GetNamespaces() (map[string]portainer.K8sNamespaceInfo, error) {
|
|
namespaces, err := kcl.cli.CoreV1().Namespaces().List(metav1.ListOptions{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
results := make(map[string]portainer.K8sNamespaceInfo)
|
|
systemNamespaces := defaultSystemNamespaces()
|
|
for _, ns := range namespaces.Items {
|
|
// setup the namespace properties if its a system or default namespace
|
|
_, isSystem := systemNamespaces[ns.Name]
|
|
results[ns.Name] = portainer.K8sNamespaceInfo{
|
|
IsSystem: isSystem,
|
|
IsDefault: ns.Name == defaultNamespace,
|
|
}
|
|
}
|
|
|
|
return results, nil
|
|
}
|