---
policy: /ce/ca/aws/vpc/disable-transit-gateway-auto-accept-shared-attachments
logic: /ce/ca/aws/vpc/disable-transit-gateway-auto-accept-shared-attachments/prod.logic.yaml
executionTime: 2025-09-02T01:30:51.513363885Z
generationMs: 56
executionMs: 782
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: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10A1__autoAcceptSharedAttachments__c') == 'enable'
      actual: extract('CA10A1__autoAcceptSharedAttachments__c') == 'enable'
    runtimeError: {}
  - id: test3
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10A1__autoAcceptSharedAttachments__c') == 'disable'
      actual: extract('CA10A1__autoAcceptSharedAttachments__c') == 'disable'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/vpc/disable-transit-gateway-auto-accept-shared-attachments/policy.yaml
    md5Hash: D2592B9AF21E8D80DD2BAA63FAC61154
    content: "---\nnames:\n  full: AWS VPC Transit Gateway Auto Accept Shared Attachments\
      \ is enabled\n  contextual: Transit Gateway Auto Accept Shared Attachments is\
      \ enabled\ndescription: >\n  Ensure that VPC Transit Gateways are not configured\
      \ to automatically accept \n  shared attachments. Disabling this feature ensures\
      \ that all cross-account \n  attachment requests are manually reviewed and approved.\n\
      type: COMPLIANCE_POLICY\ncategories:\n  - SECURITY\nframeworkMappings:\n  -\
      \ \"/frameworks/cloudaware/resource-security/secure-access\"\n  - \"/frameworks/aws-fsbp-v1.0.0/ec2/23\"\
      \nsimilarPolicies:\n  awsSecurityHub:\n    - name: \"[EC2.23] Amazon EC2 Transit\
      \ Gateways should not automatically accept VPC attachment requests\"\n     \
      \ url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/ec2-controls.html#ec2-23\"\
      \n"
  - path: /ce/ca/aws/vpc/disable-transit-gateway-auto-accept-shared-attachments/prod.logic.yaml
    md5Hash: 130991AE3F4D38AB1A5535F528229925
    content: |-
      inputType: "CA10A1__CaAwsVpcTransitGateway__c"
      testData:
        - file: "./test-data.json"
      importExtracts:
        - file: /types/CA10A1__CaAwsVpcTransitGateway__c/object.extracts.yaml
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "Transit Gateway is configured to automatically accept shared attachments."
          remediationMessage: "Disable the Auto Accept Shared Attachments feature for\
            \ the Transit Gateway to ensure all cross-account connections are manually reviewed."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10A1__autoAcceptSharedAttachments__c"
              right:
                TEXT: "enable"
        - status: "COMPLIANT"
          currentStateMessage: "Transit Gateway requires manual approval for shared attachments."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10A1__autoAcceptSharedAttachments__c"
              right:
                TEXT: "disable"
      otherwise:
        status: "UNDETERMINED"
        currentStateMessage: "Unexpected value in the field."
  - path: /ce/ca/aws/vpc/disable-transit-gateway-auto-accept-shared-attachments/test-data.json
    md5Hash: 3ABAC51461EE44D42CA689A0810B6F59
    content: |-
      [
          {
              "expectedResult": {
                  "status": "DISAPPEARED",
                  "conditionIndex": "99",
                  "conditionText": "isDisappeared(CA10A1__disappearanceTime__c)",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test1",
              "CA10A1__disappearanceTime__c": "2025-08-31T15:18:03Z",
              "CA10A1__autoAcceptSharedAttachments__c": "enable"
          },
          {
              "expectedResult": {
                  "status": "INCOMPLIANT",
                  "conditionIndex": "199",
                  "conditionText": "extract('CA10A1__autoAcceptSharedAttachments__c') == 'enable'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test2",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__autoAcceptSharedAttachments__c": "enable"
          },
          {
              "expectedResult": {
                  "status": "COMPLIANT",
                  "conditionIndex": "299",
                  "conditionText": "extract('CA10A1__autoAcceptSharedAttachments__c') == 'disable'",
                  "runtimeError": null
              },
              "context": {
                  "snapshotTime": "2025-08-31T15:18:03Z"
              },
              "Id": "test3",
              "CA10A1__disappearanceTime__c": null,
              "CA10A1__autoAcceptSharedAttachments__c": "disable"
          }
      ]
  - path: /types/CA10A1__CaAwsVpcTransitGateway__c/object.extracts.yaml
    md5Hash: F82921743F9A4B66CDD67DEAEB4AB401
    content: "---\nextracts:\n# Values: enable | disable. Not nullable. Can't have\
      \ no access, retrieved via ec2:DescribeTransitGateways\n  - name: CA10A1__autoAcceptSharedAttachments__c\n\
      \    value:\n      FIELD: \n        path: CA10A1__autoAcceptSharedAttachments__c\n\
      \        undeterminedIf:\n          isEmpty: Possibly corrupted data. Transit\
      \ Gateway Auto Accept Shared Attachment should not be empty.\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(CA10A1__disappearanceTime__c)",
      "runtimeError" : null
    }
  }, {
    "Id" : "test2",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10A1__autoAcceptSharedAttachments__c') == 'enable'",
      "runtimeError" : null
    }
  }, {
    "Id" : "test3",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10A1__autoAcceptSharedAttachments__c') == 'disable'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10A1__CaAwsVpcTransitGateway__c()
  RETURNS ARRAY<STRUCT<
      Id STRING,
      CA10A1__disappearanceTime__c TIMESTAMP,
      CA10A1__autoAcceptSharedAttachments__c STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test1",
    "CA10A1__disappearanceTime__c" : new Date("2025-08-31T15:18:03Z"),
    "CA10A1__autoAcceptSharedAttachments__c" : "enable"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test2",
    "CA10A1__autoAcceptSharedAttachments__c" : "enable"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-08-31T15:18:03Z")
    },
    "Id" : "test3",
    "CA10A1__autoAcceptSharedAttachments__c" : "disable"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10A1__CaAwsVpcTransitGateway__c(
      obj STRUCT<
          Id STRING,
          CA10A1__disappearanceTime__c TIMESTAMP,
          CA10A1__autoAcceptSharedAttachments__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));
          };
          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 [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__autoAcceptSharedAttachments__c)) {
              throw new Error("UNDETERMINED condition:101", {cause: {status: 'UNDETERMINED', conditionIndex: 101, conditionText: "CA10A1__autoAcceptSharedAttachments__c.isEmpty()", currentStateMessage: "Possibly corrupted data. Transit Gateway Auto Accept Shared Attachment should not be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A1__autoAcceptSharedAttachments__c;
      }
      function extract3() { if (!this.out) { this.out = fieldChecked4(); } return this.out; };
      references1.push('Auto Accept Shared Attachments [obj.CA10A1__autoAcceptSharedAttachments__c]: ' + obj.CA10A1__autoAcceptSharedAttachments__c);
      try {
          if (TextLib.equal(extract3.call(extract3), 'enable')) {
              return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10A1__autoAcceptSharedAttachments__c') == 'enable'", currentStateMessage: "Transit Gateway is configured to automatically accept shared attachments.", currentStateReferences: references1.join('\n'), remediation: "Disable the Auto Accept Shared Attachments feature for the Transit Gateway to ensure all cross-account connections are manually reviewed.", runtimeError: null};
          }
      } catch (err) {
          if (err.cause && err.cause.status) { return err.cause; } else { throw err; }
      }
      // condition[2], conditionIndex:[200..299]
      function fieldChecked7() {
          if (TextLib.isEmpty(obj.CA10A1__autoAcceptSharedAttachments__c)) {
              throw new Error("UNDETERMINED condition:201", {cause: {status: 'UNDETERMINED', conditionIndex: 201, conditionText: "CA10A1__autoAcceptSharedAttachments__c.isEmpty()", currentStateMessage: "Possibly corrupted data. Transit Gateway Auto Accept Shared Attachment should not be empty.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null}});
          }
          return obj.CA10A1__autoAcceptSharedAttachments__c;
      }
      function extract6() { if (!this.out) { this.out = fieldChecked7(); } return this.out; };
      try {
          if (TextLib.equal(extract6.call(extract6), 'disable')) {
              return {status: 'COMPLIANT', conditionIndex: 299, conditionText: "extract('CA10A1__autoAcceptSharedAttachments__c') == 'disable'", currentStateMessage: "Transit Gateway requires manual approval for shared attachments.", 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: 300, conditionText: "otherwise", currentStateMessage: "Unexpected value 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.Id AS Id,
          sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
          sObject.CA10A1__autoAcceptSharedAttachments__c AS CA10A1__autoAcceptSharedAttachments__c,
          process_CA10A1__CaAwsVpcTransitGateway__c(
              STRUCT(
                  sObject.Id AS Id,
                  sObject.CA10A1__disappearanceTime__c AS CA10A1__disappearanceTime__c,
                  sObject.CA10A1__autoAcceptSharedAttachments__c AS CA10A1__autoAcceptSharedAttachments__c
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10A1__CaAwsVpcTransitGateway__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
