--- policy: /ce/ca/aws/s3/bucket-lifecycle-configuration logic: /ce/ca/aws/s3/bucket-lifecycle-configuration/prod.logic.yaml executionTime: 2026-06-06T12:03:22.90149465Z generationMs: 47 executionMs: 1174 rows: - id: test1 match: true status: expected: DISAPPEARED actual: DISAPPEARED conditionIndex: expected: 99 actual: 99 conditionText: expected: isDisappeared(CA10__disappearanceTime__c) actual: isDisappeared(CA10__disappearanceTime__c) runtimeError: {} - id: test2 match: true status: expected: INAPPLICABLE actual: INAPPLICABLE conditionIndex: expected: 199 actual: 199 conditionText: expected: extract('CA10__versioningMfaDeleteEnabled__c') == true actual: extract('CA10__versioningMfaDeleteEnabled__c') == true runtimeError: {} - id: test3 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 399 actual: 399 conditionText: expected: not(extract('caJsonBoolean__lifecycleRulesJsonStatusEnabled__c')) actual: not(extract('caJsonBoolean__lifecycleRulesJsonStatusEnabled__c')) runtimeError: {} - id: test4 match: true status: expected: COMPLIANT actual: COMPLIANT conditionIndex: expected: 499 actual: 499 conditionText: expected: extract('caJsonBoolean__lifecycleRulesJsonStatusEnabled__c') actual: extract('caJsonBoolean__lifecycleRulesJsonStatusEnabled__c') runtimeError: {} - id: test5 match: true status: expected: INCOMPLIANT actual: INCOMPLIANT conditionIndex: expected: 299 actual: 299 conditionText: expected: extract('CA10__lifecycleRulesJson__c').isEmpty() actual: extract('CA10__lifecycleRulesJson__c').isEmpty() runtimeError: {} - id: test6 match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 101 actual: 101 conditionText: expected: CA10__versioningMfaDeleteEnabled__c.delegatedTo(CA10__versioningStatus__c).isEmpty() actual: CA10__versioningMfaDeleteEnabled__c.delegatedTo(CA10__versioningStatus__c).isEmpty() runtimeError: {} - id: test7 match: true status: expected: UNDETERMINED actual: UNDETERMINED conditionIndex: expected: 301 actual: 301 conditionText: expected: extract('CA10__lifecycleRulesJson__c').asJson().isInvalid() actual: extract('CA10__lifecycleRulesJson__c').asJson().isInvalid() runtimeError: expected: "Expected property name or '}' in JSON at position 2 (line 1 column\ \ 3)" actual: "Expected property name or '}' in JSON at position 2 (line 1 column\ \ 3)" usedFiles: - path: /ce/ca/aws/s3/bucket-lifecycle-configuration/policy.yaml md5Hash: 3513D2444E5F4DEA5EA05F8CEA634A9F content: | --- names: contextual: "Bucket Lifecycle Configuration is not enabled" full: "AWS S3 Bucket Lifecycle Configuration is not enabled" description: "Configure Amazon S3 Lifecycle in order to ensure that your objects\ \ are stored cost effectively throughout their lifecycle. An S3 Lifecycle configuration\ \ is a set of rules that define actions (such as Transition and Expiration actions)\ \ that Amazon S3 applies to a group of objects." type: "COMPLIANCE_POLICY" categories: - "COST" - "RELIABILITY" frameworkMappings: - "/frameworks/cloudaware/cost-efficiency-and-optimization/resource-optimization" - "/frameworks/aws-fsbp-v1.0.0/s3/13" - "/frameworks/aws-well-architected/sus/04/03" - "/frameworks/cloudaware/resource-reliability/system-configuration" similarPolicies: internal: - dec-x-edc86d3d cloudConformity: - url: https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/S3/lifecycle-configuration.html name: S3 Buckets Lifecycle Configuration awsTrustedAdvisor: - checkId: "c18d2gz100" name: "Amazon S3 Bucket Lifecycle Policy Configured" url: "https://docs.aws.amazon.com/awssupport/latest/user/cost-optimization-checks.html#amazon-s3-bucket-lifecycle-policy-configured" - path: /ce/ca/aws/s3/bucket-lifecycle-configuration/prod.logic.yaml md5Hash: 0B5BDC43FBB189EF12C9F0E5150CDF6B content: "---\n# This policy is based on ce:ca:aws:s3:enable-bucket-lifecycle-configuration.\n\ # We're able to determine if the Lifecycle configuration is enabled on a bucket\ \ \n# using the CA10__lifecycleRulesJson__c field.\n# Lifecycle configuration\ \ is not supported for MFA-enabled buckets and directory buckets.\ninputType:\ \ \"CA10__CaAwsBucket__c\"\ntestData:\n - file: \"test-data.json\"\nimportExtracts:\n\ \ - file: \"/types/CA10__CaAwsBucket__c/object.extracts.yaml\"\nconditions:\n\ \ # Lifecycle configuration on multi-factor authentication (MFA)-enabled buckets\ \ is not supported. \n # https://docs.aws.amazon.com/AmazonS3/latest/userguide/lifecycle-and-other-bucket-config.html#lifecycle-general-considerations-mfa-enabled-bucket\n\ \ - status: \"INAPPLICABLE\"\n currentStateMessage: \"Lifecycle configuration\ \ on multi-factor authentication (MFA)-enabled buckets is not supported.\"\n\ \ check:\n IS_EQUAL:\n left: \n EXTRACT: \"CA10__versioningMfaDeleteEnabled__c\"\ \n right: \n BOOLEAN: true\n - status: \"INCOMPLIANT\"\n \ \ currentStateMessage: \"The bucket does not have a lifecycle configuration.\"\ \n remediationMessage: \"Create an S3 lifecycle configuration for the bucket.\"\ \n check:\n IS_EMPTY:\n arg:\n EXTRACT: \"CA10__lifecycleRulesJson__c\"\ \n - status: \"INCOMPLIANT\"\n currentStateMessage: \"Bucket lifecycle configuration\ \ rules are disabled.\"\n remediationMessage: \"Enable or adding active rules\ \ to the bucket lifecycle configuration.\"\n check:\n NOT:\n \ \ arg:\n EXTRACT: \"caJsonBoolean__lifecycleRulesJsonStatusEnabled__c\"\ \n - status: \"COMPLIANT\"\n currentStateMessage: \"The bucket lifecycle\ \ configuration is enabled.\"\n check:\n EXTRACT: \"caJsonBoolean__lifecycleRulesJsonStatusEnabled__c\"\ \notherwise:\n status: \"UNDETERMINED\"\n currentStateMessage: \"Unexpected\ \ values in the fields.\"\n" - path: /ce/ca/aws/s3/bucket-lifecycle-configuration/test-data.json md5Hash: D33B968D1A1563E5B087347AE8A1B629 content: |- [ { "expectedResult": { "status": "DISAPPEARED", "conditionIndex": "99", "conditionText": "isDisappeared(CA10__disappearanceTime__c)", "runtimeError": null }, "context": { "snapshotTime": "2024-05-25T00:00:00Z" }, "Id": "test1", "CA10__disappearanceTime__c": "2024-05-06T19:25:32Z", "CA10__versioningMfaDeleteEnabled__c": false, "CA10__versioningStatus__c": "", "CA10__lifecycleRulesJson__c": "" }, { "expectedResult": { "status": "INAPPLICABLE", "conditionIndex": "199", "conditionText": "extract('CA10__versioningMfaDeleteEnabled__c') == true", "runtimeError": null }, "context": { "snapshotTime": "2024-05-25T00:00:00Z" }, "Id": "test2", "CA10__disappearanceTime__c": null, "CA10__versioningMfaDeleteEnabled__c": true, "CA10__versioningStatus__c": "Enabled", "CA10__lifecycleRulesJson__c": "" }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "399", "conditionText": "not(extract('caJsonBoolean__lifecycleRulesJsonStatusEnabled__c'))", "runtimeError": null }, "context": { "snapshotTime": "2024-05-25T00:00:00Z" }, "Id": "test3", "CA10__disappearanceTime__c": null, "CA10__versioningMfaDeleteEnabled__c": false, "CA10__versioningStatus__c": "Enabled", "CA10__lifecycleRulesJson__c": "[{\"id\":\"default\",\"status\":\"Disabled\",\"filter\":{\"predicate\":{\"prefix\":\"\"}},\"expirationInDays\":365,\"expiredObjectDeleteMarker\":false,\"noncurrentVersionExpirationInDays\":365,\"transition\":{\"storageClass\":\"StandardInfrequentAccess\",\"storageClassAsString\":\"STANDARD_IA\",\"days\":30},\"transitions\":[{\"storageClass\":\"StandardInfrequentAccess\",\"storageClassAsString\":\"STANDARD_IA\",\"days\":30}]}]" }, { "expectedResult": { "status": "COMPLIANT", "conditionIndex": "499", "conditionText": "extract('caJsonBoolean__lifecycleRulesJsonStatusEnabled__c')", "runtimeError": null }, "context": { "snapshotTime": "2024-05-25T00:00:00Z" }, "Id": "test4", "CA10__disappearanceTime__c": null, "CA10__versioningMfaDeleteEnabled__c": false, "CA10__versioningStatus__c": "Enabled", "CA10__lifecycleRulesJson__c": "[{\"id\":\"default\",\"status\":\"Enabled\",\"filter\":{\"predicate\":{\"prefix\":\"\"}},\"expirationInDays\":365,\"expiredObjectDeleteMarker\":false,\"noncurrentVersionExpirationInDays\":365,\"transition\":{\"storageClass\":\"StandardInfrequentAccess\",\"storageClassAsString\":\"STANDARD_IA\",\"days\":30},\"transitions\":[{\"storageClass\":\"StandardInfrequentAccess\",\"storageClassAsString\":\"STANDARD_IA\",\"days\":30}]}]" }, { "expectedResult": { "status": "INCOMPLIANT", "conditionIndex": "299", "conditionText": "extract('CA10__lifecycleRulesJson__c').isEmpty()", "runtimeError": null }, "context": { "snapshotTime": "2024-05-25T00:00:00Z" }, "Id": "test5", "CA10__disappearanceTime__c": null, "CA10__versioningMfaDeleteEnabled__c": false, "CA10__versioningStatus__c": "Enabled", "CA10__lifecycleRulesJson__c": "" }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "101", "conditionText": "CA10__versioningMfaDeleteEnabled__c.delegatedTo(CA10__versioningStatus__c).isEmpty()", "runtimeError": null }, "context": { "snapshotTime": "2024-05-25T00:00:00Z" }, "Id": "test6", "CA10__disappearanceTime__c": null, "CA10__versioningMfaDeleteEnabled__c": false, "CA10__versioningStatus__c": null, "CA10__lifecycleRulesJson__c": "" }, { "expectedResult": { "status": "UNDETERMINED", "conditionIndex": "301", "conditionText": "extract('CA10__lifecycleRulesJson__c').asJson().isInvalid()", "runtimeError": "Expected property name or '}' in JSON at position 2 (line 1 column 3)" }, "context": { "snapshotTime": "2024-05-25T00:00:00Z" }, "Id": "test7", "CA10__disappearanceTime__c": null, "CA10__versioningMfaDeleteEnabled__c": false, "CA10__versioningStatus__c": "Enabled", "CA10__lifecycleRulesJson__c": "[{]" } ] - path: /types/CA10__CaAwsBucket__c/object.extracts.yaml md5Hash: F56AFA293B0B19D4F39C1EBB70F4C56F content: "---\nextracts:\n# Values: yes, no. Not Nullable.\n - name: \"CA10__objectLockEnabled__c\"\ \n value: \n FIELD:\n path: \"CA10__objectLockEnabled__c\"\n\ \ undeterminedIf:\n noAccessDelegate:\n path: \"\ CA10__objectLockEnabled__c\"\n currentStateMessage: \"Unable to determine\ \ Object Lock status. Possible permission issue with s3:GetObjectLockConfiguration\"\ \n isEmpty: \"Object Lock status is not populated yet\"\n# Nullable.\n\ \ - name: \"CA10__lifecycleRulesJson__c\"\n value: \n FIELD:\n \ \ path: \"CA10__lifecycleRulesJson__c\"\n returnType: BYTES\n \ \ # undeterminedIf:\n # noAccessDelegate:\n # path: \"\ CA10__lifecycleRulesJson__c\"\n # currentStateMessage: \"Unable to\ \ determine Lifecycle Configuration. Possible permission issue with s3:GetLifecycleConfiguration\"\ \n# Values: enabled, suspended, off. Not Nullable.\n - name: \"CA10__versioningStatus__c\"\ \n value: \n FIELD:\n path: \"CA10__versioningStatus__c\"\n \ \ undeterminedIf:\n noAccessDelegate:\n path: \"CA10__versioningStatus__c\"\ \n currentStateMessage: \"Unable to determine versioning status.\ \ Possible permission issue with s3:GetBucketVersioning\"\n isEmpty:\ \ \"Status is not populated yet\"\n# Checkbox.\n - name: \"CA10__versioningMfaDeleteEnabled__c\"\ \n value: \n FIELD:\n path: \"CA10__versioningMfaDeleteEnabled__c\"\ \n undeterminedIf:\n noAccessDelegate:\n path: \"\ CA10__versioningStatus__c\"\n currentStateMessage: \"Unable to determine\ \ versioning status. Possible permission issue with s3:GetBucketVersioning\"\ \n# The field can be empty if server access logging is not enabled\n - name:\ \ \"CA10__loggingDestinationBucketName__c\"\n value: \n FIELD:\n \ \ path: \"CA10__loggingDestinationBucketName__c\"\n # undeterminedIf:\n\ \ # noAccessDelegate:\n # path: \"CA10__loggingDestinationBucketName__c\"\ \n # currentStateMessage: \"Unable to determine if server access\ \ logging is enabled. Possible permission issue with s3:GetBucketLogging\"\n\ # Cloudaware derives this field from CA10__loggingDestinationBucketName__c\n\ \ - name: \"CA10__loggingDestinationBucketArn__c\"\n value: \n FIELD:\n\ \ path: \"CA10__loggingDestinationBucketArn__c\"\n undeterminedIf:\n\ \ noAccessDelegate:\n path: \"CA10__loggingDestinationBucketName__c\"\ \n currentStateMessage: \"Unable to determine if server access logging\ \ is enabled. Possible permission issue with s3:GetBucketLogging\"\n# This is\ \ a look up on CA10__CaAwsBucket__c derived from CA10__loggingDestinationBucketName__c\n\ \ - name: \"CA10__loggingDestinationBucket__c\"\n value: \n FIELD:\n\ \ path: \"CA10__loggingDestinationBucket__c\"\n undeterminedIf:\n\ \ noAccessDelegate:\n path: \"CA10__loggingDestinationBucketName__c\"\ \n currentStateMessage: \"Unable to determine if server access logging\ \ is enabled. Possible permission issue with s3:GetBucketLogging\"\n - name:\ \ \"CA10__arn__c\"\n value: \n FIELD:\n path: \"CA10__arn__c\"\ \n undeterminedIf:\n isEmpty: \"Bucket ARN cannot be empty.\ \ Potential data corruption\"\n - name: \"caJsonFrom__lifecycleRulesJson__c\"\ \n value: \n JSON_FROM:\n arg: \n EXTRACT: \"CA10__lifecycleRulesJson__c\"\ \n undeterminedIf:\n isInvalid: \"S3 Bucket Lifecycle Rules\ \ JSON is invalid.\"\n# Returns BOOLEAN true if number of enabled lifecycle\ \ rules more than 0 otherwise returns false\n - name: \"caJsonBoolean__lifecycleRulesJsonStatusEnabled__c\"\ \n value: \n JSON_QUERY_BOOLEAN:\n arg: \n EXTRACT:\ \ \"caJsonFrom__lifecycleRulesJson__c\"\n expression: \"length([?status=='Enabled'])\ \ > `0`\"\n undeterminedIf: \n evaluationError: \"The JSON query\ \ has failed.\"\n resultTypeMismatch: \"The JSON query did not return\ \ a boolean.\"\n - name: \"CA10__blockPublicAcls__c\"\n value: \n FIELD:\n\ \ path: \"CA10__blockPublicAcls__c\"\n undeterminedIf:\n \ \ noAccessDelegate:\n path: \"CA10__blockPublicAcls__c\"\n \ \ currentStateMessage: \"Unable to determine the bucket policy. Possible\ \ permission issue with s3:GetBucketPublicAccessBlock\"\n - name: \"CA10__blockPublicPolicy__c\"\ \n value: \n FIELD:\n path: \"CA10__blockPublicPolicy__c\"\n\ \ undeterminedIf:\n noAccessDelegate:\n path: \"\ CA10__blockPublicPolicy__c\"\n currentStateMessage: \"Unable to determine\ \ the bucket policy. Possible permission issue with s3:GetBucketPublicAccessBlock\"\ \n - name: \"CA10__ignorePublicAcls__c\"\n value: \n FIELD:\n \ \ path: \"CA10__ignorePublicAcls__c\"\n undeterminedIf:\n \ \ noAccessDelegate:\n path: \"CA10__ignorePublicAcls__c\"\n \ \ currentStateMessage: \"Unable to determine the bucket policy. Possible\ \ permission issue with s3:GetBucketPublicAccessBlock\"\n - name: \"CA10__restrictPublicBuckets__c\"\ \n value: \n FIELD:\n path: \"CA10__restrictPublicBuckets__c\"\ \n undeterminedIf:\n noAccessDelegate:\n path: \"\ CA10__restrictPublicBuckets__c\"\n currentStateMessage: \"Unable\ \ to determine the bucket policy. Possible permission issue with s3:GetBucketPublicAccessBlock\"\ \n# Nullable.\n - name: \"CA10__policyDocument__c\"\n value: \n FIELD:\n\ \ path: \"CA10__policyDocument__c\"\n returnType: BYTES\n \ \ # undeterminedIf:\n # noAccessDelegate:\n # path: \"\ CA10__policyDocument__c\"\n # currentStateMessage: \"Unable to determine\ \ the bucket policy. Possible permission issue with s3:GetBucketPolicy\"\n \ \ - name: \"caJsonFrom__policyDocument__c\"\n value: \n JSON_FROM:\n\ \ arg: \n EXTRACT: \"CA10__policyDocument__c\"\n undeterminedIf:\n\ \ isInvalid: \"S3 Bucket Policy Document JSON is invalid.\"\n# Nullable.\n\ \ - name: \"CA10__intelligentTieringConfigurationsJson__c\"\n value: \n\ \ FIELD:\n path: \"CA10__intelligentTieringConfigurationsJson__c\"\ \n returnType: BYTES\n - name: \"caJsonFrom__intelligentTieringConfigurationsJson__c\"\ \n value: \n JSON_FROM:\n arg: \n EXTRACT: \"CA10__intelligentTieringConfigurationsJson__c\"\ \n undeterminedIf:\n isInvalid: \"S3 Bucket Policy Document\ \ JSON is invalid.\"\n# Nullable.\n - name: \"CA10__regionName__c\"\n value:\n\ \ FIELD:\n path: \"CA10__regionName__c\"\n# Nullable.\n - name:\ \ \"CA10__intelligentTieringStorageGb__c\"\n value:\n FIELD:\n \ \ path: \"CA10__intelligentTieringStorageGb__c\"\n# Values: AES256 | aws:fsx\ \ | aws:kms | aws:kms:dsse | None. Not Nullable.\n - name: \"CA10__serverSideEncryptionAlgorithm__c\"\ \n value:\n FIELD:\n path: \"CA10__serverSideEncryptionAlgorithm__c\"\ \n undeterminedIf:\n noAccessDelegate:\n path: \"\ CA10__serverSideEncryptionAlgorithm__c\"\n currentStateMessage: \"\ Unable to determine Bucket Encryption Algorithm. Possible permissions issue\ \ with s3:GetEncryptionConfiguration\"\n - name: \"CA10__accessControlPolicy__c\"\ \n value: \n FIELD:\n path: \"CA10__accessControlPolicy__c\"\n\ \ undeterminedIf:\n noAccessDelegate:\n path: \"\ CA10__accessControlPolicy__c\"\n currentStateMessage: \"Unable to\ \ determine the bucket ACL. Possible permission issue with s3:GetBucketAcl\"\ \n - name: \"caJsonFrom__accessControlPolicy__c\"\n value: \n JSON_FROM:\n\ \ arg:\n EXTRACT: \"CA10__accessControlPolicy__c\"\n \ \ undeterminedIf:\n isInvalid: \"The Access Control Policy JSON is\ \ invalid.\"\n - name: \"CA10__accessControlGrants__c\"\n value: \n \ \ FIELD:\n path: \"CA10__accessControlGrants__c\"\n undeterminedIf:\n\ \ noAccessDelegate:\n path: \"CA10__accessControlGrants__c\"\ \n currentStateMessage: \"Unable to determine the bucket ACL. Possible\ \ permission issue with s3:GetBucketAcl\"\n - name: \"CA10__policyIsPublic__c\"\ \n value: \n FIELD:\n path: \"CA10__policyIsPublic__c\"\n \ \ undeterminedIf:\n noAccessDelegate:\n path: \"CA10__policyIsPublic__c\"\ \n currentStateMessage: \"Unable to determine the bucket policy status.\ \ Possible permission issue with s3:GetBucketPolicyStatus\"\n" script: |- CREATE TEMP FUNCTION mock_ExpectedResult() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "Id" : "test1", "expectedResult" : { "status" : "DISAPPEARED", "conditionIndex" : "99", "conditionText" : "isDisappeared(CA10__disappearanceTime__c)", "runtimeError" : null } }, { "Id" : "test2", "expectedResult" : { "status" : "INAPPLICABLE", "conditionIndex" : "199", "conditionText" : "extract('CA10__versioningMfaDeleteEnabled__c') == true", "runtimeError" : null } }, { "Id" : "test3", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "399", "conditionText" : "not(extract('caJsonBoolean__lifecycleRulesJsonStatusEnabled__c'))", "runtimeError" : null } }, { "Id" : "test4", "expectedResult" : { "status" : "COMPLIANT", "conditionIndex" : "499", "conditionText" : "extract('caJsonBoolean__lifecycleRulesJsonStatusEnabled__c')", "runtimeError" : null } }, { "Id" : "test5", "expectedResult" : { "status" : "INCOMPLIANT", "conditionIndex" : "299", "conditionText" : "extract('CA10__lifecycleRulesJson__c').isEmpty()", "runtimeError" : null } }, { "Id" : "test6", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "101", "conditionText" : "CA10__versioningMfaDeleteEnabled__c.delegatedTo(CA10__versioningStatus__c).isEmpty()", "runtimeError" : null } }, { "Id" : "test7", "expectedResult" : { "status" : "UNDETERMINED", "conditionIndex" : "301", "conditionText" : "extract('CA10__lifecycleRulesJson__c').asJson().isInvalid()", "runtimeError" : "Expected property name or '}' in JSON at position 2 (line 1 column 3)" } } ]; """; CREATE TEMP FUNCTION mock_CA10__CaAwsBucket__c() RETURNS ARRAY >> DETERMINISTIC LANGUAGE js AS r""" return [ { "context" : { "snapshotTime" : new Date("2024-05-25T00:00:00Z") }, "CA10__disappearanceTime__c" : new Date("2024-05-06T19:25:32Z"), "CA10__versioningMfaDeleteEnabled__c" : false, "CA10__versioningStatus__c" : "", "CA10__lifecycleRulesJson__c" : "", "Id" : "test1" }, { "context" : { "snapshotTime" : new Date("2024-05-25T00:00:00Z") }, "CA10__versioningMfaDeleteEnabled__c" : true, "CA10__versioningStatus__c" : "Enabled", "CA10__lifecycleRulesJson__c" : "", "Id" : "test2" }, { "context" : { "snapshotTime" : new Date("2024-05-25T00:00:00Z") }, "CA10__versioningMfaDeleteEnabled__c" : false, "CA10__versioningStatus__c" : "Enabled", "CA10__lifecycleRulesJson__c" : "[{\"id\":\"default\",\"status\":\"Disabled\",\"filter\":{\"predicate\":{\"prefix\":\"\"}},\"expirationInDays\":365,\"expiredObjectDeleteMarker\":false,\"noncurrentVersionExpirationInDays\":365,\"transition\":{\"storageClass\":\"StandardInfrequentAccess\",\"storageClassAsString\":\"STANDARD_IA\",\"days\":30},\"transitions\":[{\"storageClass\":\"StandardInfrequentAccess\",\"storageClassAsString\":\"STANDARD_IA\",\"days\":30}]}]", "Id" : "test3" }, { "context" : { "snapshotTime" : new Date("2024-05-25T00:00:00Z") }, "CA10__versioningMfaDeleteEnabled__c" : false, "CA10__versioningStatus__c" : "Enabled", "CA10__lifecycleRulesJson__c" : "[{\"id\":\"default\",\"status\":\"Enabled\",\"filter\":{\"predicate\":{\"prefix\":\"\"}},\"expirationInDays\":365,\"expiredObjectDeleteMarker\":false,\"noncurrentVersionExpirationInDays\":365,\"transition\":{\"storageClass\":\"StandardInfrequentAccess\",\"storageClassAsString\":\"STANDARD_IA\",\"days\":30},\"transitions\":[{\"storageClass\":\"StandardInfrequentAccess\",\"storageClassAsString\":\"STANDARD_IA\",\"days\":30}]}]", "Id" : "test4" }, { "context" : { "snapshotTime" : new Date("2024-05-25T00:00:00Z") }, "CA10__versioningMfaDeleteEnabled__c" : false, "CA10__versioningStatus__c" : "Enabled", "CA10__lifecycleRulesJson__c" : "", "Id" : "test5" }, { "context" : { "snapshotTime" : new Date("2024-05-25T00:00:00Z") }, "CA10__versioningMfaDeleteEnabled__c" : false, "CA10__versioningStatus__c" : null, "CA10__lifecycleRulesJson__c" : "", "Id" : "test6" }, { "context" : { "snapshotTime" : new Date("2024-05-25T00:00:00Z") }, "CA10__versioningMfaDeleteEnabled__c" : false, "CA10__versioningStatus__c" : "Enabled", "CA10__lifecycleRulesJson__c" : "[{]", "Id" : "test7" } ]; """; CREATE TEMP FUNCTION process_CA10__CaAwsBucket__c( obj STRUCT< CA10__disappearanceTime__c TIMESTAMP, CA10__versioningMfaDeleteEnabled__c BOOLEAN, CA10__versioningStatus__c STRING, CA10__lifecycleRulesJson__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 AWS [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__versioningStatus__c)) { throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__versioningMfaDeleteEnabled__c.delegatedTo(CA10__versioningStatus__c).isEmpty()", currentStateMessage: "Unable to determine versioning status. Possible permission issue with s3:GetBucketVersioning", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } return obj.CA10__versioningMfaDeleteEnabled__c; } function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; }; references1.push('Versioning MFA Delete Enabled [obj.CA10__versioningMfaDeleteEnabled__c]: ' + obj.CA10__versioningMfaDeleteEnabled__c); try { if (extract3.call(extract3) == true) { return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__versioningMfaDeleteEnabled__c') == true", currentStateMessage: "Lifecycle configuration on multi-factor authentication (MFA)-enabled buckets is not supported.", 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 extract6() { if (!this.out) { this.out = obj.CA10__lifecycleRulesJson__c; } return this.out; }; references1.push('Lifecycle Rules JSON [obj.CA10__lifecycleRulesJson__c]: ' + obj.CA10__lifecycleRulesJson__c); if (BytesLib.isEmpty(extract6.call(extract6))) { return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__lifecycleRulesJson__c').isEmpty()", currentStateMessage: "The bucket does not have a lifecycle configuration.", currentStateReferences: references1.join('\n'), remediation: "Create an S3 lifecycle configuration for the bucket.", runtimeError: null}; } // condition[3], conditionIndex:[300..399] function jsonQueryChecked10() { var input = extract12.call(extract12); var out; try { out = jmespath.search(input, 'length([?status==\'Enabled\']) > `0`'); if (out != null && typeof out != 'boolean') { throw new Error("UNDETERMINED condition:302", {cause: {status: 'UNDETERMINED', conditionIndex: 302, conditionText: "extract('caJsonFrom__lifecycleRulesJson__c').jsonQueryText('length([?status==\\'Enabled\\']) > `0`').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return a boolean.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } } catch (e) { throw new Error("UNDETERMINED condition:303", {cause: {status: 'UNDETERMINED', conditionIndex: 303, conditionText: "extract('caJsonFrom__lifecycleRulesJson__c').jsonQueryText('length([?status==\\'Enabled\\']) > `0`').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}}); } return out; } function jsonChecked13() { var input = extract15.call(extract15); input = TextLib.isEmpty(input) ? null : input; var out; try { out = JSON.parse(input); } catch (e) { throw new Error("UNDETERMINED condition:301", {cause: {status: 'UNDETERMINED', conditionIndex: 301, conditionText: "extract('CA10__lifecycleRulesJson__c').asJson().isInvalid()", currentStateMessage: "S3 Bucket Lifecycle Rules JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}}); } return out; } function extract15() { if (!this.out) { this.out = obj.CA10__lifecycleRulesJson__c; } return this.out; }; function extract12() { if (!this.out) { this.out = jsonChecked13(); } return this.out; }; function extract9() { if (!this.out) { this.out = jsonQueryChecked10(); } return this.out; }; try { if (!extract9.call(extract9)) { return {status: 'INCOMPLIANT', conditionIndex: 399, conditionText: "not(extract('caJsonBoolean__lifecycleRulesJsonStatusEnabled__c'))", currentStateMessage: "Bucket lifecycle configuration rules are disabled.", currentStateReferences: references1.join('\n'), remediation: "Enable or adding active rules to the bucket lifecycle configuration.", runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } // condition[4], conditionIndex:[400..499] function jsonQueryChecked19() { var input = extract21.call(extract21); var out; try { out = jmespath.search(input, 'length([?status==\'Enabled\']) > `0`'); if (out != null && typeof out != 'boolean') { throw new Error("UNDETERMINED condition:402", {cause: {status: 'UNDETERMINED', conditionIndex: 402, conditionText: "extract('caJsonFrom__lifecycleRulesJson__c').jsonQueryText('length([?status==\\'Enabled\\']) > `0`').isResultTypeMismatch()", currentStateMessage: "The JSON query did not return a boolean.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}}); } } catch (e) { throw new Error("UNDETERMINED condition:403", {cause: {status: 'UNDETERMINED', conditionIndex: 403, conditionText: "extract('caJsonFrom__lifecycleRulesJson__c').jsonQueryText('length([?status==\\'Enabled\\']) > `0`').isEvaluationFailed()", currentStateMessage: "The JSON query has failed.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}}); } return out; } function jsonChecked22() { var input = extract24.call(extract24); input = TextLib.isEmpty(input) ? null : input; var out; try { out = JSON.parse(input); } catch (e) { throw new Error("UNDETERMINED condition:401", {cause: {status: 'UNDETERMINED', conditionIndex: 401, conditionText: "extract('CA10__lifecycleRulesJson__c').asJson().isInvalid()", currentStateMessage: "S3 Bucket Lifecycle Rules JSON is invalid.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: e.message}}); } return out; } function extract24() { if (!this.out) { this.out = obj.CA10__lifecycleRulesJson__c; } return this.out; }; function extract21() { if (!this.out) { this.out = jsonChecked22(); } return this.out; }; function extract18() { if (!this.out) { this.out = jsonQueryChecked19(); } return this.out; }; try { if (extract18.call(extract18)) { return {status: 'COMPLIANT', conditionIndex: 499, conditionText: "extract('caJsonBoolean__lifecycleRulesJsonStatusEnabled__c')", currentStateMessage: "The bucket lifecycle configuration is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}; } } catch (err) { if (err.cause && err.cause.status) { return err.cause; } else { throw err; } } return {status: 'UNDETERMINED', conditionIndex: 500, conditionText: "otherwise", currentStateMessage: "Unexpected values in the fields.", 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__versioningMfaDeleteEnabled__c AS CA10__versioningMfaDeleteEnabled__c, sObject.CA10__versioningStatus__c AS CA10__versioningStatus__c, sObject.CA10__lifecycleRulesJson__c AS CA10__lifecycleRulesJson__c, sObject.Id AS Id, process_CA10__CaAwsBucket__c( STRUCT( sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c, sObject.CA10__versioningMfaDeleteEnabled__c AS CA10__versioningMfaDeleteEnabled__c, sObject.CA10__versioningStatus__c AS CA10__versioningStatus__c, sObject.CA10__lifecycleRulesJson__c AS CA10__lifecycleRulesJson__c, sObject.Id AS Id ), sObject.context.snapshotTime ) as result FROM UNNEST(mock_CA10__CaAwsBucket__c()) AS sObject ) sObject ON sObject.Id = expectedResult.Id;