pkg/server: log api key in debug traffic

Change-Id: I677832200c9599c37c22cf742b396ca12542a803
This commit is contained in:
Egon Elbre 2020-04-30 17:41:39 +03:00
parent 4e5e6c8e5c
commit 2c47a9b1d9

View File

@ -16,6 +16,7 @@ import (
"storj.io/common/identity" "storj.io/common/identity"
"storj.io/common/rpc/rpcpeer" "storj.io/common/rpc/rpcpeer"
"storj.io/storj/pkg/auth"
"storj.io/storj/storage" "storj.io/storj/storage"
) )
@ -61,6 +62,7 @@ type nodeRequestLog struct {
GRPCMethod string `json:"grpc_method"` GRPCMethod string `json:"grpc_method"`
PeerAddress string `json:"peer_address"` PeerAddress string `json:"peer_address"`
PeerNodeID string `json:"peer_node_id"` PeerNodeID string `json:"peer_node_id"`
APIKey string `json:"api_key,omitempty"`
Msg interface{} `json:"msg"` Msg interface{} `json:"msg"`
} }
@ -69,6 +71,7 @@ func prepareRequestLog(ctx context.Context, req, server interface{}, methodName
GRPCService: fmt.Sprintf("%T", server), GRPCService: fmt.Sprintf("%T", server),
GRPCMethod: methodName, GRPCMethod: methodName,
PeerAddress: "<no peer???>", PeerAddress: "<no peer???>",
APIKey: "",
Msg: req, Msg: req,
} }
if peer, err := rpcpeer.FromContext(ctx); err == nil { if peer, err := rpcpeer.FromContext(ctx); err == nil {
@ -79,6 +82,9 @@ func prepareRequestLog(ctx context.Context, req, server interface{}, methodName
reqLog.PeerNodeID = fmt.Sprintf("<no peer id: %v>", err) reqLog.PeerNodeID = fmt.Sprintf("<no peer id: %v>", err)
} }
} }
if key, ok := auth.GetAPIKey(ctx); ok {
reqLog.APIKey = string(key)
}
return json.Marshal(reqLog) return json.Marshal(reqLog)
} }