diff --git a/Code.js b/Code.js index 0027ee4..6485b5a 100644 --- a/Code.js +++ b/Code.js @@ -14,6 +14,7 @@ function runAudit() { const auditFunctionsToTrigger = [ 'auditAllUsersIAMPolicies', 'auditPublicCloudAssetInventory', + 'auditServiceAccounts', 'auditServiceAccountKeyUsage', 'auditGKEClusters', 'auditUnattendedProjects', @@ -43,6 +44,7 @@ function runAudit() { auditPublicCloudAssetInventory(); + auditServiceAccounts(); auditServiceAccountKeyUsage(); auditGKEClusters(); @@ -366,6 +368,31 @@ function fetchAllFolders(callback) { }); } +function auditServiceAccounts() { + initializeGlobals(); + + sendGAMP('auditSerivceAccounts'); + + var sheet = createSheet("All Service Accounts", ["Project", "Email", "Description", "Status"]); + + // https://cloud.google.com/iam/docs/reference/rest/v1/projects.serviceAccounts + var assetTypes = "iam.googleapis.com/ServiceAccount"; + fetchAllAssets(assetTypes, (assets) => { + if (assets == null) { + return; + } + assets.forEach((asset) => { + var data = asset.resource.data; + var activeRange = sheet.getActiveRange(); + activeRange.setValues([[data.projectId, data.email, data.description, data.disabled ? "DISABLED" : "ACTIVE"]]); + sheet.setActiveRange(activeRange.offset(1, 0)); + + }); + // Logger.log(assets.length); + SpreadsheetApp.flush(); + }); +} + function auditServiceAccountKeyUsage() { initializeGlobals();