Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize dns config #321

Merged
merged 2 commits into from
Mar 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ kind-test:

model: oapi-codegen
@mkdir -p tmp
go run openapi/main.go v0.107.44
go run openapi/main.go v0.107.46
$(OAPI_CODEGEN) -package model -generate types,client -config .oapi-codegen.yaml tmp/schema.yaml > pkg/client/model/model_generated.go

model-diff:
go run openapi/main.go v0.107.44
go run openapi/main.go v0.107.46
go run openapi/main.go
diff tmp/schema.yaml tmp/schema-master.yaml
10 changes: 10 additions & 0 deletions pkg/client/model/model-functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/bakito/adguardhome-sync/pkg/utils"
"github.com/jinzhu/copier"
"go.uber.org/zap"
)

// Clone the config
Expand Down Expand Up @@ -401,3 +402,12 @@ func ArrayString(a *[]string) string {
sort.Strings(sorted)
return fmt.Sprintf("[%s]", strings.Join(sorted, ","))
}

func (c *DNSConfig) Sanitize(l *zap.SugaredLogger) {
// disable UsePrivatePtrResolvers if not configured
if c.UsePrivatePtrResolvers != nil && *c.UsePrivatePtrResolvers &&
(c.LocalPtrUpstreams == nil || len(*c.LocalPtrUpstreams) == 0) {
l.Warn("disabling replica 'Use private reverse DNS resolvers' as no 'Private reverse DNS servers' are configured on origin")
c.UsePrivatePtrResolvers = utils.Ptr(false)
}
}
29 changes: 29 additions & 0 deletions pkg/client/model/model_private_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package model

import (
"github.com/bakito/adguardhome-sync/pkg/log"
"github.com/bakito/adguardhome-sync/pkg/utils"
. "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
"go.uber.org/zap"
)

var _ = Describe("Types", func() {
Expand Down Expand Up @@ -71,4 +73,31 @@ var _ = Describe("Types", func() {
Entry(`When SubnetMask is ""`, DhcpConfigV6{RangeStart: utils.Ptr("")}),
)
})
Context("DNSConfig", func() {
var (
cfg *DNSConfig
l *zap.SugaredLogger
)

BeforeEach(func() {
cfg = &DNSConfig{
UsePrivatePtrResolvers: utils.Ptr(true),
}
l = log.GetLogger("test")
})
Context("Sanitize", func() {
It("should disable UsePrivatePtrResolvers resolvers is nil ", func() {
cfg.LocalPtrUpstreams = nil
cfg.Sanitize(l)
gomega.Ω(cfg.UsePrivatePtrResolvers).ShouldNot(gomega.BeNil())
gomega.Ω(*cfg.UsePrivatePtrResolvers).Should(gomega.Equal(false))
})
It("should disable UsePrivatePtrResolvers resolvers is empty ", func() {
cfg.LocalPtrUpstreams = utils.Ptr([]string{})
cfg.Sanitize(l)
gomega.Ω(cfg.UsePrivatePtrResolvers).ShouldNot(gomega.BeNil())
gomega.Ω(*cfg.UsePrivatePtrResolvers).Should(gomega.Equal(false))
})
})
})
})
3 changes: 3 additions & 0 deletions pkg/sync/action-general.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ var (
if err != nil {
return err
}

dc.Sanitize(ac.rl)

if !dc.Equals(ac.origin.dnsConfig) {
if err = ac.client.SetDNSConfig(ac.origin.dnsConfig); err != nil {
return err
Expand Down