---
policy: /ce/ca/aws/acm/certificate-with-wildcard-domain-name
logic: /ce/ca/aws/acm/certificate-with-wildcard-domain-name/prod.logic.yaml
executionTime: 2025-04-24T23:44:16.384577059Z
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: UNDETERMINED
      actual: UNDETERMINED
    conditionIndex:
      expected: 101
      actual: 101
    conditionText:
      expected: CA10__status__c.delegatedTo(CA10__status__c).isEmpty()
      actual: CA10__status__c.delegatedTo(CA10__status__c).isEmpty()
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10__status__c') != 'ISSUED' && extract('CA10__domainName__c').startsWith('*')
      actual: extract('CA10__status__c') != 'ISSUED' && extract('CA10__domainName__c').startsWith('*')
    runtimeError: {}
  - id: test4
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/acm/certificate-with-wildcard-domain-name/policy.yaml
    md5Hash: E56C2E34D6975950BE89B74D85601474
    content: "---\nnames:\n  full: AWS ACM Certificate with Wildcard Domain Name\n\
      \  contextual: Certificate with Wildcard Domain Name\ndescription: >\n  Ensure\
      \ that ACM single domain name certificates are used instead of\n  wildcard certificates\
      \ within your AWS account in order to follow security best\n  practices and\
      \ protect each domain/subdomain with its own unique private key. An\n  AWS ACM\
      \ wildcard certificate can match any first-level subdomain, potentially \n \
      \ increasing vulnerability if compromised. For example, a wildcard certificate\
      \ \n  issued for *.cloudaware.com can protect both www.cloudaware.com and images.cloudaware.com.\n\
      categories:\n  - \"SECURITY\"\ntype: \"COMPLIANCE_POLICY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/secret-and-certificate-governance/cryptographic-configuration\"\
      \nsimilarPolicies:\n  internal:\n    - \"dec-x-d25f7dfa\""
  - path: /ce/ca/aws/acm/certificate-with-wildcard-domain-name/prod.logic.yaml
    md5Hash: E5241D6D51376FCC00449A1864FFE883
    content: |
      ---
      inputType: "CA10__CaAwsAcmCertificate__c"
      testData:
        - file: test-data.json
      importExtracts:
        - file: /types/CA10__CaAwsAcmCertificate__c/object.extracts.yaml
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "This certificate is issued for a wildcard (*) domain."
          remediationMessage: "Delete the wildcard certificate and add single domain certificates\
            \ for each domain you use."
          check:
            AND:
              args:
                - NOT_EQUAL:
                    left:
                      EXTRACT: CA10__status__c
                    right:
                      TEXT: "ISSUED"
                - STARTS_WITH:
                    arg:
                      EXTRACT: CA10__domainName__c
                    prefix:
                      TEXT: "*"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "This is not a wildcard certificate."
  - path: /ce/ca/aws/acm/certificate-with-wildcard-domain-name/test-data.json
    md5Hash: 78732DBEB4638EC3512CD40D52EEC979
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-29T03:06:28Z"
              },
              "Id": "test1",
              "CA10__disappearanceTime__c": "2024-05-22T19:05:46Z",
              "CA10__status__c": "ISSUED",
              "CA10__domainName__c": "*.abc.example.com"
          },
          {
              "expectedResult": {
                  "status": "UNDETERMINED",
                  "conditionIndex": "101",
                  "conditionText": "CA10__status__c.delegatedTo(CA10__status__c).isEmpty()",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-29T03:06:28Z"
              },
              "Id": "test2",
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "",
              "CA10__domainName__c": "*.opd.example.com"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10__status__c') != 'ISSUED' && extract('CA10__domainName__c').startsWith('*')",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-29T03:06:28Z"
              },
              "Id": "test3",
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "EXPIRED",
              "CA10__domainName__c": "*.def.example.com"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "200",
                  "conditionText": "otherwise",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2024-05-29T03:06:28Z"
              },
              "Id": "test4",
              "CA10__disappearanceTime__c": null,
              "CA10__status__c": "ISSUED",
              "CA10__domainName__c": "*.ghi.example.com"
          }
      ]
  - path: /types/CA10__CaAwsAcmCertificate__c/object.extracts.yaml
    md5Hash: D20EE095842A506CDEF3AC47E90A5A3B
    content: "---\nextracts:\n# Values: PENDING_VALIDATION | ISSUED | INACTIVE | EXPIRED\
      \ | REVOKED | FAILED | VALIDATION_TIMED_OUT\n# Not Nullable can't have no access\n\
      \  - name: CA10__status__c\n    value: \n      FIELD:\n        path: CA10__status__c\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: CA10__status__c\n\
      \            currentStateMessage: Unable to determine certificate status. Possible\
      \ permission issue with acm:DescribeCertificate\n          isEmpty: Status is\
      \ not populated yet\n# Nullable\n  - name: CA10__notAfter__c\n    value: \n\
      \      FIELD:\n        path: CA10__notAfter__c\n        undeterminedIf:\n  \
      \        noAccessDelegate:\n            path: CA10__notAfter__c\n          \
      \  currentStateMessage: Unable to determine certificate 'NotAfter'. Possible\
      \ permission issue with acm:DescribeCertificate\n# Not Nullable\n  - name: CA10__domainName__c\n\
      \    value: \n      FIELD:\n        path: CA10__domainName__c\n        undeterminedIf:\n\
      \          noAccessDelegate:\n            path: CA10__domainName__c\n      \
      \      currentStateMessage: Unable to determine certificate domain name. Possible\
      \ permission issue with acm:DescribeCertificate\n          isEmpty: Domain name\
      \ is not populated yet\n# Values: ELIGIBLE | INELIGIBLE, Not Nullable\n  - name:\
      \ CA10__renewalEligibility__c\n    value: \n      FIELD:\n        path: CA10__renewalEligibility__c\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: CA10__renewalEligibility__c\n\
      \            currentStateMessage: Unable to determine certificate renewal eligibility.\
      \ Possible permission issue with acm:DescribeCertificate\n          isEmpty:\
      \ Renewal eligibility is not populated yet\n# Values: RSA-1024 | RSA-2048 |\
      \ RSA-3072 | RSA-4096 | EC-prime256v1 | EC-secp384r1 | EC-secp521r1\n# Not Nullable\n\
      \  - name: CA10__keyAlgorithm__c\n    value: \n      FIELD:\n        path: CA10__keyAlgorithm__c\n\
      \        undeterminedIf:\n          noAccessDelegate:\n            path: CA10__keyAlgorithm__c\n\
      \            currentStateMessage: Unable to determine certificate status. Possible\
      \ permission issue with acm:DescribeCertificate\n          isEmpty: Key Algorithm\
      \ is not populated yet\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" : "UNDETERMINED",
      "conditionIndex" : "101",
      "conditionText" : "CA10__status__c.delegatedTo(CA10__status__c).isEmpty()",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10__status__c') != 'ISSUED' && extract('CA10__domainName__c').startsWith('*')",
      "runtimeError" : null
    }
  }, {
    "Id" : "test4",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsAcmCertificate__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__domainName__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "Id" : "test1",
    "CA10__disappearanceTime__c" : new Date("2024-05-22T19:05:46Z"),
    "CA10__status__c" : "ISSUED",
    "CA10__domainName__c" : "*.abc.example.com"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "Id" : "test2",
    "CA10__status__c" : "",
    "CA10__domainName__c" : "*.opd.example.com"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "Id" : "test3",
    "CA10__status__c" : "EXPIRED",
    "CA10__domainName__c" : "*.def.example.com"
  }, {
    "context" : {
      "snapshotTime" : new Date("2024-05-29T03:06:28Z")
    },
    "Id" : "test4",
    "CA10__status__c" : "ISSUED",
    "CA10__domainName__c" : "*.ghi.example.com"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsAcmCertificate__c(
      obj STRUCT<
          Id STRING,
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__domainName__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 [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__status__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10__status__c.delegatedTo(CA10__status__c).isEmpty()", currentStateMessage: "Unable to determine certificate status. Possible permission issue with acm:DescribeCertificate", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__status__c)) {
              throw new Error("UNDETERMINED condition:102", {cause: {status: 'UNDETERMINED', conditionIndex: 102, conditionText: "CA10__status__c.isEmpty()", currentStateMessage: "Status is not populated yet", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__status__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      function fieldChecked7() {
          if (TextLib.isEmpty(obj.CA10__domainName__c)) {
              throw new Error("UNDETERMINED condition:103", {cause: {status: 'UNDETERMINED', conditionIndex: 103, conditionText: "CA10__domainName__c.delegatedTo(CA10__domainName__c).isEmpty()", currentStateMessage: "Unable to determine certificate domain name. Possible permission issue with acm:DescribeCertificate", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          if (TextLib.isEmpty(obj.CA10__domainName__c)) {
              throw new Error("UNDETERMINED condition:104", {cause: {status: 'UNDETERMINED', conditionIndex: 104, conditionText: "CA10__domainName__c.isEmpty()", currentStateMessage: "Domain name is not populated yet", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10__domainName__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      references1.push('Domain Name [obj.CA10__domainName__c]: ' + obj.CA10__domainName__c);
      try {
          if (TextLib.notEqual(extract3.call(extract3), 'ISSUED') && TextLib.startsWith(extract6.call(extract6), '*')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'ISSUED' && extract('CA10__domainName__c').startsWith('*')", currentStateMessage: "This certificate is issued for a wildcard (*) domain.", currentStateReferences: references1.join('\n'), remediation: "Delete the wildcard certificate and add single domain certificates for each domain you use.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "This is not a wildcard certificate.", 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__status__c AS CA10__status__c,
          sObject.CA10__domainName__c AS CA10__domainName__c,
          process_CA10__CaAwsAcmCertificate__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__domainName__c AS CA10__domainName__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsAcmCertificate__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
