--- policy: /ce/ca/google/iam/service-account-admin-privileges logic: /ce/ca/google/iam/service-account-admin-privileges/prod.logic.yaml executionTime: 2026-06-06T12:04:29.740349123Z generationMs: 51 executionMs: 963 rows: - id: aAL1 match: true status: expected: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 199 actual: 199 conditionText: expected: not(extract('CA10__serviceAccountEmail__c').endsWith('.iam.gserviceaccount.com') && extract('CA10__serviceAccountEmail__c').contains(extract('serviceAccountProjectId'))) actual: not(extract('CA10__serviceAccountEmail__c').endsWith('.iam.gserviceaccount.com') && extract('CA10__serviceAccountEmail__c').contains(extract('serviceAccountProjectId'))) runtimeError: {} - id: aAL2 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 299 actual: 299 conditionText: expected: CA10__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT) actual: CA10__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT) runtimeError: {} - id: aAL3 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 300 actual: 300 conditionText: expected: otherwise actual: otherwise runtimeError: {} usedFiles: - path: /ce/ca/google/iam/service-account-admin-privileges/policy.yaml md5Hash: 78D01A71F480FA1A124AFBBF58441868 content: "---\nnames: \n full: \"Google IAM Service Account has admin privileges\"\ \n contextual: \"Service Account has admin privileges\"\ndescription: \"A service\ \ account is a special Google account that belongs to an application or a VM,\ \ \\\n instead of to an individual end-user. The application uses the service\ \ account to call the \\\n service's Google API so that users aren't directly\ \ involved. It's recommended not to use \\\n admin access for ServiceAccount.\"\ \ntype: COMPLIANCE_POLICY\ncategories:\n - \"SECURITY\"\nframeworkMappings:\n\ \ - /frameworks/cis-gcp-v5.0.0/01/06\n - /frameworks/cloudaware/identity-and-access-governance/rbac-management\n\ \ - /frameworks/nist-sp-800-53-r5/ac/06\n - /frameworks/iso-iec-27001-2022/05/15\n\ \ - /frameworks/iso-iec-27001-2022/08/02\n - /frameworks/nist-csf-v1.1/pr-ac/04\n\ \ - /frameworks/soc-2/cc6/01/03\n - /frameworks/soc-2/cc6/01/04\n - /frameworks/soc-2/cc6/01/07\n\ \ - /frameworks/soc-2/cc6/01/08\n - /frameworks/soc-2/cc6/03/01\n - /frameworks/soc-2/cc6/03/02\n\ \ - /frameworks/soc-2/cc6/03/03\nsimilarPolicies:\n cloudConformity:\n \ \ - url: \"https://www.trendmicro.com/cloudoneconformity-staging/knowledge-base/gcp/CloudIAM/restrict-admin-access-for-service-accounts.html\"\ \n name: \"Restrict Administrator Access for Service Accounts\"\n " - path: /ce/ca/google/iam/service-account-admin-privileges/prod.logic.yaml md5Hash: 5A13476E27B21F7E90ED1E852134F14A content: "---\ninputType: \"CA10__CaGoogleIamServiceAccount__c\"\ntestData:\n\ \ - file: test-data.json\nimportExtracts:\n - file: /types/CA10__CaGoogleIamServiceAccount__c/object.extracts.yaml\n\ conditions: \n - status: \"INAPPLICABLE\"\n currentStateMessage: \"This\ \ recommendation applies only to user-managed service accounts.\"\n check:\n\ ## NOT: SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com\n NOT:\n\ \ arg:\n AND:\n args:\n - ENDS_WITH:\n\ \ arg:\n EXTRACT: CA10__serviceAccountEmail__c\n\ \ search:\n TEXT: \".iam.gserviceaccount.com\"\ \ \n - CONTAINS:\n arg:\n EXTRACT:\ \ CA10__serviceAccountEmail__c\n search:\n \ \ EXTRACT: serviceAccountProjectId\n - status: \"INCOMPLIANT\"\n currentStateMessage:\ \ \"This service account has roles with admin privileges.\"\n remediationMessage:\ \ \"Restrict the service account privileges.\"\n check:\n RELATED_LIST_HAS:\n\ \ status: \"INCOMPLIANT\"\n relationshipName: \"CA10__Google_IAM_Policy_Bindings__r\"\ \notherwise:\n status: \"COMPLIANT\"\n currentStateMessage: \"The service\ \ account has no admin privileges.\"\nrelatedLists:\n - relationshipName: \"\ CA10__Google_IAM_Policy_Bindings__r\"\n importExtracts:\n - file: /types/CA10__CaGoogleIamPolicyBinding__c/object.extracts.yaml\n\ \ - file: /types/CA10__CaGoogleIamRole__c/object.extracts.yaml\n recordTypes:\n\ \ - \"caGoogleIamPolicyBindingProject\"\n conditions:\n - status:\ \ \"COMPLIANT\"\n currentStateMessage: \"There is no role with admin\ \ privileges.\"\n check:\n IS_EMPTY_LOOKUP: \"CA10__iamRole__r\"\ \n - status: \"INCOMPLIANT\"\n currentStateMessage: \"Role with\ \ admin privileges.\"\n check:\n OR:\n args:\n\ \ - CONTAINS:\n arg:\n EXTRACT:\ \ \"CA10__iamRole__r.CA10__roleName__c\"\n search:\n \ \ TEXT: \"admin\"\n - IS_EQUAL:\n \ \ left:\n EXTRACT: \"CA10__iamRole__r.CA10__roleName__c\"\ \n right:\n TEXT: \"editor\"\n \ \ - IS_EQUAL:\n left:\n EXTRACT:\ \ \"CA10__iamRole__r.CA10__roleName__c\"\n right:\n \ \ TEXT: \"owner\"\n otherwise:\n status: \"COMPLIANT\"\ \n currentStateMessage: \"Role without admin privileges.\"\n" - path: /ce/ca/google/iam/service-account-admin-privileges/test-data.json md5Hash: ACA19B77F93426BBAD39F75BEC16899B content: | [ { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "199", "conditionText": "not(extract('CA10__serviceAccountEmail__c').endsWith('.iam.gserviceaccount.com') && extract('CA10__serviceAccountEmail__c').contains(extract('serviceAccountProjectId')))", "runtimeError": null }, "context": { "snapshotTime": "2024-08-20T17:39:01Z" }, "Id": "aAL1", "CA10__disappearanceTime__c": null, "CA10__serviceAccountEmail__c": "compute@developer.gserviceaccount.com", "CA10__googleProject__c": "a41", "CA10__googleProject__r": { "CA10__projectId__c": "dev", "Id": "a41" }, "CA10__Google_IAM_Policy_Bindings__r": [ { "Id": "aAI1", "RecordTypeId": "0121", "CA10__disappearanceTime__c": null, "CA10__iamRole__c": "aAJ1", "CA10__iamCuratedRoleId__c": "roles/editor", "CA10__membersServiceAccount__c": "aAL1", "RecordType": { "DeveloperName": "caGoogleIamPolicyBindingProject", "Id": "0121" }, "CA10__iamRole__r": { "Id": "aAJ1", "CA10__disappearanceTime__c": null, "CA10__roleName__c": "roles/editor" } } ] }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "299", "conditionText": "CA10__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT)", "runtimeError": null }, "context": { "snapshotTime": "2024-08-20T17:39:01Z" }, "Id": "aAL2", "CA10__disappearanceTime__c": null, "CA10__serviceAccountEmail__c": "upload@lan.iam.gserviceaccount.com", "CA10__googleProject__c": "a4p72", "CA10__googleProject__r": { "CA10__projectId__c": "lan", "Id": "a4p72" }, "CA10__Google_IAM_Policy_Bindings__r": [ { "Id": "aAIV2", "RecordTypeId": "0122", "CA10__disappearanceTime__c": null, "CA10__iamRole__c": "aAJ2", "CA10__iamCuratedRoleId__c": "roles/storage.admin", "CA10__membersServiceAccount__c": "aAL2", "RecordType": { "DeveloperName": "caGoogleIamPolicyBindingProject", "Id": "0122" }, "CA10__iamRole__r": { "Id": "aAJ2", "CA10__disappearanceTime__c": null, "CA10__roleName__c": "roles/storage.admin" } } ] }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "300", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2024-08-20T17:39:01Z" }, "Id": "aAL3", "CA10__disappearanceTime__c": null, "CA10__serviceAccountEmail__c": "account@marine.iam.gserviceaccount.com", "CA10__googleProject__c": "a4p7V3", "CA10__googleProject__r": { "CA10__projectId__c": "marine", "Id": "a4p7V3" }, "CA10__Google_IAM_Policy_Bindings__r": [ { "Id": "aAIV3", "RecordTypeId": "0123", "CA10__disappearanceTime__c": null, "CA10__iamRole__c": "aAJ3", "CA10__iamCuratedRoleId__c": "roles/viewer", "CA10__membersServiceAccount__c": "aAL3", "RecordType": { "DeveloperName": "caGoogleIamPolicyBindingProject", "Id": "0123" }, "CA10__iamRole__r": { "Id": "aAJ3", "CA10__disappearanceTime__c": null, "CA10__roleName__c": "roles/viewer" } } ] } ] - path: /types/CA10__CaGoogleIamRole__c/object.extracts.yaml md5Hash: 545CD4D347F041DCDD9980D122D63882 content: "---\nextracts:\n - name: \"Name\"\n value: \n FIELD:\n \ \ path: \"Name\"\n undeterminedIf:\n isEmpty: \"Name should\ \ not be empty\"\n - name: \"CA10__roleName__c\"\n value: \n FIELD:\n\ \ path: \"CA10__roleName__c\"\n undeterminedIf:\n isEmpty:\ \ \"Name should not be empty\"\n" - path: /types/CA10__CaGoogleIamPolicyBinding__c/object.extracts.yaml md5Hash: DA65DB880E2440923287921FF4E70B30 content: "---\nextracts:\n - name: \"Name\"\n value: \n FIELD:\n \ \ path: \"Name\"\n undeterminedIf:\n isEmpty: \"Name should\ \ not be empty\"\n - name: \"CA10__membersAllUsers__c\"\n value: \n \ \ FIELD:\n path: \"CA10__membersAllUsers__c\"\n undeterminedIf:\n\ \ isEmpty: \"Field should not be empty\"\n - name: \"CA10__membersAllAuthenticatedUsers__c\"\ \n value: \n FIELD:\n path: \"CA10__membersAllAuthenticatedUsers__c\"\ \n undeterminedIf:\n isEmpty: \"Field should not be empty\"\ \n" - path: /types/CA10__CaGoogleIamServiceAccount__c/object.extracts.yaml md5Hash: EB5FB013DE89FCA54D6B42804FC725D6 content: "---\nextracts:\n - name: \"CA10__serviceAccountEmail__c\"\n value:\ \ \n FIELD:\n path: \"CA10__serviceAccountEmail__c\"\n \ \ undeterminedIf:\n isEmpty: \"Corrupted data. Service Account Email\ \ cannot be empty.\"\n - name: \"Name\"\n value: \n FIELD:\n \ \ path: \"Name\"\n undeterminedIf:\n isEmpty: \"Corrupted data.\ \ Service Account Name cannot be empty.\"\n - name: \"serviceAccountProjectId\"\ \n value: \n FIELD:\n path: \"CA10__googleProject__r.CA10__projectId__c\"\ \n undeterminedIf:\n isEmpty: \"Master detail Id cannot be empty.\"\ \n\n" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "aAL1", "expectedResult" : { "status" : "INAPPLICABLE", "conditionIndex" : "199", "conditionText" : "not(extract('CA10__serviceAccountEmail__c').endsWith('.iam.gserviceaccount.com') && extract('CA10__serviceAccountEmail__c').contains(extract('serviceAccountProjectId')))", "runtimeError" : null } }, { "Id" : "aAL2", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "299", "conditionText" : "CA10__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT)", "runtimeError" : null } }, { "Id" : "aAL3", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "300", "conditionText" : "otherwise", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10__CaGoogleIamServiceAccount__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "CA10__serviceAccountEmail__c" : "compute@developer.gserviceaccount.com", "Id" : "aAL1", "CA10__googleProject__c" : "a41" }, { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "CA10__serviceAccountEmail__c" : "upload@lan.iam.gserviceaccount.com", "Id" : "aAL2", "CA10__googleProject__c" : "a4p72" }, { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "CA10__serviceAccountEmail__c" : "account@marine.iam.gserviceaccount.com", "Id" : "aAL3", "CA10__googleProject__c" : "a4p7V3" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaGoogleProject__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "CA10__projectId__c" : "dev", "Id" : "a41" }, { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "CA10__projectId__c" : "lan", "Id" : "a4p72" }, { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "CA10__projectId__c" : "marine", "Id" : "a4p7V3" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaGoogleIamPolicyBinding__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "CA10__iamRole__c" : "aAJ1", "CA10__iamCuratedRoleId__c" : "roles/editor", "CA10__membersServiceAccount__c" : "aAL1", "Id" : "aAI1", "RecordTypeId" : "0121" }, { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "CA10__iamRole__c" : "aAJ2", "CA10__iamCuratedRoleId__c" : "roles/storage.admin", "CA10__membersServiceAccount__c" : "aAL2", "Id" : "aAIV2", "RecordTypeId" : "0122" }, { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "CA10__iamRole__c" : "aAJ3", "CA10__iamCuratedRoleId__c" : "roles/viewer", "CA10__membersServiceAccount__c" : "aAL3", "Id" : "aAIV3", "RecordTypeId" : "0123" } ]; """; CREATE TEMP FUNCTION mock_RecordType() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "DeveloperName" : "caGoogleIamPolicyBindingProject", "Id" : "0121" }, { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "DeveloperName" : "caGoogleIamPolicyBindingProject", "Id" : "0122" }, { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "DeveloperName" : "caGoogleIamPolicyBindingProject", "Id" : "0123" } ]; """; CREATE TEMP FUNCTION mock_CA10__CaGoogleIamRole__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "Id" : "aAJ1", "CA10__roleName__c" : "roles/editor" }, { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "Id" : "aAJ2", "CA10__roleName__c" : "roles/storage.admin" }, { "context" : { "snapshotTime" : new Date("2024-08-20T17:39:01Z") }, "Id" : "aAJ3", "CA10__roleName__c" : "roles/viewer" } ]; """; CREATE TEMP FUNCTION process_CA10__CaGoogleIamServiceAccount__c( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__serviceAccountEmail__c STRING, CA10__googleProject__r STRUCT< CA10__projectId__c STRING, Id STRING >, CA10__Google_IAM_Policy_Bindings__r ARRAY, CA10__iamRole__r STRUCT< Id STRING, CA10__disappearanceTime__c TIMESTAMP, CA10__roleName__c STRING >, CA10__iamRole__c STRING, CA10__iamCuratedRoleId__c STRING, CA10__membersServiceAccount__c STRING, Id STRING, RecordTypeId STRING, result STRUCT >>, Id STRING, CA10__googleProject__c STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var TextLib = new function () { this.normalize = function(arg) { return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase(); }; this.isEmpty = function(arg) { return this.normalize(arg) == ''; }; this.isNotEmpty = function(arg) { return this.normalize(arg) != ''; }; this.equal = function(left, right) { return this.normalize(left) == this.normalize(right); }; this.notEqual = function(left, right) { return this.normalize(left) != this.normalize(right); }; this.startsWith = function(arg, substring) { return this.normalize(arg).startsWith(this.normalize(substring)); }; this.endsWith = function(arg, substring) { return this.normalize(arg).endsWith(this.normalize(substring)); }; this.contains = function(arg, substring) { return this.normalize(arg).includes(this.normalize(substring)); }; this.containsAll = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.every(sub => normalizedArg.includes(this.normalize(sub))); }; this.containsAny = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.some(sub => normalizedArg.includes(this.normalize(sub))); }; }(); var references1 = []; // condition[0], conditionIndex:[0..99] references1.push('Deleted From Google [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c); if (obj.CA10__disappearanceTime__c != null) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[1], conditionIndex:[100..199] function fieldChecked4() { if (TextLib.isEmpty(obj.CA10__serviceAccountEmail__c)) { throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__serviceAccountEmail__c.isEmpty()", currentStateMessage: "Corrupted data. Service Account Email cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__serviceAccountEmail__c; } function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; }; function fieldChecked8() { if (TextLib.isEmpty(obj.CA10__googleProject__r.CA10__projectId__c)) { throw new Error("UNDETERMINED condition:102", {cause: {status: 'UNDETERMINED', conditionIndex: 102, conditionText: "CA10__googleProject__r.CA10__projectId__c.isEmpty()", currentStateMessage: "Master detail Id cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__googleProject__r.CA10__projectId__c; } function extract7() { if (!this.out) { this.out = fieldChecked8(); } return this.out; }; references1.push('Email [obj.CA10__serviceAccountEmail__c]: ' + obj.CA10__serviceAccountEmail__c); references1.push('Project ID [obj.CA10__googleProject__r.CA10__projectId__c]: ' + obj.CA10__googleProject__r.CA10__projectId__c); try { if (!(TextLib.endsWith(extract3.call(extract3), '.iam.gserviceaccount.com') && TextLib.contains(extract3.call(extract3), extract7.call(extract7)))) { return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(extract('CA10__serviceAccountEmail__c').endsWith('.iam.gserviceaccount.com') && extract('CA10__serviceAccountEmail__c').contains(extract('serviceAccountProjectId')))", currentStateMessage: "This recommendation applies only to user-managed service accounts.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } var count_CA10__Google_IAM_Policy_Bindings__r_INCOMPLIANT9 = 0; if (obj.CA10__Google_IAM_Policy_Bindings__r != null) { for (var i10 = 0; i10 < obj.CA10__Google_IAM_Policy_Bindings__r.length; i10++) { if (typeof(obj.CA10__Google_IAM_Policy_Bindings__r[i10].status) !== 'undefined') { if (obj.CA10__Google_IAM_Policy_Bindings__r[i10].status == 'INCOMPLIANT') { count_CA10__Google_IAM_Policy_Bindings__r_INCOMPLIANT9 += obj.CA10__Google_IAM_Policy_Bindings__r[i10].count; } } else { if (obj.CA10__Google_IAM_Policy_Bindings__r[i10].result.status == 'INCOMPLIANT') { count_CA10__Google_IAM_Policy_Bindings__r_INCOMPLIANT9 += 1; } } } } // condition[2], conditionIndex:[200..299] references1.push('Related list [CA10__Google_IAM_Policy_Bindings__r] ' + (count_CA10__Google_IAM_Policy_Bindings__r_INCOMPLIANT9 > 0 ? 'has' : 'does not have') + ' objects in INCOMPLIANT status'); if (count_CA10__Google_IAM_Policy_Bindings__r_INCOMPLIANT9 > 0) { return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "CA10__Google_IAM_Policy_Bindings__r.has(INCOMPLIANT)", currentStateMessage: "This service account has roles with admin privileges.", currentStateReferences: references1.join('\n'), remediation: "Restrict the service account privileges.", runtimeError: null}; } return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The service account has no admin privileges.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; CREATE TEMP FUNCTION process_CA10__Google_IAM_Policy_Bindings__r( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, RecordType STRUCT< DeveloperName STRING, Id STRING >, CA10__iamRole__r STRUCT< Id STRING, CA10__disappearanceTime__c TIMESTAMP, CA10__roleName__c STRING >, CA10__iamRole__c STRING, CA10__iamCuratedRoleId__c STRING, CA10__membersServiceAccount__c STRING, Id STRING, RecordTypeId STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js AS r""" var BytesLib = new function () { this.normalize = function(arg) { return arg == null ? '' : arg; }; this.isEmpty = function(arg) { return this.normalize(arg) == ''; }; this.isNotEmpty = function(arg) { return this.normalize(arg) != ''; }; this.equal = function(left, right) { return this.normalize(left) == this.normalize(right); }; this.notEqual = function(left, right) { return this.normalize(left) != this.normalize(right); }; this.startsWith = function(arg, substring) { return this.normalize(arg).startsWith(this.normalize(substring)); }; this.endsWith = function(arg, substring) { return this.normalize(arg).endsWith(this.normalize(substring)); }; this.contains = function(arg, substring) { return this.normalize(arg).includes(this.normalize(substring)); }; this.containsAll = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.every(sub => normalizedArg.includes(this.normalize(sub))); }; this.containsAny = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.some(sub => normalizedArg.includes(this.normalize(sub))); }; }(); var CollectionLib = new function () { this.parse = function(arg, separator, skipEmpty, skipDuplicates, sort, normalize) { if (arg == null) return []; let parts = arg.split(separator); return this.fromArray(parts, skipEmpty, skipDuplicates, sort, normalize); }; this.fromArray = function(arr, skipEmpty, skipDuplicates, sort, normalize) { if (arr == null) return []; let result = []; let seen = new Set(); arr.forEach(el => { let normalized = normalize ? TextLib.normalize(el) : BytesLib.normalize(el); if (!skipEmpty || (normalize ? TextLib.isNotEmpty(el) : BytesLib.isNotEmpty(el))) { if (!skipDuplicates || !seen.has(normalized)) { if (skipDuplicates) seen.add(normalized); result.push(normalized); } } }); if (sort) result.sort(); return result; }; this.equal = function(left, right) { left = left == null ? [] : left; right = right == null ? [] : right; if (left.length !== right.length) return false; for (let i = 0; i < left.length; i++) { if (left[i] !== right[i]) return false; } return true; }; this.notEqual = function(left, right) { return !this.equal(left, right); }; this.size = function(collection) { return collection == null ? 0 : collection.length; }; this.startsWith = function(collection, search, normalize) { if (collection == null || collection.length === 0) return false; let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search); return collection[0] === normalizedSearch; }; this.endsWith = function(collection, search, normalize) { if (collection == null || collection.length === 0) return false; let normalizedSearch = normalize ? TextLib.normalize(search) : BytesLib.normalize(search); return collection[collection.length - 1] === normalizedSearch; }; this.contains = function(collection, search, normalize) { if (collection == null || collection.length === 0) return false; return collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search)); }; this.containsAll = function(collection, searchArray, normalize) { if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false; return searchArray.every(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search))); }; this.containsAny = function(collection, searchArray, normalize) { if (collection == null || collection.length === 0 || searchArray == null || searchArray.length === 0) return false; return searchArray.some(search => collection.includes(normalize ? TextLib.normalize(search) : BytesLib.normalize(search))); }; }(); var TextLib = new function () { this.normalize = function(arg) { return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase(); }; this.isEmpty = function(arg) { return this.normalize(arg) == ''; }; this.isNotEmpty = function(arg) { return this.normalize(arg) != ''; }; this.equal = function(left, right) { return this.normalize(left) == this.normalize(right); }; this.notEqual = function(left, right) { return this.normalize(left) != this.normalize(right); }; this.startsWith = function(arg, substring) { return this.normalize(arg).startsWith(this.normalize(substring)); }; this.endsWith = function(arg, substring) { return this.normalize(arg).endsWith(this.normalize(substring)); }; this.contains = function(arg, substring) { return this.normalize(arg).includes(this.normalize(substring)); }; this.containsAll = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.every(sub => normalizedArg.includes(this.normalize(sub))); }; this.containsAny = function(arg, substrings) { if (substrings == null || substrings.length === 0) return false; let normalizedArg = this.normalize(arg); return substrings.some(sub => normalizedArg.includes(this.normalize(sub))); }; }(); var references1 = []; // condition[0], conditionIndex:[0..99] references1.push('Deleted From Google [CA10__disappearanceTime__c]: ' + obj.CA10__disappearanceTime__c); if (obj.CA10__disappearanceTime__c != null) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[1], conditionIndex:[100..199] references1.push('Record Type Name [obj.RecordType.DeveloperName]: ' + obj.RecordType.DeveloperName); if (!CollectionLib.contains(CollectionLib.fromArray(['caGoogleIamPolicyBindingProject'], true, true, true, true), obj.RecordType.DeveloperName, true)) { return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "not(setOfText(['caGoogleIamPolicyBindingProject']).contains(RecordType.DeveloperName))", currentStateMessage: "Object record type is not applicable", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[2], conditionIndex:[200..299] if (TextLib.isEmpty(obj.CA10__iamCuratedRoleId__c) || TextLib.isEmpty(obj.CA10__iamRole__c) || obj.CA10__iamRole__r.CA10__disappearanceTime__c != null) { return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "isEmptyLookup('CA10__iamRole__r')", currentStateMessage: "There is no role with admin privileges.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } // condition[3], conditionIndex:[300..399] function extractChecked3() { if (TextLib.isEmpty(obj.CA10__iamCuratedRoleId__c)) { throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "extractCheck(obj.CA10__iamCuratedRoleId__c)", currentStateMessage: "Related object via CA10__iamCuratedRoleId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } if (TextLib.isEmpty(obj.CA10__iamRole__c)) { throw new Error("UNDETERMINED condition:302", {cause: {status: 'UNDETERMINED', conditionIndex: 302, conditionText: "extractCheck(obj.CA10__iamRole__c)", currentStateMessage: "Related object via CA10__iamRole__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } if (obj.CA10__iamRole__r.CA10__disappearanceTime__c != null) { throw new Error("UNDETERMINED condition:303", {cause: {status: 'UNDETERMINED', conditionIndex: 303, conditionText: "extractCheck(obj.CA10__iamRole__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__iamRole__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return extract4.call(extract4); } function fieldChecked5() { if (TextLib.isEmpty(obj.CA10__iamRole__r.CA10__roleName__c)) { throw new Error("UNDETERMINED condition:304", {cause: {status: 'UNDETERMINED', conditionIndex: 304, conditionText: "CA10__roleName__c.isEmpty()", currentStateMessage: "Name should not be empty", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__iamRole__r.CA10__roleName__c; } function extract4() { if (!this.out) { this.out = fieldChecked5(); } return this.out; }; function extractChecked6() { if (TextLib.isEmpty(obj.CA10__iamCuratedRoleId__c)) { throw new Error("UNDETERMINED condition:305", {cause: {status: 'UNDETERMINED', conditionIndex: 305, conditionText: "extractCheck(obj.CA10__iamCuratedRoleId__c)", currentStateMessage: "Related object via CA10__iamCuratedRoleId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } if (TextLib.isEmpty(obj.CA10__iamRole__c)) { throw new Error("UNDETERMINED condition:306", {cause: {status: 'UNDETERMINED', conditionIndex: 306, conditionText: "extractCheck(obj.CA10__iamRole__c)", currentStateMessage: "Related object via CA10__iamRole__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } if (obj.CA10__iamRole__r.CA10__disappearanceTime__c != null) { throw new Error("UNDETERMINED condition:307", {cause: {status: 'UNDETERMINED', conditionIndex: 307, conditionText: "extractCheck(obj.CA10__iamRole__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__iamRole__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return extract4.call(extract4); } function extractChecked7() { if (TextLib.isEmpty(obj.CA10__iamCuratedRoleId__c)) { throw new Error("UNDETERMINED condition:308", {cause: {status: 'UNDETERMINED', conditionIndex: 308, conditionText: "extractCheck(obj.CA10__iamCuratedRoleId__c)", currentStateMessage: "Related object via CA10__iamCuratedRoleId__c has empty ID", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } if (TextLib.isEmpty(obj.CA10__iamRole__c)) { throw new Error("UNDETERMINED condition:309", {cause: {status: 'UNDETERMINED', conditionIndex: 309, conditionText: "extractCheck(obj.CA10__iamRole__c)", currentStateMessage: "Related object via CA10__iamRole__c is not present", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } if (obj.CA10__iamRole__r.CA10__disappearanceTime__c != null) { throw new Error("UNDETERMINED condition:310", {cause: {status: 'UNDETERMINED', conditionIndex: 310, conditionText: "extractCheck(obj.CA10__iamRole__r.CA10__disappearanceTime__c)", currentStateMessage: "Related object via CA10__iamRole__c is present, but deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return extract4.call(extract4); } references1.push('Role Name [obj.CA10__iamRole__r.CA10__roleName__c]: ' + obj.CA10__iamRole__r.CA10__roleName__c); try { if (TextLib.contains(extractChecked3(), 'admin') || TextLib.equal(extractChecked6(), 'editor') || TextLib.equal(extractChecked7(), 'owner')) { return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('CA10__iamRole__r.CA10__roleName__c').contains('admin') || extract('CA10__iamRole__r.CA10__roleName__c') == 'editor' || extract('CA10__iamRole__r.CA10__roleName__c') == 'owner'", currentStateMessage: "Role with admin privileges.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } return {status: 'COMPLIANT', conditionIndex: 400, conditionText: "otherwise", currentStateMessage: "Role without admin privileges.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; """; SELECT expectedResult.Id as Id, IF ( IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '') AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1) AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '') AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''), "MATCH", "FAIL" ) as match, expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus, expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex, expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText, expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError FROM UNNEST(mock_ExpectedResult()) expectedResult LEFT JOIN ( SELECT sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__serviceAccountEmail__c AS CA10__serviceAccountEmail__c, STRUCT ( `CA10__googleProject__r`.CA10__projectId__c AS CA10__projectId__c, `CA10__googleProject__r`.Id AS Id ) AS CA10__googleProject__r, `CA10__Google_IAM_Policy_Bindings__r`.arr AS CA10__Google_IAM_Policy_Bindings__r, sObject.Id AS Id, sObject.CA10__googleProject__c AS CA10__googleProject__c, process_CA10__CaGoogleIamServiceAccount__c( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__serviceAccountEmail__c AS CA10__serviceAccountEmail__c, STRUCT ( `CA10__googleProject__r`.CA10__projectId__c AS CA10__projectId__c, `CA10__googleProject__r`.Id AS Id ) AS CA10__googleProject__r, `CA10__Google_IAM_Policy_Bindings__r`.arr AS CA10__Google_IAM_Policy_Bindings__r, sObject.Id AS Id, sObject.CA10__googleProject__c AS CA10__googleProject__c ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10__CaGoogleIamServiceAccount__c()) AS sObject LEFT JOIN UNNEST(mock_CA10__CaGoogleProject__c()) AS `CA10__googleProject__r` ON sObject.CA10__googleProject__c = `CA10__googleProject__r`.Id LEFT JOIN ( SELECT sObject.CA10__membersServiceAccount__c, ARRAY_AGG( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, STRUCT ( `RecordType`.DeveloperName AS DeveloperName, `RecordType`.Id AS Id ) AS RecordType, STRUCT ( `CA10__iamRole__r`.Id AS Id, `CA10__iamRole__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, `CA10__iamRole__r`.CA10__roleName__c AS CA10__roleName__c ) AS CA10__iamRole__r, sObject.CA10__iamRole__c AS CA10__iamRole__c, sObject.CA10__iamCuratedRoleId__c AS CA10__iamCuratedRoleId__c, sObject.CA10__membersServiceAccount__c AS CA10__membersServiceAccount__c, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId, process_CA10__Google_IAM_Policy_Bindings__r( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, STRUCT ( `RecordType`.DeveloperName AS DeveloperName, `RecordType`.Id AS Id ) AS RecordType, STRUCT ( `CA10__iamRole__r`.Id AS Id, `CA10__iamRole__r`.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, `CA10__iamRole__r`.CA10__roleName__c AS CA10__roleName__c ) AS CA10__iamRole__r, sObject.CA10__iamRole__c AS CA10__iamRole__c, sObject.CA10__iamCuratedRoleId__c AS CA10__iamCuratedRoleId__c, sObject.CA10__membersServiceAccount__c AS CA10__membersServiceAccount__c, sObject.Id AS Id, sObject.RecordTypeId AS RecordTypeId ), sObject.context.snapshotTime ) as result ) ) AS arr FROM UNNEST(mock_CA10__CaGoogleIamPolicyBinding__c()) AS sObject LEFT JOIN UNNEST(mock_RecordType()) AS `RecordType` ON sObject.RecordTypeId = `RecordType`.Id LEFT JOIN UNNEST(mock_CA10__CaGoogleIamRole__c()) AS `CA10__iamRole__r` ON sObject.CA10__iamRole__c = `CA10__iamRole__r`.Id GROUP BY sObject.CA10__membersServiceAccount__c ) AS `CA10__Google_IAM_Policy_Bindings__r` ON sObject.Id = `CA10__Google_IAM_Policy_Bindings__r`.CA10__membersServiceAccount__c ) sObject ON sObject.Id = expectedResult.Id;