Skip to content

Commit

Permalink
Add Audit Service Accounts sheet
Browse files Browse the repository at this point in the history
  • Loading branch information
somethingnew2-0 committed Jun 11, 2024
1 parent 04195b1 commit c64f5cf
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function runAudit() {
const auditFunctionsToTrigger = [
'auditAllUsersIAMPolicies',
'auditPublicCloudAssetInventory',
'auditServiceAccounts',
'auditServiceAccountKeyUsage',
'auditGKEClusters',
'auditUnattendedProjects',
Expand Down Expand Up @@ -43,6 +44,7 @@ function runAudit() {

auditPublicCloudAssetInventory();

auditServiceAccounts();
auditServiceAccountKeyUsage();

auditGKEClusters();
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit c64f5cf

Please sign in to comment.