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

fix(rule): GCP dnssec not applicable for private zones #539

Merged
merged 2 commits into from
Apr 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion internal/adapters/terraform/google/dns/adapt.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func adaptManagedZones(modules terraform.Modules) []dns.ManagedZone {
func adaptManagedZone(resource *terraform.Block) dns.ManagedZone {

zone := dns.ManagedZone{
Metadata: resource.GetMetadata(),
Metadata: resource.GetMetadata(),
Visibility: types.StringDefault("public", resource.GetMetadata()),
DNSSec: dns.DNSSec{
Metadata: resource.GetMetadata(),
Enabled: types.BoolDefault(false, resource.GetMetadata()),
Expand All @@ -47,6 +48,10 @@ func adaptManagedZone(resource *terraform.Block) dns.ManagedZone {
},
}

if resource.HasChild("visibility") {
zone.Visibility = resource.GetAttribute("visibility").AsStringValueOrDefault("public", resource)
}

if resource.HasChild("dnssec_config") {
DNSSecBlock := resource.GetBlock("dnssec_config")
zone.DNSSec.Metadata = DNSSecBlock.GetMetadata()
Expand Down
3 changes: 2 additions & 1 deletion internal/adapters/terraform/google/dns/adapt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func Test_Adapt(t *testing.T) {
expected: dns.DNS{
ManagedZones: []dns.ManagedZone{
{
Metadata: types.NewTestMetadata(),
Metadata: types.NewTestMetadata(),
Visibility: types.String("public", types.NewTestMetadata()),
DNSSec: dns.DNSSec{
Enabled: types.Bool(true, types.NewTestMetadata()),
DefaultKeySpecs: dns.KeySpecs{
Expand Down
2 changes: 1 addition & 1 deletion internal/rules/google/dns/enable_dnssec.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var CheckEnableDnssec = rules.Register(
},
func(s *state.State) (results scan.Results) {
for _, zone := range s.Google.DNS.ManagedZones {
if zone.IsUnmanaged() {
if zone.IsUnmanaged() || zone.IsPrivate() {
continue
}
if zone.DNSSec.Enabled.IsFalse() {
Expand Down
24 changes: 21 additions & 3 deletions internal/rules/google/dns/enable_dnssec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ func TestCheckEnableDnssec(t *testing.T) {
expected bool
}{
{
name: "DNSSec disabled",
name: "DNSSec disabled and required when visibility explicitly public",
input: dns.DNS{
ManagedZones: []dns.ManagedZone{
{
Metadata: types.NewTestMetadata(),
Metadata: types.NewTestMetadata(),
Visibility: types.String("public", types.NewTestMetadata()),
DNSSec: dns.DNSSec{
Metadata: types.NewTestMetadata(),
Enabled: types.Bool(false, types.NewTestMetadata()),
Expand All @@ -39,7 +40,24 @@ func TestCheckEnableDnssec(t *testing.T) {
input: dns.DNS{
ManagedZones: []dns.ManagedZone{
{
Metadata: types.NewTestMetadata(),
Metadata: types.NewTestMetadata(),
Visibility: types.String("public", types.NewTestMetadata()),
DNSSec: dns.DNSSec{
Metadata: types.NewTestMetadata(),
Enabled: types.Bool(true, types.NewTestMetadata()),
},
},
},
},
expected: false,
},
{
name: "DNSSec not required when private",
input: dns.DNS{
ManagedZones: []dns.ManagedZone{
{
Metadata: types.NewTestMetadata(),
Visibility: types.String("private", types.NewTestMetadata()),
DNSSec: dns.DNSSec{
Metadata: types.NewTestMetadata(),
Enabled: types.Bool(true, types.NewTestMetadata()),
Expand Down
7 changes: 6 additions & 1 deletion pkg/providers/google/dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ type DNS struct {

type ManagedZone struct {
types.Metadata
DNSSec DNSSec
DNSSec DNSSec
Visibility types.StringValue
}

func (m ManagedZone) IsPrivate() bool {
return m.Visibility.EqualTo("private", types.IgnoreCase)
}

type DNSSec struct {
Expand Down