--- policy: /ce/ca/azure/postgresql-database/disable-flexible-server-allows-access-to-azure-services logic: /ce/ca/azure/postgresql-database/disable-flexible-server-allows-access-to-azure-services/prod.logic.yaml executionTime: 2026-02-10T22:33:32.715575805Z generationMs: 72 executionMs: 951 rows: - id: test1 match: true status: expected: DISAPPEARED actual: DISAPPEARED conditionIndex: expected: 99 actual: 99 conditionText: expected: isDisappeared(CA10Z1__disappearanceTime__c) actual: isDisappeared(CA10Z1__disappearanceTime__c) runtimeError: {} - id: test2 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 399 actual: 399 conditionText: expected: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([?\ \ properties.startIpAddress == \\'0.0.0.0\\' && (properties.endIpAddress ==\ \ \\'0.0.0.0\\' || properties.endIpAddress == \\'255.255.255.255\\')])') >\ \ number(0.0)" actual: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? properties.startIpAddress\ \ == \\'0.0.0.0\\' && (properties.endIpAddress == \\'0.0.0.0\\' || properties.endIpAddress\ \ == \\'255.255.255.255\\')])') > number(0.0)" runtimeError: {} - id: test3 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 299 actual: 299 conditionText: expected: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([?\ \ starts_with(name, \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])')\ \ > number(0.0)" actual: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? starts_with(name,\ \ \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])') > number(0.0)" runtimeError: {} - id: test4 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 399 actual: 399 conditionText: expected: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([?\ \ properties.startIpAddress == \\'0.0.0.0\\' && (properties.endIpAddress ==\ \ \\'0.0.0.0\\' || properties.endIpAddress == \\'255.255.255.255\\')])') >\ \ number(0.0)" actual: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? properties.startIpAddress\ \ == \\'0.0.0.0\\' && (properties.endIpAddress == \\'0.0.0.0\\' || properties.endIpAddress\ \ == \\'255.255.255.255\\')])') > number(0.0)" runtimeError: {} - id: test5 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 500 actual: 500 conditionText: expected: otherwise actual: otherwise runtimeError: {} - id: test6 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 500 actual: 500 conditionText: expected: otherwise actual: otherwise runtimeError: {} - id: test7 match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 204 actual: 204 conditionText: expected: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([?\ \ starts_with(name, \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])').isEvaluationFailed()" actual: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? starts_with(name,\ \ \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])').isEvaluationFailed()" runtimeError: expected: "TypeError: starts_with() expected argument 1 to be type 2 but received\ \ type 7 instead." actual: "TypeError: starts_with() expected argument 1 to be type 2 but received\ \ type 7 instead." - id: test8 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 500 actual: 500 conditionText: expected: otherwise actual: otherwise runtimeError: {} - id: test9 match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 201 actual: 201 conditionText: expected: CA10Z1__firewallRules__c.delegatedTo(CA10Z1__firewallRules__c).isEmpty() actual: CA10Z1__firewallRules__c.delegatedTo(CA10Z1__firewallRules__c).isEmpty() runtimeError: {} - id: test10 match: true status: expected: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 199 actual: 199 conditionText: expected: extract('CA10Z1__deploymentMode__c') != 'Flexible' actual: extract('CA10Z1__deploymentMode__c') != 'Flexible' runtimeError: {} usedFiles: - path: /ce/ca/azure/postgresql-database/disable-flexible-server-allows-access-to-azure-services/policy.yaml md5Hash: 36E75FE441963552505613F88F297027 content: | --- names: full: Azure PostgreSQL Flexible Server Firewall Rules allow access to Azure services contextual: Flexible Server Firewall Rules allow access to Azure services description: Disable access from Azure services to PostgreSQL Database Server. type: COMPLIANCE_POLICY categories: - SECURITY frameworkMappings: - "/frameworks/cis-azure-v3.0.0/05/02/05" - "/frameworks/cloudaware/resource-security/secure-access" similarPolicies: internal: - dec-x-bf1f13f6 cloudConformity: - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/azure/PostgreSQL/disable-all-services-access.html name: Disable 'Allow access to Azure services' for PostgreSQL database servers - path: /ce/ca/azure/postgresql-database/disable-flexible-server-allows-access-to-azure-services/prod.logic.yaml md5Hash: 346B846366A7B1DE85EB1883AAB784C2 content: "---\ninputType: \"CA10Z1__CaAzurePostgreSqlServer__c\"\ntestData:\n\ \ - file: \"test-data.json\"\nimportExtracts:\n - file: \"/types/CA10Z1__CaAzurePostgreSqlServer__c/object.extracts.yaml\"\ \nconditions:\n - status: \"INAPPLICABLE\"\n currentStateMessage: \"This\ \ is not the flexible server deployment mode.\"\n check:\n NOT_EQUAL:\n\ \ left:\n EXTRACT: \"CA10Z1__deploymentMode__c\"\n right:\n\ \ TEXT: \"Flexible\"\n - status: \"INCOMPLIANT\"\n currentStateMessage:\ \ \"PostgreSQL server firewall rules allow ingress from 0.0.0.0/0 (ANY IP) via\ \ the AllowAllWindowsAzureIps rule.\"\n remediationMessage: \"Remove or disable\ \ the overly permissive rule.\"\n check:\n# returns the number of rules which\ \ names start with AllowAllAzureServicesAndResourcesWithinAzureIps\n GREATER_THAN:\n\ \ left:\n JSON_QUERY_NUMBER:\n arg: \n \ \ EXTRACT: \"caJsonFrom__firewallRules__c\"\n expression:\ \ \"length([? starts_with(name, 'AllowAllAzureServicesAndResourcesWithinAzureIps')])\"\ \n undeterminedIf: \n evaluationError: \"The JSON\ \ query has failed.\"\n resultTypeMismatch: \"The JSON query\ \ did not return number type.\"\n right:\n NUMBER: 0.0\n -\ \ status: \"INCOMPLIANT\"\n currentStateMessage: \"PostgreSQL server firewall\ \ rules allow ingress from 0.0.0.0/0 (ANY IP).\"\n remediationMessage: \"\ Remove or disable the overly permissive rule.\"\n check:\n# number of rules\ \ with start and end IPs as 0.0.0.0\n GREATER_THAN:\n left:\n \ \ JSON_QUERY_NUMBER:\n arg: \n EXTRACT: \"\ caJsonFrom__firewallRules__c\"\n expression: \"length([? properties.startIpAddress\ \ == '0.0.0.0' && (properties.endIpAddress == '0.0.0.0' || properties.endIpAddress\ \ == '255.255.255.255')])\"\n undeterminedIf: \n \ \ evaluationError: \"The JSON query has failed.\"\n resultTypeMismatch:\ \ \"The JSON query did not return number type.\"\n right:\n \ \ NUMBER: 0.0\n - status: \"COMPLIANT\"\n currentStateMessage: \"PostgreSQL\ \ server firewall rules are not defined.\"\n check:\n IS_EMPTY:\n \ \ arg:\n EXTRACT: \"CA10Z1__firewallRules__c\"\notherwise:\n \ \ status: \"COMPLIANT\"\n currentStateMessage: \"PostgreSQL server firewall\ \ rules do not allow ingress from 0.0.0.0/0 (ANY IP).\"\n" - path: /ce/ca/azure/postgresql-database/disable-flexible-server-allows-access-to-azure-services/test-data.json md5Hash: D368F0DE994691DB4F945A6D5306C790 content: |- [ { "expectedResult": { "status": "DISAPPEARED", "conditionIndex": "99", "conditionText": "isDisappeared(CA10Z1__disappearanceTime__c)", "runtimeError": null }, "context": { "snapshotTime": "2024-06-13T04:17:29Z" }, "Id": "test1", "CA10Z1__disappearanceTime__c": "2024-06-07T13:58:24Z", "CA10Z1__firewallRules__c": "[{\"properties\":{\"startIpAddress\":\"0.0.0.0\",\"endIpAddress\":\"0.0.0.0\"},\"name\":\"AllowAllAzureServicesAndResourcesWithinAzureIps\"}]", "CA10Z1__deploymentMode__c": "Flexible" }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "399", "conditionText": "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? properties.startIpAddress == \\'0.0.0.0\\' && (properties.endIpAddress == \\'0.0.0.0\\' || properties.endIpAddress == \\'255.255.255.255\\')])') > number(0.0)", "runtimeError": null }, "context": { "snapshotTime": "2024-06-13T04:17:29Z" }, "Id": "test2", "CA10Z1__disappearanceTime__c": null, "CA10Z1__firewallRules__c": "[{\"properties\":{\"startIpAddress\":\"0.0.0.0\",\"endIpAddress\":\"0.0.0.0\"},\"name\":\"FirewallRuleName\"}]", "CA10Z1__deploymentMode__c": "Flexible" }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "299", "conditionText": "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? starts_with(name, \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])') > number(0.0)", "runtimeError": null }, "context": { "snapshotTime": "2024-06-13T04:17:29Z" }, "Id": "test3", "CA10Z1__disappearanceTime__c": null, "CA10Z1__firewallRules__c": "[{\"properties\":{\"startIpAddress\":\"1.1.1.1\",\"endIpAddress\":\"255.255.255.0\"},\"name\":\"AllowAllAzureServicesAndResourcesWithinAzureIps\"}]", "CA10Z1__deploymentMode__c": "Flexible" }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "399", "conditionText": "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? properties.startIpAddress == \\'0.0.0.0\\' && (properties.endIpAddress == \\'0.0.0.0\\' || properties.endIpAddress == \\'255.255.255.255\\')])') > number(0.0)", "runtimeError": null }, "context": { "snapshotTime": "2024-06-13T04:17:29Z" }, "Id": "test4", "CA10Z1__disappearanceTime__c": null, "CA10Z1__firewallRules__c": "[{\"properties\":{\"startIpAddress\":\"0.0.0.0\",\"endIpAddress\":\"255.255.255.255\"},\"name\":\"FirewallRuleName\"}]", "CA10Z1__deploymentMode__c": "Flexible" }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "500", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2024-06-13T04:17:29Z" }, "Id": "test5", "CA10Z1__disappearanceTime__c": null, "CA10Z1__firewallRules__c": "[{\"properties\":{\"startIpAddress\":\"1.1.1.1\",\"endIpAddress\":\"1.1.1.1\"},\"name\":\"FirewallRuleName\"}]", "CA10Z1__deploymentMode__c": "Flexible" }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "500", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2024-06-13T04:17:29Z" }, "Id": "test6", "CA10Z1__disappearanceTime__c": null, "CA10Z1__firewallRules__c": "[{\"name\":\"FirewallRuleName\"}]", "CA10Z1__deploymentMode__c": "Flexible" }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "204", "conditionText": "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? starts_with(name, \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])').isEvaluationFailed()", "runtimeError": "TypeError: starts_with() expected argument 1 to be type 2 but received type 7 instead." }, "context": { "snapshotTime": "2024-06-13T04:17:29Z" }, "Id": "test7", "CA10Z1__disappearanceTime__c": null, "CA10Z1__firewallRules__c": "[{\"properties\":{\"startIpAddress\":\"1.1.1.1\",\"endIpAddress\":\"1.1.1.1\"}}]", "CA10Z1__deploymentMode__c": "Flexible" }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "500", "conditionText": "otherwise", "runtimeError": null }, "context": { "snapshotTime": "2024-06-13T04:17:29Z" }, "Id": "test8", "CA10Z1__disappearanceTime__c": null, "CA10Z1__firewallRules__c": "[]", "CA10Z1__deploymentMode__c": "Flexible" }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "201", "conditionText": "CA10Z1__firewallRules__c.delegatedTo(CA10Z1__firewallRules__c).isEmpty()", "runtimeError": null }, "context": { "snapshotTime": "2024-06-13T04:17:29Z" }, "Id": "test9", "CA10Z1__disappearanceTime__c": null, "CA10Z1__firewallRules__c": null, "CA10Z1__deploymentMode__c": "Flexible" }, { "expectedResult":{ "status": "INAPPLICABLE", "conditionIndex": "199", "conditionText": "extract('CA10Z1__deploymentMode__c') != 'Flexible'", "runtimeError": null }, "context":{ "snapshotTime": "2024-06-13T04:17:29Z" }, "Id": "test10", "CA10Z1__disappearanceTime__c": null, "CA10Z1__configurations__c": "[{\"name\":\"require_secure_transport\",\"value\":\"on\"}]", "CA10Z1__deploymentMode__c": "Single" } ] - path: /types/CA10Z1__CaAzurePostgreSqlServer__c/object.extracts.yaml md5Hash: 57EE11B2A1C370B47B2D4FE4AF22C8D0 content: "---\nextracts:\n# Values: Enabled, Disabled. Not Nullable. Can't have\ \ no access, retrieved via Microsoft.DBforPostgreSQL/servers/read\n - name:\ \ \"CA10Z1__sslEnforcement__c\"\n value: \n FIELD:\n path: \"\ CA10Z1__sslEnforcement__c\"\n undeterminedIf:\n isEmpty: \"\ Corrupted Data. PostgreSQL Server SSL Enforcement cannot be empty.\"\n# Values:\ \ Enabled, Disabled. Not Nullable. Can't have no access, retrieved via Microsoft.DBforPostgreSQL/servers/read\n\ \ - name: \"CA10Z1__infrastructureEncryption__c\"\n value: \n FIELD:\n\ \ path: \"CA10Z1__infrastructureEncryption__c\"\n undeterminedIf:\n\ \ isEmpty: \"Corrupted Data. PostgreSQL Server Infrastructure Encryption\ \ cannot be empty.\"\n# Not nullable\n - name: \"CA10Z1__configurations__c\"\ \n value:\n FIELD:\n path: \"CA10Z1__configurations__c\"\n \ \ returnType: BYTES\n undeterminedIf:\n noAccessDelegate:\n\ \ path: \"CA10Z1__configurations__c\"\n currentStateMessage:\ \ \"Unable to determine Server Configurations. Possible permission issue with\ \ Microsoft.DBforPostgreSQL/servers/configurations/read\"\n - name: \"caJsonFrom__configurations__c\"\ \n value: \n JSON_FROM:\n arg: \n EXTRACT: \"CA10Z1__configurations__c\"\ \n undeterminedIf:\n isInvalid: \"Configurations JSON is invalid.\"\ \n - name: \"CA10Z1__firewallRules__c\"\n value: \n FIELD:\n \ \ path: \"CA10Z1__firewallRules__c\"\n returnType: BYTES\n undeterminedIf:\n\ \ noAccessDelegate:\n path: \"CA10Z1__firewallRules__c\"\ \n currentStateMessage: \"Unable to determine Firewall Rules. Possible\ \ permission issue with Microsoft.Sql/servers/firewallRules/read\"\n - name:\ \ \"caJsonFrom__firewallRules__c\"\n value: \n JSON_FROM:\n arg:\ \ \n EXTRACT: \"CA10Z1__firewallRules__c\"\n undeterminedIf:\n\ \ isInvalid: \"Firewall Rules JSON is invalid.\"\n - name: \"CA10Z1__deploymentMode__c\"\ \n value: \n FIELD:\n path: \"CA10Z1__deploymentMode__c\"\n \ \ undeterminedIf:\n isEmpty: \"Corrupted Data. PostgreSQL Deployment\ \ Mode cannot be empty.\"\n# Not nullable \n - name: \"CA10Z1__state__c\"\n\ \ value: \n FIELD:\n path: \"CA10Z1__state__c\"\n# Nullable \n\ \ - name: \"CA10Z1__monitorCpuPercentAvg30Day__c\"\n value: \n FIELD:\n\ \ path: \"CA10Z1__monitorCpuPercentAvg30Day__c\"\n# Nullable \n - name:\ \ \"CA10Z1__monitorMemoryPercentAvg30Day__c\"\n value: \n FIELD:\n \ \ path: \"CA10Z1__monitorMemoryPercentAvg30Day__c\"\n# Nullable \n -\ \ name: \"CA10Z1__monitorIoConsumptionPercentAvg30Day__c\"\n value: \n \ \ FIELD:\n path: \"CA10Z1__monitorIoConsumptionPercentAvg30Day__c\"\ \n - name: \"CA10Z1__locationName__c\"\n value: \n FIELD:\n \ \ path: \"CA10Z1__locationName__c\"\n\n\n" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "test1", "expectedResult" : { "status" : "DISAPPEARED", "conditionIndex" : "99", "conditionText" : "isDisappeared(CA10Z1__disappearanceTime__c)", "runtimeError" : null } }, { "Id" : "test2", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "399", "conditionText" : "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? properties.startIpAddress == \\'0.0.0.0\\' && (properties.endIpAddress == \\'0.0.0.0\\' || properties.endIpAddress == \\'255.255.255.255\\')])') > number(0.0)", "runtimeError" : null } }, { "Id" : "test3", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "299", "conditionText" : "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? starts_with(name, \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])') > number(0.0)", "runtimeError" : null } }, { "Id" : "test4", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "399", "conditionText" : "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? properties.startIpAddress == \\'0.0.0.0\\' && (properties.endIpAddress == \\'0.0.0.0\\' || properties.endIpAddress == \\'255.255.255.255\\')])') > number(0.0)", "runtimeError" : null } }, { "Id" : "test5", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "500", "conditionText" : "otherwise", "runtimeError" : null } }, { "Id" : "test6", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "500", "conditionText" : "otherwise", "runtimeError" : null } }, { "Id" : "test7", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "204", "conditionText" : "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? starts_with(name, \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])').isEvaluationFailed()", "runtimeError" : "TypeError: starts_with() expected argument 1 to be type 2 but received type 7 instead." } }, { "Id" : "test8", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "500", "conditionText" : "otherwise", "runtimeError" : null } }, { "Id" : "test9", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "201", "conditionText" : "CA10Z1__firewallRules__c.delegatedTo(CA10Z1__firewallRules__c).isEmpty()", "runtimeError" : null } }, { "Id" : "test10", "expectedResult" : { "status" : "INAPPLICABLE", "conditionIndex" : "199", "conditionText" : "extract('CA10Z1__deploymentMode__c') != 'Flexible'", "runtimeError" : null } } ]; """; CREATE TEMP FUNCTION mock_CA10Z1__CaAzurePostgreSqlServer__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-06-13T04:17:29Z") }, "CA10Z1__disappearanceTime__c" : new Date("2024-06-07T13:58:24Z"), "CA10Z1__deploymentMode__c" : "Flexible", "CA10Z1__firewallRules__c" : "[{\"properties\":{\"startIpAddress\":\"0.0.0.0\",\"endIpAddress\":\"0.0.0.0\"},\"name\":\"AllowAllAzureServicesAndResourcesWithinAzureIps\"}]", "Id" : "test1" }, { "context" : { "snapshotTime" : new Date("2024-06-13T04:17:29Z") }, "CA10Z1__deploymentMode__c" : "Flexible", "CA10Z1__firewallRules__c" : "[{\"properties\":{\"startIpAddress\":\"0.0.0.0\",\"endIpAddress\":\"0.0.0.0\"},\"name\":\"FirewallRuleName\"}]", "Id" : "test2" }, { "context" : { "snapshotTime" : new Date("2024-06-13T04:17:29Z") }, "CA10Z1__deploymentMode__c" : "Flexible", "CA10Z1__firewallRules__c" : "[{\"properties\":{\"startIpAddress\":\"1.1.1.1\",\"endIpAddress\":\"255.255.255.0\"},\"name\":\"AllowAllAzureServicesAndResourcesWithinAzureIps\"}]", "Id" : "test3" }, { "context" : { "snapshotTime" : new Date("2024-06-13T04:17:29Z") }, "CA10Z1__deploymentMode__c" : "Flexible", "CA10Z1__firewallRules__c" : "[{\"properties\":{\"startIpAddress\":\"0.0.0.0\",\"endIpAddress\":\"255.255.255.255\"},\"name\":\"FirewallRuleName\"}]", "Id" : "test4" }, { "context" : { "snapshotTime" : new Date("2024-06-13T04:17:29Z") }, "CA10Z1__deploymentMode__c" : "Flexible", "CA10Z1__firewallRules__c" : "[{\"properties\":{\"startIpAddress\":\"1.1.1.1\",\"endIpAddress\":\"1.1.1.1\"},\"name\":\"FirewallRuleName\"}]", "Id" : "test5" }, { "context" : { "snapshotTime" : new Date("2024-06-13T04:17:29Z") }, "CA10Z1__deploymentMode__c" : "Flexible", "CA10Z1__firewallRules__c" : "[{\"name\":\"FirewallRuleName\"}]", "Id" : "test6" }, { "context" : { "snapshotTime" : new Date("2024-06-13T04:17:29Z") }, "CA10Z1__deploymentMode__c" : "Flexible", "CA10Z1__firewallRules__c" : "[{\"properties\":{\"startIpAddress\":\"1.1.1.1\",\"endIpAddress\":\"1.1.1.1\"}}]", "Id" : "test7" }, { "context" : { "snapshotTime" : new Date("2024-06-13T04:17:29Z") }, "CA10Z1__deploymentMode__c" : "Flexible", "CA10Z1__firewallRules__c" : "[]", "Id" : "test8" }, { "context" : { "snapshotTime" : new Date("2024-06-13T04:17:29Z") }, "CA10Z1__deploymentMode__c" : "Flexible", "CA10Z1__firewallRules__c" : null, "Id" : "test9" }, { "context" : { "snapshotTime" : new Date("2024-06-13T04:17:29Z") }, "CA10Z1__deploymentMode__c" : "Single", "CA10Z1__firewallRules__c" : null, "Id" : "test10" } ]; """; CREATE TEMP FUNCTION process_CA10Z1__CaAzurePostgreSqlServer__c( obj STRUCT< CA10Z1__disappearanceTime__c TIMESTAMP, CA10Z1__deploymentMode__c STRING, CA10Z1__firewallRules__c STRING, Id STRING >, snapshotTime TIMESTAMP ) RETURNS STRUCT DETERMINISTIC LANGUAGE js OPTIONS (library=['gs://compliance-platform-public/jmespath.min.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 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 Azure [CA10Z1__disappearanceTime__c]: ' + obj.CA10Z1__disappearanceTime__c); if (obj.CA10Z1__disappearanceTime__c != null) { return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10Z1__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.CA10Z1__deploymentMode__c)) { throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10Z1__deploymentMode__c.isEmpty()", currentStateMessage: "Corrupted Data. PostgreSQL Deployment Mode cannot be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10Z1__deploymentMode__c; } function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; }; references1.push('Deployment Mode [obj.CA10Z1__deploymentMode__c]: ' + obj.CA10Z1__deploymentMode__c); try { if (TextLib.notEqual(extract3.call(extract3), 'Flexible')) { return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10Z1__deploymentMode__c') != 'Flexible'", currentStateMessage: "This is not the flexible server deployment mode.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } // condition[2], conditionIndex:[200..299] function comparison5() { var comparisonLeft13 = jsonQueryChecked6(); return comparisonLeft13 != null && 0.0 != null && comparisonLeft13 > 0.0; } function jsonQueryChecked6() { var input = extract8.call(extract8); var out; try { out = jmespath.search(input, 'length([? starts_with(name, \'AllowAllAzureServicesAndResourcesWithinAzureIps\')])'); if (out != null && typeof out != 'number') { throw new Error("UNDETERMINED condition:203", {cause: {status: 'UNDETERMINED', conditionIndex: 203, conditionText: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? starts_with(name, \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return number type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } } catch (e) { throw new Error("UNDETERMINED condition:204", {cause: {status: 'UNDETERMINED', conditionIndex: 204, conditionText: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? starts_with(name, \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}}); } return out; } function jsonChecked9() { var input = extract11.call(extract11); input = TextLib.isEmpty(input) ? null : input; var out; try { out = JSON.parse(input); } catch (e) { throw new Error("UNDETERMINED condition:202", {cause: {status: 'UNDETERMINED', conditionIndex: 202, conditionText: "extract('CA10Z1__firewallRules__c').asJson().isInvalid()", currentStateMessage: "Firewall Rules JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}}); } return out; } function fieldChecked12() { if (BytesLib.isEmpty(obj.CA10Z1__firewallRules__c)) { throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10Z1__firewallRules__c.delegatedTo(CA10Z1__firewallRules__c).isEmpty()", currentStateMessage: "Unable to determine Firewall Rules. Possible permission issue with Microsoft.Sql/servers/firewallRules/read", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10Z1__firewallRules__c; } function extract11() { if (!this.out) { this.out = fieldChecked12(); } return this.out; }; function extract8() { if (!this.out) { this.out = jsonChecked9(); } return this.out; }; references1.push('Firewall Rules [obj.CA10Z1__firewallRules__c]: ' + obj.CA10Z1__firewallRules__c); try { if (comparison5()) { return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? starts_with(name, \\'AllowAllAzureServicesAndResourcesWithinAzureIps\\')])') > number(0.0)", currentStateMessage: "PostgreSQL server firewall rules allow ingress from 0.0.0.0/0 (ANY IP) via the AllowAllWindowsAzureIps rule.", currentStateReferences: references1.join('\n'), remediation: "Remove or disable the overly permissive rule.", runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } // condition[3], conditionIndex:[300..399] function comparison14() { var comparisonLeft22 = jsonQueryChecked15(); return comparisonLeft22 != null && 0.0 != null && comparisonLeft22 > 0.0; } function jsonQueryChecked15() { var input = extract17.call(extract17); var out; try { out = jmespath.search(input, 'length([? properties.startIpAddress == \'0.0.0.0\' && (properties.endIpAddress == \'0.0.0.0\' || properties.endIpAddress == \'255.255.255.255\')])'); if (out != null && typeof out != 'number') { throw new Error("UNDETERMINED condition:303", {cause: {status: 'UNDETERMINED', conditionIndex: 303, conditionText: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? properties.startIpAddress == \\'0.0.0.0\\' && (properties.endIpAddress == \\'0.0.0.0\\' || properties.endIpAddress == \\'255.255.255.255\\')])').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return number type.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } } catch (e) { throw new Error("UNDETERMINED condition:304", {cause: {status: 'UNDETERMINED', conditionIndex: 304, conditionText: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? properties.startIpAddress == \\'0.0.0.0\\' && (properties.endIpAddress == \\'0.0.0.0\\' || properties.endIpAddress == \\'255.255.255.255\\')])').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}}); } return out; } function jsonChecked18() { var input = extract20.call(extract20); input = TextLib.isEmpty(input) ? null : input; var out; try { out = JSON.parse(input); } catch (e) { throw new Error("UNDETERMINED condition:302", {cause: {status: 'UNDETERMINED', conditionIndex: 302, conditionText: "extract('CA10Z1__firewallRules__c').asJson().isInvalid()", currentStateMessage: "Firewall Rules JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}}); } return out; } function fieldChecked21() { if (BytesLib.isEmpty(obj.CA10Z1__firewallRules__c)) { throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "CA10Z1__firewallRules__c.delegatedTo(CA10Z1__firewallRules__c).isEmpty()", currentStateMessage: "Unable to determine Firewall Rules. Possible permission issue with Microsoft.Sql/servers/firewallRules/read", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10Z1__firewallRules__c; } function extract20() { if (!this.out) { this.out = fieldChecked21(); } return this.out; }; function extract17() { if (!this.out) { this.out = jsonChecked18(); } return this.out; }; try { if (comparison14()) { return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "extract('caJsonFrom__firewallRules__c').jsonQueryText('length([? properties.startIpAddress == \\'0.0.0.0\\' && (properties.endIpAddress == \\'0.0.0.0\\' || properties.endIpAddress == \\'255.255.255.255\\')])') > number(0.0)", currentStateMessage: "PostgreSQL server firewall rules allow ingress from 0.0.0.0/0 (ANY IP).", currentStateReferences: references1.join('\n'), remediation: "Remove or disable the overly permissive rule.", runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } // condition[4], conditionIndex:[400..499] function fieldChecked25() { if (BytesLib.isEmpty(obj.CA10Z1__firewallRules__c)) { throw new Error("UNDETERMINED condition:401", {cause: {status: 'UNDETERMINED', conditionIndex: 401, conditionText: "CA10Z1__firewallRules__c.delegatedTo(CA10Z1__firewallRules__c).isEmpty()", currentStateMessage: "Unable to determine Firewall Rules. Possible permission issue with Microsoft.Sql/servers/firewallRules/read", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10Z1__firewallRules__c; } function extract24() { if (!this.out) { this.out = fieldChecked25(); } return this.out; }; try { if (BytesLib.isEmpty(extract24.call(extract24))) { return {status: 'COMPLIANT', conditionIndex: 499, conditionText: "extract('CA10Z1__firewallRules__c').isEmpty()", currentStateMessage: "PostgreSQL server firewall rules are not defined.", 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: 500, conditionText: "otherwise", currentStateMessage: "PostgreSQL server firewall rules do not allow ingress from 0.0.0.0/0 (ANY IP).", 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.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c, sObject.CA10Z1__deploymentMode__c AS CA10Z1__deploymentMode__c, sObject.CA10Z1__firewallRules__c AS CA10Z1__firewallRules__c, sObject.Id AS Id, process_CA10Z1__CaAzurePostgreSqlServer__c( STRUCT( sObject.CA10Z1__disappearanceTime__c AS CA10Z1__disappearanceTime__c, sObject.CA10Z1__deploymentMode__c AS CA10Z1__deploymentMode__c, sObject.CA10Z1__firewallRules__c AS CA10Z1__firewallRules__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10Z1__CaAzurePostgreSqlServer__c()) AS sObject ) sObject ON sObject.Id = expectedResult.Id;