---
policy: /ce/ca/aws/vpc/disable-subnet-map-public-ip-on-launch
logic: /ce/ca/aws/vpc/disable-subnet-map-public-ip-on-launch/prod.logic.yaml
executionTime: 2025-08-29T17:46:57.969199786Z
generationMs: 58
executionMs: 644
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: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__mapPublicIpOnLaunch__c') == true
      actual: extract('CA10__mapPublicIpOnLaunch__c') == true
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/vpc/disable-subnet-map-public-ip-on-launch/policy.yaml
    md5Hash: 45E132D818308283FF5F4F9E811EECDE
    content: "---\nnames:\n  full: AWS VPC Subnet Map Public IP On Launch is enabled\n\
      \  contextual: Subnet Map Public IP On Launch is enabled\ndescription: >\n \
      \ Ensure that AWS VPC Subnets are not configured to automatically assign \n\
      \  public IP addresses to EC2 Instances launched within them.\ntype: COMPLIANCE_POLICY\n\
      categories:\n  - SECURITY\nframeworkMappings:\n  - \"/frameworks/cloudaware/resource-security/public-and-anonymous-access\"\
      \n  - \"/frameworks/aws-fsbp-v1.0.0/ec2/15\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[EC2.15] Amazon EC2 subnets should not automatically assign public\
      \ IP addresses\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/ec2-controls.html#ec2-15\"\
      \n"
  - path: /ce/ca/aws/vpc/disable-subnet-map-public-ip-on-launch/prod.logic.yaml
    md5Hash: 6E5BC73B7856205B117671D98B2EC47A
    content: |-
      ---
      inputType: "CA10__CaAwsSubnet__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10__CaAwsSubnet__c/object.extracts.yaml"
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "The subnet is configured to automatically assign public IP addresses to instances at launch."
          remediationMessage: "Consider disabling the 'auto-assign public IP address' setting for this subnet to prevent unintended exposure of instances to the internet."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__mapPublicIpOnLaunch__c"
              right:
                BOOLEAN: true
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The subnet is not configured to automatically assign public IP addresses."
  - path: /ce/ca/aws/vpc/disable-subnet-map-public-ip-on-launch/test-data.json
    md5Hash: E76E46EBAE1FCD54AA5B6E81D54EACA8
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-29T11:12:55Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2025-08-19T22:01:14Z",
              "CA10__mapPublicIpOnLaunch__c": false
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__mapPublicIpOnLaunch__c') == true",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-29T11:12:55Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__mapPublicIpOnLaunch__c": true
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-29T11:12:55Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__mapPublicIpOnLaunch__c": false
          }
      ]
  - path: /types/CA10__CaAwsSubnet__c/object.extracts.yaml
    md5Hash: 7F012284F2BF194EA79A157883554CA2
    content: "---\nextracts:\n# Checkbox. Can't have no access, retrieved via ec2:DescribeSubnets\n\
      \  - name: CA10__defaultForAz__c\n    value: \n      FIELD:\n        path: CA10__defaultForAz__c\n\
      # Checkbox. Can't have no access, retrieved via ec2:DescribeSubnets\n  - name:\
      \ CA10__mapPublicIpOnLaunch__c\n    value: \n      FIELD:\n        path: CA10__mapPublicIpOnLaunch__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" : "test1",
    "expectedResult" : {
      "status" : "DISAPPEARED",
      "conditionIndex" : "99",
      "conditionText" : "isDisappeared(CA10__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__mapPublicIpOnLaunch__c') == true",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsSubnet__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__mapPublicIpOnLaunch__c BOOLEAN,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-08-29T11:12:55Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2025-08-19T22:01:14Z"),
    "CA10__mapPublicIpOnLaunch__c" : false
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-29T11:12:55Z")
    },
    "Id" : "test2",
    "CA10__mapPublicIpOnLaunch__c" : true
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-29T11:12:55Z")
    },
    "Id" : "test3",
    "CA10__mapPublicIpOnLaunch__c" : false
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsSubnet__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__mapPublicIpOnLaunch__c BOOLEAN
      >,
      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__mapPublicIpOnLaunch__c; } return this.out; };
      references1.push('Map Public IP On Launch [obj.CA10__mapPublicIpOnLaunch__c]: ' + obj.CA10__mapPublicIpOnLaunch__c);
      if (extract3.call(extract3) == true) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__mapPublicIpOnLaunch__c') == true", currentStateMessage: "The subnet is configured to automatically assign public IP addresses to instances at launch.", currentStateReferences: references1.join('\n'), remediation: "Consider disabling the 'auto-assign public IP address' setting for this subnet to prevent unintended exposure of instances to the internet.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "The subnet is not configured to automatically assign public IP addresses.", 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.Id AS Id,
          sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
          sObject.CA10__mapPublicIpOnLaunch__c AS CA10__mapPublicIpOnLaunch__c,
          process_CA10__CaAwsSubnet__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__mapPublicIpOnLaunch__c AS CA10__mapPublicIpOnLaunch__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsSubnet__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
