Skip to content

Commit

Permalink
mt-broker ingress: Reject unauthorized requests
Browse files Browse the repository at this point in the history
  • Loading branch information
joyxxi committed Jul 17, 2024
1 parent 57b52ea commit 6274697
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions pkg/broker/ingress/ingress_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,11 @@ 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...")
err = h.tokenVerifier.VerifyRequest(ctx, features, broker.Status.Address.Audience, brokerNamespace, broker.Status.Policies, request, writer)
if err != nil {
h.Logger.Warn("Failed to verify AuthN and AuthZ.", zap.Error(err))
writer.WriteHeader(http.StatusForbidden)
return
}

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

0 comments on commit 6274697

Please sign in to comment.