- Newest
- Most votes
- Most comments
Hello! I finally got the correct syntax from AWS Support. I needed to specify the catalog ID and use the string 'IAMPrincipals' in the Principal field
entries = [
{
'Id': f'ReadOnly-{database}-{table_name}',
'Principal': {'DataLakeIdentifier': f'{catalog_id}:IAMPrincipals'},
'Resource': {
'Table': {
'CatalogId': catalog_id,
'DatabaseName': database,
'Name': table_name
}
},
'Permissions': ['SELECT', 'DESCRIBE'],
# 'PermissionsWithGrantOption': ['SELECT', 'DESCRIBE'],
'Condition': {
'Expression': f'context.iam.principalTags.hasTag("{session_tag_key}") && context.iam.principalTags.getTag("{session_tag_key}") == "{session_tag_value}"'
}
}
]
answered a year ago
To grant permissions using attribute-based access control (ABAC) in AWS Lake Formation via Boto3, you need to make a few adjustments to your code.
When using ABAC in Lake Formation, you need to specify that you're using attribute-based access control by including a special principal type. Your current code is missing this specification.
Here's how you should structure your batch_grant_permissions call:
entries = [ { 'Id': f'ReadOnly-{database}-{table_name}', 'Principal': { 'DataLakePrincipalIdentifier': 'IAM_ALLOWED_PRINCIPALS' }, 'Resource': { 'Table': { 'DatabaseName': database, 'Name': table_name } }, 'Permissions': ['SELECT', 'DESCRIBE'], 'PermissionsWithGrantOption': ['SELECT', 'DESCRIBE'], 'Condition': { 'Expression': 'context.iam.principalTags.hasTag("accesMode") && context.iam.principalTags.getTag("accesMode") == "readOnly"' } } ] lf.batch_grant_permissions(CatalogId=account_id, Entries=entries)
Addressing you queries below:
->Do i have to set a Principal? Yes, you have to set a Principal.
->Is this the correct syntaxis? Yes, the syntax looks correct.
For your queries, you can refer to the document attached below. [+] https://docs.aws.amazon.com/lake-formation/latest/APIReference/API_GrantPermissions.html
As mentioned above, the key difference is setting the Principal with an Principal with DataLakePrincipalIdentifier set to 'IAM_ALLOWED_PRINCIPALS'. This special identifier is used when you're applying attribute-based conditions.
Your Cedar policy expression looks correct, checking if the principal has a tag "accesMode" with the value "readOnly".
Before implementing ABAC in Lake Formation, ensure you've completed these prerequisites:
- Updated the Data Catalog settings to enable Lake Formation permissions for Data Catalog objects
- Set the cross-account version settings to two or higher
- Attached the appropriate attributes (tags) to the IAM entities that require access
- Verified you have the required permissions to grant access on Data Catalog objects
With ABAC, any IAM principal with matching tag keys and values will automatically gain access to the resource, making permission management more efficient as your user base grows.
Sources
Prerequisites for granting permissions using attributes - AWS Lake Formation
Attribute-based access control - AWS Lake Formation
Granting permissions using attribute-based access control - AWS Lake Formation
Lake Formation examples using AWS CLI
[grant-permissions] (https://docs.aws.amazon.com/cli/latest/reference/lakeformation/grant-permissions.html)
Relevant content
- AWS OFFICIALUpdated 3 months ago
