Grant access in the source account
In the source account, grant the Agent Context account’s roles access to the source.
Before you begin, get the ARNs of the ingestion role and of the identity that reads the source from the Agent Context account (see Set up the connection in the Agent Context account). That identity is the caller’s IAM role or the connection’s data access role. The roles must exist before you reference them in a policy.
AWS Glue Data Catalog sources
In the following examples, ContextQueryRole is the identity that reads the source: the caller’s IAM role or the connection’s data access role (see Cross-account access). 111122223333 is the source account, and 444455556666 is the Agent Context account. Replace these values, the Region, and the resource names with your own.
Sources that support real-time retrieval also need the additional grants after these steps. To grant access for all AWS Glue Data Catalog sources, complete the following steps:
-
Add the following statements to the AWS Glue Data Catalog resource policy in the source account:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ContextReadAccess", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextQueryRole" }, "Action": [ "glue:GetCatalog", "glue:GetDatabase", "glue:GetDatabases", "glue:GetTable", "glue:GetTables", "glue:GetPartitions", "glue:GetConnection", "glue:GetConnections" ], "Resource": [ "arn:aws:glue:us-east-1:111122223333:catalog", "arn:aws:glue:us-east-1:111122223333:catalog/*", "arn:aws:glue:us-east-1:111122223333:database/*", "arn:aws:glue:us-east-1:111122223333:table/*", "arn:aws:glue:us-east-1:111122223333:connection/*" ] }, { "Sid": "ContextIngestionSendMetadata", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextIngestionRole" }, "Action": "glue:SendMetadata", "Resource": [ "arn:aws:glue:us-east-1:111122223333:catalog", "arn:aws:glue:us-east-1:111122223333:catalog/*" ] } ] }The
ContextReadAccessstatement grants that identity read access to the catalog. List the identity that reads the source for each connection that reads this catalog. TheContextIngestionSendMetadatastatement grants the ingestion role permission to send metadata to AWS Context.(Optional) To browse the source account’s resources when you create a connection in the console, add the following statements. Name the role that you use in the console, shown here as
ContextConsoleRole. TheContextConsoleDiscoverystatement lists catalog assets. Keep it in its own statement, and use only the root catalog ARN as its resource. TheContextConsoleConnectionsstatement lists the source account’s AWS Glue connections in the console’s connection picker, for example, when you set up real-time retrieval for DynamoDB:{ "Sid": "ContextConsoleDiscovery", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextConsoleRole" }, "Action": [ "glue:SearchAssets", "glue:GetAsset" ], "Resource": "arn:aws:glue:us-east-1:111122223333:catalog" }, { "Sid": "ContextConsoleConnections", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextConsoleRole" }, "Action": [ "glue:GetConnections", "glue:GetConnection" ], "Resource": [ "arn:aws:glue:us-east-1:111122223333:catalog", "arn:aws:glue:us-east-1:111122223333:connection/*" ] } -
Apply the policy.
PutResourcePolicyreplaces the entire policy, so merge your statements into the existing one:-
Get the current policy and its hash:
aws glue get-resource-policy -
Add the statements to the
Statementarray of the current policy, and save the result to a file. -
Write the merged policy back:
aws glue put-resource-policy \ --policy-in-json file://merged-policy.json\ --policy-hash-conditionpolicy-hash\ --policy-exists-condition MUST_EXIST \ --enable-hybrid TRUEIf someone changes the policy after you read it, the call fails. In that case, repeat these steps. An AWS Glue Data Catalog resource policy can be up to 10 KB. Plan for this when you share one catalog with many Agent Context accounts.
-
Additional grants for AWS Glue Data Catalog tables
For real-time retrieval, add the following policy to the Amazon S3 buckets that store the table data. You don’t need this policy if AWS Lake Formation manages the database or its tables:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ContextReadAccess", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextQueryRole" }, "Action": [ "s3:GetObject", "s3:ListBucket", "s3:GetBucketLocation" ], "Resource": [ "arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*" ] } ] }
If AWS Lake Formation manages the database or its tables, the bucket policy isn’t used. AWS Lake Formation provides the credentials instead. As an AWS Lake Formation administrator in the source account, grant that identity DESCRIBE on the database, and DESCRIBE and SELECT on its tables. Run the following commands:
aws lakeformation grant-permissions \ --principal DataLakePrincipalIdentifier=arn:aws:iam::444455556666:role/ContextQueryRole\ --permissions DESCRIBE \ --resource '{"Database":{"CatalogId":"111122223333","Name":"databaseName"}}' aws lakeformation grant-permissions \ --principal DataLakePrincipalIdentifier=arn:aws:iam::444455556666:role/ContextQueryRole\ --permissions DESCRIBE SELECT \ --resource '{"Table":{"CatalogId":"111122223333","DatabaseName":"databaseName","TableWildcard":{}}}'
Additional grants for Amazon S3 Tables
To give AWS Context access to Amazon S3 Tables in the source account, complete both of the following steps:
-
Add the following policy to the table bucket. Apply it with
aws s3tables put-table-bucket-policy:{ "Version": "2012-10-17", "Statement": [ { "Sid": "ContextReadTableBucket", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextQueryRole" }, "Action": [ "s3tables:GetTableBucket", "s3tables:GetNamespace", "s3tables:ListNamespaces", "s3tables:ListTables", "s3tables:GetTable", "s3tables:GetTableMetadataLocation", "s3tables:GetTableData" ], "Resource": [ "arn:aws:s3tables:us-east-1:111122223333:bucket/amzn-s3-demo-table-bucket", "arn:aws:s3tables:us-east-1:111122223333:bucket/amzn-s3-demo-table-bucket/table/*" ] } ] } -
As an AWS Lake Formation administrator in the source account, grant the identity that reads the source permission to read the table bucket’s namespace and tables. You must create these grants even if you use the
IAM_ALLOWED_PRINCIPALSpermission mode. Run the following commands:aws lakeformation grant-permissions \ --principal DataLakePrincipalIdentifier=arn:aws:iam::444455556666:role/ContextQueryRole\ --permissions DESCRIBE \ --resource '{"Database":{"CatalogId":"111122223333:s3tablescatalog/amzn-s3-demo-table-bucket","Name":"namespaceName"}}' aws lakeformation grant-permissions \ --principal DataLakePrincipalIdentifier=arn:aws:iam::444455556666:role/ContextQueryRole\ --permissions DESCRIBE SELECT \ --resource '{"Table":{"CatalogId":"111122223333:s3tablescatalog/amzn-s3-demo-table-bucket","DatabaseName":"namespaceName","TableWildcard":{}}}'
Additional grants for Amazon DynamoDB
You don’t need these grants for metadata ingestion. For real-time retrieval, create a DYNAMODB
AWS Glue connection that uses IAM authentication. Then add the following resource policy to each table with aws dynamodb put-resource-policy:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ContextReadAccess", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextQueryRole" }, "Action": [ "dynamodb:DescribeTable", "dynamodb:Scan", "dynamodb:Query", "dynamodb:GetItem", "dynamodb:PartiQLSelect" ], "Resource": "arn:aws:dynamodb:us-east-1:111122223333:table/tableName" } ] }
If you encrypt a DynamoDB table with a key other than the default AWS owned key, use a customer managed AWS KMS key. Cross-account queries don’t work with the AWS managed key for DynamoDB (aws/dynamodb).
Additional grants for databases that use Secrets Manager
You don’t need these grants for metadata ingestion. For real-time retrieval, the source account needs an AWS Glue connection for the database. The connection must authenticate with an AWS Secrets Manager secret instead of IAM authentication. Encrypt the secret with a customer managed AWS KMS key. You can’t share the AWS managed key for Secrets Manager (aws/secretsmanager) with another account.
To grant access to the secret, complete the following steps:
-
Attach the following resource policy to the secret:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ContextReadSecret", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextQueryRole" }, "Action": [ "secretsmanager:GetSecretValue", "secretsmanager:DescribeSecret" ], "Resource": "*" } ] } -
Add the following statement to the key policy of the secret’s customer managed key. Keep the key’s existing statements:
{ "Sid": "ContextDecryptViaSecretsManager", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextQueryRole" }, "Action": [ "kms:Decrypt", "kms:DescribeKey" ], "Resource": "*", "Condition": { "StringEquals": { "kms:ViaService": "secretsmanager.us-east-1.amazonaws.com" } } }
Stop sharing
To stop sharing, remove the grants that you added:
-
Remove the
ContextReadAccessandContextIngestionSendMetadatastatements, and any console statements, from the AWS Glue Data Catalog resource policy. -
Remove the additional grants that you added for your source type: the bucket policy, table bucket policy, AWS Lake Formation grants, DynamoDB table policy, or secret and key policy statements.
Amazon Bedrock Managed Knowledge Bases
In the source account, add statements to the knowledge base’s resource policy for the ingestion role and the identity that reads the source. In the following examples, ContextQueryRole is the identity that reads the source: the caller’s IAM role or the connection’s data access role (see Cross-account access). 111122223333 is the source account, 444455556666 is the Agent Context account, and KB12345678 is the knowledge base ID. Replace these values and the Region with your own.
To share the knowledge base, complete the following steps:
-
Add the following statements to the knowledge base’s resource policy:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "ContextIngestion", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextIngestionRole" }, "Action": "bedrock:SendKnowledgeBaseEntities", "Resource": "arn:aws:bedrock:us-east-1:111122223333:knowledge-base/KB12345678" }, { "Sid": "ContextReadKnowledgeBase", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::444455556666:role/ContextQueryRole" }, "Action": [ "bedrock:Retrieve", "bedrock:GetDocumentContent", "bedrock:GetKnowledgeBase" ], "Resource": "arn:aws:bedrock:us-east-1:111122223333:knowledge-base/KB12345678" } ] }You can grant either statement without the other:
-
The
ContextIngestionstatement grants the ingestion role permission to send the knowledge base’s content to AWS Context. It grants no read access to the knowledge base. -
The
ContextReadKnowledgeBasestatement grants that identity access to the knowledge base. You needbedrock:GetKnowledgeBasewhen you create the connection, andbedrock:Retrieveandbedrock:GetDocumentContentfor retrieval.
-
-
Apply the policy with
aws bedrock-agent put-resource-policy. The call replaces the entire policy, so merge your statements into the existing one:-
Get the current policy and its revision ID.
-
Add the two statements to the
Statementarray of the current policy. -
Write the merged policy back, and pass the revision ID. If someone changes the policy after you read it, the call fails. In that case, repeat these steps.
-
The following limits apply:
-
The knowledge base must be an active Amazon Bedrock Managed Knowledge Base. Other knowledge base types don’t support resource policies.
-
The knowledge base and the Agent Context must be in the same Region.
To stop sharing, remove the two statements from the knowledge base policy.