Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbac: fix usage of AuthInfo #7522

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions internal/xds/rbac/rbac_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,9 @@ func newRPCData(ctx context.Context) (*rpcData, error) {

var authType string
var peerCertificates []*x509.Certificate
if pi.AuthInfo != nil {
tlsInfo, ok := pi.AuthInfo.(credentials.TLSInfo)
if ok {
authType = pi.AuthInfo.AuthType()
peerCertificates = tlsInfo.State.PeerCertificates
}
if tlsInfo, ok := pi.AuthInfo.(credentials.TLSInfo); ok {
authType = pi.AuthInfo.AuthType()
peerCertificates = tlsInfo.State.PeerCertificates
}

return &rpcData{
Expand Down Expand Up @@ -281,11 +278,12 @@ func (e *engine) doAuditLogging(rpcData *rpcData, rule string, authorized bool)
// In the RBAC world, we need to have a SPIFFE ID as the principal for this
// to be meaningful
principal := ""
if rpcData.peerInfo != nil && rpcData.peerInfo.AuthInfo != nil && rpcData.peerInfo.AuthInfo.AuthType() == "tls" {
if rpcData.peerInfo != nil {
// If AuthType = tls, then we can cast AuthInfo to TLSInfo.
tlsInfo := rpcData.peerInfo.AuthInfo.(credentials.TLSInfo)
if tlsInfo.SPIFFEID != nil {
principal = tlsInfo.SPIFFEID.String()
if tlsInfo, ok := rpcData.peerInfo.AuthInfo.(credentials.TLSInfo); ok {
if tlsInfo.SPIFFEID != nil {
principal = tlsInfo.SPIFFEID.String()
}
}
}

Expand Down
Loading