

# Security and data governance for usage system tables

You control who can read the Amazon SageMaker Unified Studio usage system tables and how long their data is kept. Amazon SageMaker Unified Studio doesn't apply read permissions or mask data for you.

## Configuring retention
<a name="usage-system-tables-security-retention"></a>

When Amazon SageMaker Unified Studio creates a usage system table, it sets an S3 Tables record expiration of 365 days on `snapshot_time`. Amazon S3 Tables automatically removes rows whose `snapshot_time` is older than that.

You can change the expiration for each table. Amazon SageMaker Unified Studio doesn't reset your setting when the integration is turned on again or the tables are set up again. When you turn off the integration, data that was already delivered stays in S3 Tables and keeps following the expiration that you set. For more information, see [Record expiration for tables](https://docs.aws.amazon.com/AmazonS3/latest/userguide/s3-tables-record-expiration.html) in the *Amazon S3 User Guide*.

## Encryption at rest
<a name="usage-system-tables-security-encryption"></a>

The usage system tables use the same encryption as the domain. You don't specify a separate key.
+ If the domain uses an AWS owned key, the tables are encrypted with Amazon S3 managed keys (SSE-S3).
+ If the domain uses a customer managed AWS Key Management Service (AWS KMS) key, the tables are encrypted with that key (SSE-KMS).

The tables' encryption is set when they're created and can't be changed.

## Key management
<a name="usage-system-tables-security-key-management"></a>

If the domain uses a customer managed key, its key policy must allow two service principals to use the key. The Amazon SageMaker Unified Studio system tables service principal uses it to write your tables, and the S3 Tables maintenance service principal uses it during table maintenance. Add the following statements to the key policy. Replace {{my-partition}} with your AWS partition (for example, `aws`), {{my-region}} with your Region, {{111122223333}} with your AWS account ID, and {{my-key-id}} with your AWS KMS key ID.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "EnableSageMakerSystemTablesKeyUsage",
      "Effect": "Allow",
      "Principal": {
        "Service": "systemtables.sagemaker-catalog.amazonaws.com"
      },
      "Action": [
        "kms:DescribeKey",
        "kms:GenerateDataKey",
        "kms:Decrypt"
      ],
      "Resource": "arn:{{my-partition}}:kms:{{my-region}}:{{111122223333}}:key/{{my-key-id}}",
      "Condition": {
        "StringEquals": {
          "aws:SourceAccount": "{{111122223333}}"
        }
      }
    },
    {
      "Sid": "EnableS3TablesMaintenanceKeyUsage",
      "Effect": "Allow",
      "Principal": {
        "Service": "maintenance.s3tables.amazonaws.com"
      },
      "Action": [
        "kms:GenerateDataKey",
        "kms:Decrypt"
      ],
      "Resource": "arn:{{my-partition}}:kms:{{my-region}}:{{111122223333}}:key/{{my-key-id}}",
      "Condition": {
        "StringLike": {
          "kms:EncryptionContext:aws:s3:arn": "arn:{{my-partition}}:s3tables:{{my-region}}:{{111122223333}}:bucket/aws-sagemaker-unified-studio/*"
        }
      }
    }
  ]
}
```

If the key policy doesn't include these statements, turning on the integration fails with `KMS_KEY_ACCESS_DENIED`.

AWS manages the table bucket's resource policy, which names `systemtables.sagemaker-catalog.amazonaws.com` as the writer. You can read the policy, but you can't change it.

## Access control
<a name="usage-system-tables-security-access-control"></a>

After you integrate the table bucket with the AWS Glue Data Catalog, govern read access with IAM or AWS Lake Formation. Because each domain has its own namespace, you can grant access for each domain separately.

When the admin project's role is a Lake Formation administrator, the Domain and project usage dashboard grants that role `DESCRIBE` and `SELECT` on the domain's usage tables, and on no other tables. It doesn't grant access to any other principal.

## Sensitive data
<a name="usage-system-tables-security-sensitive"></a>

The `user_profile` table contains personal information: `user_name`, `email`, and `iam_principal_arn`. The `domain_entity` table contains names and descriptions that people in your organization wrote. With Lake Formation, you can use column-level permissions, for example to share `user_profile` without `email` and `user_name`.

## Best practices for usage system tables
<a name="usage-system-tables-security-best-practices"></a>

Follow these practices to keep the data secure and your query results correct:
+ **Restrict access to `user_profile`**: Treat it as personal data. Grant `SELECT` only to the principals that need it, and consider column-level permissions.
+ **Filter on `snapshot_time`**: Every snapshot is a full copy of the inventory. Filtering to the latest snapshot or a date range keeps results correct and avoids scanning all history.
+ **Join on IDs, not names**: Names such as `entity_name`, `domain_name`, `owning_project_name`, and `domain_unit_name` can change. Group and join on the matching ID columns, and use names for display only.
+ **Pair `status_enum` with `category_enum`**: The same status can mean different things in different categories.
+ **Set retention to match your requirements**: The default is 365 days. Increase it for longer trend history, or reduce it to lower storage costs.