Skip to content

Commit 773bdb8

Browse files
dfawleyinfovivek2020
authored andcommitted
rbac: fix usage of AuthInfo (grpc#7522)
1 parent ded7eb8 commit 773bdb8

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

internal/xds/rbac/rbac_engine.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,9 @@ func newRPCData(ctx context.Context) (*rpcData, error) {
237237

238238
var authType string
239239
var peerCertificates []*x509.Certificate
240-
if pi.AuthInfo != nil {
241-
tlsInfo, ok := pi.AuthInfo.(credentials.TLSInfo)
242-
if ok {
243-
authType = pi.AuthInfo.AuthType()
244-
peerCertificates = tlsInfo.State.PeerCertificates
245-
}
240+
if tlsInfo, ok := pi.AuthInfo.(credentials.TLSInfo); ok {
241+
authType = pi.AuthInfo.AuthType()
242+
peerCertificates = tlsInfo.State.PeerCertificates
246243
}
247244

248245
return &rpcData{
@@ -281,11 +278,12 @@ func (e *engine) doAuditLogging(rpcData *rpcData, rule string, authorized bool)
281278
// In the RBAC world, we need to have a SPIFFE ID as the principal for this
282279
// to be meaningful
283280
principal := ""
284-
if rpcData.peerInfo != nil && rpcData.peerInfo.AuthInfo != nil && rpcData.peerInfo.AuthInfo.AuthType() == "tls" {
281+
if rpcData.peerInfo != nil {
285282
// If AuthType = tls, then we can cast AuthInfo to TLSInfo.
286-
tlsInfo := rpcData.peerInfo.AuthInfo.(credentials.TLSInfo)
287-
if tlsInfo.SPIFFEID != nil {
288-
principal = tlsInfo.SPIFFEID.String()
283+
if tlsInfo, ok := rpcData.peerInfo.AuthInfo.(credentials.TLSInfo); ok {
284+
if tlsInfo.SPIFFEID != nil {
285+
principal = tlsInfo.SPIFFEID.String()
286+
}
289287
}
290288
}
291289

0 commit comments

Comments
 (0)