---
policy: /ce/ca/aws/eks/cluster-allows-unrestricted-public-traffic
logic: /ce/ca/aws/eks/cluster-allows-unrestricted-public-traffic/prod.logic.yaml
executionTime: 2025-06-28T12:02:50.789932635Z
rows:
  - id: test1
    match: true
    status:
      expected: DISAPPEARED
      actual: DISAPPEARED
    conditionIndex:
      expected: 99
      actual: 99
    conditionText:
      expected: isDisappeared(CA10A1__disappearanceTime__c)
      actual: isDisappeared(CA10A1__disappearanceTime__c)
    runtimeError: {}
  - id: test2
    match: true
    status:
      expected: INAPPLICABLE
      actual: INAPPLICABLE
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10A1__endpointPublicAccess__c') == 'Disabled'
      actual: extract('CA10A1__endpointPublicAccess__c') == 'Disabled'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10A1__publicAccessCidrs__c').contains('0.0.0.0/0')
      actual: extract('CA10A1__publicAccessCidrs__c').contains('0.0.0.0/0')
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/eks/cluster-allows-unrestricted-public-traffic/policy.yaml
    md5Hash: F69B35F9FB10482888137326C6089A56
    content: "names:\n  full: \"AWS EKS Cluster allows unrestricted public traffic\"\
      \n  contextual: \"Cluster allows unrestricted public traffic\"\ndescription:\
      \ >\n  Ensure that Amazon EKS clusters are configured to restrict public access\
      \ to their \n  Kubernetes API server endpoint to specific CIDR blocks. Unrestricted\
      \ public \n  access can expose the cluster to unauthorized access and potential\
      \ attacks.\ncategories:\n  - \"SECURITY\"\ntype: \"COMPLIANCE_POLICY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/resource-security/public-and-anonymous-access\"\
      \nsimilarPolicies:\n  internal:\n    - \"dec-x-cffc7d8e\""
  - path: /ce/ca/aws/eks/cluster-allows-unrestricted-public-traffic/prod.logic.yaml
    md5Hash: 48FDED0C6ED47B3217F6F1134892CDA2
    content: "inputType: \"CA10A1__CaAwsEksCluster__c\"\nimportExtracts:\n  - file:\
      \ \"/types/CA10A1__CaAwsEksCluster__c/object.extracts.yaml\"\ntestData:\n  -\
      \ file: \"test-data.json\"\nconditions:\n  - status: \"INAPPLICABLE\"\n    currentStateMessage:\
      \ \"Cluster endpoint public access is disabled.\"\n    check:\n      IS_EQUAL:\n\
      \        left:\n          EXTRACT: \"CA10A1__endpointPublicAccess__c\"\n   \
      \     right:\n          TEXT: \"Disabled\"\n  - status: \"INCOMPLIANT\"\n  \
      \  currentStateMessage: \"Cluster endpoint public access allows all IP addresses.\"\
      \ \n    check:\n      CONTAINS:\n        arg:\n          EXTRACT: \"CA10A1__publicAccessCidrs__c\"\
      \n        substring:\n          TEXT: \"0.0.0.0/0\"\notherwise:\n  status: \"\
      COMPLIANT\" \n  currentStateMessage: \"Cluster endpoint public access does not\
      \ allow all IP addresses.\" "
  - path: /ce/ca/aws/eks/cluster-allows-unrestricted-public-traffic/test-data.json
    md5Hash: FFA2CFF997BD8C71496F55C37B191F39
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10A1__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-05-22T08:12:49Z"
              },
              "Id": "test1",
              "CA10A1__disappearanceTime__c": "2025-05-22T08:12:49Z",
              "CA10A1__endpointPublicAccess__c": "Enabled",
              "CA10A1__publicAccessCidrs__c": "0.0.0.0/0"
          },
          {
              "expectedResult": {
                  "status": "INAPPLICABLE",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10A1__endpointPublicAccess__c') == 'Disabled'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-05-22T08:12:49Z"
              },
              "Id": "test2",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__endpointPublicAccess__c": "Disabled",
              "CA10A1__publicAccessCidrs__c": "0.0.0.0/0"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10A1__publicAccessCidrs__c').contains('0.0.0.0/0')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-05-22T08:12:49Z"
              },
              "Id": "test3",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__endpointPublicAccess__c": "Enabled",
              "CA10A1__publicAccessCidrs__c": "0.0.0.0/0"
          }
      ]
  - path: /types/CA10A1__CaAwsEksCluster__c/object.extracts.yaml
    md5Hash: 601E751040B9EB5B832935218E31F406
    content: "---\nextracts:\n#Values: Enabled | Disabled. Not Nullable.\n  - name:\
      \ CA10A1__endpointPublicAccess__c\n    value: \n      FIELD:\n        path:\
      \ CA10A1__endpointPublicAccess__c\n        undeterminedIf:\n          noAccessDelegate:\n\
      \            path: CA10A1__endpointPublicAccess__c\n            currentStateMessage:\
      \ \"Endpoint Public Access cannot be empty. Possible permission issues with\
      \ eks:DescribeCluster.\"\n#LONG_TEXT_AREA with IP addresses divided by \\n.\
      \ Nullable\n  - name: CA10A1__publicAccessCidrs__c\n    value: \n      FIELD:\n\
      \        path: CA10A1__publicAccessCidrs__c\n#Values: array of strings\n   \
      \   # api: Enabled\\n\n      # audit: Enabled\\n\n      # authenticator: Enabled\\\
      n\n      # controllerManager: Enabled\\n\n      # scheduler: Enabled\\n\n  -\
      \ name: CA10A1__logging__c\n    value: \n      FIELD:\n        path: CA10A1__logging__c\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: CA10A1__logging__c\n\
      \            currentStateMessage: \"Cluster Logging cannot be empty. Possible\
      \ permission issues with eks:DescribeCluster.\"\n  - name: caExtract_logging_asCollection__c\n\
      \    value:\n      COLLECTION_FROM:\n        separator: \"\\n\"\n        emptyValues:\
      \ SKIP\n        duplicateValues: SKIP\n        ordering: SORTED\n        arg:\
      \ \n          EXTRACT: \"CA10A1__logging__c\""
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(CA10A1__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INAPPLICABLE",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10A1__endpointPublicAccess__c') == 'Disabled'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10A1__publicAccessCidrs__c').contains('0.0.0.0/0')",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsEksCluster__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__endpointPublicAccess__c STRING,
      CA10A1__publicAccessCidrs__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-05-22T08:12:49Z")
    },
    "Id" : "test1",
    "CA10A1__disappearanceTime__c" : new Date("2025-05-22T08:12:49Z"),
    "CA10A1__endpointPublicAccess__c" : "Enabled",
    "CA10A1__publicAccessCidrs__c" : "0.0.0.0/0"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-05-22T08:12:49Z")
    },
    "Id" : "test2",
    "CA10A1__endpointPublicAccess__c" : "Disabled",
    "CA10A1__publicAccessCidrs__c" : "0.0.0.0/0"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-05-22T08:12:49Z")
    },
    "Id" : "test3",
    "CA10A1__endpointPublicAccess__c" : "Enabled",
    "CA10A1__publicAccessCidrs__c" : "0.0.0.0/0"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10A1__CaAwsEksCluster__c(
      obj STRUCT<
          Id STRING,
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__endpointPublicAccess__c STRING,
          CA10A1__publicAccessCidrs__c 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 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));
          };
      }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From AWS [CA10A1__disappearanceTime__c]: ' + obj.CA10A1__disappearanceTime__c);
      if (obj.CA10A1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10A1__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.CA10A1__endpointPublicAccess__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10A1__endpointPublicAccess__c.delegatedTo(CA10A1__endpointPublicAccess__c).isEmpty()", currentStateMessage: "Endpoint Public Access cannot be empty. Possible permission issues with eks:DescribeCluster.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A1__endpointPublicAccess__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Endpoint Public Access [obj.CA10A1__endpointPublicAccess__c]: ' + obj.CA10A1__endpointPublicAccess__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'Disabled')) {
              return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10A1__endpointPublicAccess__c') == 'Disabled'", currentStateMessage: "Cluster endpoint public access is disabled.", 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.CA10A1__publicAccessCidrs__c; } return this.out; };
      references1.push('Public Access CIDRs [obj.CA10A1__publicAccessCidrs__c]: ' + obj.CA10A1__publicAccessCidrs__c);
      if (TextLib.contains(extract6.call(extract6), '0.0.0.0/0')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10A1__publicAccessCidrs__c').contains('0.0.0.0/0')", currentStateMessage: "Cluster endpoint public access allows all IP addresses.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "Cluster endpoint public access does not allow all 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.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
          sObject.CA10A1__endpointPublicAccess__c AS CA10A1__endpointPublicAccess__c,
          sObject.CA10A1__publicAccessCidrs__c AS CA10A1__publicAccessCidrs__c,
          process_CA10A1__CaAwsEksCluster__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                  sObject.CA10A1__endpointPublicAccess__c AS CA10A1__endpointPublicAccess__c,
                  sObject.CA10A1__publicAccessCidrs__c AS CA10A1__publicAccessCidrs__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10A1__CaAwsEksCluster__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
