fbpx

How to query and visualize Macie sensitive data discovery results with Athena and QuickSight

Amazon Macie is a fully managed data security service that uses machine learning and pattern matching to help you discover and protect sensitive data in Amazon Simple Storage Service (Amazon S3). With Macie, you can analyze objects in your S3 buckets to detect occurrences of sensitive data, such as personally identifiable information (PII), financial information, personal health information, and access credentials.

   <p>In this post, we walk you through a solution to gain comprehensive and organization-wide visibility into which types of sensitive data are present in your S3 storage, where the data is located, and how much is present. Once enabled, Macie <a href="https://docs.aws.amazon.com/macie/latest/user/discovery-asdd.html" target="_blank" rel="noopener">automatically starts discovering</a> sensitive data in your S3 storage and builds a sensitive data profile for each bucket. The profiles are organized in a visual, interactive data map, and you can use the data map to run targeted <a href="https://docs.aws.amazon.com/macie/latest/user/discovery-jobs.html" target="_blank" rel="noopener">sensitive data discovery jobs</a>. Both automated data discovery and targeted jobs produce rich, detailed <a href="https://docs.aws.amazon.com/macie/latest/user/discovery-results-repository-s3.html" target="_blank" rel="noopener">sensitive data discovery results</a>. This solution uses <a href="https://aws.amazon.com/athena/" target="_blank" rel="noopener">Amazon Athena</a> and <a href="https://aws.amazon.com/quicksight/" target="_blank" rel="noopener">Amazon QuickSight</a> to deep-dive on the Macie results, and to help you analyze, visualize, and report on sensitive data discovered by Macie, even when the data is distributed across millions of objects, thousands of S3 buckets, and thousands of AWS accounts. Athena is an interactive query service that makes it simpler to analyze data directly in Amazon S3 using standard <a href="https://docs.aws.amazon.com/athena/latest/ug/ddl-sql-reference.html" target="_blank" rel="noopener">SQL</a>. QuickSight is a cloud-scale business intelligence tool that connects to multiple data sources, including Athena databases and tables.</p> 
   <p>This solution is relevant to data security, data governance, and security operations engineering teams.</p> 
   <h2>The challenge: how to summarize sensitive data discovered in your growing S3 storage</h2> 
   <p>Macie issues <a href="https://docs.aws.amazon.com/macie/latest/user/findings-types.html" target="_blank" rel="noopener">findings</a> when an object is found to contain sensitive data. In addition to findings, Macie keeps a record of each S3 object analyzed in a bucket of your choice for long-term storage. These records are known as <a href="https://docs.aws.amazon.com/macie/latest/user/discovery-results-repository-s3.html" target="_blank" rel="noopener">sensitive data discovery results</a>, and they include additional context about your data in Amazon S3. Due to the large size of the results file, Macie exports the sensitive data discovery results to an S3 bucket, so you need to take additional steps to query and visualize the results. We discuss the differences between findings and results in more detail later in this post.</p> 
   <p>With the increasing number of data privacy guidelines and compliance mandates, customers need to scale their monitoring to encompass thousands of S3 buckets across their organization. The growing volume of data to assess, and the growing list of findings from discovery jobs, can make it difficult to review and remediate issues in a timely manner. In addition to viewing individual findings for specific objects, customers need a way to comprehensively view, summarize, and monitor sensitive data discovered across their S3 buckets.</p> 
   <p>To illustrate this point, we ran a Macie sensitive data discovery job on a dataset created by AWS. The dataset contains about 7,500 files that have sensitive information, and Macie generated a finding for each sensitive file analyzed, as shown in Figure 1.</p> 
   <div id="attachment_28094" class="wp-caption alignnone"> 
    <img aria-describedby="caption-attachment-28094" src="https://infracom.com.sg/wp-content/uploads/2023/01/Image1-1.png" alt="Figure 1: Macie findings from the dataset" width="1249" height="797" class="size-full wp-image-28094"> 
    <p id="caption-attachment-28094" class="wp-caption-text">Figure 1: Macie findings from the dataset</p> 
   </div> 
   <p>Your security team could spend days, if not months, analyzing these individual findings manually. Instead, we outline how you can use <a href="https://aws.amazon.com/athena/" target="_blank" rel="noopener">Athena</a> and <a href="https://aws.amazon.com/quicksight/" target="_blank" rel="noopener">QuickSight</a> to query and visualize the Macie sensitive data discovery results to understand your data security posture.</p> 
   <p>The additional information in the sensitive data discovery results will help you gain comprehensive visibility into your data security posture. With this visibility, you can answer questions such as the following:</p> 
   <ul> 
    <li>What are the top 5 most commonly occurring sensitive data types?</li> 
    <li>Which AWS accounts have the most findings?</li> 
    <li>How many S3 buckets are affected by each of the sensitive data types?</li> 
   </ul> 
   <p>Your security team can write their own customized queries to answer questions such as the following:</p> 
   <ul> 
    <li>Is there sensitive data in AWS accounts that are used for development purposes?</li> 
    <li>Is sensitive data present in S3 buckets that previously did not contain sensitive information?</li> 
    <li>Was there a change in configuration for S3 buckets containing the greatest amount of sensitive data?</li> 
   </ul> 
   <h2>How are findings different from results?</h2> 
   <p>As a Macie job progresses, it produces two key types of output: <a href="https://docs.aws.amazon.com/macie/latest/user/findings-types.html" target="_blank" rel="noopener">sensitive data findings</a> (or <em>findings</em> for short), and <a href="https://docs.aws.amazon.com/macie/latest/user/discovery-results-repository-s3.html" target="_blank" rel="noopener">sensitive data discovery results</a> (or <em>results</em>).</p> 
   <p>Findings provide a report of potential policy violations with an S3 bucket, or the presence of sensitive data in a specific S3 object. Each finding provides a severity rating, information about the affected resource, and additional details, such as when Macie found the issue. Findings are published to the Macie console, <a href="https://aws.amazon.com/security-hub/" target="_blank" rel="noopener">AWS Security Hub</a>, and <a href="https://aws.amazon.com/eventbridge/" target="_blank" rel="noopener">Amazon EventBridge</a>.</p> 
   <p>In contrast, results are a collection of records for each S3 object that a Macie job analyzed. These records contain information about objects that do and do not contain sensitive data, including up to 1,000 occurrences of each sensitive data type that Macie found in a given object, and whether Macie was unable to analyze an object because of issues such as permissions settings or use of an unsupported format. If an object contains sensitive data, the results record includes detailed information that isn’t available in the finding for the object.</p> 
   <p>One of the key benefits of querying results is to uncover gaps in your data protection initiatives—these gaps can occur when data in certain buckets can’t be analyzed because Macie was denied access to those buckets, or was unable to decrypt specific objects. The following table maps some of the key differences between findings and results.</p> 
   <table border="1" width="0"> 
    <tbody> 
     <tr> 
      <td></td> 
      <td><strong>Findings</strong></td> 
      <td><strong>Results</strong></td> 
     </tr> 
     <tr> 
      <td>Enabled by default</td> 
      <td>Yes</td> 
      <td>No</td> 
     </tr> 
     <tr> 
      <td>Location of published results</td> 
      <td>Macie console, Security Hub, and EventBridge</td> 
      <td>S3 bucket</td> 
     </tr> 
     <tr> 
      <td>Details of S3 objects that couldn’t be scanned</td> 
      <td>No</td> 
      <td>Yes</td> 
     </tr> 
     <tr> 
      <td>Details of S3 objects in which no sensitive data was found</td> 
      <td>No</td> 
      <td>Yes</td> 
     </tr> 
     <tr> 
      <td>Identification of files inside compressed archives that contain sensitive data</td> 
      <td>No</td> 
      <td>Yes</td> 
     </tr> 
     <tr> 
      <td>Number of occurrences reported per object</td> 
      <td>Up to 15</td> 
      <td>Up to 1,000</td> 
     </tr> 
     <tr> 
      <td>Retention period</td> 
      <td>90 days in Macie console</td> 
      <td>Defined by customer</td> 
     </tr> 
    </tbody> 
   </table> 
   <h2>Architecture</h2> 
   <p>As shown in Figure 2, you can build out the solution in three steps:</p> 
   <ol> 
    <li>Enable the results and publish them to an S3 bucket</li> 
    <li>Build out the Athena table to query the results by using SQL</li> 
    <li>Visualize the results with QuickSight</li> 
   </ol> 
   <div id="attachment_28091" class="wp-caption alignnone"> 
    <img aria-describedby="caption-attachment-28091" loading="lazy" src="https://infracom.com.sg/wp-content/uploads/2023/01/Image2.png" alt="Figure 2: Architecture diagram showing the flow of the solution" width="809" height="262" class="size-full wp-image-28091"> 
    <p id="caption-attachment-28091" class="wp-caption-text">Figure 2: Architecture diagram showing the flow of the solution</p> 
   </div> 
   <h2>Prerequisites</h2> 
   <p>To implement the solution in this blog post, you must first complete the following prerequisites:</p> 
   <ul> 
    <li>Enable Macie in your account. For instructions, see <a href="https://docs.aws.amazon.com/macie/latest/user/getting-started.html" target="_blank" rel="noopener">Getting started with Amazon Macie</a>.</li> 
    <li>Set your account as the <a href="https://docs.aws.amazon.com/macie/latest/user/accounts-mgmt-ao-notes.html#accounts-mgmt-ao-notes-admin-designate" target="_blank" rel="noopener">delegated Macie administrator account</a> by using <a href="https://aws.amazon.com/organizations/" target="_blank" rel="noopener">AWS Organizations</a>. Optionally, you can also <a href="https://docs.aws.amazon.com/macie/latest/user/accounts-mgmt-ao.html" target="_blank" rel="noopener">enable Macie in additional member accounts</a> using AWS Organizations.</li> 
    <li>Sign up for QuickSight in the account that you set as the delegated Macie administrator. For instructions on how to sign up, see <a href="https://docs.aws.amazon.com/quicksight/latest/user/signing-up.html" target="_blank" rel="noopener">Signing up for an Amazon QuickSight subscription</a>. You can use the <a href="https://aws.amazon.com/quicksight/pricing/" target="_blank" rel="noopener">QuickSight Standard Edition</a> for this post.</li> 
    <li>To follow along with the examples in this post, download the <a href="https://awsiammedia.s3.amazonaws.com/public/sample/1204-macie-sensitive-data-discovery-results/sample_data.zip" target="_blank" rel="noopener">sample dataset</a>. The dataset is a single .ZIP file that contains three directories (<span>fk, rt,</span> and <span>mkro</span>). For this post, we used three accounts in our organization, created an S3 bucket in each of them, and then copied each directory to an individual bucket, as shown in Figure 3.</li> 
   </ul> 
   <div id="attachment_28090" class="wp-caption alignnone"> 
    <img aria-describedby="caption-attachment-28090" loading="lazy" src="https://infracom.com.sg/wp-content/uploads/2023/01/Image3.png" alt="Figure 3: Sample data loaded into three different AWS accounts" width="711" height="422" class="size-full wp-image-28090"> 
    <p id="caption-attachment-28090" class="wp-caption-text">Figure 3: Sample data loaded into three different AWS accounts</p> 
   </div> 
   <blockquote> 
    <p><strong>Note</strong>: All data in this blog post has been artificially created by AWS for demonstration purposes and has not been collected from any individual person. Similarly, such data does not, nor is it intended, to relate back to any individual person.</p> 
   </blockquote> 
   <h2>Step 1: Enable the results and publish them to an S3 bucket</h2> 
   <p>Publication of the discovery results to Amazon S3 is not enabled by default. The setup requires that you specify an S3 bucket to store the results (we also refer to this as the <em>discovery results bucket</em>), and use an <a href="https://aws.amazon.com/kms/" target="_blank" rel="noopener">AWS Key Management Service (AWS KMS)</a> key to encrypt the bucket.</p> 
   <p>If you are analyzing data across multiple accounts in your organization, then you need to enable the results in your delegated Macie administrator account. You do not need to enable results in individual member accounts. However, if you’re running Macie jobs in a standalone account, then you should enable the Macie results directly in that account.</p> 
   <p><strong>To enable the results</strong></p> 
   <ol> 
    <li>Open the <a href="https://console.aws.amazon.com/macie" target="_blank" rel="noopener">Macie console</a>.</li> 
    <li>Select the AWS Region from the upper right of the page.</li> 
    <li>From the left navigation pane, select <strong>Discovery results</strong>.</li> 
    <li>Select <strong>Configure now</strong>.</li> 
    <li>Select <strong>Create Bucket</strong>, and enter a unique bucket name. This will be the discovery results bucket name. Make note of this name because you will use it when you configure the Athena tables later in this post.</li> 
    <li>Under <strong>Encryption settings</strong>, select <strong>Create new key</strong>. This takes you to the AWS KMS console in a new browser tab.</li> 
    <li>In the AWS KMS console, do the following: 
     <ol type="a"> 
      <li>For <strong>Key type</strong>, choose <strong>symmetric</strong>, and for <strong>Key usage</strong>, choose <strong>Encrypt and Decrypt</strong>.</li> 
      <li>Enter a meaningful key alias (for example, <span>macie-results-key</span>) and description.</li> 
      <li>(Optional) For simplicity, set your current user or role as the <strong>Key Administrator</strong>.</li> 
      <li>Set your current user/role as a user of this key in the key usage permissions step. This will give you the right permissions to run the Athena queries later.</li> 
      <li>Review the settings and choose <strong>Finish</strong>.</li> 
     </ol> </li> 
    <li>Navigate to the browser tab with the <a href="https://console.aws.amazon.com/macie/" target="_blank" rel="noopener">Macie console</a>.</li> 
    <li>From the <strong>AWS KMS Key</strong> dropdown, select the new key.</li> 
    <li>To view KMS key policy statements that were automatically generated for your specific key, account, and Region, select <strong>View Policy</strong>. Copy these statements in their entirety to your clipboard.</li> 
    <li>Navigate back to the browser tab with the <a href="https://console.aws.amazon/kms" target="_blank" rel="noopener">AWS KMS console</a> and then do the following: 
     <ol type="a"> 
      <li>Select <strong>Customer managed keys</strong>.</li> 
      <li>Choose the KMS key that you created, choose <strong>Switch to policy view</strong>, and under <strong>Key policy</strong>, select <strong>Edit</strong>.</li> 
      <li>In the key policy, paste the statements that you copied. When you add the statements, do not delete any existing statements and make sure that the syntax is valid. Policies are in JSON format.</li> 
     </ol> </li> 
    <li>Navigate back to the <a href="https://console.aws.amazon.com/macie/" target="_blank" rel="noopener">Macie console</a> browser tab.</li> 
    <li>Review the inputs in the <strong>Settings</strong> page for <strong>Discovery results</strong> and then choose <strong>Save</strong>. Macie will perform a check to make sure that it has the right access to the KMS key, and then it will create a new S3 bucket with the required permissions.</li> 
    <li>If you haven’t run a Macie discovery job in the last 90 days, you will need to run a new discovery job to publish the results to the bucket.</li> 
   </ol> 
   <p>In this step, you created a new S3 bucket and KMS key that you are using only for Macie. For instructions on how to enable and configure the results using existing resources, see <a href="https://docs.aws.amazon.com/macie/latest/user/discovery-results-repository-s3.html" target="_blank" rel="noopener">Storing and retaining sensitive data discovery results with Amazon Macie</a>. Make sure to review Macie <a href="https://aws.amazon.com/macie/pricing/" target="_blank" rel="noopener">pricing details</a> before creating and running a sensitive data discovery job.</p> 
   <h2>Step 2: Build out the Athena table to query the results using SQL</h2> 
   <p>Now that you have enabled the discovery results, Macie will begin publishing them into your discovery results bucket in the form of jsonl.gz files. Depending on the amount of data, there could be thousands of individual files, with each file containing multiple records. To identify the top five most commonly occurring sensitive data types in your organization, you would need to query all of these files together.</p> 
   <p>In this step, you will configure Athena so that it can query the results using SQL syntax. Before you can run an Athena query, you must specify a query result bucket location in Amazon S3. This is different from the Macie discovery results bucket that you created in the previous step.</p> 
   <p>If you haven’t set up Athena previously, we recommend that you create a separate S3 bucket, and <a href="https://docs.aws.amazon.com/athena/latest/ug/querying.html#query-results-specify-location-console" target="_blank" rel="noopener">specify a query result location using the Athena console</a>. After you’ve set up the query result location, you can configure Athena.</p> 
   <p><strong>To create a new Athena database and table for the Macie results</strong></p> 
   <ol> 
    <li>Open the <a href="https://console.aws.amazon.com/athena/" target="_blank" rel="noopener">Athena console</a>, and in the query editor, enter the following data definition language (DDL) statement. In the context of <a href="https://en.wikipedia.org/wiki/SQL" target="_blank" rel="noopener">SQL</a>, a DDL statement is a syntax for creating and modifying database objects, such as tables. For this example, we named our database <span>macie_results</span><em>.</em> 
     <div class="hide-language"> 
      <pre><code class="lang-text">CREATE DATABASE macie_results;
      After running this step, you’ll see a new database in the <strong>Database</strong> dropdown. Make sure that the new <strong>macie_results</strong> database is selected for the next queries.</p><br />
     <div id="attachment_28127" class="wp-caption aligncenter"> 
      <img aria-describedby="caption-attachment-28127" loading="lazy" src="https://infracom.com.sg/wp-content/uploads/2023/01/Query-visualize-Macie-Figure-4.png" alt="Figure 4: Create database in the Athena console" width="2590" height="590" class="size-full wp-image-28127" /> 
      <p id="caption-attachment-28127" class="wp-caption-text">Figure 4: Create database in the Athena console</p> 
     </div>  
    <li>Create a table in the database by using the following DDL statement. Make sure to replace<code> <RESULTS-BUCKET-NAME> </code>with the name of the discovery results bucket that you created previously. 
     <div class="hide-language"> 
      <pre><code class="lang-text">CREATE EXTERNAL TABLE maciedetail_all_jobs(
accountid string,
category string,
classificationdetails struct&lt;jobArn:string,result:struct&lt;status:struct<code>,sizeClassified:string,mimeType:string,sensitiveData:array&lt;struct&lt;category:string,totalCount:string,detections:array&lt;struct&lt;type:string,count:string,occurrences:struct&lt;lineRanges:array&lt;struct&gt;,pages:array&lt;struct&gt;,records:array&lt;struct&gt;,cells:array&lt;struct&gt;&gt;&gt;&gt;&gt;&gt;,customDataIdentifiers:struct&lt;totalCount:string,detections:array&lt;struct&lt;arn:string,name:string,count:string,occurrences:struct&lt;lineRanges:array&lt;struct&gt;,pages:array,records:array,cells:array&gt;&gt;&gt;&gt;&gt;,detailedResultsLocation:string,jobId:string&gt;,
createdat string,
description string,
id string,
partition string,
region string,
resourcesaffected struct&lt;s3Bucket:struct&lt;arn:string,name:string,createdAt:string,owner:struct,tags:array,defaultServerSideEncryption:struct,publicAccess:struct&lt;permissionConfiguration:struct&lt;bucketLevelPermissions:struct&lt;accessControlList:struct,bucketPolicy:struct,blockPublicAccess:struct&gt;,accountLevelPermissions:struct&lt;blockPublicAccess:struct&gt;&gt;,effectivePermission:string&gt;&gt;,s3Object:struct&lt;bucketArn:string,key:string,path:string,extension:string,lastModified:string,eTag:string,serverSideEncryption:struct,size:string,storageClass:string,tags:array,embeddedFileDetails:struct,publicAccess:boolean&gt;&gt;,
schemaversion string,
severity struct,
title string,
type string,
updatedat string)

ROW FORMAT SERDE
‘org.openx.data.jsonserde.JsonSerDe’
WITH SERDEPROPERTIES (
‘paths’=’accountId,category,classificationDetails,createdAt,description,id,partition,region,resourcesAffected,schemaVersion,severity,title,type,updatedAt’)
STORED AS INPUTFORMAT
‘org.apache.hadoop.mapred.TextInputFormat’
OUTPUTFORMAT
‘org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat’
LOCATION
‘s3://<RESULTS-BUCKET-NAME>/AWSLogs/’

After you complete this step, you will see a new table named maciedetail_all_jobs in the Tables section of the query editor.

 

  • Query the results to start gaining insights. For example, to identify the top five most common sensitive data types, run the following query:
    select sensitive_data.category,
        detections_data.type,
        sum(cast(detections_data.count as INT)) total_detections
    from maciedetail_all_jobs,
        unnest(classificationdetails.result.sensitiveData) as t(sensitive_data),
        unnest(sensitive_data.detections) as t(detections_data)
    where classificationdetails.result.sensitiveData is not null
    and resourcesaffected.s3object.embeddedfiledetails is null
    group by sensitive_data.category, detections_data.type
    order by total_detections desc
    LIMIT 5
    

    Running this query on the sample dataset gives the following output.

     

    Results of a query showing the five most common sensitive data types in the dataset

 

Figure 5: Results of a query showing the five most common sensitive data types in the dataset

  • (Optional) The previous query ran on all of the results available for Macie. You can further query which accounts have the greatest amount of sensitive data detected.
    select accountid,
        sum(cast(detections_data.count as INT)) total_detections
    from maciedetail_all_jobs,
        unnest(classificationdetails.result.sensitiveData) as t(sensitive_data),
        unnest(sensitive_data.detections) as t(detections_data)
    where classificationdetails.result.sensitiveData is not null
    and resourcesaffected.s3object.embeddedfiledetails is null
    group by accountid
    order by total_detections desc
    

    To test this query, we distributed the synthetic dataset across three member accounts in our organization, ran the query, and received the following output. If you enable Macie in just a single account, then you will only receive results for that one account.

     

    Figure 6: Query results for total number of sensitive data detections across all accounts in an organization

    Figure 6: Query results for total number of sensitive data detections across all accounts in an organization

   <p>For a list of more example queries, see the <a href="https://github.com/aws-samples/amazon-macie-results-analytics" target="_blank" rel="noopener">amazon-macie-results-analytics</a> GitHub repository.</p> 
   <h2>Step 3: Visualize the results with QuickSight</h2> 
   <p>In the previous step, you used Athena to query your Macie discovery results. Although the queries were powerful, they only produced tabular data as their output. In this step, you will use QuickSight to visualize the results of your Macie jobs.</p> 
   <p>Before creating the visualizations, you first need to grant QuickSight the right permissions to access Athena, the results bucket, and the KMS key that you used to encrypt the results.</p> 
   <p><strong>To allow QuickSight access to the KMS key</strong></p> 
   <ol> 
    <li>Open the <a href="https://console.aws.amazon.com/iamv2/" target="_blank" rel="noopener">AWS Identity and Access Management (IAM) console</a>, and then do the following: 
     <ol type="a"> 
      <li>In the navigation pane, choose <strong>Roles</strong>.</li> 
      <li>In the search pane for roles, search for <span>aws-quicksight-s3-consumers-role-v0</span>. If this role does not exist, search for <span>aws-quicksight-service-role-v0</span>.</li> 
      <li>Select the role and copy the role ARN. You will need this role ARN to modify the KMS key policy to grant permissions for this role.</li> 
     </ol> </li> 
    <li>Open the <a href="https://console.aws.amazon/kms" target="_blank" rel="noopener">AWS KMS console</a> and then do the following: 
     <ol type="a"> 
      <li>Select <strong>Customer managed keys</strong>.</li> 
      <li>Choose the KMS key that you created.</li> 
      <li>Paste the following statement in the key policy. When you add the statement, do not delete any existing statements, and make sure that the syntax is valid. Replace <code> </code>and <code></code> with your own information. Policies are in JSON format.</li> 
     </ol> </li> 
   </ol> 
   <div class="hide-language"> 
    <pre><code class="lang-text">   { "Sid": "Allow Quicksight Service Role to use the key",
    "Effect": "Allow",
    "Principal": {
        "AWS": <code></code>
    },
    "Action": "kms:Decrypt",
    "Resource": <code></code>
}

To allow QuickSight access to Athena and the discovery results S3 bucket

  1. In QuickSight, in the upper right, choose your user icon to open the profile menu, and choose US East (N.Virginia). You can only modify permissions in this Region.
  2. In the upper right, open the profile menu again, and select Manage QuickSight.
  3. Select Security & permissions.
  4. Under QuickSight access to AWS services, choose Manage.
  5. Make sure that the S3 checkbox is selected, click on Select S3 buckets, and then do the following:
    1. Choose the discovery results bucket.
    2. You do not need to check the box under Write permissions for Athena workgroup. The write permissions are not required for this post.
    3. Select Finish.
  6. Make sure that the Amazon Athena checkbox is selected.
  7. Review the selections and be careful that you don’t inadvertently disable AWS services and resources that other users might be using.
  8. Select Save.
  9. In QuickSight, in the upper right, open the profile menu, and choose the Region where your results bucket is located.

Now that you’ve granted QuickSight the right permissions, you can begin creating visualizations.

To create a new dataset referencing the Athena table

  1. On the QuickSight start page, choose Datasets.
  2. On the Datasets page, choose New dataset.
  3. From the list of data sources, select Athena.
  4. Enter a meaningful name for the data source (for example, macie_datasource) and choose Create data source.
  5. Select the database that you created in Athena (for example, macie_results).
  6. Select the table that you created in Athena (for example, maciedetail_all_jobs), and choose Select.
  7. You can either import the data into SPICE or query the data directly. We recommend that you use SPICE for improved performance, but the visualizations will still work if you query the data directly.
  8. To create an analysis using the data as-is, choose Visualize.

You can then visualize the Macie results in the QuickSight console. The following example shows a delegated Macie administrator account that is running a visualization, with account IDs on the y axis and the count of affected resources on the x axis.

Figure 7: Visualize query results to identify total number of sensitive data detections across accounts in an organization

Figure 7: Visualize query results to identify total number of sensitive data detections across accounts in an organization

You can also visualize the aggregated data in QuickSight. For example, you can view the number of findings for each sensitive data category in each S3 bucket. The Athena table doesn’t provide aggregated data necessary for visualization. Instead, you need to query the table and then visualize the output of the query.

To query the table and visualize the output in QuickSight

  1. On the Amazon QuickSight start page, choose Datasets.
  2. On the Datasets page, choose New dataset.
  3. Select the data source that you created in Athena (for example, macie_datasource) and then choose Create Dataset.
  4. Select the database that you created in Athena (for example, macie_results).
  5. Choose Use Custom SQL, enter the following query below, and choose Confirm Query.
     select resourcesaffected.s3bucket.name as bucket_name,
            sensitive_data.category,
            detections_data.type,
            sum(cast(detections_data.count as INT)) total_detections
        from macie_results.maciedetail_all_jobs,
            unnest(classificationdetails.result.sensitiveData) as t(sensitive_data),unnest(sensitive_data.detections) as t(detections_data)
    where classificationdetails.result.sensitiveData is not null
    and resourcesaffected.s3object.embeddedfiledetails is null
    group by resourcesaffected.s3bucket.name, sensitive_data.category, detections_data.type
    order by total_detections desc
        
  6. You can either import the data into SPICE or query the data directly.
  7. To create an analysis using the data as-is, choose Visualize.

Now you can visualize the output of the query that aggregates data across your S3 buckets. For example, we used the name of the S3 bucket to group the results, and then we created a donut chart of the output, as shown in Figure 6.

Figure 8: Visualize query results for total number of sensitive data detections across each S3 bucket in an organization

Figure 8: Visualize query results for total number of sensitive data detections across each S3 bucket in an organization

From the visualizations, we can identify which buckets or accounts in our organizations contain the most sensitive data, for further action. Visualizations can also act as a dashboard to track remediation.

If you encounter permissions issues, see Insufficient permissions when using Athena with Amazon QuickSight and Troubleshooting key access for troubleshooting steps.

You can replicate the preceding steps by using the sample queries from the amazon-macie-results-analytics GitHub repo to view data that is aggregated across S3 buckets, AWS accounts, or individual Macie jobs. Using these queries with the results of your Macie results will help you get started with tracking the security posture of your data in Amazon S3.

Conclusion

In this post, you learned how to enable sensitive data discovery results for Macie, query those results with Athena, and visualize the results in QuickSight.

Because Macie sensitive data discovery results provide more granular data than the findings, you can pursue a more comprehensive incident response when sensitive data is discovered. The sample queries in this post provide answers to some generic questions that you might have. After you become familiar with the structure, you can run other interesting queries on the data.

We hope that you can use this solution to write your own queries to gain further insights into sensitive data discovered in S3 buckets, according to the business needs and regulatory requirements of your organization. You can consider using this solution to better understand and identify data security risks that need immediate attention. For example, you can use this solution to answer questions such as the following:

  • Is financial information present in an AWS account where it shouldn’t be?
  • Are S3 buckets that contain PII properly hardened with access controls and encryption?

You can also use this solution to understand gaps in your data security initiatives by tracking files that Macie couldn’t analyze due to encryption or permission issues. To further expand your knowledge of Macie capabilities and features, see the following resources:

   <p>If you have feedback about this post, submit comments in the Comments section below. If you have questions about this post, start a new thread on <a href="https://repost.aws/tags/TA_J7v39UoTdiBWCAlEs2svA/amazon-macie" target="_blank" rel="noopener">Amazon Macie re:Post</a>.</p> 
   <p><strong>Want more AWS Security news? Follow us on <a href="https://twitter.com/AWSsecurityinfo" title="Twitter" target="_blank" rel="noopener noreferrer">Twitter</a>.</strong></p> 



   <!-- '"` -->