diff --git a/api/http/handler/endpointproxy/handler.go b/api/http/handler/endpointproxy/handler.go index 037cb4dfb..ec3da1e7b 100644 --- a/api/http/handler/endpointproxy/handler.go +++ b/api/http/handler/endpointproxy/handler.go @@ -29,6 +29,10 @@ func NewHandler(bouncer *security.RequestBouncer) *Handler { bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.proxyRequestsToDockerAPI))) h.PathPrefix("/{id}/kubernetes").Handler( bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.proxyRequestsToKubernetesAPI))) + h.PathPrefix("/{id}/agent/docker").Handler( + bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.proxyRequestsToDockerAPI))) + h.PathPrefix("/{id}/agent/kubernetes").Handler( + bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.proxyRequestsToKubernetesAPI))) h.PathPrefix("/{id}/storidge").Handler( bouncer.AuthenticatedAccess(httperror.LoggerHandler(h.proxyRequestsToStoridgeAPI))) return h diff --git a/api/http/handler/endpointproxy/proxy_docker.go b/api/http/handler/endpointproxy/proxy_docker.go index c4671506d..9ac89edbc 100644 --- a/api/http/handler/endpointproxy/proxy_docker.go +++ b/api/http/handler/endpointproxy/proxy_docker.go @@ -3,6 +3,7 @@ package endpointproxy import ( "errors" "strconv" + "strings" "time" httperror "github.com/portainer/libhttp/error" @@ -65,6 +66,12 @@ func (handler *Handler) proxyRequestsToDockerAPI(w http.ResponseWriter, r *http. } id := strconv.Itoa(endpointID) - http.StripPrefix("/"+id+"/docker", proxy).ServeHTTP(w, r) + + prefix := "/" + id + "/agent/docker"; + if !strings.HasPrefix(r.URL.Path, prefix) { + prefix = "/" + id + "/docker"; + } + + http.StripPrefix(prefix, proxy).ServeHTTP(w, r) return nil } diff --git a/api/http/handler/endpointproxy/proxy_kubernetes.go b/api/http/handler/endpointproxy/proxy_kubernetes.go index 1f6ed3bfd..88a369486 100644 --- a/api/http/handler/endpointproxy/proxy_kubernetes.go +++ b/api/http/handler/endpointproxy/proxy_kubernetes.go @@ -65,17 +65,18 @@ func (handler *Handler) proxyRequestsToKubernetesAPI(w http.ResponseWriter, r *h } } + // For KubernetesLocalEnvironment requestPrefix := fmt.Sprintf("/%d/kubernetes", endpointID) + if endpoint.Type == portainer.AgentOnKubernetesEnvironment || endpoint.Type == portainer.EdgeAgentOnKubernetesEnvironment { - if isKubernetesRequest(strings.TrimPrefix(r.URL.String(), requestPrefix)) { - requestPrefix = fmt.Sprintf("/%d", endpointID) + requestPrefix = fmt.Sprintf("/%d", endpointID) + + agentPrefix := fmt.Sprintf("/%d/agent/kubernetes", endpointID) + if strings.HasPrefix(r.URL.Path, agentPrefix) { + requestPrefix = agentPrefix } } http.StripPrefix(requestPrefix, proxy).ServeHTTP(w, r) return nil -} - -func isKubernetesRequest(requestURL string) bool { - return strings.HasPrefix(requestURL, "/api") || strings.HasPrefix(requestURL, "/healthz") -} +} \ No newline at end of file diff --git a/api/http/handler/handler.go b/api/http/handler/handler.go index b924ad660..a5c4e1dd5 100644 --- a/api/http/handler/handler.go +++ b/api/http/handler/handler.go @@ -176,6 +176,8 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { http.StripPrefix("/api/endpoints", h.EndpointProxyHandler).ServeHTTP(w, r) case strings.Contains(r.URL.Path, "/azure/"): http.StripPrefix("/api/endpoints", h.EndpointProxyHandler).ServeHTTP(w, r) + case strings.Contains(r.URL.Path, "/agent/"): + http.StripPrefix("/api/endpoints", h.EndpointProxyHandler).ServeHTTP(w, r) case strings.Contains(r.URL.Path, "/edge/"): http.StripPrefix("/api/endpoints", h.EndpointEdgeHandler).ServeHTTP(w, r) default: diff --git a/app/agent/rest/dockerhub.js b/app/agent/rest/dockerhub.js index eb901b494..369feda3e 100644 --- a/app/agent/rest/dockerhub.js +++ b/app/agent/rest/dockerhub.js @@ -4,7 +4,7 @@ angular.module('portainer.agent').factory('AgentDockerhub', AgentDockerhub); function AgentDockerhub($resource, API_ENDPOINT_ENDPOINTS) { return $resource( - `${API_ENDPOINT_ENDPOINTS}/:endpointId/:endpointType/v2/dockerhub/:registryId`, + `${API_ENDPOINT_ENDPOINTS}/:endpointId/agent/:endpointType/v2/dockerhub/:registryId`, {}, { limits: { method: 'GET', params: { registryId: '@registryId' } },