Skip to content

Commit 2122461

Browse files
authored
chore(cognito-identitypool): update README to encourage least privilege (#31811)
### Issue # (if applicable) N/A ### Reason for this change To ensure customers are using the module securely, we want to encourage them to follow the best practice of the principal of least privilege. That is, customers are only providing as much access as necessary to complete the task, and no privileges greater than that. ### Description of changes * Updated the README to include sentences around the privilege and access granting sections encouraging only giving the least amount of privileges necessary. * Updated the README example to remove wildcard privilege. ### Description of how you validated changes `yarn rosetta:extract` passes. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b35adf1 commit 2122461

File tree

1 file changed

+7
-5
lines changed
  • packages/@aws-cdk/aws-cognito-identitypool-alpha

1 file changed

+7
-5
lines changed

Diff for: packages/@aws-cdk/aws-cognito-identitypool-alpha/README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ unauthenticated (guest) roles applied to the identity pool:
7474
new IdentityPool(this, 'myIdentityPool');
7575
```
7676

77-
By default, both the authenticated and unauthenticated roles will have no permissions attached. Grant permissions
77+
By default, both the authenticated and unauthenticated roles will have no permissions attached. When granting permissions,
78+
you should ensure that you are granting the least privileged permissions required for your use case. Grant permissions
7879
to roles using the public `authenticatedRole` and `unauthenticatedRole` properties:
7980

8081
```ts
@@ -88,11 +89,11 @@ table.grantReadWriteData(identityPool.authenticatedRole);
8889
// Grant permissions to unauthenticated guest users
8990
table.grantReadData(identityPool.unauthenticatedRole);
9091

91-
//Or add policy statements straight to the role
92+
// Or add policy statements straight to the role
9293
identityPool.authenticatedRole.addToPrincipalPolicy(new iam.PolicyStatement({
9394
effect: iam.Effect.ALLOW,
94-
actions: ['dynamodb:*'],
95-
resources: ['*'],
95+
actions: ['dynamodb:UpdateItem'],
96+
resources: [table.tableArn],
9697
}));
9798
```
9899

@@ -253,7 +254,8 @@ new IdentityPool(this, 'myidentitypool', {
253254

254255
In addition to setting default roles for authenticated and unauthenticated users, identity pools can also be used to
255256
define rules to choose the role for each user based on claims in the user's ID token by using Role Mapping. When using
256-
role mapping, it's important to be aware of some of the permissions the role will need. An in depth
257+
role mapping, it's important to be aware of some of the permissions the role will need, and that the least privileged
258+
roles necessary are given for your specific use case. An in depth
257259
review of roles and role mapping can be found [here](https://docs.aws.amazon.com/cognito/latest/developerguide/role-based-access-control.html).
258260

259261
Using a [token-based approach](https://docs.aws.amazon.com/cognito/latest/developerguide/role-based-access-control.html#using-tokens-to-assign-roles-to-users) to role mapping will allow mapped roles to be passed through the `cognito:roles` or

0 commit comments

Comments
 (0)