mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-29 15:59:10 +01:00
[management] Match account ids from the request and service config (#8386)
* match account ids from the request and service config Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io> * match account ids from the request and service config Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io> * add tests Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io> --------- Signed-off-by: Dmitri Dolguikh <dmitri.external@netbird.io>
This commit is contained in:
+16
-1
@@ -19,6 +19,7 @@ import (
|
||||
"github.com/netbirdio/netbird/client/embed"
|
||||
"github.com/netbirdio/netbird/proxy/internal/auth"
|
||||
"github.com/netbirdio/netbird/proxy/internal/debug"
|
||||
"github.com/netbirdio/netbird/proxy/internal/proxy"
|
||||
nbtcp "github.com/netbirdio/netbird/proxy/internal/tcp"
|
||||
"github.com/netbirdio/netbird/proxy/internal/types"
|
||||
)
|
||||
@@ -141,7 +142,7 @@ func (m *inboundManager) bringUp(ctx context.Context, accountID types.AccountID,
|
||||
|
||||
router := nbtcp.NewRouter(m.logger, accountDialResolver(accountID, client), tlsListener.Addr(), nbtcp.WithPlainHTTP(plainListener.Addr()))
|
||||
|
||||
scopedHandler := withTunnelLookup(m.handler, accountTunnelLookup(client))
|
||||
scopedHandler := withCapturedData(withTunnelLookup(m.handler, accountTunnelLookup(client)), accountID)
|
||||
|
||||
// markOverlayOrigin stamps every connection accepted by an inbound
|
||||
// listener with a context value middlewares can read to skip
|
||||
@@ -530,6 +531,20 @@ func withTunnelLookup(next http.Handler, lookup auth.TunnelLookupFunc) http.Hand
|
||||
})
|
||||
}
|
||||
|
||||
func withCapturedData(next http.Handler, accountID types.AccountID) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
if d := proxy.CapturedDataFromContext(ctx); d != nil {
|
||||
d.SetAccountID(accountID)
|
||||
} else {
|
||||
d := &proxy.CapturedData{}
|
||||
d.SetAccountID(accountID)
|
||||
ctx = proxy.WithCapturedData(ctx, d)
|
||||
}
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
||||
// inboundDebugAdapter adapts *inboundManager to the debug.InboundProvider
|
||||
// interface so the debug HTTP handler can render per-account inbound
|
||||
// listener state without importing the proxy package.
|
||||
|
||||
Reference in New Issue
Block a user