From bd14bf925f3cdffc4abe8facf59bc7ee252749f6 Mon Sep 17 00:00:00 2001 From: vj Date: Wed, 29 Jan 2025 21:18:11 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20fetching=20of=20service=20?= =?UTF-8?q?accounts=20on=20gke=20cluster=20nodepool=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/gcp/resources/gke.go | 2 +- providers/gcp/resources/iam.go | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/providers/gcp/resources/gke.go b/providers/gcp/resources/gke.go index dd3501aeea..00ead9a49a 100644 --- a/providers/gcp/resources/gke.go +++ b/providers/gcp/resources/gke.go @@ -589,7 +589,7 @@ func (g *mqlGcpProjectGkeServiceClusterNodepoolConfig) serviceAccount() (*mqlGcp } email := g.ServiceAccountEmail.Data - res, err := CreateResource(g.MqlRuntime, "gcp.project.iamService.serviceAccount", map[string]*llx.RawData{ + res, err := NewResource(g.MqlRuntime, "gcp.project.iamService.serviceAccount", map[string]*llx.RawData{ "projectId": llx.StringData(projectId), "email": llx.StringData(email), }) diff --git a/providers/gcp/resources/iam.go b/providers/gcp/resources/iam.go index 91100eb160..231a04dec3 100644 --- a/providers/gcp/resources/iam.go +++ b/providers/gcp/resources/iam.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" + "github.com/rs/zerolog/log" "go.mondoo.com/cnquery/v11/llx" "go.mondoo.com/cnquery/v11/providers-sdk/v1/plugin" "go.mondoo.com/cnquery/v11/providers/gcp/connection" @@ -74,7 +75,15 @@ func initGcpProjectIamServiceServiceAccount(runtime *plugin.Runtime, args map[st return args, sa, nil } } - return nil, nil, errors.New("service account not found") + + args["name"] = llx.NilData + args["uniqueId"] = llx.NilData + args["displayName"] = llx.NilData + args["description"] = llx.NilData + args["oauth2ClientId"] = llx.NilData + args["disabled"] = llx.NilData + log.Error().Interface("email", args["email"].Value).Err(errors.New("service account not found")).Send() + return args, nil, nil } func (g *mqlGcpProjectIamService) serviceAccounts() ([]interface{}, error) { @@ -137,6 +146,13 @@ func (g *mqlGcpProjectIamServiceServiceAccount) keys() ([]interface{}, error) { } email := g.Email.Data + // if the unique id is null, we were not able to find a record of this service account + // so skip the keys discovery + if g.UniqueId.IsNull() { + g.Keys.State = plugin.StateIsNull | plugin.StateIsSet + return nil, nil + } + conn := g.MqlRuntime.Connection.(*connection.GcpConnection) creds, err := conn.Credentials(admin.DefaultAuthScopes()...)