Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add a dns.OSConfigurator implementation that uses the CoderVPN protocol#15342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ethanndickson merged 2 commits intomainfromethan/vpn-dns-config
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletionstailnet/conn.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,7 @@ import (
"tailscale.com/envknob"
"tailscale.com/ipn/ipnstate"
"tailscale.com/net/connstats"
"tailscale.com/net/dns"
"tailscale.com/net/netmon"
"tailscale.com/net/netns"
"tailscale.com/net/tsdial"
Expand DownExpand Up@@ -106,6 +107,9 @@ type Options struct {
ClientType proto.TelemetryEvent_ClientType
// TelemetrySink is optional.
TelemetrySink TelemetrySink
// DNSConfigurator is optional, and is passed to the underlying wireguard
// engine.
DNSConfigurator dns.OSConfigurator
}

// TelemetrySink allows tailnet.Conn to send network telemetry to the Coder
Expand DownExpand Up@@ -178,6 +182,7 @@ func NewConn(options *Options) (conn *Conn, err error) {
Dialer: dialer,
ListenPort: options.ListenPort,
SetSubsystem: sys.Set,
DNS: options.DNSConfigurator,
})
if err != nil {
return nil, xerrors.Errorf("create wgengine: %w", err)
Expand Down
58 changes: 58 additions & 0 deletionsvpn/dns.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
package vpn

import "tailscale.com/net/dns"

func NewDNSConfigurator(t *Tunnel) dns.OSConfigurator {
return &dnsManager{tunnel: t}
}

type dnsManager struct {
tunnel *Tunnel
}

func (v *dnsManager) SetDNS(cfg dns.OSConfig) error {
settings := convertDNSConfig(cfg)
return v.tunnel.ApplyNetworkSettings(v.tunnel.ctx, &NetworkSettingsRequest{
DnsSettings: settings,
})
}

func (*dnsManager) GetBaseConfig() (dns.OSConfig, error) {
// Tailscale calls this function to blend the OS's DNS configuration with
// it's own, so this is only called if `SupportsSplitDNS` returns false.
return dns.OSConfig{}, dns.ErrGetBaseConfigNotSupported
}

func (*dnsManager) SupportsSplitDNS() bool {
// macOS & Windows 10+ support split DNS, so we'll assume all CoderVPN
// clients do too.
return true
}

// Close implements dns.OSConfigurator.
func (*dnsManager) Close() error {
// There's no cleanup that we need to initiate from within the dylib.
return nil
}

func convertDNSConfig(cfg dns.OSConfig) *NetworkSettingsRequest_DNSSettings {
servers := make([]string, 0, len(cfg.Nameservers))
for _, ns := range cfg.Nameservers {
servers = append(servers, ns.String())
}
searchDomains := make([]string, 0, len(cfg.SearchDomains))
for _, domain := range cfg.SearchDomains {
searchDomains = append(searchDomains, domain.WithoutTrailingDot())
}
matchDomains := make([]string, 0, len(cfg.MatchDomains))
for _, domain := range cfg.MatchDomains {
matchDomains = append(matchDomains, domain.WithoutTrailingDot())
}
return &NetworkSettingsRequest_DNSSettings{
Servers: servers,
SearchDomains: searchDomains,
DomainName: "coder",
MatchDomains: matchDomains,
MatchDomainsNoSearch: false,
}
}
73 changes: 73 additions & 0 deletionsvpn/dns_internal_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
package vpn

import (
"net/netip"
"testing"

"github.com/stretchr/testify/require"
"tailscale.com/net/dns"
"tailscale.com/util/dnsname"
)

func TestConvertDNSConfig(t *testing.T) {
t.Parallel()

tests := []struct {
name string
input dns.OSConfig
expected *NetworkSettingsRequest_DNSSettings
}{
{
name: "Basic",
input: dns.OSConfig{
Nameservers: []netip.Addr{
netip.MustParseAddr("1.1.1.1"),
netip.MustParseAddr("8.8.8.8"),
},
SearchDomains: []dnsname.FQDN{
"example.com.",
"test.local.",
},
MatchDomains: []dnsname.FQDN{
"internal.domain.",
},
},
expected: &NetworkSettingsRequest_DNSSettings{
Servers: []string{"1.1.1.1", "8.8.8.8"},
SearchDomains: []string{"example.com", "test.local"},
DomainName: "coder",
MatchDomains: []string{"internal.domain"},
MatchDomainsNoSearch: false,
},
},
{
name: "Empty",
input: dns.OSConfig{
Nameservers: []netip.Addr{},
SearchDomains: []dnsname.FQDN{},
MatchDomains: []dnsname.FQDN{},
},
expected: &NetworkSettingsRequest_DNSSettings{
Servers: []string{},
SearchDomains: []string{},
DomainName: "coder",
MatchDomains: []string{},
MatchDomainsNoSearch: false,
},
},
}

//nolint:paralleltest // outdated rule
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

result := convertDNSConfig(tt.input)
require.Equal(t, tt.expected.Servers, result.Servers)
require.Equal(t, tt.expected.SearchDomains, result.SearchDomains)
require.Equal(t, tt.expected.DomainName, result.DomainName)
require.Equal(t, tt.expected.MatchDomains, result.MatchDomains)
require.Equal(t, tt.expected.MatchDomainsNoSearch, result.MatchDomainsNoSearch)
})
}
}
Loading

[8]ページ先頭

©2009-2025 Movatter.jp