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 gcp platform family and nil bucket id panic #1883

Merged
merged 2 commits into from
Sep 26, 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
10 changes: 10 additions & 0 deletions providers/gcp/resources/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func Discover(runtime *plugin.Runtime) (*inventory.Inventory, error) {
Title: "GCP Project",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery())},
Expand Down Expand Up @@ -142,6 +143,7 @@ func discoverOrganization(conn *connection.GcpConnection, gcpOrg *mqlGcpOrganiza
Title: "GCP Project " + project.Name.Data,
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{projectConf}, // pass-in the parent connection config
Expand Down Expand Up @@ -192,6 +194,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject)
Title: "GCP Compute Instance",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: labels,
// TODO: the current connection handling does not work well for instances
Expand Down Expand Up @@ -225,6 +228,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject)
Title: "GCP Compute Image",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: labels,
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery())}, // pass-in the parent connection config
Expand Down Expand Up @@ -252,6 +256,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject)
Title: "GCP Compute Network",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery())}, // pass-in the parent connection config
Expand Down Expand Up @@ -283,6 +288,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject)
Title: "GCP Compute Subnetwork",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery())}, // pass-in the parent connection config
Expand Down Expand Up @@ -310,6 +316,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject)
Title: "GCP Compute Firewall",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery())}, // pass-in the parent connection config
Expand Down Expand Up @@ -337,6 +344,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject)
Title: "GCP GKE Cluster",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery())}, // pass-in the parent connection config
Expand Down Expand Up @@ -364,6 +372,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject)
Title: "GCP Storage Bucket",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery())}, // pass-in the parent connection config
Expand Down Expand Up @@ -391,6 +400,7 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject)
Title: "GCP BigQuery Dataset",
Runtime: "gcp",
Kind: "gcp-object",
Family: []string{"google"},
},
Labels: map[string]string{},
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery())}, // pass-in the parent connection config
Expand Down
13 changes: 9 additions & 4 deletions providers/gcp/resources/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ package resources
import (
"context"
"fmt"
"strings"

"go.mondoo.com/cnquery/llx"
"go.mondoo.com/cnquery/providers-sdk/v1/util/convert"
"go.mondoo.com/cnquery/providers/gcp/connection"
"go.mondoo.com/cnquery/types"
"strings"

"cloud.google.com/go/logging/logadmin"
"google.golang.org/api/iterator"
Expand All @@ -27,7 +28,6 @@ func (g *mqlGcpProjectLoggingservice) id() (string, error) {
}

func (g *mqlGcpProject) logging() (*mqlGcpProjectLoggingservice, error) {

if g.Id.Error != nil {
return nil, g.Id.Error
}
Expand Down Expand Up @@ -263,17 +263,22 @@ func (g *mqlGcpProjectLoggingservice) sinks() ([]interface{}, error) {
if err != nil {
return nil, err
}
sink, err := CreateResource(g.MqlRuntime, "gcp.project.loggingservice.sink", map[string]*llx.RawData{
args := map[string]*llx.RawData{
"id": llx.StringData(s.ID),
"projectId": llx.StringData(projectId),
"destination": llx.StringData(s.Destination),
"filter": llx.StringData(s.Filter),
"writerIdentity": llx.StringData(s.WriterIdentity),
"includeChildren": llx.BoolData(s.IncludeChildren),
})
}
if !strings.HasPrefix(s.Destination, "storage.googleapis.com/") {
args["storageBucket"] = llx.NilData
}
sink, err := CreateResource(g.MqlRuntime, "gcp.project.loggingservice.sink", args)
if err != nil {
return nil, err
}

sinks = append(sinks, sink)
}
return sinks, nil
Expand Down