dns

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: MIT Imports: 11 Imported by: 0

README

DNS IP module for Caddy

This module retrieves IP addresses from DNS and returns them as single-IP prefixes, for use in Caddy trusted_proxies directives.

Example config

For example, if you're running cloudflared in a Docker container on the same bridge network as Caddy, this will look up that container by service name:

trusted_proxies dns cloudflared {
    # Explicitly set the default value.
    interval 1m
}

Alternatively, the hostname can be specified inside the block:

trusted_proxies dns {
    host cloudflared
}

Multiple hosts can be specified, either on the same line or as separate host directives.

trusted_proxies dns {
    host proxy-1.example.com proxy-2.example.com
    host proxy-3.example.com
}

You can even mix these, though I would advise against it due to readability:

trusted_proxies dns proxy-1.example.com proxy-2.example.com {
    host proxy-3.example.com
}

Settings

Name Description Type Default
host The host name(s) to look up. string N/A, must be specified.
interval How often the IP address(es) should be refreshed. duration 1m (every minute)

Documentation

Index

Constants

View Source
const (
	DefaultInterval = caddy.Duration(time.Minute)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DNSRange

type DNSRange struct {
	// A list of DNS names to look up.
	Hosts []string `json:"hosts,omitempty"`

	// The refresh interval. Defaults to DefaultInterval.
	Interval caddy.Duration `json:"interval,omitempty"`
	// contains filtered or unexported fields
}

DNSRange provides a range of IP addresses associated with a DNS name. Each range will only contain a single IP.

func (*DNSRange) CaddyModule

func (d *DNSRange) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*DNSRange) GetIPRanges

func (d *DNSRange) GetIPRanges(_ *http.Request) (result []netip.Prefix)

func (*DNSRange) Provision

func (d *DNSRange) Provision(ctx caddy.Context) error

func (*DNSRange) UnmarshalCaddyfile

func (m *DNSRange) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler.

Example config, if you're running cloudflared on the same Docker bridge network as Caddy:

trusted_proxies dns cloudflared {
    # Explicitly set the default value.
    interval 1m
}

Alternative syntax:

trusted_proxies dns {
    host cloudflared
    # Explicitly set the default value.
    interval 1m
}

Multiple host names are supported, all on the same line and/or in multiple host directives.

Jump to

Keyboard shortcuts

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