rpc_proxy+litcli: replace dummy string with empty macaroon

To avoid the macaroon parsing to fail in session.IsSuperMacaroon(), we
want the dummy macaroon to be formally valid (meaning, it can be parsed)
but not actually valid (meaning, it will fail the signature verification
since we don't have the root key for it anywhere).
This commit is contained in:
Oliver Gugger 2022-02-07 16:13:16 +01:00
parent 517b598665
commit 43ed7ed27a
No known key found for this signature in database
GPG key ID: 8E4256593F177720
2 changed files with 12 additions and 2 deletions

View file

@ -3,6 +3,7 @@ package main
import (
"context"
"encoding/base64"
"encoding/hex"
"fmt"
"os"
"path/filepath"
@ -210,7 +211,7 @@ func getAuthContext(cliCtx *cli.Context) context.Context {
ctxb := context.Background()
md := metadata.MD{}
md.Set("macaroon", "no-macaroons-for-litcli")
md.Set("macaroon", hex.EncodeToString(terminal.EmptyMacaroonBytes))
md.Set("authorization", fmt.Sprintf("Basic %s", basicAuth))
return metadata.NewOutgoingContext(ctxb, md)

View file

@ -33,6 +33,15 @@ const (
HeaderMacaroon = "Macaroon"
)
var (
// EmptyMacaroonBytes is the byte representation of an empty but
// formally valid macaroon.
EmptyMacaroonBytes, _ = hex.DecodeString(
"020205656d7074790000062062083e2ea599285ac29350abb4ea21fd7c5a" +
"15aca8b4c0d38e6c058829369e50",
)
)
// proxyErr is an error type that adds more context to an error occurring in the
// proxy.
type proxyErr struct {
@ -499,7 +508,7 @@ func (p *rpcProxy) basicAuthToMacaroon(basicAuth, requestURI string,
}
case isLitURI(requestURI):
return []byte("no-macaroons-for-litcli"), nil
return EmptyMacaroonBytes, nil
default:
return nil, fmt.Errorf("unknown gRPC web request: %v",