Documentation
¶
Index ¶
- Constants
- Variables
- func ActionFromChannel(channel string) (string, error)
- func FetchTLSCert(ctx context.Context, client *redis.Client, name string) (*tls.Certificate, time.Time, error)
- func GetSystemNameservers() []string
- func SendDNSAction[R any, T TypedDNSAction[R]](ctx context.Context, action T, opts ...optionHandler) (*R, error)
- func WithRedis(redis *redis.Client) optionHandler
- func WithReply(reply bool) optionHandler
- func WithTimeout(timeout time.Duration) optionHandler
- func WithTransport(transport Transport) optionHandler
- func WriteResolvConf(filename string) error
- type Answer
- type DNS
- type DNSAction
- type DNSAddAction
- func (a *DNSAddAction) WithExpires(expires time.Duration) *DNSAddAction
- func (a *DNSAddAction) WithPort(port int) *DNSAddAction
- func (a *DNSAddAction) WithPriority(priority int) *DNSAddAction
- func (a *DNSAddAction) WithTTL(ttl time.Duration) *DNSAddAction
- func (a *DNSAddAction) WithWeight(weight int) *DNSAddAction
- type DNSBaseAction
- type DNSCert
- type DNSCertAction
- type DNSConfig
- type DNSDeleteAction
- type DNSRecord
- type DNSRecordType
- type DNSResolver
- type DNSResponse
- type Dns
- type Message
- type ParsedResolvConf
- type RecordType
- type Result
- type StatusType
- type Subscriber
- type Transport
- type TypedDNSAction
- type WithConfig
Constants ¶
const DefaultDNSTimeout = 10 * time.Second
DefaultDNSTimeout is the default timeout for a DNS action which is 10 seconds
Variables ¶
var DefaultDNS = NewResolver()
DefaultDNS is the default DNS resolver.
var DefaultDNSServers = []string{
"ns0.agentuity.com:53",
"ns1.agentuity.com:53",
"ns2.agentuity.com:53",
}
DefaultDNSServers is the default list of internal DNS servers.
var DefaultExternalDNSServers = []string{
"9.9.9.9:53",
"1.1.1.1:53",
"8.8.8.8:53",
}
DefaultExternalDNSServers is the default list of external DNS servers.
var DefaultInternalDomain = "agentuity.internal"
DefaultInternalDomain is the default internal domain.
var DefaultManagedDomains = []string{ DefaultInternalDomain, "agentuity.cloud", "agentuity.cloud.internal", "agentuity.run", "agentuity.run.internal", "agentuity.ai", "agentuity.ai.internal", "agentuity.app", "agentuity.app.internal", "agentuity.dev", "agentuity.dev.internal", }
DefaultManagedDomains is the default list of managed domains that will use the internal DNS servers otherwise will go to the external DNS servers.
var DefaultResolveConfFilename = "/etc/resolv.conf"
DefaultResolveConfFilename is the default filename for the resolv.conf file.
var ErrClosed = errors.New("closed")
var ErrInvalidIP = fmt.Errorf("invalid ip address resolved for hostname")
ErrInvalidIP is returned when an invalid IP address is resolved for a hostname.
var ErrTimeout = errors.New("timeout")
var ErrTransportRequired = errors.New("transport is required")
Functions ¶
func ActionFromChannel ¶ added in v1.0.49
ActionFromChannel returns the action from the channel string
func FetchTLSCert ¶ added in v1.0.63
func FetchTLSCert(ctx context.Context, client *redis.Client, name string) (*tls.Certificate, time.Time, error)
FetchTLSCert fetches a TLS certificate from aether
func GetSystemNameservers ¶ added in v1.0.131
func GetSystemNameservers() []string
GetSystemNameservers returns a merged list of nameservers: first the nameservers from the system's resolv.conf (excluding loopback addresses), then the DefaultExternalDNSServers as fallbacks. Duplicates are removed.
func SendDNSAction ¶ added in v1.0.48
func SendDNSAction[R any, T TypedDNSAction[R]](ctx context.Context, action T, opts ...optionHandler) (*R, error)
SendDNSAction sends a DNS action to the DNS server with a timeout. If the timeout is 0, the default timeout will be used.
func WithReply ¶ added in v1.0.48
func WithReply(reply bool) optionHandler
WithReply sets whether the DNS action should wait for a reply from the DNS server
func WithTimeout ¶ added in v1.0.48
WithTimeout sets a custom timeout for the DNS action
func WithTransport ¶ added in v1.0.48
func WithTransport(transport Transport) optionHandler
WithTransport sets a custom transport for the DNS action
func WriteResolvConf ¶ added in v1.0.109
WriteResolvConf writes a resolv.conf file that points to a local DNS server with the default internal domain as the search domain. If filename is empty, it defaults to /etc/resolv.conf
Types ¶
type Answer ¶
type Answer struct {
Name string `json:"name"`
Type RecordType `json:"type"`
TTL uint `json:"ttl"`
Data string `json:"data"`
}
type DNSAction ¶ added in v1.0.48
type DNSAction interface {
// GetID returns the unique ID of the DNS action
GetID() string
// GetReply returns the reply of the DNS action
GetReply() string
// SetReply sets the reply of the DNS action
SetReply(string)
// GetAction returns the action of the DNS action
GetAction() string
}
DNSAction is an interface for a DNS action
type DNSAddAction ¶ added in v1.0.48
type DNSAddAction struct {
DNSBaseAction
Name string `json:"name"`
Type string `json:"type,omitempty"`
Value string `json:"value,omitempty"`
// TTL is the DNS TTL for the record
TTL time.Duration `json:"ttl,omitempty"`
// Expires is the expiration time of the DNS record
// if not provided the record will never expire
Expires time.Duration `json:"expires,omitempty"`
// Priority is the priority of the DNS record
// only used for MX and SRV records
Priority int `json:"priority,omitempty"`
// Weight is the weight of the DNS record
// only used for SRV records
Weight int `json:"weight,omitempty"`
// Port is the port of the DNS record
// only used for SRV records
Port int `json:"port,omitempty"`
}
func AddDNSAction ¶ added in v1.0.48
func AddDNSAction(name string, recordType DNSRecordType, value string, ttl time.Duration, expires time.Duration) *DNSAddAction
AddDNSAction adds a DNS action to the DNS server
func NewAddAction ¶ added in v1.0.65
func NewAddAction(name string, recordType DNSRecordType, value string) *DNSAddAction
NewAddDNSAction creates a new DNS add action
func (*DNSAddAction) WithExpires ¶ added in v1.0.65
func (a *DNSAddAction) WithExpires(expires time.Duration) *DNSAddAction
WithExpires sets the expiration if not provided the record will never expire
func (*DNSAddAction) WithPort ¶ added in v1.0.65
func (a *DNSAddAction) WithPort(port int) *DNSAddAction
WithPort sets the port of the DNS action only used for SRV records
func (*DNSAddAction) WithPriority ¶ added in v1.0.65
func (a *DNSAddAction) WithPriority(priority int) *DNSAddAction
WithPriority sets the priority of the DNS action only used for MX and SRV records
func (*DNSAddAction) WithTTL ¶ added in v1.0.65
func (a *DNSAddAction) WithTTL(ttl time.Duration) *DNSAddAction
func (*DNSAddAction) WithWeight ¶ added in v1.0.65
func (a *DNSAddAction) WithWeight(weight int) *DNSAddAction
WithWeight sets the weight of the DNS action only used for SRV records
type DNSBaseAction ¶ added in v1.0.48
type DNSBaseAction struct {
MsgID string `json:"msg_id"`
Action string `json:"action"`
Reply string `json:"reply,omitempty"`
}
func (DNSBaseAction) GetAction ¶ added in v1.0.49
func (a DNSBaseAction) GetAction() string
GetAction returns the action of the DNS action
func (DNSBaseAction) GetID ¶ added in v1.0.48
func (a DNSBaseAction) GetID() string
GetID returns the unique ID of the DNS action
func (DNSBaseAction) GetReply ¶ added in v1.0.48
func (a DNSBaseAction) GetReply() string
GetReply returns the reply of the DNS action
func (*DNSBaseAction) SetReply ¶ added in v1.0.48
func (a *DNSBaseAction) SetReply(reply string)
SetReply sets the reply of the DNS action
type DNSCertAction ¶ added in v1.0.48
type DNSCertAction struct {
DNSBaseAction
Name string `json:"name"`
}
func CertRequestDNSAction ¶ added in v1.0.48
func CertRequestDNSAction(name string) *DNSCertAction
CertRequestDNSAction requests a certificate from the DNS server
type DNSConfig ¶ added in v1.0.109
type DNSConfig struct {
// ListenAddress is the address to bind DNS server to (default: :53)
ListenAddress string
// ManagedDomains are domains that should be forwarded to internal nameservers
ManagedDomains []string
// InternalNameservers are the nameservers to forward managed domain queries to
InternalNameservers []string
// UpstreamNameservers are the nameservers to forward other queries to
UpstreamNameservers []string
// Timeout for DNS queries
QueryTimeout string
// DialContext is the function to use for dialing connections
DialContext func(ctx context.Context, network, address string) (net.Conn, error)
// DefaultProtocol is the default protocol to use for dialing connections which is UDP
DefaultProtocol string
// DefaultNegativeTTL is the TTL (in seconds) to use for negative responses when no SOA record
// is present. Per RFC 2308, negative responses should include an SOA record, but some servers
// don't comply. Set to 0 to disable caching when SOA is missing. Default is 30 seconds.
DefaultNegativeTTL uint32
}
DNSConfig holds configuration for DNS resolver
func DefaultDNSConfig ¶ added in v1.0.109
func DefaultDNSConfig() DNSConfig
DefaultDNSConfig returns a default DNS configuration. It automatically detects upstream nameservers from the system's /etc/resolv.conf before it gets overwritten, falling back to DefaultExternalDNSServers if parsing fails.
func (*DNSConfig) IsManagedDomain ¶ added in v1.0.109
IsManagedDomain checks if a domain should be resolved by internal nameservers
type DNSDeleteAction ¶ added in v1.0.48
type DNSDeleteAction struct {
DNSBaseAction
// Name is the name of the DNS record to delete.
Name string `json:"name"`
// IDs are the IDs of the DNS records to delete (within a name). This allows for clients to manage a specific record if they keep track of the ID.
// If not provided, any name match will be deleted.
IDs []string `json:"ids,omitempty"`
}
func DeleteDNSAction ¶ added in v1.0.48
func DeleteDNSAction(name string, ids ...string) *DNSDeleteAction
DeleteDNSAction deletes a DNS action from the DNS server
type DNSRecordType ¶ added in v1.0.48
type DNSRecordType string
const ( RecordTypeA DNSRecordType = "A" RecordTypeAAAA DNSRecordType = "AAAA" RecordTypeCNAME DNSRecordType = "CNAME" RecordTypeMX DNSRecordType = "MX" RecordTypeNS DNSRecordType = "NS" RecordTypeTXT DNSRecordType = "TXT" RecordTypeSRV DNSRecordType = "SRV" )
type DNSResolver ¶ added in v1.0.109
type DNSResolver struct {
// contains filtered or unexported fields
}
DNSResolver implements a basic DNS resolver with conditional forwarding
func (*DNSResolver) IsRunning ¶ added in v1.0.109
func (s *DNSResolver) IsRunning() bool
IsRunning returns whether the DNS server is currently running
func (*DNSResolver) Start ¶ added in v1.0.109
func (s *DNSResolver) Start() error
Start starts the DNS server
func (*DNSResolver) Stop ¶ added in v1.0.109
func (s *DNSResolver) Stop() error
Stop stops the DNS server
func (*DNSResolver) ValidateUpstream ¶ added in v1.0.131
func (s *DNSResolver) ValidateUpstream(testDomain string) error
ValidateUpstream tests that the DNS server can reach upstream nameservers by resolving a known domain. Returns an error if resolution fails. The testDomain parameter specifies which domain to test (e.g., "agentuity.com").
type DNSResponse ¶ added in v1.0.48
type DNSResponse[T any] struct { MsgID string `json:"msg_id"` Success bool `json:"success"` Error string `json:"error,omitempty"` Data *T `json:"data,omitempty"` }
func NewDNSResponse ¶ added in v1.0.55
func NewDNSResponse[R any, T TypedDNSAction[R]](action T, data *R, err error) *DNSResponse[R]
type Dns ¶
type Dns struct {
// contains filtered or unexported fields
}
func NewResolver ¶ added in v1.0.109
func NewResolver(opts ...WithConfig) *Dns
NewResolver creates a new DNS caching resolver.
type Message ¶ added in v1.0.48
type Message struct {
Payload []byte
}
Message is a message from the transport layer
type ParsedResolvConf ¶ added in v1.0.131
ParsedResolvConf represents the parsed contents of a resolv.conf file
func ParseResolvConf ¶ added in v1.0.131
func ParseResolvConf(filename string) (*ParsedResolvConf, error)
ParseResolvConf parses a resolv.conf file and returns the nameservers and search domains. It skips nameservers pointing to 127.0.0.1 (any port) to avoid circular references. If filename is empty, it defaults to /etc/resolv.conf
type Result ¶
type Result struct {
Status StatusType `json:"Status"`
Answer []Answer `json:"Answer"`
}
type StatusType ¶
type StatusType uint8
const ( NoError StatusType = 0 FormErr StatusType = 1 ServFail StatusType = 2 NXDomain StatusType = 3 Refused StatusType = 5 NotAuth StatusType = 9 NotZone StatusType = 10 )
func (StatusType) String ¶
func (s StatusType) String() string
type Subscriber ¶ added in v1.0.48
type Subscriber interface {
// Close closes the subscriber
Close() error
// Channel returns a channel of messages
Channel() <-chan *Message
}
Subscriber is an interface for a subscriber to the transport layer
type Transport ¶ added in v1.0.48
type Transport interface {
Subscribe(ctx context.Context, channel string) Subscriber
Publish(ctx context.Context, channel string, payload []byte) error
}
Transport is an interface for a transport layer for the DNS server
type TypedDNSAction ¶ added in v1.0.55
TypedDNSAction is an interface for a DNS action that also specifies its expected response data type.
type WithConfig ¶
type WithConfig func(config *dnsConfig)
func WithCache ¶ added in v1.0.51
func WithCache(cache cache.Cache) WithConfig
WithCache will set the cache for the DNS resolver.
func WithFailIfLocal ¶
func WithFailIfLocal() WithConfig
WithFailIfLocal will cause the DNS resolver to fail if the hostname is a local hostname.