

# Security for integrations with Amazon S3 Tables

**Important**  
This is preview documentation for the Aurora PostgreSQL integration with Amazon S3 Tables. Before using this capability, review the Betas and Previews terms in the [AWS Service Terms](https://aws.amazon.com/service-terms/).

Security for an Aurora PostgreSQL integration with Amazon S3 Tables covers how the replicated data is encrypted and which permissions the integration needs on the target table bucket. It also covers how you control access to the replicated tables. You control access to the replicated tables with AWS Identity and Access Management (IAM), separately from your Aurora database permissions.

**Topics**
+ [Data protection and encryption](#s3tables-integration.security.encryption)
+ [Identity and access management](#s3tables-integration.security.iam)
+ [Table bucket resource policy](#s3tables-integration.security.bucket-policy)
+ [Cross-account access](#s3tables-integration.security.cross-account)
+ [Best practices for IAM and bucket policies](#s3tables-integration.security.iam-best-practices)
+ [Namespace-level access control and Lake Formation](#s3tables-integration.security.namespaces)

## Data protection and encryption
<a name="s3tables-integration.security.encryption"></a>

An integration encrypts data with an AWS owned key or a customer managed AWS Key Management Service (AWS KMS) key. If you use AWS owned keys, you don't need a key policy. If you use customer managed keys, each key policy must allow the integration to use the key. Up to three keys can be involved:
+ The key that encrypts the integration.
+ The key of the source DB cluster.
+ The key of the target table bucket.

**Topics**
+ [Customer managed key for the integration](#s3tables-integration.security.integration-key)
+ [Customer managed key for the source DB cluster](#s3tables-integration.security.cluster-key)
+ [Customer managed key for the target table bucket](#s3tables-integration.security.bucket-key)

### Customer managed key for the integration
<a name="s3tables-integration.security.integration-key"></a>

When you create an integration with a customer managed key (`--kms-key-id`), Amazon RDS creates grants on the key with the credentials of the identity that calls `create-integration`. For the option, see [Encrypting the integration with a customer managed key](s3tables-integration.creating.md#s3tables-integration.creating.encryption).

Add the statements from the following examples to the `Statement` array of a single key policy for the integration key. Include the key administration and key use statements. The deny statements are optional. Replace 111122223333 with your AWS account ID.

Key administration  
This statement lets identities in your account administer the key. It deliberately doesn't allow `kms:CreateGrant`, `kms:DescribeKey`, or any cryptographic operation.  

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowKeyAdministration",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
      "Action": [
        "kms:GetKeyPolicy", "kms:PutKeyPolicy", "kms:ListGrants", "kms:ListResourceTags",
        "kms:RevokeGrant", "kms:RetireGrant", "kms:EnableKey", "kms:DisableKey",
        "kms:TagResource", "kms:UntagResource", "kms:UpdateKeyDescription",
        "kms:ScheduleKeyDeletion", "kms:CancelKeyDeletion"
      ],
      "Resource": "*"
    }
  ]
}
```

Key use through Amazon RDS  
These statements let your account call `kms:CreateGrant` and `kms:DescribeKey` on the key only through Amazon RDS (`kms:ViaService` matches `*rds*`). They don't name a service principal. The `kms:GrantOperations` list limits the grants that Amazon RDS can create to the operations that the integration uses. The `*rds*` pattern matches any `kms:ViaService` value that contains `rds`. Published Aurora key policy examples use the narrower value `rds.{{aws-region}}.amazonaws.com`.  

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowRDSZeroEtlCreateGrantOnIntegrationKey",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
      "Action": "kms:CreateGrant",
      "Resource": "*",
      "Condition": {
        "Bool": { "kms:GrantIsForAWSResource": "true" },
        "StringLike": { "kms:ViaService": "*rds*" },
        "ForAllValues:StringEquals": {
          "kms:GrantOperations": [
            "Decrypt",
            "GenerateDataKey",
            "GenerateDataKeyWithoutPlaintext",
            "CreateGrant",
            "DescribeKey"
          ]
        }
      }
    },
    {
      "Sid": "AllowRDSZeroEtlDescribeIntegrationKey",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
      "Action": "kms:DescribeKey",
      "Resource": "*",
      "Condition": {
        "StringLike": { "kms:ViaService": "*rds*" }
      }
    }
  ]
}
```

Optional deny statements  
To limit access further, you can add the following statements. The first statement denies requests that AWS services make on your behalf, called forward access sessions (FAS), unless they come through a service that is integrated with AWS KMS (`kms:ViaService`). The second statement denies requests from principals outside your account that aren't AWS services.  

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "DenyFASRequestsWithoutViaService",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "kms:*",
      "Resource": "*",
      "Condition": {
        "Bool": { "aws:ViaAWSService": "true" },
        "Null": { "kms:ViaService": "true" }
      }
    },
    {
      "Sid": "DenyCrossAccountAccessExceptViaAWSService",
      "Effect": "Deny",
      "Principal": "*",
      "Action": "kms:*",
      "Resource": "*",
      "Condition": {
        "StringNotEquals": { "aws:PrincipalAccount": "${aws:ResourceAccount}" },
        "Bool": { "aws:PrincipalIsAWSService": "false" }
      }
    }
  ]
}
```

If the key policy denies the caller's use of the key through Amazon RDS, `create-integration` fails with `KMSKeyNotAccessibleFault`. The error message includes the key's Amazon Resource Name (ARN).

Grants on the integration key  
When you create the integration, Amazon RDS creates three named grants on the key:  
+ `zero-etl-s3t-staging-source-`
+ `zero-etl-s3t-staging-target-`
+ `zero-etl-s3t-ebs-`
While the integration is active, more grants appear on the key. Each of them requests only operations from the `kms:GrantOperations` list in the key policy: `Decrypt`, `GenerateDataKey`, `GenerateDataKeyWithoutPlaintext`, `CreateGrant`, and `DescribeKey`.  
Only the `zero-etl-s3t-staging-source-` grant has an encryption context constraint: `aws:servicename:id` = `s3tables` and `aws:s3tables:integration:arn` = the integration ARN. The other two named grants have no constraint. When you delete the integration, Amazon RDS removes the three named grants from the key.

Revoking grants  
If you revoke all of the integration's grants on the key while the integration is active, the integration enters the `failed` status. For more information, see [My integration has a status of `failed`](s3tables-integration.troubleshooting.md#s3tables-integration.troubleshooting.failed).

### Customer managed key for the source DB cluster
<a name="s3tables-integration.security.cluster-key"></a>

If your source DB cluster is encrypted with a customer managed key, `create-integration` checks that the caller can use that key: `kms:DescribeKey`, a `kms:Decrypt` dry run, and `kms:CreateGrant`. The following key policy works with an integration. Replace 111122223333 with your AWS account ID, and {{cluster-ABCDEFGHIJKL0123456789}} with the resource ID of your DB cluster (`DbClusterResourceId`).

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowKeyAdministration",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
      "Action": [
        "kms:GetKeyPolicy", "kms:PutKeyPolicy", "kms:ListGrants", "kms:ListResourceTags",
        "kms:RevokeGrant", "kms:RetireGrant", "kms:EnableKey", "kms:DisableKey",
        "kms:TagResource", "kms:UntagResource", "kms:UpdateKeyDescription",
        "kms:ScheduleKeyDeletion", "kms:CancelKeyDeletion"
      ],
      "Resource": "*"
    },
    {
      "Sid": "AllowRDSZeroEtlDescribeSourceClusterKey",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
      "Action": "kms:DescribeKey",
      "Resource": "*",
      "Condition": {
        "StringLike": { "kms:ViaService": "*rds*" }
      }
    },
    {
      "Sid": "AllowRDSZeroEtlDecryptWithSourceClusterKey",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
      "Action": "kms:Decrypt",
      "Resource": "*",
      "Condition": {
        "StringLike": { "kms:ViaService": "*rds*" },
        "StringEquals": { "kms:EncryptionContext:aws:rds:dbc-id": "{{cluster-ABCDEFGHIJKL0123456789}}" }
      }
    },
    {
      "Sid": "AllowRDSZeroEtlCreateGrantOnSourceClusterKey",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
      "Action": "kms:CreateGrant",
      "Resource": "*",
      "Condition": {
        "Bool": { "kms:GrantIsForAWSResource": "true" },
        "StringLike": { "kms:ViaService": "*rds*" },
        "ForAllValues:StringEquals": {
          "kms:GrantOperations": [
            "Encrypt",
            "Decrypt",
            "GenerateDataKey",
            "GenerateDataKeyWithoutPlaintext",
            "ReEncryptFrom",
            "ReEncryptTo",
            "CreateGrant",
            "DescribeKey",
            "RetireGrant"
          ]
        }
      }
    }
  ]
}
```

Grant on the source cluster key  
When you create the integration, Amazon RDS creates the following grant on the source cluster key. During a full sync, more grants appear on the key, and Amazon RDS retires them when the full sync finishes. When you delete the integration, Amazon RDS removes the grant.  
The following table describes the grant.  


<table>
<thead>
  <tr><th>Grant name</th><th>Operations</th><th>Encryption context constraint</th></tr>
</thead>
<tbody>
  <tr><td><code>CustomerId:</code>…<code>:DbClusterResourceId:</code>…<code>:IntegrationId:</code>…<code>:ExportSourceKey</code></td><td><code>Encrypt</code>, <code>Decrypt</code>, <code>GenerateDataKey</code>, <code>GenerateDataKeyWithoutPlaintext</code>, <code>ReEncryptFrom</code>, <code>ReEncryptTo</code>, <code>CreateGrant</code>, <code>DescribeKey</code>, <code>RetireGrant</code></td><td>None</td></tr>
</tbody>
</table>

The `kms:GrantOperations` list in the `AllowRDSZeroEtlCreateGrantOnSourceClusterKey` statement contains exactly these operations.

### Customer managed key for the target table bucket
<a name="s3tables-integration.security.bucket-key"></a>

Your target table bucket can use server-side encryption with AWS KMS keys (SSE-KMS) with a customer managed key. In that case, the key policy must allow Amazon S3 Tables maintenance and the integration to use the key. The following key policy works with an integration. Replace the values as follows:
+ In `AllowKeyAdministration` and `EnableAccountRoot`, use the ID of the account that owns the key.
+ In `aws:SourceArn`, use the ARN of your source DB cluster. The ARN contains the ID of the account that owns the source DB cluster.

If the source DB cluster, the table bucket, and the key are in one account, every value uses the same account ID.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowKeyAdministration",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
      "Action": [
        "kms:GetKeyPolicy", "kms:PutKeyPolicy", "kms:ListGrants", "kms:ListResourceTags",
        "kms:RevokeGrant", "kms:RetireGrant", "kms:EnableKey", "kms:DisableKey",
        "kms:TagResource", "kms:UntagResource", "kms:UpdateKeyDescription",
        "kms:ScheduleKeyDeletion", "kms:CancelKeyDeletion"
      ],
      "Resource": "*"
    },
    {
      "Sid": "EnableAccountRoot",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:root" },
      "Action": ["kms:Decrypt", "kms:GenerateDataKey", "kms:DescribeKey"],
      "Resource": "*"
    },
    {
      "Sid": "EnableS3TablesMaintenance",
      "Effect": "Allow",
      "Principal": {
        "Service": "maintenance.s3tables.amazonaws.com"
      },
      "Action": ["kms:GenerateDataKey", "kms:Decrypt"],
      "Resource": "*"
    },
    {
      "Sid": "AllowZeroEtlServicePrincipalsForSourceCluster",
      "Effect": "Allow",
      "Principal": {
        "Service": ["export.rds.amazonaws.com"]
      },
      "Action": ["kms:GenerateDataKey", "kms:Decrypt", "kms:DescribeKey"],
      "Resource": "*",
      "Condition": {
        "ArnEquals": {
          "aws:SourceArn": "arn:aws:rds:{{aws-region}}:111122223333:cluster:{{my-source-cluster}}"
        }
      }
    }
  ]
}
```

The `EnableAccountRoot` statement lets IAM policies in your account grant use of the key, for example `kms:Decrypt` and `kms:GenerateDataKey` for the principals that query the tables. Without it, IAM policies that allow access to the key have no effect. For more information, see [Allows access to the AWS account and enables IAM policies](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-default.html#key-policy-default-allow-root-enable-iam) in the *AWS Key Management Service Developer Guide*. In IAM policies, grant `kms:Decrypt` and `kms:GenerateDataKey` on the key only to the principals that need to query the tables.

With this policy, the tables from the initial full sync and the tables that the integration creates later are encrypted with the table bucket key. The `aws:SourceArn` condition names the source DB cluster. A `Deny` statement for `kms:GenerateDataKey` and `kms:Decrypt` with the same `aws:SourceArn` condition makes the integration enter the `failed` status.

## Identity and access management
<a name="s3tables-integration.security.iam"></a>

You do not create or attach an IAM role for the integration. The integration reaches your resources as follows:
+ **Integration key:** Through grants that Amazon RDS creates on the key when you create the integration. For more information, see [Customer managed key for the integration](#s3tables-integration.security.integration-key).
+ **Target table bucket:** Through the table bucket resource policy, which allows the service principal `export.rds.amazonaws.com`. For the policy, see [Creating the table bucket and resource policy](zero-etl.setting-up.md#s3tables-integration.setting-up.bucket-policy).
+ **Table bucket key:** If the table bucket uses SSE-KMS with a customer managed key, through the key policy. For more information, see [Customer managed key for the target table bucket](#s3tables-integration.security.bucket-key).

For the permissions that the identity that creates the integration needs, see [Required permissions](s3tables-integration.creating.md#s3tables-integration.creating.permissions).

## Table bucket resource policy
<a name="s3tables-integration.security.bucket-policy"></a>

The resource policy of the target table bucket must allow the integration's service principal, `export.rds.amazonaws.com`, to act on the table bucket and its tables. The integration's requests to the table bucket carry the ARN of the source DB cluster as `aws:SourceArn` and the cluster's account as `aws:SourceAccount`. With these condition keys, the policy can limit the service principal to integrations from one source DB cluster. For the policy and the steps to attach it, see [Creating the table bucket and resource policy](zero-etl.setting-up.md#s3tables-integration.setting-up.bucket-policy).

Table bucket resource policies accept only `s3tables:` actions. A `Deny` statement for the service principal with the same `aws:SourceArn` condition makes `create-integration` fail for that source DB cluster.

## Cross-account access
<a name="s3tables-integration.security.cross-account"></a>

The source DB cluster and the target table bucket can be in different AWS accounts if both are in the same AWS Region. When they are, both accounts must allow the replication actions. In the bucket resource policy, `aws:SourceAccount` and `aws:SourceArn` name the source account, not the table bucket owner's account. For the steps, see [Using a table bucket in another account](zero-etl.setting-up.md#s3tables-integration.setting-up.cross-account).

## Best practices for IAM and bucket policies
<a name="s3tables-integration.security.iam-best-practices"></a>

Follow these practices for the policies that give access to the table bucket:
+ Grant the service principal only the actions in [Creating the table bucket and resource policy](zero-etl.setting-up.md#s3tables-integration.setting-up.bucket-policy), and avoid wildcard actions.
+ Scope the resource ARNs to the specific table bucket and its tables, not to all Amazon S3 Tables resources in the account.
+ Regularly review the table bucket resource policy and any IAM policies that use the `s3tables:namespace` condition key, especially after you add or remove integrations that share the table bucket.

## Namespace-level access control and Lake Formation
<a name="s3tables-integration.security.namespaces"></a>

Aurora creates one namespace for each source database, with a name that you know before you create the integration. For how namespaces are named, see [Namespace and table names](s3tables-integration.data-organization.md#s3tables-integration.data-organization.names).

You can set IAM permissions for each namespace, which gives fine-grained control similar to database-level permissions in PostgreSQL. A table's ARN identifies the table bucket and a table ID. The namespace is not part of the ARN, and the table ID is not derived from the table or namespace name. To scope a policy to one namespace, use the `s3tables:namespace` condition key.

For example, the following identity-based policy lets a principal read the tables in the namespace `sales_replica_postgres` and no other namespace in the table bucket.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "ReadOneNamespace",
      "Effect": "Allow",
      "Action": [
        "s3tables:GetTable",
        "s3tables:GetTableMetadataLocation",
        "s3tables:GetTableData"
      ],
      "Resource": "arn:aws:s3tables:{{aws-region}}:111122223333:bucket/{{my-table-bucket}}/table/*",
      "Condition": {
        "StringEquals": { "s3tables:namespace": "{{sales_replica_postgres}}" }
      }
    }
  ]
}
```

To query through AWS analytics services such as Amazon Athena, the principal also needs AWS Glue Data Catalog permissions. If you use Lake Formation access control, grant Lake Formation permissions on the namespace instead.

After you turn on the table bucket's integration with AWS analytics services (a table bucket setting, separate from the Aurora integration), each namespace appears as an AWS Glue Data Catalog database. Lake Formation permissions and governance then apply to the replicated tables without extra catalog setup; you still grant Lake Formation permissions to the principals that query them. For more information, see [Managed target tables](s3tables-integration.data-organization.md#s3tables-integration.data-organization.managed).

Users cannot write to the target tables, regardless of the permissions you grant. However, users with delete permissions can delete a table, a namespace, or the table bucket, and these actions are destructive. Grant `s3tables:DeleteTable`, `s3tables:DeleteNamespace`, and `s3tables:DeleteTableBucket` only to the people who need them.

Deleting target tables and namespaces  
Aurora manages the target tables and namespaces. If you delete a target table, the integration's per-table status for that table changes to `FAILED` with the reason `TARGET_TABLE_DELETED`, and the other tables keep replicating. To restore the table, resync that table. For more information, see [Per-table status](s3tables-integration.monitoring.md#s3tables-integration.monitoring.per-table-status).  
If you delete all the tables in a namespace and then delete the namespace, resync the whole integration to restore the namespace. The resync recreates the namespace and its tables and reloads the data from the source DB cluster. For more information, see [Resyncing integrations with Amazon S3 Tables](s3tables-integration.resyncing.md).