16212: Add clues/details to authentication error messages.
[arvados.git] / lib / controller / fed_containers.go
index 7b8cdabe5524898e215120941e9400bcae5d510c..a923f757f2eb61afc29d27ee18bfbd42a27a6c1c 100644 (file)
@@ -12,8 +12,8 @@ import (
        "net/http"
        "strings"
 
-       "git.curoverse.com/arvados.git/sdk/go/auth"
-       "git.curoverse.com/arvados.git/sdk/go/httpserver"
+       "git.arvados.org/arvados.git/sdk/go/auth"
+       "git.arvados.org/arvados.git/sdk/go/httpserver"
 )
 
 func remoteContainerRequestCreate(
@@ -33,9 +33,12 @@ func remoteContainerRequestCreate(
        creds := auth.NewCredentials()
        creds.LoadTokensFromHTTPRequest(req)
 
-       currentUser, err := h.handler.validateAPItoken(req, creds.Tokens[0])
+       currentUser, ok, err := h.handler.validateAPItoken(req, creds.Tokens[0])
        if err != nil {
-               httpserver.Error(w, err.Error(), http.StatusForbidden)
+               httpserver.Error(w, err.Error(), http.StatusInternalServerError)
+               return true
+       } else if !ok {
+               httpserver.Error(w, "invalid API token", http.StatusForbidden)
                return true
        }
 
@@ -99,8 +102,14 @@ func remoteContainerRequestCreate(
                        containerRequest["runtime_token"] = newtok.TokenV2()
                } else {
                        // Remote user. Container request will use the
-                       // current token.
-                       containerRequest["runtime_token"] = creds.Tokens[0]
+                       // current token, minus the trailing portion
+                       // (optional container uuid).
+                       sp := strings.Split(creds.Tokens[0], "/")
+                       if len(sp) >= 3 {
+                               containerRequest["runtime_token"] = strings.Join(sp[0:3], "/")
+                       } else {
+                               containerRequest["runtime_token"] = creds.Tokens[0]
+                       }
                }
        }