|
| 1 | +# S3-Based Storage Using IAM Role for EC2 Docker-based ReportPortal |
| 2 | + |
| 3 | +This document outlines the requirements and configuration steps to enable read/write access to Amazon S3 from a Dockerized ReportPortal installation on an Amazon EC2 instance using IAM roles (Instance Profiles). This setup leverages role-based authentication provided by the EC2 Instance Metadata Service (IMDS). |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Requirements](#requirements) |
| 8 | +- [S3 Bucket](#1-s3-bucket) |
| 9 | +- [AWS IAM Role](#2-aws-iam-role) |
| 10 | + - [Step 1: Define the Trust Policy](#step-1-define-the-trust-policy) |
| 11 | + - [Step 2: Create the IAM Role](#step-2-create-the-iam-role) |
| 12 | + - [Step 3: Define the Permissions Policy](#step-3-define-the-permissions-policy) |
| 13 | + - [Step 4: Attach the Permissions Policy](#step-4-attach-the-permissions-policy) |
| 14 | +- [IAM Instance Profile](#3-iam-instance-profile) |
| 15 | + - [Step 1: Create an Instance Profile](#step-1-create-an-instance-profile) |
| 16 | + - [Step 2: Attach the Role to the Instance Profile](#step-2-attach-the-role-to-the-instance-profile) |
| 17 | + - [Step 3: Associate the Profile with the EC2 Instance](#step-3-associate-the-profile-with-the-ec2-instance) |
| 18 | + - [Step 4: Enable Instance Metadata Access](#step-4-enable-instance-metadata-access) |
| 19 | +- [ReportPortal Configuration](#4-reportportal-configuration) |
| 20 | +- [Docker-Based Installation](#5-docker-based-installation) |
| 21 | + |
| 22 | +## Requirements |
| 23 | + |
| 24 | +1. An Amazon EC2 instance with Docker and Docker Compose installed. |
| 25 | +2. An Amazon S3 bucket. |
| 26 | +3. AWS IAM role configured with appropriate trust and permissions policies. |
| 27 | +4. Instance metadata service (IMDSv2) enabled on the EC2 instance. |
| 28 | + |
| 29 | +## 1. S3 Bucket |
| 30 | + |
| 31 | +Create an Amazon S3 bucket to store ReportPortal data: |
| 32 | + |
| 33 | +```bash |
| 34 | +aws s3api create-bucket --bucket my-rp-docker-bucket --region us-east-1 |
| 35 | +``` |
| 36 | + |
| 37 | +> 💡 To create a bucket outside `us-east-1`, add the following option: |
| 38 | +> |
| 39 | +> ```bash |
| 40 | +> --create-bucket-configuration LocationConstraint=<region> |
| 41 | +> ``` |
| 42 | +
|
| 43 | +Ensure your bucket name complies with [S3 bucket naming rules](https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html). |
| 44 | +
|
| 45 | +## 2. AWS IAM Role |
| 46 | +
|
| 47 | +The IAM role enables the EC2 instance to assume identity and access S3 using instance metadata. |
| 48 | +
|
| 49 | +### Step 1: Define the Trust Policy |
| 50 | +
|
| 51 | +Save the following to a file named `trust-policy.json`: |
| 52 | +
|
| 53 | +```json |
| 54 | +{ |
| 55 | + "Version": "2012-10-17", |
| 56 | + "Statement": [ |
| 57 | + { |
| 58 | + "Effect": "Allow", |
| 59 | + "Action": [ |
| 60 | + "sts:AssumeRole" |
| 61 | + ], |
| 62 | + "Principal": { |
| 63 | + "Service": [ |
| 64 | + "ec2.amazonaws.com" |
| 65 | + ] |
| 66 | + } |
| 67 | + } |
| 68 | + ] |
| 69 | +} |
| 70 | +``` |
| 71 | +
|
| 72 | +### Step 2: Create the IAM Role |
| 73 | + |
| 74 | +Create the role using the trust policy: |
| 75 | + |
| 76 | +```bash |
| 77 | +aws iam create-role --role-name my-ec2-rp-s3-role \ |
| 78 | + --assume-role-policy-document file://trust-policy.json |
| 79 | +``` |
| 80 | + |
| 81 | +### Step 3: Define the Permissions Policy |
| 82 | + |
| 83 | +Save the following to `s3-rw-policy.json`, replacing `my-rp-docker-bucket` with your bucket name: |
| 84 | + |
| 85 | +```json |
| 86 | +{ |
| 87 | + "Version": "2012-10-17", |
| 88 | + "Statement": [ |
| 89 | + { |
| 90 | + "Sid": "AllowListAndLocation", |
| 91 | + "Effect": "Allow", |
| 92 | + "Action": [ |
| 93 | + "s3:ListBucket", |
| 94 | + "s3:GetBucketLocation" |
| 95 | + ], |
| 96 | + "Resource": "arn:aws:s3:::my-rp-docker-bucket" |
| 97 | + }, |
| 98 | + { |
| 99 | + "Sid": "AllowObjectOpsAnywhere", |
| 100 | + "Effect": "Allow", |
| 101 | + "Action": [ |
| 102 | + "s3:PutObject", |
| 103 | + "s3:GetObject", |
| 104 | + "s3:DeleteObject", |
| 105 | + "s3:GetObjectAcl", |
| 106 | + "s3:GetObjectVersion" |
| 107 | + ], |
| 108 | + "Resource": "arn:aws:s3:::my-rp-docker-bucket/*" |
| 109 | + } |
| 110 | + ] |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +### Step 4: Attach the Permissions Policy |
| 115 | + |
| 116 | +Attach the inline policy to the role: |
| 117 | + |
| 118 | +```bash |
| 119 | +aws iam put-role-policy --role-name my-ec2-rp-s3-role \ |
| 120 | + --policy-name S3AccessPolicy \ |
| 121 | + --policy-document file://s3-rw-policy.json |
| 122 | +``` |
| 123 | + |
| 124 | +## 3. IAM Instance Profile |
| 125 | + |
| 126 | +### Step 1: Create an Instance Profile |
| 127 | + |
| 128 | +```bash |
| 129 | +aws iam create-instance-profile --instance-profile-name my-ec2-rp-s3-profile |
| 130 | +``` |
| 131 | + |
| 132 | +### Step 2: Attach the Role to the Instance Profile |
| 133 | + |
| 134 | +```bash |
| 135 | +aws iam add-role-to-instance-profile \ |
| 136 | + --instance-profile-name my-ec2-rp-s3-profile \ |
| 137 | + --role-name my-ec2-rp-s3-role |
| 138 | +``` |
| 139 | + |
| 140 | +### Step 3: Associate the Profile with the EC2 Instance |
| 141 | + |
| 142 | +Replace `INSTANCE_ID` with your EC2 instance ID: |
| 143 | + |
| 144 | +```bash |
| 145 | +aws ec2 associate-iam-instance-profile \ |
| 146 | + --region us-east-1 \ |
| 147 | + --instance-id <INSTANCE_ID> \ |
| 148 | + --iam-instance-profile Name=my-ec2-rp-s3-profile |
| 149 | +``` |
| 150 | + |
| 151 | +### Step 4: Enable Instance Metadata Access |
| 152 | + |
| 153 | +To allow a Docker container to access IMDSv2 metadata, you must increase the instance metadata service (IMDS) hop limit in the EC2 instance configuration: |
| 154 | + |
| 155 | +```bash |
| 156 | +aws ec2 modify-instance-metadata-options \ |
| 157 | + --instance-id <INSTANCE_ID> \ |
| 158 | + --http-put-response-hop-limit 2 \ |
| 159 | + --http-endpoint enabled \ |
| 160 | + --region us-east-1 |
| 161 | +``` |
| 162 | +Ref.: [Access instance metadata for an EC2 instance (AWS Docs)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html) |
| 163 | + |
| 164 | +## 4. ReportPortal Configuration |
| 165 | + |
| 166 | +In your `docker-compose.yml`, configure ReportPortal to use IAM-based S3 access: |
| 167 | + |
| 168 | +```yaml |
| 169 | +x-environment: &common-environment |
| 170 | + # IAM Role-Based S3 Access - Leave credentials empty |
| 171 | + DATASTORE_ACCESSKEY: "" |
| 172 | + DATASTORE_SECRETKEY: "" |
| 173 | + DATASTORE_TYPE: s3 |
| 174 | + DATASTORE_REGION: us-standard # JClouds alias for us-east-1 |
| 175 | + DATASTORE_DEFAULTBUCKETNAME: my-rp-docker-bucket |
| 176 | +``` |
| 177 | +
|
| 178 | +> For full configuration options, see the [ReportPortal S3 integration guide](https://reportportal.io/docs/installation-steps-advanced/FileStorageOptions). |
| 179 | +
|
| 180 | +## 5. Docker-Based Installation |
| 181 | +
|
| 182 | +Launch ReportPortal with Docker Compose: |
| 183 | +
|
| 184 | +```bash |
| 185 | +docker-compose -p reportportal up -d --force-recreate |
| 186 | +``` |
| 187 | + |
| 188 | +This step brings up all ReportPortal services configured to use S3 as the storage backend with IAM role-based credentials via EC2 instance metadata. |
0 commit comments