# Provisioning Role-Based Access

In order to enable Activeloop to connect to data stored in a user's cloud, a role must be created in that cloud using the steps below:

### AWS S3

#### Step 1: Create the IAM Policy

1\. Login to the AWS account where the IAM Role will be created and where the data is stored.

2\. Go to the IAM page in the AWS UI, which can be done by searching "IAM" in the console and locating the IAM page under Services.

3\. In the left nav, open the `Policies` under `Access management` and on `Create policy` on the right.

<figure><img src="https://3773397762-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBVXReLWauk44ITltb5I%2Fuploads%2FpJiOP6RWuHRbm2qQs4JC%2FIAM_Provisioning_Screenshots.001.jpeg?alt=media&#x26;token=0f709cdd-30a5-401c-911a-0b797d4e4307" alt=""><figcaption></figcaption></figure>

5\. Select the `JSON` tab instead of `Visual editor`.

<figure><img src="https://3773397762-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBVXReLWauk44ITltb5I%2Fuploads%2FPWuXRqwxMIbdSiMbYdCl%2FIAM_Provisioning_Screenshots.002.jpeg?alt=media&#x26;token=3297d38d-9e26-4680-80a2-a649561a6577" alt=""><figcaption></figcaption></figure>

6\. Replace the code in the editor with the code below. Replace `BUCKET_NAME` with the bucket names for which you want to grant role-based access:

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [ 
                "s3:ListBucket",
                "s3:GetBucketLocation",
                "s3:*Object*"
            ],
            "Resource": [
                "arn:aws:s3:::BUCKET_NAME",
                "arn:aws:s3:::BUCKET_NAME/*"
            ]
        }
    ]
}

```

7\. On the bottom right, click `Next: Tags` (create tags if needed) and `Next: Preview`, enter the policy `name` and `description`, and click `Create policy`

<figure><img src="https://3773397762-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBVXReLWauk44ITltb5I%2Fuploads%2FQcJGeGlTc8ywZJEzw2QT%2FIAM_Provisioning_Screenshots.003.jpeg?alt=media&#x26;token=47d961b0-7491-460a-9405-fde918e3f837" alt=""><figcaption></figcaption></figure>

#### Step 2: Create the IAM Role&#x20;

1\. On the `IAM` page, in the left nav, open the `Roles` under `Access management`, and click `Create role` on the right.

<figure><img src="https://3773397762-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBVXReLWauk44ITltb5I%2Fuploads%2Ffhby8tTC4IwJWsTK22bU%2FIAM_Provisioning_Screenshots.004.jpeg?alt=media&#x26;token=14ece48c-3675-4dac-aadf-5bfaf6bdaed3" alt=""><figcaption></figcaption></figure>

3\. Select `Custom trust policy` from the list of options.

<figure><img src="https://3773397762-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBVXReLWauk44ITltb5I%2Fuploads%2FL6gMfTf79Pt6yUReXfMf%2FIAM_Provisioning_Screenshots.005.jpeg?alt=media&#x26;token=d413a472-efe5-4cfa-8efa-8a4832a0a5c4" alt=""><figcaption></figcaption></figure>

4\. Replace the policy definition with the code below and click `Next`

```
{
    "Version": "2012-10-17",
    "Statement": 
    [
        {
            "Sid": "AllowAssumeRoleFromActiveloopSaaS",
            "Effect": "Allow",
            "Principal": {
                 "AWS": [
                     "arn:aws:iam::574987031486:role/activeloop_backend_dev",
                     "arn:aws:iam::574987031486:role/activeloop_backend",
                     "arn:aws:iam::597713067985:role/activeloop_backend"
                 ]
        },
        "Action": "sts:AssumeRole"
      }
   ]
}

```

5\. From the provided policy list, select the previously created policy from Step 1 and click `Next`

<figure><img src="https://3773397762-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBVXReLWauk44ITltb5I%2Fuploads%2F2YTGluOa6THaw8RjEekF%2FIAM_Provisioning_Screenshots.010.jpeg?alt=media&#x26;token=8598c7a8-0c05-4b46-9dc0-fe4b0c6d5cba" alt=""><figcaption></figcaption></figure>

6\. Set the `name` and `description` for the role and click `Create role` at the bottom.

<figure><img src="https://3773397762-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBVXReLWauk44ITltb5I%2Fuploads%2F5dY6Db7y20vOKb0ydcmY%2FIAM_Provisioning_Screenshots.007.jpeg?alt=media&#x26;token=f63cbe7c-8913-4e9b-836d-5f9fb8a3583d" alt=""><figcaption></figcaption></figure>

#### Step 3: Grant Access to KMS Key (**only for buckets that are encrypted with customer managed KMS keys**)

1\. Navigate to the bucket in the AWS S3 UI

2\. Open the bucket Properties

<figure><img src="https://3773397762-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBVXReLWauk44ITltb5I%2Fuploads%2FeVk84QZrZYhPogsRBWpb%2FIAM_Provisioning_Screenshots.008.jpeg?alt=media&#x26;token=cc1563f9-9358-4888-8b11-818f808deeff" alt=""><figcaption></figcaption></figure>

3\. Scroll down to Default encryption and copy the `AWS KMS key ARN`&#x20;

<figure><img src="https://3773397762-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiBVXReLWauk44ITltb5I%2Fuploads%2F1YlMHMk8spC5EBokjtsN%2FIAM_Provisioning_Screenshots.009.jpeg?alt=media&#x26;token=38fa6827-0f94-42b1-a630-3d47ff85e8b9" alt=""><figcaption></figcaption></figure>

4\. In the Policy creation step (Step 1, Sub-step 6), use the JSON below in the policy statement, and replace `YOUR_KMS_KEY_ARN` with the copied Key ARN for the encrypted bucket.

```
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket",
		 "s3:GetBucketLocation",
                "s3:*Object*"
            ],
            "Resource": [
                "arn:aws:s3:::BUCKET_NAME",
                "arn:aws:s3:::BUCKET_NAME/*"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "kms:Encrypt",
                "kms:Decrypt",
                "kms:ReEncrypt*",
                "kms:GenerateDataKey*",
                "kms:DescribeKey"
            ],
            "Resource": [
                "YOUR_KMS_KEY_ARN”
            ]
        }
    ]
}

```

#### Step 4: Enter the created Role ARN (Step 2) into the Activeloop UI
