---
policy: /ce/ca/aws/ec2/image-public
logic: /ce/ca/aws/ec2/image-public/prod.logic.yaml
executionTime: 2025-12-27T12:01:48.216197955Z
generationMs: 65
executionMs: 607
rows:
  - id: '001'
    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: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__public__c') == true
      actual: extract('CA10__public__c') == true
    runtimeError: {}
  - id: '004'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__public__c') == false
      actual: extract('CA10__public__c') == false
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/ec2/image-public/policy.yaml
    md5Hash: 855AC06F7DDB8C6158B16148D4C1EFEF
    content: "---\nnames:\n  full: \"AWS EC2 Image is publicly accessible\"\n  contextual:\
      \ \"EC2 Image is publicly accessible\"\ndescription: >\n  Ensure that your AWS\
      \ AMIs are not publicly shared with the other \n  AWS accounts. Public AMIs\
      \ are available to all AWS accounts, which creates a \n  significant risk of\
      \ exposing sensitive data, intellectual property, or credentials \n  stored\
      \ within the image.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\
      \nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/public-and-anonymous-access\"\
      \n  - \"/frameworks/aws-well-architected/sec/03/07\"\nsimilarPolicies:\n   \
      \ cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/EC2/publicly-shared-ami.html\"\
      \n      name: Publicly Shared AMI"
  - path: /ce/ca/aws/ec2/image-public/prod.logic.yaml
    md5Hash: 5B2D9553A4973C91D039C2BE0DAAB4ED
    content: |-
      inputType: "CA10__CaAwsImage__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: /types/CA10__CaAwsImage__c/object.extracts.yaml
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The EC2 Image is publicly accessible."
          remediationMessage: "Consider restricting the image access to private or sharing only with specific AWS accounts."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__public__c"
              right:
                BOOLEAN: true
        - status: "COMPLIANT"
          currentStateMessage: "The EC2 Image is not publicly accessible."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__public__c"
              right:
                BOOLEAN: false
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected values in the field."
  - path: /ce/ca/aws/ec2/image-public/test-data.json
    md5Hash: BE5ACA9A6D53615EF42A6649C1ADA03A
    content: |
      [
        {
          "expectedResult": {
            "status": "DISAPPEARED",
            "conditionIndex": "99",
            "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-03T09:28:25Z" },
          "CA10__disappearanceTime__c": "2025-11-24T12:43:45Z",
          "CA10__public__c": false,
          "Id": "001"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10__public__c') == true",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-03T09:28:25Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__public__c": true,
          "Id": "003"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__public__c') == false",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-03T09:28:25Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__public__c": false,
          "Id": "004"
        }
      ]
  - path: /types/CA10__CaAwsImage__c/object.extracts.yaml
    md5Hash: C8CCEBD443D124E5F81FD189F4E6E404
    content: "---\nextracts:\n# Nulable. Boolean. Values: true, false.\n  - name:\
      \ \"CA10__public__c\"\n    value: \n      FIELD:\n        path: \"CA10__public__c\"\
      \n# Values: pending | available | invalid | deregistered | transient | failed\
      \ | error | disabled. \n# Not nullable\n  - name: \"CA10__state__c\"\n    value:\
      \ \n      FIELD:\n        path: \"CA10__state__c\"\n#Not nullable\n  - name:\
      \ \"CA10__creationDate__c\"\n    value: \n      FIELD:\n        path: \"CA10__creationDate__c\"\
      \n# Nullable\n  - name: \"CA10__lastLaunchedTime__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10__lastLaunchedTime__c\"\n"
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "001",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__public__c') == true",
      "runtimeError" : null
    }
  }, {
    "Id" : "004",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__public__c') == false",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsImage__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__public__c BOOLEAN,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-12-03T09:28:25Z")
    },
    "CA10__disappearanceTime__c" : new Date("2025-11-24T12:43:45Z"),
    "CA10__public__c" : false,
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-03T09:28:25Z")
    },
    "CA10__public__c" : true,
    "Id" : "003"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-03T09:28:25Z")
    },
    "CA10__public__c" : false,
    "Id" : "004"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsImage__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__public__c BOOLEAN,
          Id STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
      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 extract3() { if (!this.out) { this.out = obj.CA10__public__c; } return this.out; };
      references1.push('Public [obj.CA10__public__c]: ' + obj.CA10__public__c);
      if (extract3.call(extract3) == true) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__public__c') == true", currentStateMessage: "The EC2 Image is publicly accessible.", currentStateReferences: references1.join('\n'), remediation: "Consider restricting the image access to private or sharing only with specific AWS accounts.", runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__public__c; } return this.out; };
      if (extract6.call(extract6) == false) {
          return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__public__c') == false", currentStateMessage: "The EC2 Image is not publicly accessible.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'UNDETERMINED', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Unexpected values in the field.", 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__public__c AS CA10__public__c,
          sObject.Id AS Id,
          process_CA10__CaAwsImage__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__public__c AS CA10__public__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsImage__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
