@@ -39,8 +39,6 @@ import (
3939 "google.golang.org/grpc/status"
4040)
4141
42- const logLevel = 2
43-
4442var logger = grpclog .Component ("rbac" )
4543
4644var getConnection = transport .GetConnection
@@ -65,6 +63,16 @@ func NewChainEngine(policies []*v3rbacpb.RBAC) (*ChainEngine, error) {
6563 return & ChainEngine {chainedEngines : engines }, nil
6664}
6765
66+ func (cre * ChainEngine ) logRequestDetails (rpcData * rpcData ) {
67+ if logger .V (2 ) {
68+ logger .Infof ("checking request: url path=%s" , rpcData .fullMethod )
69+ if len (rpcData .certs ) > 0 {
70+ cert := rpcData .certs [0 ]
71+ logger .Infof ("uri sans=%q, dns sans=%q, subject=%v" , cert .URIs , cert .DNSNames , cert .Subject )
72+ }
73+ }
74+ }
75+
6876// IsAuthorized determines if an incoming RPC is authorized based on the chain of RBAC
6977// engines and their associated actions.
7078//
@@ -79,14 +87,16 @@ func (cre *ChainEngine) IsAuthorized(ctx context.Context) error {
7987 }
8088 for _ , engine := range cre .chainedEngines {
8189 matchingPolicyName , ok := engine .findMatchingPolicy (rpcData )
82- if logger .V (logLevel ) && ok {
90+ if logger .V (2 ) && ok {
8391 logger .Infof ("incoming RPC matched to policy %v in engine with action %v" , matchingPolicyName , engine .action )
8492 }
8593
8694 switch {
8795 case engine .action == v3rbacpb .RBAC_ALLOW && ! ok :
96+ cre .logRequestDetails (rpcData )
8897 return status .Errorf (codes .PermissionDenied , "incoming RPC did not match an allow policy" )
8998 case engine .action == v3rbacpb .RBAC_DENY && ok :
99+ cre .logRequestDetails (rpcData )
90100 return status .Errorf (codes .PermissionDenied , "incoming RPC matched a deny policy %q" , matchingPolicyName )
91101 }
92102 // Every policy in the engine list must be queried. Thus, iterate to the
0 commit comments