---
policy: /ce/ca/aws/redshift/cluster-master-username
logic: /ce/ca/aws/redshift/cluster-master-username/prod.logic.yaml
executionTime: 2026-01-31T12:02:16.999461497Z
generationMs: 70
executionMs: 770
rows:
  - id: '001'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 299
      actual: 299
    conditionText:
      expected: extract('CA10__masterUsername__c') == 'awsuser'
      actual: extract('CA10__masterUsername__c') == 'awsuser'
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 300
      actual: 300
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
usedFiles:
  - path: /ce/ca/aws/redshift/cluster-master-username/policy.yaml
    md5Hash: 386F7482AEB54A6E6E462B52C3B1FD95
    content: "---\nnames:\n  full: \"AWS Redshift Cluster Master Username is a default\
      \ values\"\n  contextual: \"Cluster Master Username is a default values\"\n\
      description: >\n  Identify AWS Redshift Clusters that use default master usernames\
      \ (i.e., 'awsuser'). \n  Using non-default usernames enhances security by making\
      \ brute-force attacks more \n  difficult and reducing predictability for unauthorized\
      \ actors.\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n  - \"SECURITY\"\nframeworkMappings:\n\
      \  - \"/frameworks/cloudaware/resource-security/threat-protection\"\n  - \"\
      /frameworks/aws-fsbp-v1.0.0/redshift/08\"\nsimilarPolicies:\n  awsSecurityHub:\n\
      \    - name: \"[Redshift.8] Amazon Redshift clusters should not use the default\
      \ Admin username\"\n      url: \"https://docs.aws.amazon.com/securityhub/latest/userguide/redshift-controls.html#redshift-8\"\
      \n  cloudConformity:\n    - url: \"https://www.trendmicro.com/cloudoneconformity/knowledge-base/aws/Redshift/master-username.html\"\
      \n      name: Redshift Cluster Default Master Username"
  - path: /ce/ca/aws/redshift/cluster-master-username/prod.logic.yaml
    md5Hash: A8F89927836299FA16C9202D90E53A9C
    content: |-
      ---
      inputType: "CA10__CaAwsRedshiftCluster__c"
      importExtracts:
        - file: "/types/CA10__CaAwsRedshiftCluster__c/object.extracts.yaml"
      testData:
        - file: "test-data.json"
      conditions:
        - status: "INAPPLICABLE"
          currentStateMessage: "The Cluster is not available."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10__status__c"
              right:
                TEXT: "available"
        - status: "INCOMPLIANT"
          currentStateMessage: "The Redshift Cluster has a default master username."
          remediationMessage: "Consider recreating the cluster using a unique, non-default master username."
          check:
            IS_EQUAL:
              left:
                EXTRACT: "CA10__masterUsername__c"
              right:
                TEXT: "awsuser"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "The Redshift Cluster has a custom master username."
  - path: /ce/ca/aws/redshift/cluster-master-username/test-data.json
    md5Hash: FE41AC31F3231224A0860489530C90B0
    content: |
      [
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "299",
            "conditionText": "extract('CA10__masterUsername__c') == 'awsuser'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-23T05:07:23Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "available",
          "CA10__masterUsername__c": "awsuser",
          "Id": "001"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "300",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-12-23T05:07:23Z" },
          "CA10__disappearanceTime__c": null,
          "CA10__status__c": "available",
          "CA10__masterUsername__c": "admin",
          "Id": "002"
        }
      ]
  - path: /types/CA10__CaAwsRedshiftCluster__c/object.extracts.yaml
    md5Hash: DBF4D0413CB4EF01D13D17E4ED636EC5
    content: |
      ---
      extracts:
      # Nullable. Values: available, modifying, creating ...
        - name: "CA10__status__c"
          value:
            FIELD:
              path: "CA10__status__c"
      # Nullable.
        - name: "CA10__createTime__c"
          value:
            FIELD:
              path: "CA10__createTime__c"
      # Nullable.
        - name: "CA10__cpuUtilizationAvg30d__c"
          value:
            FIELD:
              path: "CA10__cpuUtilizationAvg30d__c"
      # Nullable.
        - name: "CA10__diskReadIopsAvg30d__c"
          value:
            FIELD:
              path: "CA10__diskReadIopsAvg30d__c"
      # Nullable.
        - name: "CA10__diskWriteIopsAvg30d__c"
          value:
            FIELD:
              path: "CA10__diskWriteIopsAvg30d__c"
      # Nullable.
        - name: "CA10__logging__c"
          value:
            FIELD:
              path: "CA10__logging__c"
      # Nullable.
        - name: "CA10__automatedSnapshotRetentionPeriod__c"
          value:
            FIELD:
              path: "CA10__automatedSnapshotRetentionPeriod__c"
      # Text.
        - name: "CA10__encryption__c"
          value:
            FIELD:
              path: "CA10__encryption__c"
      # Text.
        - name: "CA10__masterUsername__c"
          value:
            FIELD:
              path: "CA10__masterUsername__c"
      # Text.
        - name: "CA10__versionUpgrade__c"
          value:
            FIELD:
              path: "CA10__versionUpgrade__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" : "001",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "299",
      "conditionText" : "extract('CA10__masterUsername__c') == 'awsuser'",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "300",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10__CaAwsRedshiftCluster__c()
  RETURNS ARRAY<STRUCT<
      CA10__disappearanceTime__c TIMESTAMP,
      CA10__status__c STRING,
      CA10__masterUsername__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-12-23T05:07:23Z")
    },
    "CA10__status__c" : "available",
    "CA10__masterUsername__c" : "awsuser",
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-12-23T05:07:23Z")
    },
    "CA10__status__c" : "available",
    "CA10__masterUsername__c" : "admin",
    "Id" : "002"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10__CaAwsRedshiftCluster__c(
      obj STRUCT<
          CA10__disappearanceTime__c TIMESTAMP,
          CA10__status__c STRING,
          CA10__masterUsername__c STRING,
          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 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 [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__status__c; } return this.out; };
      references1.push('Status [obj.CA10__status__c]: ' + obj.CA10__status__c);
      if (TextLib.notEqual(extract3.call(extract3), 'available')) {
          return {status: 'INAPPLICABLE', conditionIndex: 199, conditionText: "extract('CA10__status__c') != 'available'", currentStateMessage: "The Cluster is not available.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[2], conditionIndex:[200..299]
      function extract6() { if (!this.out) { this.out = obj.CA10__masterUsername__c; } return this.out; };
      references1.push('Master Username [obj.CA10__masterUsername__c]: ' + obj.CA10__masterUsername__c);
      if (TextLib.equal(extract6.call(extract6), 'awsuser')) {
          return {status: 'INCOMPLIANT', conditionIndex: 299, conditionText: "extract('CA10__masterUsername__c') == 'awsuser'", currentStateMessage: "The Redshift Cluster has a default master username.", currentStateReferences: references1.join('\n'), remediation: "Consider recreating the cluster using a unique, non-default master username.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 300, conditionText: "otherwise", currentStateMessage: "The Redshift Cluster has a custom master username.", 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__status__c AS CA10__status__c,
          sObject.CA10__masterUsername__c AS CA10__masterUsername__c,
          sObject.Id AS Id,
          process_CA10__CaAwsRedshiftCluster__c(
              STRUCT(
                  sObject.CA10__disappearanceTime__c AS CA10__disappearanceTime__c,
                  sObject.CA10__status__c AS CA10__status__c,
                  sObject.CA10__masterUsername__c AS CA10__masterUsername__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10__CaAwsRedshiftCluster__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
