Granting permissions to IAM federated users - AWS Lake Formation
Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.

Granting permissions to IAM federated users

When users sign in through a SAML 2.0 or OpenID Connect (OIDC) identity provider in IAM, they assume IAM roles with AssumeRoleWithSAML or AssumeRoleWithWebIdentity. Enhanced trusted identity propagation is available for these users automatically. You don't need to connect Lake Formation with IAM Identity Center.

You can grant Lake Formation permissions to the following principals:

  • An individual user, by subject

  • A group

  • All users whose attributes match a condition, such as department=finance

You can also filter the rows that each user sees based on the user's attributes.

Prerequisites

Before you grant permissions to IAM federated users, complete the following prerequisites.

  1. Create a SAML 2.0 or OIDC identity provider in IAM for your IdP. For more information, see Create a SAML identity provider in IAM and Create an OpenID Connect (OIDC) identity provider in IAM in the IAM User Guide.

  2. Configure the identity provider to pass the user's identity and attributes to AWS. Choose the claim or SAML attribute that identifies the user, such as the user's email address. This value becomes the subject that Lake Formation matches. Add the attributes that you want to use in grants, such as department.

  3. Create the carrier role with a trust policy that allows sts:AssumeRoleWithSAML or sts:AssumeRoleWithWebIdentity from the identity provider. For more information, see Create a role for a third-party identity provider in the IAM User Guide. You don't need to add sts:SetContext to the trust policy of the carrier role or of any role that the request passes through.

  4. Register the Amazon S3 locations of your data with Lake Formation, and revoke the IAM_ALLOWED_PRINCIPALS group's permissions on the resources that you want to govern per user. For more information, see Adding an Amazon S3 location to your data lake.

  5. Confirm that the analytics engines your users use support enhanced trusted identity propagation. For more information, see Trusted identity propagation support.

Granting permissions to users and groups

To grant permissions to a user, set DataLakePrincipalIdentifier to user:subject. To grant permissions to a group, use group:group-name. You can grant permissions on named resources or with LF-Tag expressions.

The following example grants SELECT on all tables in the retail database to a user.

aws lakeformation grant-permissions \ --principal '{"DataLakePrincipalIdentifier": "user:mary_major@example.com"}' \ --permissions "SELECT" \ --resource '{"Table": {"DatabaseName": "retail", "TableWildcard": {}}}'

The following example grants SELECT on the tables that have the LF-Tag domain=sales to a group.

aws lakeformation grant-permissions \ --principal '{"DataLakePrincipalIdentifier": "group:data-analysts"}' \ --permissions "SELECT" \ --resource '{"LFTagPolicy": {"CatalogId": "111122223333", "ResourceType": "TABLE", "Expression": [{"TagKey": "domain", "TagValues": ["sales"]}]}}'

For all principal formats, see Specifying principals in Lake Formation.

Granting permissions based on user attributes

To grant permissions to every user whose attributes match a condition, grant the permissions to the IdpUsers principal and add a condition. The condition reads the user's attributes from context.idp.transactionContext.

The following example grants SELECT on a table to users whose department attribute is finance.

aws lakeformation grant-permissions \ --principal '{"DataLakePrincipalIdentifier": "IdpUsers"}' \ --permissions "SELECT" \ --resource '{"Table": {"CatalogId": "111122223333", "DatabaseName": "finance_db", "Name": "invoices"}}' \ --condition '{"Expression": "context has idp && context.idp.transactionContext.hasTag(\"department\") && context.idp.transactionContext.getTag(\"department\") == \"finance\""}'

You can combine a condition with an LF-Tag expression, so that access scales both with the resources that you tag and with the users whose attributes match. The following example grants SELECT on the tables that have the LF-Tag domain=sales to users whose department attribute is sales.

aws lakeformation grant-permissions \ --principal '{"DataLakePrincipalIdentifier": "IdpUsers"}' \ --permissions "SELECT" \ --resource '{"LFTagPolicy": {"CatalogId": "111122223333", "ResourceType": "TABLE", "Expression": [{"TagKey": "domain", "TagValues": ["sales"]}]}}' \ --condition '{"Expression": "context has idp && context.idp.transactionContext.hasTag(\"department\") && context.idp.transactionContext.getTag(\"department\") == \"sales\""}'

When you write a condition, follow these rules:

  • Start the expression with context has idp.

  • Before each getTag, check that the attribute exists with hasTag on the same key. Otherwise, Lake Formation rejects the grant with the error Unsupported condition expression.

  • Use the attribute key exactly as your IdP sends it. Keys are case sensitive.

Grants with a condition have the following limits:

  • You can't include the grant option. Users who receive permissions through a grant with a condition can't grant those permissions to other principals.

  • A grant on a table doesn't give DESCRIBE on the table's database. Grant DESCRIBE on the database separately.

Warning

If you grant permissions to IdpUsers without a condition, every IdP user who can assume a role in your account receives the permissions.

Filtering rows based on user attributes

With a row-level security policy, you can filter rows based on a user's attributes at query time, so one policy returns different rows to each user. For example, the following filter expression returns only the rows where the department column matches the user's department attribute.

department = ${idp.department}

To read an attribute, use ${idp.attribute-key}, where attribute-key is the attribute name exactly as your IdP sends it. The attribute values must match the values in the filter column of the table. You can combine the policy with LF-Tag expressions and with grants based on user attributes. For example, grant SELECT on tables that have an LF-Tag to users whose department attribute matches, and attach a policy that filters rows by the same attribute.

Limitations on IAM federated users and row-level security

You can attach row-level security policies only to all IdP users (IdpUsers) or to specific IdP users (user:). You can't attach row-level security policies to IdpUsers grants with a condition on user attributes.

For more information about row-level security policies, see Attaching and detaching RLS policies.