* feat(rbac): EE-226 Add a new RBAC "Operator" Role * feat(rbac): EE-226 prioritize Operator after EndpointAdmin and before Helpdesk * feat(rbac): EE-226 access viewer shows incorrect effective role after introduce of Operator * feat(rbac): EE-226 show roles order by priority other than name * feat(rbac): EE-226 remove OperationK8sVolumeDetailsW authorization from operator role * feat(rbac): EE-226 always increase bucket next sequence when create a role Co-authored-by: Simon Meng <simon.meng@portainer.io>
74 lines
3.1 KiB
Go
74 lines
3.1 KiB
Go
package endpoints
|
|
|
|
import (
|
|
"github.com/portainer/portainer/api/docker"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
httperror "github.com/portainer/libhttp/error"
|
|
portainer "github.com/portainer/portainer/api"
|
|
"github.com/portainer/portainer/api/http/proxy"
|
|
"github.com/portainer/portainer/api/http/security"
|
|
"github.com/portainer/portainer/api/internal/authorization"
|
|
"github.com/portainer/portainer/api/kubernetes/cli"
|
|
)
|
|
|
|
func hideFields(endpoint *portainer.Endpoint) {
|
|
endpoint.AzureCredentials = portainer.AzureCredentials{}
|
|
if len(endpoint.Snapshots) > 0 {
|
|
endpoint.Snapshots[0].SnapshotRaw = portainer.DockerSnapshotRaw{}
|
|
}
|
|
}
|
|
|
|
// Handler is the HTTP handler used to handle endpoint operations.
|
|
type Handler struct {
|
|
*mux.Router
|
|
requestBouncer *security.RequestBouncer
|
|
AuthorizationService *authorization.Service
|
|
DataStore portainer.DataStore
|
|
FileService portainer.FileService
|
|
ProxyManager *proxy.Manager
|
|
ReverseTunnelService portainer.ReverseTunnelService
|
|
SnapshotService portainer.SnapshotService
|
|
K8sClientFactory *cli.ClientFactory
|
|
ComposeStackManager portainer.ComposeStackManager
|
|
DockerClientFactory *docker.ClientFactory
|
|
}
|
|
|
|
// NewHandler creates a handler to manage endpoint operations.
|
|
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
|
h := &Handler{
|
|
Router: mux.NewRouter(),
|
|
requestBouncer: bouncer,
|
|
}
|
|
|
|
h.Handle("/endpoints",
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointCreate))).Methods(http.MethodPost)
|
|
h.Handle("/endpoints/{id}/settings",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.endpointSettingsUpdate))).Methods(http.MethodPut)
|
|
h.Handle("/endpoints/snapshot",
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointSnapshots))).Methods(http.MethodPost)
|
|
h.Handle("/endpoints",
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointList))).Methods(http.MethodGet)
|
|
h.Handle("/endpoints/{id}",
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointInspect))).Methods(http.MethodGet)
|
|
h.Handle("/endpoints/{id}",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.endpointUpdate))).Methods(http.MethodPut)
|
|
h.Handle("/endpoints/{id}",
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointDelete))).Methods(http.MethodDelete)
|
|
h.Handle("/endpoints/{id}/extensions",
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointExtensionAdd))).Methods(http.MethodPost)
|
|
h.Handle("/endpoints/{id}/extensions/{extensionType}",
|
|
bouncer.RestrictedAccess(httperror.LoggerHandler(h.endpointExtensionRemove))).Methods(http.MethodDelete)
|
|
h.Handle("/endpoints/{id}/snapshot",
|
|
bouncer.AdminAccess(httperror.LoggerHandler(h.endpointSnapshot))).Methods(http.MethodPost)
|
|
h.Handle("/endpoints/{id}/status",
|
|
bouncer.PublicAccess(httperror.LoggerHandler(h.endpointStatusInspect))).Methods(http.MethodGet)
|
|
h.Handle("/endpoints/{id}/pools/{rpn}/access",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.endpointPoolsAccessUpdate))).Methods(http.MethodPut)
|
|
h.Handle("/endpoints/{id}/forceupdateservice",
|
|
bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.endpointForceUpdateService))).Methods(http.MethodPut)
|
|
|
|
return h
|
|
}
|