mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
* #960 feat(UAC): change ownership to admins for externally created ressources * feat(UAC): change ownership to admins for externally created resources Deprecated AdministratorsOnly js and go backend * #960 feat(UAC): remove AdministratorsOnly property and minor GUI fixes Update swagger definition changing AdministratorsOnly to Public * #960 feat(UAC): fix create resource with access control data * #960 feat(UAC): authorization of non-admin users for restricted operations On stacks, containers networks, services , tasks and volumes. * #960 feat(UAC): database migration to version 14 The administrator resources are deleted and Public resources are now managed by admins * #960 feat(UAC): small fixes from PR #2137 * #960 feat(UAC): improve the readability of the source code * feat(UAC) fix displayed ownership for Swarm related resources (#960)
52 lines
2.2 KiB
Go
52 lines
2.2 KiB
Go
package stacks
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/portainer/portainer"
|
|
httperror "github.com/portainer/portainer/http/error"
|
|
"github.com/portainer/portainer/http/proxy"
|
|
"github.com/portainer/portainer/http/request"
|
|
"github.com/portainer/portainer/http/response"
|
|
"github.com/portainer/portainer/http/security"
|
|
)
|
|
|
|
// GET request on /api/stacks/:id
|
|
func (handler *Handler) stackInspect(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
|
stackID, err := request.RetrieveNumericRouteVariableValue(r, "id")
|
|
if err != nil {
|
|
return &httperror.HandlerError{http.StatusBadRequest, "Invalid stack identifier route variable", err}
|
|
}
|
|
|
|
stack, err := handler.StackService.Stack(portainer.StackID(stackID))
|
|
if err == portainer.ErrObjectNotFound {
|
|
return &httperror.HandlerError{http.StatusNotFound, "Unable to find a stack with the specified identifier inside the database", err}
|
|
} else if err != nil {
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to find a stack with the specified identifier inside the database", err}
|
|
}
|
|
|
|
resourceControl, err := handler.ResourceControlService.ResourceControlByResourceID(stack.Name)
|
|
if err != nil && err != portainer.ErrObjectNotFound {
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve a resource control associated to the stack", err}
|
|
}
|
|
|
|
securityContext, err := security.RetrieveRestrictedRequestContext(r)
|
|
if err != nil {
|
|
return &httperror.HandlerError{http.StatusInternalServerError, "Unable to retrieve info from request context", err}
|
|
}
|
|
|
|
extendedStack := proxy.ExtendedStack{*stack, portainer.ResourceControl{}}
|
|
if !securityContext.IsAdmin && resourceControl == nil {
|
|
return &httperror.HandlerError{http.StatusForbidden, "Access denied to resource", portainer.ErrResourceAccessDenied}
|
|
}
|
|
|
|
if resourceControl != nil {
|
|
if securityContext.IsAdmin || proxy.CanAccessStack(stack, resourceControl, securityContext.UserID, securityContext.UserMemberships) {
|
|
extendedStack.ResourceControl = *resourceControl
|
|
} else {
|
|
return &httperror.HandlerError{http.StatusForbidden, "Access denied to resource", portainer.ErrResourceAccessDenied}
|
|
}
|
|
}
|
|
|
|
return response.JSON(w, extendedStack)
|
|
}
|