Skip to content

Commit

Permalink
credentials/alts: ClientAuthorizationCheck to case-fold compare of pe…
Browse files Browse the repository at this point in the history
…er SA (#3792)
  • Loading branch information
AntonNep committed Sep 1, 2020
1 parent d8ef479 commit 48bf772
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions credentials/alts/utils.go
Expand Up @@ -152,12 +152,13 @@ func AuthInfoFromPeer(p *peer.Peer) (AuthInfo, error) {
func ClientAuthorizationCheck(ctx context.Context, expectedServiceAccounts []string) error {
authInfo, err := AuthInfoFromContext(ctx)
if err != nil {
return status.Newf(codes.PermissionDenied, "The context is not an ALTS-compatible context: %v", err).Err()
return status.Errorf(codes.PermissionDenied, "The context is not an ALTS-compatible context: %v", err)
}
peer := authInfo.PeerServiceAccount()
for _, sa := range expectedServiceAccounts {
if authInfo.PeerServiceAccount() == sa {
if strings.EqualFold(peer, sa) {
return nil
}
}
return status.Newf(codes.PermissionDenied, "Client %v is not authorized", authInfo.PeerServiceAccount()).Err()
return status.Errorf(codes.PermissionDenied, "Client %v is not authorized", peer)
}
7 changes: 7 additions & 0 deletions credentials/alts/utils_test.go
Expand Up @@ -175,6 +175,13 @@ func (s) TestClientAuthorizationCheck(t *testing.T) {
true,
codes.OK, // err is nil, code is OK.
},
{
"working case (case ignored)",
peer.NewContext(ctx, p),
[]string{strings.ToUpper(testServiceAccount1), testServiceAccount2},
true,
codes.OK, // err is nil, code is OK.
},
{
"context does not have AuthInfo",
ctx,
Expand Down

0 comments on commit 48bf772

Please sign in to comment.