mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
add domain validation using values from proxies
This commit is contained in:
@@ -34,14 +34,20 @@ type store interface {
|
||||
DeleteCustomDomain(ctx context.Context, accountID string, domainID string) error
|
||||
}
|
||||
|
||||
type Manager struct {
|
||||
store store
|
||||
validator Validator
|
||||
type proxyURLProvider interface {
|
||||
GetConnectedProxyURLs() []string
|
||||
}
|
||||
|
||||
func NewManager(store store) Manager {
|
||||
type Manager struct {
|
||||
store store
|
||||
validator Validator
|
||||
proxyURLProvider proxyURLProvider
|
||||
}
|
||||
|
||||
func NewManager(store store, proxyURLProvider proxyURLProvider) Manager {
|
||||
return Manager{
|
||||
store: store,
|
||||
store: store,
|
||||
proxyURLProvider: proxyURLProvider,
|
||||
validator: Validator{
|
||||
resolver: net.DefaultResolver,
|
||||
},
|
||||
@@ -95,8 +101,10 @@ func (m Manager) CreateDomain(ctx context.Context, accountID, domainName string)
|
||||
// because the user may not yet have configured their DNS records, or the DNS update
|
||||
// has not yet reached the servers that are queried by the validation resolver.
|
||||
var validated bool
|
||||
// TODO: retrieve in use reverse proxy addresses from somewhere!
|
||||
var reverseProxyAddresses []string
|
||||
if m.proxyURLProvider != nil {
|
||||
reverseProxyAddresses = m.proxyURLProvider.GetConnectedProxyURLs()
|
||||
}
|
||||
if m.validator.IsValid(ctx, domainName, reverseProxyAddresses) {
|
||||
validated = true
|
||||
}
|
||||
@@ -123,8 +131,10 @@ func (m Manager) ValidateDomain(accountID, domainID string) {
|
||||
// TODO: something? Log?
|
||||
return
|
||||
}
|
||||
// TODO: retrieve in use reverse proxy addresses from somewhere!
|
||||
var reverseProxyAddresses []string
|
||||
if m.proxyURLProvider != nil {
|
||||
reverseProxyAddresses = m.proxyURLProvider.GetConnectedProxyURLs()
|
||||
}
|
||||
if m.validator.IsValid(context.Background(), d.Domain, reverseProxyAddresses) {
|
||||
d.Validated = true
|
||||
if _, err := m.store.UpdateCustomDomain(context.Background(), accountID, d); err != nil {
|
||||
|
||||
@@ -186,6 +186,6 @@ func (s *BaseServer) ReverseProxyManager() reverseproxy.Manager {
|
||||
|
||||
func (s *BaseServer) ReverseProxyDomainManager() domain.Manager {
|
||||
return Create(s, func() domain.Manager {
|
||||
return domain.NewManager(s.Store())
|
||||
return domain.NewManager(s.Store(), s.ReverseProxyGRPCServer())
|
||||
})
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ type ProxyServiceServer struct {
|
||||
// proxyConnection represents a connected proxy
|
||||
type proxyConnection struct {
|
||||
proxyID string
|
||||
address string
|
||||
stream proto.ProxyService_GetMappingUpdateServer
|
||||
sendChan chan *proto.ProxyMapping
|
||||
ctx context.Context
|
||||
@@ -94,6 +95,7 @@ func (s *ProxyServiceServer) GetMappingUpdate(req *proto.GetMappingUpdateRequest
|
||||
connCtx, cancel := context.WithCancel(ctx)
|
||||
conn := &proxyConnection{
|
||||
proxyID: proxyID,
|
||||
address: req.GetAddress(),
|
||||
stream: stream,
|
||||
sendChan: make(chan *proto.ProxyMapping, 100),
|
||||
ctx: connCtx,
|
||||
@@ -255,6 +257,21 @@ func (s *ProxyServiceServer) GetConnectedProxies() []string {
|
||||
return proxies
|
||||
}
|
||||
|
||||
// GetConnectedProxyURLs returns a deduplicated list of URLs from all connected proxies.
|
||||
func (s *ProxyServiceServer) GetConnectedProxyURLs() []string {
|
||||
seenUrls := make(map[string]struct{})
|
||||
var urls []string
|
||||
s.connectedProxies.Range(func(key, value interface{}) bool {
|
||||
conn := value.(*proxyConnection)
|
||||
if _, seen := seenUrls[conn.address]; conn.address != "" && !seen {
|
||||
seenUrls[conn.address] = struct{}{}
|
||||
urls = append(urls, conn.address)
|
||||
}
|
||||
return true
|
||||
})
|
||||
return urls
|
||||
}
|
||||
|
||||
func (s *ProxyServiceServer) Authenticate(ctx context.Context, req *proto.AuthenticateRequest) (*proto.AuthenticateResponse, error) {
|
||||
proxy, err := s.reverseProxyStore.GetReverseProxyByID(ctx, store.LockingStrengthNone, req.GetAccountId(), req.GetId())
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user