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>
64 lines
2.5 KiB
Go
64 lines
2.5 KiB
Go
package users
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
httperror "github.com/portainer/libhttp/error"
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/portainer/portainer/api/http/security"
|
|
"github.com/portainer/portainer/api/internal/authorization"
|
|
"github.com/portainer/portainer/api/kubernetes/cli"
|
|
)
|
|
|
|
var (
|
|
errUserAlreadyExists = errors.New("User already exists")
|
|
errAdminAlreadyInitialized = errors.New("An administrator user already exists")
|
|
errAdminCannotRemoveSelf = errors.New("Cannot remove your own user account. Contact another administrator")
|
|
errCannotRemoveLastLocalAdmin = errors.New("Cannot remove the last local administrator account")
|
|
errCryptoHashFailure = errors.New("Unable to hash data")
|
|
)
|
|
|
|
func hideFields(user *portainer.User) {
|
|
user.Password = ""
|
|
}
|
|
|
|
// Handler is the HTTP handler used to handle user operations.
|
|
type Handler struct {
|
|
*mux.Router
|
|
AuthorizationService *authorization.Service
|
|
CryptoService portainer.CryptoService
|
|
DataStore portainer.DataStore
|
|
K8sClientFactory *cli.ClientFactory
|
|
}
|
|
|
|
// NewHandler creates a handler to manage user operations.
|
|
func NewHandler(bouncer *security.RequestBouncer, rateLimiter *security.RateLimiter) *Handler {
|
|
h := &Handler{
|
|
Router: mux.NewRouter(),
|
|
}
|
|
h.Handle("/users",
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.userCreate))).Methods(http.MethodPost)
|
|
h.Handle("/users",
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.userList))).Methods(http.MethodGet)
|
|
h.Handle("/users/{id}",
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.userInspect))).Methods(http.MethodGet)
|
|
h.Handle("/users/{id}",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.userUpdate))).Methods(http.MethodPut)
|
|
h.Handle("/users/{id}",
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.userDelete))).Methods(http.MethodDelete)
|
|
h.Handle("/users/{id}/memberships",
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.userMemberships))).Methods(http.MethodGet)
|
|
h.Handle("/users/{id}/passwd",
|
|
rateLimiter.LimitAccess(bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.userUpdatePassword)))).Methods(http.MethodPut)
|
|
h.Handle("/users/admin/check",
|
|
bouncer.PublicAccess(httperror.LoggerHandler(h.adminCheck))).Methods(http.MethodGet)
|
|
h.Handle("/users/admin/init",
|
|
bouncer.PublicAccess(httperror.LoggerHandler(h.adminInit))).Methods(http.MethodPost)
|
|
h.Handle("/users/{id}/namespaces",
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.userNamespaces))).Methods(http.MethodGet)
|
|
|
|
return h
|
|
}
|