add auth support for forwarder node
This commit is contained in:
@ -288,6 +288,7 @@ type ForwardNodeConfig struct {
|
||||
Bypasses []string `yaml:",omitempty" json:"bypasses,omitempty"`
|
||||
HTTP *HTTPNodeConfig `yaml:",omitempty" json:"http,omitempty"`
|
||||
TLS *TLSNodeConfig `yaml:",omitempty" json:"tls,omitempty"`
|
||||
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
||||
}
|
||||
|
||||
type HTTPNodeConfig struct {
|
||||
@ -382,6 +383,7 @@ type NodeConfig struct {
|
||||
Metadata map[string]any `yaml:",omitempty" json:"metadata,omitempty"`
|
||||
HTTP *HTTPNodeConfig `yaml:",omitempty" json:"http,omitempty"`
|
||||
TLS *TLSNodeConfig `yaml:",omitempty" json:"tls,omitempty"`
|
||||
Auth *AuthConfig `yaml:",omitempty" json:"auth,omitempty"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
|
@ -12,6 +12,7 @@ import (
|
||||
"github.com/go-gost/core/logger"
|
||||
"github.com/go-gost/core/metadata"
|
||||
mdutil "github.com/go-gost/core/metadata/util"
|
||||
auther "github.com/go-gost/x/auth"
|
||||
xchain "github.com/go-gost/x/chain"
|
||||
"github.com/go-gost/x/config"
|
||||
tls_util "github.com/go-gost/x/internal/util/tls"
|
||||
@ -231,6 +232,19 @@ func ParseHop(cfg *config.HopConfig) (chain.Hop, error) {
|
||||
Secure: v.TLS.Secure,
|
||||
}))
|
||||
}
|
||||
if v.Auth != nil {
|
||||
opts = append(opts, chain.AutherNodeOption(
|
||||
auther.NewAuthenticator(
|
||||
auther.AuthsOption(map[string]string{v.Auth.Username: v.Auth.Password}),
|
||||
auther.LoggerOption(logger.Default().WithFields(map[string]any{
|
||||
"kind": "node",
|
||||
"node": v.Name,
|
||||
"addr": v.Addr,
|
||||
"host": v.Host,
|
||||
"protocol": v.Protocol,
|
||||
})),
|
||||
)))
|
||||
}
|
||||
node := chain.NewNode(v.Name, v.Addr, opts...)
|
||||
nodes = append(nodes, node)
|
||||
}
|
||||
|
@ -259,6 +259,7 @@ func parseForwarder(cfg *config.ForwarderConfig) (chain.Hop, error) {
|
||||
Bypasses: node.Bypasses,
|
||||
HTTP: node.HTTP,
|
||||
TLS: node.TLS,
|
||||
Auth: node.Auth,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user