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>
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package cli
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
portainer "github.com/portainer/portainer/api"
|
|
k8serrors "k8s.io/apimachinery/pkg/api/errors"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
)
|
|
|
|
// GetNamespaceAccessPolicies gets the namespace access policies
|
|
// from config maps in the portainer namespace
|
|
func (kcl *KubeClient) GetNamespaceAccessPolicies() (
|
|
map[string]portainer.K8sNamespaceAccessPolicy, error,
|
|
) {
|
|
configMap, err := kcl.cli.CoreV1().ConfigMaps(portainerNamespace).Get(portainerConfigMapName, metav1.GetOptions{})
|
|
if k8serrors.IsNotFound(err) {
|
|
return nil, nil
|
|
} else if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
accessData := configMap.Data[portainerConfigMapAccessPoliciesKey]
|
|
|
|
var policies map[string]portainer.K8sNamespaceAccessPolicy
|
|
err = json.Unmarshal([]byte(accessData), &policies)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return policies, nil
|
|
}
|
|
|
|
// UpdateNamespaceAccessPolicies updates the namespace access policies
|
|
func (kcl *KubeClient) UpdateNamespaceAccessPolicies(
|
|
accessPolicies map[string]portainer.K8sNamespaceAccessPolicy,
|
|
) error {
|
|
|
|
data, err := json.Marshal(accessPolicies)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
configMap, err := kcl.cli.CoreV1().ConfigMaps(portainerNamespace).Get(portainerConfigMapName, metav1.GetOptions{})
|
|
if k8serrors.IsNotFound(err) {
|
|
return nil
|
|
} else if err != nil {
|
|
return err
|
|
}
|
|
configMap.Data[portainerConfigMapAccessPoliciesKey] = string(data)
|
|
_, err = kcl.cli.CoreV1().ConfigMaps(portainerNamespace).Update(configMap)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|