dns

package
v0.0.7-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DatastorePartition = "dns/zones"

	Configuration *Config

	DefaultConfig = Config{
		Datastore: &datastore.Config{
			Backend:          "AFERO_FS",
			ConsistencyLevel: "local",
			RootDir:          "trusted-data/datastore",
			ReadBufferSize:   50,
			Serializer:       "json",
		},
		PublicServer: &PublicServer{
			Port:       8053,
			Forwarders: []string{"4.4.4.4", "8.8.8.8"},
			Zone: entities.Zone{
				ID:          1,
				Name:        "trusted-platform.io.",
				TTL:         3600,
				Description: "Public zone for trusted-platform.io",
				Internal:    false,
				RecordSet: entities.RecordSet{
					SOARecord: entities.SOARecord{
						Name:       "trusted-platform.io.",
						MName:      "ns1.trusted-platform.io.",
						RName:      "hostmaster.trusted-platform.io.",
						Serial:     1,
						Refresh:    86400,
						Retry:      7200,
						Expire:     86400,
						MinimumTTL: 3600,
						TTL:        3600,
					},
					NSRecords: []*entities.NSRecord{
						{Name: "trusted-platform.io.", Value: "ns1.trusted-platform.io.", TTL: 3600},
						{Name: "trusted-platform.io.", Value: "ns2.trusted-platform.io.", TTL: 3600},
						{Name: "trusted-platform.io.", Value: "ns3.trusted-platform.io.", TTL: 3600},
					},
					ARecords: []*entities.ARecord{
						{Name: "ns1", Value: "${PUBLIC_IPv4}", TTL: 3600},
						{Name: "ns2", Value: "${PUBLIC_IPv4}", TTL: 3600},
						{Name: "ns3", Value: "${PUBLIC_IPv4}", TTL: 3600},
						{Name: "www", Value: "${PUBLIC_IPv4}", TTL: 3600},
					},
					CNAMERecords: []*entities.CNAMERecord{
						{Name: "www", Value: "trusted-platform.io.", TTL: 3600},
					},
					MXRecords: []*entities.MXRecord{
						{Name: "trusted-platform.io.", Value: "mail.trusted-platform.io.", Priority: 10, TTL: 3600},
					},
					TXTRecords: []*entities.TXTRecord{
						{Name: "trusted-platform.io.", Value: "v=spf1 include:_spf.google.com ~all", TTL: 3600},
					},
				},
			},
		},
		InternalServer: &InternalServer{
			Port:       8054,
			Forwarders: []string{"192.168.1.1", "192.168.2.1", "192.168.3.1"},
			Zone: entities.Zone{
				ID:          2,
				Name:        "trusted-platform.internal.",
				TTL:         3600,
				Description: "Internal zone for trusted-platform.internal",
				Internal:    true,
				RecordSet: entities.RecordSet{
					SOARecord: entities.SOARecord{
						Name:       "trusted-platform.internal.",
						MName:      "ns1.trusted-platform.internal.",
						RName:      "hostmaster.trusted-platform.internal.",
						Serial:     1,
						Refresh:    86400,
						Retry:      7200,
						Expire:     86400,
						MinimumTTL: 3600,
						TTL:        3600,
					},
					NSRecords: []*entities.NSRecord{
						{Name: "trusted-platform.internal.", Value: "ns1.trusted-platform.internal.", TTL: 3600},
						{Name: "trusted-platform.internal.", Value: "ns2.trusted-platform.internal.", TTL: 3600},
						{Name: "trusted-platform.internal.", Value: "ns3.trusted-platform.internal.", TTL: 3600},
					},
					ARecords: []*entities.ARecord{
						{Name: "ns1", Value: "${LOCAL_IPv4}", TTL: 3600},
						{Name: "ns2", Value: "192.168.2.1", TTL: 3600},
						{Name: "ns3", Value: "192.168.3.1", TTL: 3600},
						{Name: "${HOSTNAME}", Value: "${LOCAL_IPv4}", TTL: 3600},
					},
					CNAMERecords: []*entities.CNAMERecord{
						{Name: "www", Value: "trusted-platform.internal.", TTL: 3600},
					},
				},
			},
		},
	}
)
View Source
var (
	ErrZoneAlreadyExists            = errors.New("zone already exists")
	ErrParsingDomainName            = errors.New("failed to parse FQDN or domain name")
	ErrInvalidIPAddress             = errors.New("invalid IP address")
	ErrZoneNotFound                 = errors.New("zone not found")
	ErrInvalidPrivateIP             = errors.New("invalid private IP address")
	ErrInvalidPublicIP              = errors.New("invalid public IP address")
	ErrInvalidPrivateTLD            = errors.New("invalid private TLD")
	ErrInvalidPublicTLD             = errors.New("invalid public TLD")
	ErrRegistrationDisabled         = errors.New("zone registration is disallowed")
	ErrExternalRegistrationDisabled = errors.New("external zone registration disallowed")
	ErrInternalRegistrationDisabled = errors.New("internal zone registration disallowed")
)
View Source
var (
	ErrInternalZoneQueryViolation = errors.New("received public query for internal zone")
)

Define log to be a logger with the plugin name in it.

View Source
var (
	ErrMacroNotFound = errors.New("dns: macro not found")
)
View Source
var ErrRecordTypeNotSupported = errors.New("dns: record type not supported")

Error for unsupported record types

Functions

func Expand

func Expand(zone *entities.Zone) error

func ExpandVar

func ExpandVar(env string) string

func IsTLD

func IsTLD(tld string) bool

IsTLD checks if a given TLD exists in the map (case-insensitively).

func LoadTLDs

func LoadTLDs(logger *logging.Logger, tldData []byte) error

Loads and processes the provided tldData as a plain text file with each TLD on it's own line. If the tldData is not provided, the TLD list from data.iana.org will be used as a default.

func NewAAAARecord

func NewAAAARecord(
	name, value string, ttl uint32) *entities.AAAARecord

NewAAAARecord creates a new AAAA record.

func NewARecord

func NewARecord(
	name, value string, ttl uint32) *entities.ARecord

NewARecord creates a new A record.

func NewCNAMERecord

func NewCNAMERecord(
	name, target string, ttl uint32) *entities.CNAMERecord

NewCNAMERecord creates a new CNAME record.

func NewDNSKEYRecord

func NewDNSKEYRecord(
	name, key string,
	flags uint16,
	protocol, algorithm uint8,
	ttl uint32) *entities.DNSKEYRecord

NewDNSKEYRecord creates a new DNSKEY record.

func NewDSRecord

func NewDSRecord(
	name string,
	keyTag uint16,
	algorithm, digestType uint8,
	digest string, ttl uint32) *entities.DSRecord

NewDSRecord creates a new DS record.

func NewMXRecord

func NewMXRecord(
	name, value string,
	priority uint16,
	ttl uint32) *entities.MXRecord

NewMXRecord creates a new MX record.

func NewNSRecord

func NewNSRecord(
	name, value string,
	ttl uint32) *entities.NSRecord

NewNSRecord creates a new NS record.

func NewRRSIGRecord

func NewRRSIGRecord(
	name, typeCovered string,
	algorithm, labels uint8,
	originalTTL uint32,
	expiration, inception string,
	keyTag uint16, signerName,
	signature string) *entities.RRSIGRecord

NewRRSIGRecord creates a new signed RRset

func NewSOARecord

func NewSOARecord(
	name, mname, rname string,
	serial, refresh, retry, expire, minimumTTL, ttl uint32) *entities.SOARecord

NewSOARecord creates a new SOA record.

func NewSRVRecord

func NewSRVRecord(
	name, target string,
	port, priority, weight uint16,
	ttl uint32) *entities.SRVRecord

NewSRVRecord creates a new SRV record.

func NewTXTRecord

func NewTXTRecord(
	name, value string, ttl uint32) *entities.TXTRecord

NewTXTRecord creates a new TXT record.

func ParseDomainName

func ParseDomainName(fqdn string) (hostname, subdomains, rootDomain, tld string, err error)

ParseDomainName parses a fully qualified domain name (FQDN) into its hostname, subdomains, root domain, and TLD. Any trailing dot in the FQDN is removed and each of the domain components are returned in their normalized form (ie: no trailing dots).

func Run

func Run(
	appName, appVersion string,
	logger *logging.Logger,
	config *Config)

func Save

func Save(zone *entities.Zone) error

Saves a new zone file to the datastore

Types

type Config

type Config struct {
	AllowRegistration         bool              `yaml:"allow-registration" json:"allow_registration" mapstructure:"allow-registration"`
	AllowExternalRegistration bool              `yaml:"allow-external-registration" json:"allow_external_registration" mapstructure:"allow-external-registration"`
	AllowInternalRegistration bool              `yaml:"allow-internal-registration" json:"allow_internal_registration" mapstructure:"allow-internal-registration"`
	Datastore                 *datastore.Config `yaml:"datastore" json:"datastore" mapstructure:"datastore"`
	DefaultTTL                int               `yaml:"default-ttl" json:"default_ttl" mapstructure:"default-ttl"`
	InternalServer            *InternalServer   `yaml:"internal" json:"internal" mapstructure:"internal"`
	Logger                    *logging.Logger   `yaml:"-" json:"-" mapstructure:"-"`
	PublicServer              *PublicServer     `yaml:"public" json:"public" mapstructure:"public"`
	PrivateIPv4               string            `yaml:"-" json:"-" mapstructure:"-"`
	PrivateIPv6               string            `yaml:"-" json:"-" mapstructure:"-"`
	PublicIPv4                string            `yaml:"-" json:"-" mapstructure:"-"`
	PublicIPv6                string            `yaml:"-" json:"-" mapstructure:"-"`
}

type Datastore

type Datastore struct {
	// contains filtered or unexported fields
}

func NewDatastore

func NewDatastore(
	params *datastore.Params[*entities.Zone],
	storeType datastore.StoreType) *Datastore

func (*Datastore) ZoneDAO

func (ds *Datastore) ZoneDAO() (dao.ZoneDAO, error)

type InternalServer

type InternalServer struct {
	Port       int           `yaml:"port" json:"port" mapstructure:"port"`
	Forwarders []string      `yaml:"forwarders" json:"forwarders" mapstructure:"forwarders"`
	Zone       entities.Zone `yaml:"zone" json:"zone" mapstructure:"zone"`
}

type Params

type Params struct {
	AppName     string
	AppVersion  string
	Config      *Config
	PublicIPv4  net.IP
	PrivateIPv4 net.IP
	PublicIPv6  net.IP
	PrivateIPv6 net.IP
	Datastore   *Datastore
}

type PublicServer

type PublicServer struct {
	Port       int           `yaml:"port" json:"port" mapstructure:"port"`
	Forwarders []string      `yaml:"forwarders" json:"forwarders" mapstructure:"forwarders"`
	Zone       entities.Zone `yaml:"zone" json:"zone" mapstructure:"zone"`
}

type RecordParserFunc

type RecordParserFunc func(qname string, zone *entities.Zone) []dns.RR

RecordParserFunc defines a function type for parsing DNS records

type SecurityLogEntry

type SecurityLogEntry struct {
	Timestamp       time.Time `json:"timestamp"`
	Severity        string    `json:"severity"`
	Category        string    `json:"category"`
	Description     string    `json:"description"`
	Details         string    `json:"details,omitempty"`
	Source          string    `json:"source,omitempty"`
	OffenderAddress string    `json:"offender_address,omitempty"`
	OffenderID      string    `json:"offender_id,omitempty"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

DNSService handles zone and record operations.

func NewService

func NewService(params *Params) (*Service, error)

NewService creates a new DNSService instance.

func (*Service) Delete

func (s *Service) Delete(zone *entities.Zone) error

Delete deletes a zone from the datastore.

func (*Service) InternalDomain

func (s *Service) InternalDomain() string

func (*Service) InternalZone

func (s *Service) InternalZone() (*entities.Zone, error)

func (*Service) PublicDomain

func (s *Service) PublicDomain() string

func (*Service) PublicZone

func (s *Service) PublicZone() (*entities.Zone, error)

func (*Service) Register

func (s *Service) Register(fqdn, ip string) (*entities.Zone, error)

Register creates a new DNS record or zone based on the provided FQDN and platform configuration. If the the FQDN does not match the DNS server's public or private zone, and the platform configuration permits, a new zone will be created with an initial A record so the host is resolvable. If the FQDN matches the DNS server's public or private zone, a new A record will be added to the existing zone for the host. If the provided IP address belongs to a private subnet, the record will be created as an internal zone, otherwise it will be created as a public zone.

func (*Service) Resolver

func (s *Service) Resolver() *net.Resolver

Returns a new net.Resolver instance that uses the internal DNS server. The internal DNS service allows queries for both internal and public zones and forwards unknown queries to the forwarders specified in the platform configuration.

func (*Service) Save

func (s *Service) Save(zone *entities.Zone) error

Save saves a zone to the datastore.

func (*Service) Zone

func (s *Service) Zone(zoneName string) (*entities.Zone, error)

Zone retrieves a zone from the datastore.

type TrustedPlatformPlugin

type TrustedPlatformPlugin struct {
	Next plugin.Handler
}

TrustedPlatformPlugin is the struct implementing the plugin.Handler interface.

func (TrustedPlatformPlugin) Name

func (cp TrustedPlatformPlugin) Name() string

func (TrustedPlatformPlugin) ServeDNS

func (cp TrustedPlatformPlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS handles incoming DNS requests.

Directories

Path Synopsis
dao

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL