Skip to content

Commit 011544f

Browse files
authz: add additional logs to sdk authz (#5094)
* Adds additional logs to sdk authz * resolve comment * adds logs displaying request details * remove sdk_server_interceptor log * log subset of rpcData * resolving comment * format log message
1 parent 18564ff commit 011544f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

authz/grpc_authz_server_interceptors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func (i *StaticInterceptor) UnaryInterceptor(ctx context.Context, req interface{
6262
err := i.engines.IsAuthorized(ctx)
6363
if err != nil {
6464
if status.Code(err) == codes.PermissionDenied {
65+
if logger.V(2) {
66+
logger.Infof("unauthorized RPC request rejected: %v", err)
67+
}
6568
return nil, status.Errorf(codes.PermissionDenied, "unauthorized RPC request rejected")
6669
}
6770
return nil, err
@@ -76,6 +79,9 @@ func (i *StaticInterceptor) StreamInterceptor(srv interface{}, ss grpc.ServerStr
7679
err := i.engines.IsAuthorized(ss.Context())
7780
if err != nil {
7881
if status.Code(err) == codes.PermissionDenied {
82+
if logger.V(2) {
83+
logger.Infof("unauthorized RPC request rejected: %v", err)
84+
}
7985
return status.Errorf(codes.PermissionDenied, "unauthorized RPC request rejected")
8086
}
8187
return err

internal/xds/rbac/rbac_engine.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ import (
3939
"google.golang.org/grpc/status"
4040
)
4141

42-
const logLevel = 2
43-
4442
var logger = grpclog.Component("rbac")
4543

4644
var 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

Comments
 (0)