Documentation
¶
Index ¶
- func AccountIdFromContext(ctx context.Context) types.AccountID
- func IsTrustedProxy(ipStr string, trusted []netip.Prefix) bool
- func ResolveClientIP(remoteAddr, xff string, trusted []netip.Prefix) string
- func ServiceIdFromContext(ctx context.Context) string
- func WithCapturedData(ctx context.Context, data *CapturedData) context.Context
- type CapturedData
- func (c *CapturedData) GetAccountId() types.AccountID
- func (c *CapturedData) GetAuthMethod() string
- func (c *CapturedData) GetClientIP() string
- func (c *CapturedData) GetOrigin() ResponseOrigin
- func (c *CapturedData) GetRequestID() string
- func (c *CapturedData) GetServiceId() string
- func (c *CapturedData) GetUserID() string
- func (c *CapturedData) SetAccountId(accountId types.AccountID)
- func (c *CapturedData) SetAuthMethod(method string)
- func (c *CapturedData) SetClientIP(ip string)
- func (c *CapturedData) SetOrigin(origin ResponseOrigin)
- func (c *CapturedData) SetServiceId(serviceId string)
- func (c *CapturedData) SetUserID(userID string)
- type Mapping
- type ResponseOrigin
- type ReverseProxy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTrustedProxy ¶
IsTrustedProxy checks if the given IP string falls within any of the trusted prefixes.
func ResolveClientIP ¶
ResolveClientIP extracts the real client IP from X-Forwarded-For using the trusted proxy list. It walks the XFF chain right-to-left, skipping IPs that match trusted prefixes. The first untrusted IP is the real client.
If the trusted list is empty or remoteAddr is not trusted, it returns the remoteAddr IP directly (ignoring any forwarding headers).
func ServiceIdFromContext ¶
func WithCapturedData ¶
func WithCapturedData(ctx context.Context, data *CapturedData) context.Context
WithCapturedData adds a CapturedData struct to the context
Types ¶
type CapturedData ¶
type CapturedData struct {
RequestID string
ServiceId string
AccountId types.AccountID
Origin ResponseOrigin
ClientIP string
UserID string
AuthMethod string
// contains filtered or unexported fields
}
CapturedData is a mutable struct that allows downstream handlers to pass data back up the middleware chain.
func CapturedDataFromContext ¶
func CapturedDataFromContext(ctx context.Context) *CapturedData
CapturedDataFromContext retrieves the CapturedData from context
func (*CapturedData) GetAccountId ¶
func (c *CapturedData) GetAccountId() types.AccountID
GetAccountId safely gets the account ID
func (*CapturedData) GetAuthMethod ¶
func (c *CapturedData) GetAuthMethod() string
GetAuthMethod safely gets the authentication method used.
func (*CapturedData) GetClientIP ¶
func (c *CapturedData) GetClientIP() string
GetClientIP safely gets the resolved client IP.
func (*CapturedData) GetOrigin ¶
func (c *CapturedData) GetOrigin() ResponseOrigin
GetOrigin safely gets the response origin
func (*CapturedData) GetRequestID ¶
func (c *CapturedData) GetRequestID() string
GetRequestID safely gets the request ID
func (*CapturedData) GetServiceId ¶
func (c *CapturedData) GetServiceId() string
GetServiceId safely gets the service ID
func (*CapturedData) GetUserID ¶
func (c *CapturedData) GetUserID() string
GetUserID safely gets the authenticated user ID.
func (*CapturedData) SetAccountId ¶
func (c *CapturedData) SetAccountId(accountId types.AccountID)
SetAccountId safely sets the account ID
func (*CapturedData) SetAuthMethod ¶
func (c *CapturedData) SetAuthMethod(method string)
SetAuthMethod safely sets the authentication method used.
func (*CapturedData) SetClientIP ¶
func (c *CapturedData) SetClientIP(ip string)
SetClientIP safely sets the resolved client IP.
func (*CapturedData) SetOrigin ¶
func (c *CapturedData) SetOrigin(origin ResponseOrigin)
SetOrigin safely sets the response origin
func (*CapturedData) SetServiceId ¶
func (c *CapturedData) SetServiceId(serviceId string)
SetServiceId safely sets the service ID
func (*CapturedData) SetUserID ¶
func (c *CapturedData) SetUserID(userID string)
SetUserID safely sets the authenticated user ID.
type ResponseOrigin ¶
type ResponseOrigin int
ResponseOrigin indicates where a response was generated.
const ( // OriginBackend means the response came from the backend service. OriginBackend ResponseOrigin = iota // OriginNoRoute means the proxy had no matching host or path. OriginNoRoute // OriginProxyError means the proxy failed to reach the backend. OriginProxyError // OriginAuth means the proxy intercepted the request for authentication. OriginAuth )
func (ResponseOrigin) String ¶
func (o ResponseOrigin) String() string
type ReverseProxy ¶
type ReverseProxy struct {
// contains filtered or unexported fields
}
func NewReverseProxy ¶
func NewReverseProxy(transport http.RoundTripper, forwardedProto string, trustedProxies []netip.Prefix, logger *log.Logger) *ReverseProxy
NewReverseProxy configures a new NetBird ReverseProxy. This is a wrapper around an httputil.ReverseProxy set to dynamically route requests based on internal mapping between requested URLs and targets. The internal mappings can be modified using the AddMapping and RemoveMapping functions.
func (*ReverseProxy) AddMapping ¶
func (p *ReverseProxy) AddMapping(m Mapping)
func (*ReverseProxy) RemoveMapping ¶
func (p *ReverseProxy) RemoveMapping(m Mapping)
func (*ReverseProxy) ServeHTTP ¶
func (p *ReverseProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)