Make normalize return multiple "hosts" (= reverse zones) when a non-octet boundary cidr is given. Added pkg/cidr package that holds the cidr calculation routines; felt they didn't really fit dnsutil. This change means the IPNet return parameter isn't needed, the hosts are all correct. The tests that tests this is also removed: TestSplitHostPortReverse The fallout was that zoneAddr _also_ doesn't need the IPNet member, that in turn make it visible that zoneAddr in address.go duplicated a bunch of stuff from register.go; removed/refactored that too. Created a plugin.OriginsFromArgsOrServerBlock to help plugins do the right things, by consuming ZONE arguments; this now expands reverse zones correctly. This is mostly mechanical. Remove the reverse test in plugin/kubernetes which is a copy-paste from a core test (which has since been fixed). Remove MustNormalize as it has no plugin users. This change is not backwards compatible to plugins that have a ZONE argument that they parse in the setup util. All in-tree plugins have been updated. Signed-off-by: Miek Gieben <miek@miek.nl>
100 lines
2.4 KiB
Go
100 lines
2.4 KiB
Go
package sign
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/coredns/caddy"
|
|
"github.com/coredns/coredns/core/dnsserver"
|
|
"github.com/coredns/coredns/plugin"
|
|
)
|
|
|
|
func init() { plugin.Register("sign", setup) }
|
|
|
|
func setup(c *caddy.Controller) error {
|
|
sign, err := parse(c)
|
|
if err != nil {
|
|
return plugin.Error("sign", err)
|
|
}
|
|
|
|
c.OnStartup(sign.OnStartup)
|
|
c.OnStartup(func() error {
|
|
for _, signer := range sign.signers {
|
|
go signer.refresh(durationRefreshHours)
|
|
}
|
|
return nil
|
|
})
|
|
c.OnShutdown(func() error {
|
|
for _, signer := range sign.signers {
|
|
close(signer.stop)
|
|
}
|
|
return nil
|
|
})
|
|
|
|
// Don't call AddPlugin, *sign* is not a plugin.
|
|
return nil
|
|
}
|
|
|
|
func parse(c *caddy.Controller) (*Sign, error) {
|
|
sign := &Sign{}
|
|
config := dnsserver.GetConfig(c)
|
|
|
|
for c.Next() {
|
|
if !c.NextArg() {
|
|
return nil, c.ArgErr()
|
|
}
|
|
dbfile := c.Val()
|
|
if !filepath.IsAbs(dbfile) && config.Root != "" {
|
|
dbfile = filepath.Join(config.Root, dbfile)
|
|
}
|
|
|
|
origins := plugin.OriginsFromArgsOrServerBlock(c.RemainingArgs(), c.ServerBlockKeys)
|
|
signers := make([]*Signer, len(origins))
|
|
for i := range origins {
|
|
signers[i] = &Signer{
|
|
dbfile: dbfile,
|
|
origin: origins[i],
|
|
jitterIncep: time.Duration(float32(durationInceptionJitter) * rand.Float32()),
|
|
jitterExpir: time.Duration(float32(durationExpirationDayJitter) * rand.Float32()),
|
|
directory: "/var/lib/coredns",
|
|
stop: make(chan struct{}),
|
|
signedfile: fmt.Sprintf("db.%ssigned", origins[i]), // origins[i] is a fqdn, so it ends with a dot, hence %ssigned.
|
|
}
|
|
}
|
|
|
|
for c.NextBlock() {
|
|
switch c.Val() {
|
|
case "key":
|
|
pairs, err := keyParse(c)
|
|
if err != nil {
|
|
return sign, err
|
|
}
|
|
for i := range signers {
|
|
for _, p := range pairs {
|
|
p.Public.Header().Name = signers[i].origin
|
|
}
|
|
signers[i].keys = append(signers[i].keys, pairs...)
|
|
}
|
|
case "directory":
|
|
dir := c.RemainingArgs()
|
|
if len(dir) == 0 || len(dir) > 1 {
|
|
return sign, fmt.Errorf("can only be one argument after %q", "directory")
|
|
}
|
|
if !filepath.IsAbs(dir[0]) && config.Root != "" {
|
|
dir[0] = filepath.Join(config.Root, dir[0])
|
|
}
|
|
for i := range signers {
|
|
signers[i].directory = dir[0]
|
|
signers[i].signedfile = fmt.Sprintf("db.%ssigned", signers[i].origin)
|
|
}
|
|
default:
|
|
return nil, c.Errf("unknown property '%s'", c.Val())
|
|
}
|
|
}
|
|
sign.signers = append(sign.signers, signers...)
|
|
}
|
|
|
|
return sign, nil
|
|
}
|