Skip to content

Commit

Permalink
credentials/alts: Add example of authz in ALTS (#2814)
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarghali committed May 16, 2019
1 parent 263405c commit 8655d47
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion interop/alts/server/server.go
Expand Up @@ -20,6 +20,7 @@
package main

import (
"context"
"flag"
"net"
"strings"
Expand All @@ -29,6 +30,7 @@ import (
"google.golang.org/grpc/grpclog"
"google.golang.org/grpc/interop"
testpb "google.golang.org/grpc/interop/grpc_testing"
"google.golang.org/grpc/tap"
)

const (
Expand Down Expand Up @@ -59,7 +61,25 @@ func main() {
opts.HandshakerServiceAddress = *hsAddr
}
altsTC := alts.NewServerCreds(opts)
grpcServer := grpc.NewServer(grpc.Creds(altsTC))
grpcServer := grpc.NewServer(grpc.Creds(altsTC), grpc.InTapHandle(authz))
testpb.RegisterTestServiceServer(grpcServer, interop.NewTestServer())
grpcServer.Serve(lis)
}

// authz shows how to access client information at the server side to perform
// application-layer authorization checks.
func authz(ctx context.Context, info *tap.Info) (context.Context, error) {
authInfo, err := alts.AuthInfoFromContext(ctx)
if err != nil {
return nil, err
}
// Access all alts.AuthInfo data:
grpclog.Infof("authInfo.ApplicationProtocol() = %v", authInfo.ApplicationProtocol())
grpclog.Infof("authInfo.RecordProtocol() = %v", authInfo.RecordProtocol())
grpclog.Infof("authInfo.SecurityLevel() = %v", authInfo.SecurityLevel())
grpclog.Infof("authInfo.PeerServiceAccount() = %v", authInfo.PeerServiceAccount())
grpclog.Infof("authInfo.LocalServiceAccount() = %v", authInfo.LocalServiceAccount())
grpclog.Infof("authInfo.PeerRPCVersions() = %v", authInfo.PeerRPCVersions())
grpclog.Infof("info.FullMethodName = %v", info.FullMethodName)
return ctx, nil
}

0 comments on commit 8655d47

Please sign in to comment.