Skip to content

Commit

Permalink
all: Move authorization middlewares before rate limiting middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansmares committed Nov 21, 2023
1 parent 17a2d7e commit a3237d3
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 15 deletions.
12 changes: 0 additions & 12 deletions pkg/basicstation/cups/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"go.thethings.network/lorawan-stack/v3/pkg/web"
"golang.org/x/sync/singleflight"
"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
)

// Server implements the Basic Station Configuration and Update Server.
Expand Down Expand Up @@ -184,17 +183,6 @@ func (s *Server) RegisterRoutes(web *web.Server) {
router.Path("/update-info").HandlerFunc(s.UpdateInfo).Methods(http.MethodPost)
}

func getContext(r *http.Request) context.Context {
ctx := r.Context()
md := metadata.New(map[string]string{
"authorization": r.Header.Get("Authorization"),
})
if ctxMd, ok := metadata.FromIncomingContext(ctx); ok {
md = metadata.Join(ctxMd, md)
}
return metadata.NewIncomingContext(ctx, md)
}

var errNoTrust = errors.DefineInternal("no_trust", "no trusted certificate found")

// parseAddress parses a CUPS or LNS address.
Expand Down
2 changes: 1 addition & 1 deletion pkg/console/internal/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ func (h *eventsHandler) RegisterRoutes(server *web.Server) {
router := server.APIRouter().PathPrefix(ttnpb.HTTPAPIPrefix + "/console/internal/events/").Subrouter()
router.Use(
mux.MiddlewareFunc(webmiddleware.Namespace("console/internal/events")),
ratelimit.HTTPMiddleware(h.component.RateLimiter(), "http:console:internal:events"),
mux.MiddlewareFunc(middleware.ProtocolAuthentication(authorizationProtocolPrefix)),
mux.MiddlewareFunc(webmiddleware.Metadata("Authorization")),
ratelimit.HTTPMiddleware(h.component.RateLimiter(), "http:console:internal:events"),
)
router.Path("/").HandlerFunc(h.handleEvents).Methods(http.MethodGet)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gatewayconfigurationserver/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (s *Server) RegisterRoutes(server *web.Server) {
router := server.Prefix(ttnpb.HTTPAPIPrefix + "/gcs/gateways/{gateway_id}/").Subrouter()
router.Use(
mux.MiddlewareFunc(webmiddleware.Namespace("gatewayconfigurationserver")),
ratelimit.HTTPMiddleware(s.Component.RateLimiter(), "http:gcs"),
mux.MiddlewareFunc(webmiddleware.Metadata("Authorization")),
ratelimit.HTTPMiddleware(s.Component.RateLimiter(), "http:gcs"),
validateAndFillIDs,
)
if s.config.RequireAuth {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gatewayconfigurationserver/v2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func (s *Server) RegisterRoutes(server *web.Server) {

middleware := []webmiddleware.MiddlewareFunc{
webmiddleware.Namespace("gatewayconfigurationserver/v2"),
ratelimit.HTTPMiddleware(s.component.RateLimiter(), "http:gcs"),
rewriteAuthorization,
webmiddleware.Metadata("Authorization"),
ratelimit.HTTPMiddleware(s.component.RateLimiter(), "http:gcs"),
}

router.Handle(
Expand Down

0 comments on commit a3237d3

Please sign in to comment.