* + 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>
45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
)
|
|
|
|
const (
|
|
defaultNamespace = "default"
|
|
portainerNamespace = "portainer"
|
|
portainerUserServiceAccountPrefix = "portainer-sa-user"
|
|
portainerRBPrefix = "portainer-rb"
|
|
portainerCRBPrefix = "portainer-crb"
|
|
portainerConfigMapName = "portainer-config"
|
|
portainerConfigMapAccessPoliciesKey = "NamespaceAccessPolicies"
|
|
)
|
|
|
|
func userServiceAccountName(userID int, instanceID string) string {
|
|
return fmt.Sprintf("%s-%s-%d", portainerUserServiceAccountPrefix, instanceID, userID)
|
|
}
|
|
|
|
func userServiceAccountTokenSecretName(serviceAccountName string, instanceID string) string {
|
|
return fmt.Sprintf("%s-%s-secret", instanceID, serviceAccountName)
|
|
}
|
|
|
|
func clusterRoleBindingName(roleName string, instanceID string) string {
|
|
return fmt.Sprintf("%s-%s-%s", portainerCRBPrefix, instanceID, roleName)
|
|
}
|
|
|
|
func namespaceRoleBindingName(roleName string, namespace string, instanceID string) string {
|
|
return fmt.Sprintf("%s-%s-%s-%s", portainerRBPrefix, instanceID, namespace, roleName)
|
|
}
|
|
|
|
// match with a portainer role binding for any role name
|
|
func matchRoleBindingName(target string, namespace string, instanceID string) bool {
|
|
return regexp.MustCompile("^" + namespaceRoleBindingName("(.*)", namespace, instanceID) + "$").
|
|
MatchString(target)
|
|
}
|
|
|
|
// match with a portainer cluster role binding for any role name
|
|
func matchClusterRoleBindingName(target string, instanceID string) bool {
|
|
return regexp.MustCompile("^" + clusterRoleBindingName("(.*)", instanceID) + "$").
|
|
MatchString(target)
|
|
}
|