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

✨ Add reference to compute network from GCP DNS policy #799

Merged
merged 1 commit into from
Jan 18, 2023
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
45 changes: 45 additions & 0 deletions resources/packs/gcp/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gcp
import (
"context"
"strconv"
"strings"

"go.mondoo.com/cnquery/resources"

Expand Down Expand Up @@ -172,13 +173,20 @@ func (g *mqlGcpProjectDnsService) GetPolicies() ([]interface{}, error) {
for i := range page.Policies {
policy := page.Policies[i]

networkNames := make([]interface{}, 0, len(policy.Networks))
for _, network := range policy.Networks {
segments := strings.Split(network.NetworkUrl, "/")
networkNames = append(networkNames, segments[len(segments)-1])
}

mqlDnsPolicy, err := g.MotorRuntime.CreateResource("gcp.project.dnsService.policy",
"projectId", projectId,
"id", strconv.FormatInt(int64(policy.Id), 10),
"name", policy.Name,
"description", policy.Description,
"enableInboundForwarding", policy.EnableInboundForwarding,
"enableLogging", policy.EnableLogging,
"networkNames", networkNames,
)
if err != nil {
return err
Expand All @@ -193,6 +201,43 @@ func (g *mqlGcpProjectDnsService) GetPolicies() ([]interface{}, error) {
return res, nil
}

func (g *mqlGcpProjectDnsServicePolicy) GetNetworks() ([]interface{}, error) {
projectId, err := g.ProjectId()
if err != nil {
return nil, err
}

networkNames, err := g.NetworkNames()
if err != nil {
return nil, err
}

obj, err := g.MotorRuntime.CreateResource("gcp.project.computeService", "projectId", projectId)
if err != nil {
return nil, err
}
gcpCompute := obj.(GcpProjectComputeService)
networks, err := gcpCompute.Networks()
if err != nil {
return nil, err
}

res := make([]interface{}, 0, len(networkNames))
for _, network := range networks {
networkName, err := network.(GcpProjectComputeServiceNetwork).Name()
if err != nil {
return nil, err
}
for _, name := range networkNames {
if name == networkName {
res = append(res, network)
break
}
}
}
return res, nil
}

func (g *mqlGcpProjectDnsServiceRecordset) id() (string, error) {
projectId, err := g.ProjectId()
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion resources/packs/gcp/gcp.lr
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ private gcp.project.dnsService.recordset @defaults("name") {
}

// Cloud DNS rules applied to one or more Virtual Private Cloud resources
private gcp.project.dnsService.policy {
private gcp.project.dnsService.policy @defaults("name") {
// Project ID
projectId string
// Managed Zone ID
Expand All @@ -1217,6 +1217,10 @@ private gcp.project.dnsService.policy {
enableInboundForwarding bool
// Indicates if logging is enabled
enableLogging bool
// List of network names specifying networks to which this policy is applied
networkNames []string
// List of networks to which this policy is applied
networks() []gcp.project.computeService.network
}

// GCP GKE
Expand Down
78 changes: 78 additions & 0 deletions resources/packs/gcp/gcp.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion resources/packs/gcp/info/gcp.lr.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/packs/k8s/k8s.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.