Skip to content

Commit

Permalink
mt-broker ingress: Reject unauthorized requests (#8105)
Browse files Browse the repository at this point in the history
* mt-broker ingress: Reject unauthorized requests

* fix: verify audience before proceeding verification

* Change to review comment

Co-authored-by: Pierangelo Di Pilato <[email protected]>

---------

Co-authored-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
joyxxi and pierDipi authored Jul 23, 2024
1 parent 7c1c46c commit c3baeda
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/broker/ingress/ingress_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"strings"
"time"

"k8s.io/utils/ptr"

opencensusclient "github.com/cloudevents/sdk-go/observability/opencensus/v2/client"
cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/cloudevents/sdk-go/v2/binding"
Expand Down Expand Up @@ -231,16 +233,14 @@ func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
}

features := feature.FromContext(ctx)
if features.IsOIDCAuthentication() {
h.Logger.Debug("OIDC authentication is enabled")

err = h.tokenVerifier.VerifyJWTFromRequest(ctx, request, broker.Status.Address.Audience, writer)
if err != nil {
h.Logger.Warn("Error when validating the JWT token in the request", zap.Error(err))
return
}

h.Logger.Debug("Request contained a valid JWT. Continuing...")
audience := ptr.To("")
if broker.Status.Address != nil {
audience = broker.Status.Address.Audience
}
err = h.tokenVerifier.VerifyRequest(ctx, features, audience, brokerNamespace, broker.Status.Policies, request, writer)
if err != nil {
h.Logger.Warn("Failed to verify AuthN and AuthZ.", zap.Error(err))
return
}

ctx, span := trace.StartSpan(ctx, tracing.BrokerMessagingDestination(brokerNamespacedName))
Expand Down

0 comments on commit c3baeda

Please sign in to comment.