20
20
package main
21
21
22
22
import (
23
+ "context"
23
24
"flag"
24
25
"net"
25
26
"strings"
@@ -29,6 +30,7 @@ import (
29
30
"google.golang.org/grpc/grpclog"
30
31
"google.golang.org/grpc/interop"
31
32
testpb "google.golang.org/grpc/interop/grpc_testing"
33
+ "google.golang.org/grpc/tap"
32
34
)
33
35
34
36
const (
@@ -59,7 +61,25 @@ func main() {
59
61
opts .HandshakerServiceAddress = * hsAddr
60
62
}
61
63
altsTC := alts .NewServerCreds (opts )
62
- grpcServer := grpc .NewServer (grpc .Creds (altsTC ))
64
+ grpcServer := grpc .NewServer (grpc .Creds (altsTC ), grpc . InTapHandle ( authz ) )
63
65
testpb .RegisterTestServiceServer (grpcServer , interop .NewTestServer ())
64
66
grpcServer .Serve (lis )
65
67
}
68
+
69
+ // authz shows how to access client information at the server side to perform
70
+ // application-layer authorization checks.
71
+ func authz (ctx context.Context , info * tap.Info ) (context.Context , error ) {
72
+ authInfo , err := alts .AuthInfoFromContext (ctx )
73
+ if err != nil {
74
+ return nil , err
75
+ }
76
+ // Access all alts.AuthInfo data:
77
+ grpclog .Infof ("authInfo.ApplicationProtocol() = %v" , authInfo .ApplicationProtocol ())
78
+ grpclog .Infof ("authInfo.RecordProtocol() = %v" , authInfo .RecordProtocol ())
79
+ grpclog .Infof ("authInfo.SecurityLevel() = %v" , authInfo .SecurityLevel ())
80
+ grpclog .Infof ("authInfo.PeerServiceAccount() = %v" , authInfo .PeerServiceAccount ())
81
+ grpclog .Infof ("authInfo.LocalServiceAccount() = %v" , authInfo .LocalServiceAccount ())
82
+ grpclog .Infof ("authInfo.PeerRPCVersions() = %v" , authInfo .PeerRPCVersions ())
83
+ grpclog .Infof ("info.FullMethodName = %v" , info .FullMethodName )
84
+ return ctx , nil
85
+ }
0 commit comments