Skip to content

Commit b4b49ae

Browse files
add Service accounts as assets
1 parent a689685 commit b4b49ae

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

providers/gcp/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Examples with the GCP project configured:
6767
resources.DiscoverDataprocClusters,
6868
resources.DiscoverLoggingBuckets,
6969
resources.DiscoverApiKeys,
70+
resources.DiscoverIamServiceAccounts,
7071
},
7172
Flags: []plugin.Flag{
7273
{

providers/gcp/connection/platform.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ func GetTitleForPlatformName(name string) string {
148148
return "GCP Logging Bucket"
149149
case "gcp-apikey":
150150
return "GCP API Key"
151+
case "gcp-iam-service-account":
152+
return "GCP IAM Service Account"
151153
}
152154
return "Google Cloud Platform"
153155
}
@@ -265,6 +267,13 @@ func ResourceTechnologyUrl(service, project, region, objectType, name string) []
265267
default:
266268
return []string{"gcp", project, "apikeys", region, "other"}
267269
}
270+
case "iam":
271+
switch objectType {
272+
case "service-account":
273+
return []string{"gcp", project, "iam", region, "service-account"}
274+
default:
275+
return []string{"gcp", project, "iam", region, "other"}
276+
}
268277
default:
269278
return []string{"gcp", project, "other"}
270279
}

providers/gcp/resources/discovery.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const (
5757
DiscoverDataprocClusters = "dataproc-clusters"
5858
DiscoverLoggingBuckets = "logging-buckets"
5959
DiscoverApiKeys = "apikeys"
60+
DiscoverIamServiceAccounts = "iam-service-accounts"
6061
)
6162

6263
var All = []string{
@@ -98,6 +99,7 @@ var Auto = []string{
9899
DiscoverDataprocClusters,
99100
DiscoverLoggingBuckets,
100101
DiscoverApiKeys,
102+
DiscoverIamServiceAccounts,
101103
}
102104

103105
var AllAPIResources = []string{
@@ -126,6 +128,7 @@ var AllAPIResources = []string{
126128
DiscoverDataprocClusters,
127129
DiscoverLoggingBuckets,
128130
DiscoverApiKeys,
131+
DiscoverIamServiceAccounts,
129132
}
130133

131134
// List of all CloudSQL types, this will be used during discovery
@@ -1133,6 +1136,35 @@ func discoverProject(conn *connection.GcpConnection, gcpProject *mqlGcpProject,
11331136
}
11341137
}
11351138

1139+
if stringx.ContainsAnyOf(discoveryTargets, DiscoverIamServiceAccounts) {
1140+
iamSvc := gcpProject.GetIam()
1141+
if iamSvc.Error != nil {
1142+
return nil, iamSvc.Error
1143+
}
1144+
sas := iamSvc.Data.GetServiceAccounts()
1145+
if sas.Error != nil {
1146+
return nil, sas.Error
1147+
}
1148+
for i := range sas.Data {
1149+
sa := sas.Data[i].(*mqlGcpProjectIamServiceServiceAccount)
1150+
assetList = append(assetList, &inventory.Asset{
1151+
PlatformIds: []string{
1152+
connection.NewResourcePlatformID("iam", gcpProject.Id.Data, "global", "service-account", sa.UniqueId.Data),
1153+
},
1154+
Name: sa.Email.Data,
1155+
Platform: &inventory.Platform{
1156+
Name: "gcp-iam-service-account",
1157+
Title: connection.GetTitleForPlatformName("gcp-iam-service-account"),
1158+
Runtime: "gcp",
1159+
Kind: "gcp-object",
1160+
Family: []string{"google"},
1161+
TechnologyUrlSegments: connection.ResourceTechnologyUrl("iam", gcpProject.Id.Data, "global", "service-account", sa.UniqueId.Data),
1162+
},
1163+
Connections: []*inventory.Config{conn.Conf.Clone(inventory.WithoutDiscovery(), inventory.WithParentConnectionId(conn.Conf.Id))},
1164+
})
1165+
}
1166+
}
1167+
11361168
return assetList, nil
11371169
}
11381170

0 commit comments

Comments
 (0)