From 2c47a9b1d98e6423211829470569e93295d93558 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Thu, 30 Apr 2020 17:41:39 +0300 Subject: [PATCH] pkg/server: log api key in debug traffic Change-Id: I677832200c9599c37c22cf742b396ca12542a803 --- pkg/server/interceptors.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/server/interceptors.go b/pkg/server/interceptors.go index 841a86fe7..4cc57087a 100644 --- a/pkg/server/interceptors.go +++ b/pkg/server/interceptors.go @@ -16,6 +16,7 @@ import ( "storj.io/common/identity" "storj.io/common/rpc/rpcpeer" + "storj.io/storj/pkg/auth" "storj.io/storj/storage" ) @@ -61,6 +62,7 @@ type nodeRequestLog struct { GRPCMethod string `json:"grpc_method"` PeerAddress string `json:"peer_address"` PeerNodeID string `json:"peer_node_id"` + APIKey string `json:"api_key,omitempty"` Msg interface{} `json:"msg"` } @@ -69,6 +71,7 @@ func prepareRequestLog(ctx context.Context, req, server interface{}, methodName GRPCService: fmt.Sprintf("%T", server), GRPCMethod: methodName, PeerAddress: "", + APIKey: "", Msg: req, } 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("", err) } } + if key, ok := auth.GetAPIKey(ctx); ok { + reqLog.APIKey = string(key) + } return json.Marshal(reqLog) }