14287: Accept rpc requests without tokens.
authorTom Clegg <tclegg@veritasgenetics.com>
Tue, 7 May 2019 13:45:58 +0000 (09:45 -0400)
committerTom Clegg <tclegg@veritasgenetics.com>
Mon, 17 Jun 2019 13:54:39 +0000 (09:54 -0400)
Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>

lib/controller/rpc/conn.go

index 7c23ed170c7228e2a53730cc72c61ebbdc56b94b..9bb3eb33fb72d17aab6bbee1c54706c254b9b58a 100644 (file)
@@ -71,10 +71,15 @@ func (conn *Conn) requestAndDecode(ctx context.Context, dst interface{}, ep arva
        tokens, err := conn.tokenProvider(ctx)
        if err != nil {
                return err
-       } else if len(tokens) == 0 {
-               return fmt.Errorf("bug: token provider returned no tokens and no error")
+       } else if len(tokens) > 0 {
+               ctx = context.WithValue(ctx, "Authorization", "Bearer "+tokens[0])
+       } else {
+               // Use a non-empty auth string to ensure we override
+               // any default token set on aClient -- and to avoid
+               // having the remote prompt us to send a token by
+               // responding 401.
+               ctx = context.WithValue(ctx, "Authorization", "Bearer -")
        }
-       ctx = context.WithValue(ctx, "Authorization", "Bearer "+tokens[0])
 
        // Encode opts to JSON and decode from there to a
        // map[string]interface{}, so we can munge the query params