diff --git a/api/http/proxy/factory/docker/transport.go b/api/http/proxy/factory/docker/transport.go index 1cfbfd921..af8251cc6 100644 --- a/api/http/proxy/factory/docker/transport.go +++ b/api/http/proxy/factory/docker/transport.go @@ -156,8 +156,14 @@ func (transport *Transport) proxyAgentRequest(r *http.Request) (*http.Response, return transport.administratorOperation(r) } + agentTargetHeader := r.Header.Get(portainer.PortainerAgentTargetHeader) + resourceID, err := transport.getVolumeResourceID(agentTargetHeader, volumeIDParameter[0]) + if err != nil { + return nil, err + } + // volume browser request - return transport.restrictedResourceOperation(r, volumeIDParameter[0], portainer.VolumeResourceControl, true) + return transport.restrictedResourceOperation(r, resourceID, portainer.VolumeResourceControl, true) } return transport.executeDockerRequest(r) diff --git a/api/http/proxy/factory/docker/volumes.go b/api/http/proxy/factory/docker/volumes.go index 61a38c72a..0d9705f82 100644 --- a/api/http/proxy/factory/docker/volumes.go +++ b/api/http/proxy/factory/docker/volumes.go @@ -168,16 +168,30 @@ func (transport *Transport) restrictedVolumeOperation(requestPath string, reques return transport.rewriteOperation(request, transport.volumeInspectOperation) } - cli := transport.dockerClient - volume, err := cli.VolumeInspect(context.Background(), path.Base(requestPath)) + agentTargetHeader := request.Header.Get(portainer.PortainerAgentTargetHeader) + + resourceID, err := transport.getVolumeResourceID(agentTargetHeader, path.Base(requestPath)) if err != nil { return nil, err } - volumeID := volume.Name + volume.CreatedAt - if request.Method == http.MethodDelete { - return transport.executeGenericResourceDeletionOperation(request, volumeID, portainer.VolumeResourceControl) + return transport.executeGenericResourceDeletionOperation(request, resourceID, portainer.VolumeResourceControl) + } + return transport.restrictedResourceOperation(request, resourceID, portainer.VolumeResourceControl, false) +} + +func (transport *Transport) getVolumeResourceID(nodename, volumeID string) (string, error) { + cli, err := transport.dockerClientFactory.CreateClient(transport.endpoint, nodename) + if err != nil { + return "", err } - return transport.restrictedResourceOperation(request, volumeID, portainer.VolumeResourceControl, false) + defer cli.Close() + + volume, err := cli.VolumeInspect(context.Background(), volumeID) + if err != nil { + return "", err + } + + return volume.Name + volume.CreatedAt, nil }