|
| 1 | +# RLS generator for QuickSight |
| 2 | + |
| 3 | +## About QS RLS generator |
| 4 | +Generate RLS csv file for QuickSight based on AWS Organizational Units. |
| 5 | + |
| 6 | +[About QuickSight RLS](https://docs.aws.amazon.com/quicksight/latest/user/restrict-access-to-a-data-set-using-row-level-security.html) |
| 7 | +[About AWS Organizational Unit ](https://docs.aws.amazon.com/organizations/latest/userguide/orgs_introduction.html) |
| 8 | + |
| 9 | + |
| 10 | +## Getting Started |
| 11 | + |
| 12 | +Code can be executed locally or as Lambda. [AWS Credentials](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html) are managed standard way. |
| 13 | +To run the lambda define following `ENV_VARS` with following DEFAULTS if ENV_VAR is not set. |
| 14 | + |
| 15 | +[Using AWS Lambda environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html) |
| 16 | + |
| 17 | + |
| 18 | +List of Variables to preconfigure |
| 19 | +``` |
| 20 | +OWNER_TAG = 'cid_users' |
| 21 | +BUCKET_NAME = 'NO DEFAULT' # Bucket where to upload the code |
| 22 | +QS_REGION = 'QS region' |
| 23 | +export MANAGEMENT_ACCOUNT_IDS='coma seaprated value of account_ids, format ACC_ID:REGION' |
| 24 | +export MANAGMENTROLENAME=WA-Lambda-Assume-Role-Management-Account # Role to Assume in every payer/management account |
| 25 | +TMP_RLS_FILE = '/tmp/cid_rls.csv' |
| 26 | +``` |
| 27 | +## Defining TAGS |
| 28 | + |
| 29 | +1) Tags at root OU level, Give full access to all data and overwrite any other rules for user at other levels. |
| 30 | +2) Tags at OU level will be Inherited TAG to all children accounts. |
| 31 | +2) Tags at Account level will be generated rules for Account level. |
| 32 | + |
| 33 | + |
| 34 | +## Output |
| 35 | + |
| 36 | +Output is writen to `TMP_RLS_FILE` location and uploaded to `BUCKET_NAME`. |
| 37 | + |
| 38 | + |
| 39 | +## Example Output |
| 40 | + |
| 41 | + |
| 42 | +``` |
| 43 | +UserName,account_id,payer_id |
| 44 | + |
| 45 | +vmindru_has_it_all,, |
| 46 | +Admin/vmindru-Isengard,, |
| 47 | +cross_ou_user,"0140000000,7200000,74700000,853000000", |
| 48 | +foo_inherit,74700000000, |
| 49 | +student1,"853000000,126000000", |
| 50 | +student2,"853678200000,126600000", |
| 51 | +other@company_foo.com,"363700000,1675000000", |
| 52 | +[email protected],"36370000000,16750000000", |
| 53 | + |
| 54 | +``` |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +## Create Lambda |
| 59 | + |
| 60 | +### Create a new Lambda in same region with your QS Dashboards |
| 61 | + |
| 62 | +1) Create new Lambda |
| 63 | +2) Select Python 3.8 |
| 64 | + |
| 65 | +### Configure Lambda |
| 66 | + |
| 67 | +1) Create and assign new Execution Role LambdaS3Org Role |
| 68 | +2) Create and Add 2 Permission Policies to above LambdaS3Org Role |
| 69 | + |
| 70 | +`LambdaOrgS3ListTags` |
| 71 | + |
| 72 | +``` |
| 73 | +{ |
| 74 | + "Version": "2012-10-17", |
| 75 | + "Statement": [ |
| 76 | + { |
| 77 | + "Sid": "VisualEditor0", |
| 78 | + "Effect": "Allow", |
| 79 | + "Action": [ |
| 80 | + "organizations:ListAccountsForParent", |
| 81 | + "organizations:ListAccounts", |
| 82 | + "organizations:ListTagsForResource", |
| 83 | + "organizations:ListOrganizationalUnitsForParent" |
| 84 | + ], |
| 85 | + "Resource": "*" |
| 86 | + } |
| 87 | + ] |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +`AWSLambdaS3ExecutionRole` |
| 92 | + |
| 93 | +``` |
| 94 | +{ |
| 95 | + "Version": "2012-10-17", |
| 96 | + "Statement": [ |
| 97 | + { |
| 98 | + "Sid": "VisualEditor0", |
| 99 | + "Effect": "Allow", |
| 100 | + "Action": "s3:GetObject", |
| 101 | + "Resource": "arn:aws:s3:::*" |
| 102 | + }, |
| 103 | + { |
| 104 | + "Sid": "VisualEditor1", |
| 105 | + "Effect": "Allow", |
| 106 | + "Action": "s3:PutObject", |
| 107 | + "Resource": "arn:aws:s3:::vmindru-cid-fr/cid_rls.csv" |
| 108 | + } |
| 109 | + ] |
| 110 | +} |
| 111 | +``` |
| 112 | + |
| 113 | +### Add ENV Variables |
| 114 | + |
| 115 | +Go to function settings and add ENV VARS |
| 116 | + |
| 117 | +`BUCKET_NAME` - Bucket where to upload RLS file |
| 118 | +`ROOT_OU` - ID of your root OU |
| 119 | + |
| 120 | +### Increase execution time to 120s |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
0 commit comments