-
Notifications
You must be signed in to change notification settings - Fork 22
provide better examples for setting up IAM roles #317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
50e758b
d98d2ba
038751b
9ca341d
e01e83c
c6f00fa
174c610
6e33402
56c8fc6
d11411b
4553221
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,4 @@ styles/ | |
| # Allow | ||
|
|
||
| !styles/config/vocabularies/Percona/** | ||
| .cache/ | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,22 +1,88 @@ | ||||||||||||||||||||||||||||||||||||||
| # Automate access to S3 buckets for Percona Backup for MongoDB | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| When you run MongoDB and Percona Backup for MongoDB using AWS resources (on EC2 instances or using EKS), you can automate access to AWS S3 buckets for Percona Backup for MongoDB. Percona Backup for MongoDB uses the AWS environment variables and metadata to access S3 buckets so that you don’t have to explicitly specify the S3 credentials in the PBM configuration file. Thereby you control the access to your cloud infrastructure from a single place. | ||||||||||||||||||||||||||||||||||||||
| When you run Percona Backup for MongoDB in AWS environment (on EC2 instances or using EKS), you can automate access to AWS S3 buckets for Percona Backup for MongoDB. Percona Backup for MongoDB uses the environment variables and metadata to access S3 buckets so that you don’t have to explicitly specify the S3 credentials in the PBM configuration file. Thereby you control the access to your cloud infrastructure from a single place. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ## IAM instance profile | ||||||||||||||||||||||||||||||||||||||
| ## Assume a role from an EC2 instance | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| IAM (Identity Access Management) is the AWS service that allows you to securely control access to AWS resources. | ||||||||||||||||||||||||||||||||||||||
| You can configure Percona Backup for MongoDB to assume an IAM role. To make this work, the `pbm-agent` leverages the AWS environment variables to assume the specified role. The steps are the following: | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Using the IAM instance profile, you can automate access to S3 buckets for Percona Backup for MongoDB running on EC2 instance. The steps are the following: | ||||||||||||||||||||||||||||||||||||||
| 1. Ensure that the EC2 instance where `pbm-agent` is running has an [IAM instance profile :octicons-link-external-16:](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) attached. The role associated with this instance profile must have a permissions policy that allows it to assume the target role. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| 1. Create the [IAM instance profile :octicons-link-external-16:](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html) and the permission policy within where you specify the access level that grants the access to S3 buckets. | ||||||||||||||||||||||||||||||||||||||
| For example, if your target role is `arn:aws:iam::TARGET_ACCOUNT_ID:role/pbm-target-role`, create a policy with the following content and attach it to your EC2 instance role: | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| 2. Attach the IAM profile to an EC2 instance. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| 3. Configure an S3 storage bucket and verify the connection from the EC2 instance to it. | ||||||||||||||||||||||||||||||||||||||
| ```json | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| "Version": "2012-10-17", | ||||||||||||||||||||||||||||||||||||||
| "Statement": [ | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| "Effect": "Allow", | ||||||||||||||||||||||||||||||||||||||
| "Action": "sts:AssumeRole", | ||||||||||||||||||||||||||||||||||||||
| "Resource": "arn:aws:iam::TARGET_ACCOUNT_ID:role/pbm-target-role" | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||
| > Remember to replace `TARGET_ACCOUNT_ID` and `pbm-target-role` with your actual target account ID and role name. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| 2. Create the target IAM role that PBM will assume. This involves setting up a trust relationship and attaching the necessary S3 permissions. | ||||||||||||||||||||||||||||||||||||||
|
Check warning on line 27 in docs/manage/automate-s3-access.md
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| * **Trust Policy**: The trust policy of the target role must allow the EC2 instance's role to assume it. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| For example, if your EC2 instance role is `arn:aws:iam::EC2_ACCOUNT_ID:role/pbm-ec2-instance-role`, use the following trust policy for your target role: | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ```json | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| "Version": "2012-10-17", | ||||||||||||||||||||||||||||||||||||||
| "Statement": [ | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| "Effect": "Allow", | ||||||||||||||||||||||||||||||||||||||
| "Principal": { | ||||||||||||||||||||||||||||||||||||||
| "AWS": "arn:aws:iam::EC2_ACCOUNT_ID:role/pbm-ec2-instance-role" | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| "Action": "sts:AssumeRole" | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||
| > Remember to replace `EC2_ACCOUNT_ID` and `pbm-ec2-instance-role` with the account ID and role name of your EC2 instance. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| * **Permissions Policy**: The target role must have a permissions policy attached that grants the necessary S3 access for PBM. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Here is an example policy that grants the required permissions. Attach it to your target role: | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ```json | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| "Version": "2012-10-17", | ||||||||||||||||||||||||||||||||||||||
| "Statement": [ | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| "Effect": "Allow", | ||||||||||||||||||||||||||||||||||||||
| "Action": [ | ||||||||||||||||||||||||||||||||||||||
| "s3:GetObject", | ||||||||||||||||||||||||||||||||||||||
| "s3:PutObject", | ||||||||||||||||||||||||||||||||||||||
| "s3:DeleteObject", | ||||||||||||||||||||||||||||||||||||||
| "s3:GetBucketLocation" | ||||||||||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||||||||||
| "Resource": "arn:aws:s3:::your-pbm-bucket/*" | ||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||
| "Effect": "Allow", | ||||||||||||||||||||||||||||||||||||||
| "Action": "s3:ListBucket", | ||||||||||||||||||||||||||||||||||||||
| "Resource": "arn:aws:s3:::your-pbm-bucket" | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||||||||||||||
| > Remember to replace `your-pbm-bucket` with the name of your S3 bucket. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| 3. Set the `AWS_ROLE_ARN` environment variable to the ARN of the target role in the environment where you start the `pbm-agent` process. You can also set `AWS_SESSION_NAME` (optional, but recommended for audit trails). | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||||||||||||||||
| export AWS_ROLE_ARN=arn:aws:iam::ACCOUNT_ID:role/pbm-target-role | ||||||||||||||||||||||||||||||||||||||
| export AWS_SESSION_NAME=pbm-session-$(hostname) | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| export AWS_SESSION_NAME=pbm-session-$(hostname) | |
| export AWS_ROLE_SESSION_NAME=pbm-session-$(hostname) |
Check warning on line 84 in docs/manage/automate-s3-access.md
GitHub Actions / vale
[vale] docs/manage/automate-s3-access.md#L84
[Google.Will] Avoid using 'will'.
Raw output
{"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "docs/manage/automate-s3-access.md", "range": {"start": {"line": 84, "column": 148}}}, "severity": "WARNING"}
Check failure on line 130 in docs/manage/automate-s3-access.md
GitHub Actions / vale
[vale] docs/manage/automate-s3-access.md#L130
[Google.Latin] Use 'for example' instead of 'e.g.'.
Raw output
{"message": "[Google.Latin] Use 'for example' instead of 'e.g.'.", "location": {"path": "docs/manage/automate-s3-access.md", "range": {"start": {"line": 130, "column": 21}}}, "severity": "ERROR"}
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The permissions in the S3 policy may be insufficient. The policy includes s3:GetBucketLocation in the object-level permissions (line 141: arn:aws:s3:::your-pbm-bucket/*), but GetBucketLocation is a bucket-level operation and should be applied to arn:aws:s3:::your-pbm-bucket (without the /*). Consider moving s3:GetBucketLocation to be with s3:ListBucket on lines 147-148, or add it as a separate statement for the bucket resource.
| "s3:DeleteObject", | |
| "s3:GetBucketLocation" | |
| ], | |
| "Resource": "arn:aws:s3:::your-pbm-bucket/*" | |
| }, | |
| { | |
| "Effect": "Allow", | |
| "Action": "s3:ListBucket", | |
| "s3:DeleteObject" | |
| ], | |
| "Resource": "arn:aws:s3:::your-pbm-bucket/*" | |
| }, | |
| { | |
| "Effect": "Allow", | |
| "Action": [ | |
| "s3:ListBucket", | |
| "s3:GetBucketLocation" | |
| ], |
Check warning on line 154 in docs/manage/automate-s3-access.md
GitHub Actions / vale
[vale] docs/manage/automate-s3-access.md#L154
[Google.WordList] Use 'command-line tool' instead of 'CLI'.
Raw output
{"message": "[Google.WordList] Use 'command-line tool' instead of 'CLI'.", "location": {"path": "docs/manage/automate-s3-access.md", "range": {"start": {"line": 154, "column": 42}}}, "severity": "WARNING"}
Check warning on line 161 in docs/manage/automate-s3-access.md
GitHub Actions / vale
[vale] docs/manage/automate-s3-access.md#L161
[Google.Will] Avoid using 'will'.
Raw output
{"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "docs/manage/automate-s3-access.md", "range": {"start": {"line": 161, "column": 11}}}, "severity": "WARNING"}
Check failure on line 163 in docs/manage/automate-s3-access.md
GitHub Actions / vale
[vale] docs/manage/automate-s3-access.md#L163
[Google.Latin] Use 'for example' instead of 'e.g.'.
Raw output
{"message": "[Google.Latin] Use 'for example' instead of 'e.g.'.", "location": {"path": "docs/manage/automate-s3-access.md", "range": {"start": {"line": 163, "column": 41}}}, "severity": "ERROR"}
Check warning on line 187 in docs/manage/automate-s3-access.md
GitHub Actions / vale
[vale] docs/manage/automate-s3-access.md#L187
[Vale.Spelling] Did you really mean 'namespace'?
Raw output
{"message": "[Vale.Spelling] Did you really mean 'namespace'?", "location": {"path": "docs/manage/automate-s3-access.md", "range": {"start": {"line": 187, "column": 73}}}, "severity": "WARNING"}
Check warning on line 187 in docs/manage/automate-s3-access.md
GitHub Actions / vale
[vale] docs/manage/automate-s3-access.md#L187
[Google.Will] Avoid using 'will'.
Raw output
{"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "docs/manage/automate-s3-access.md", "range": {"start": {"line": 187, "column": 129}}}, "severity": "WARNING"}
Copilot
AI
Nov 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Inconsistent placeholder format. Throughout the document, placeholders use different formats: <cluster_name> (line 119), <region> and <cluster-name> (line 123), <account-id>, <region>, and <oidc-id> (line 163), <namespace> and <service-account-name> (lines 180, 187), and <role_arn> (line 213). Consider using a consistent format for all placeholders, either all with hyphens (e.g., <cluster-name>) or all with underscores (e.g., <cluster_name>).
| Then, annotate the service account. Replace `<namespace>`, `<service-account-name>`, and `<role_arn>` with the correct values. | |
| ```bash | |
| kubectl annotate serviceaccount <service-account-name> -n <namespace> \ | |
| eks.amazonaws.com/role-arn="<role_arn>" | |
| Then, annotate the service account. Replace `<namespace>`, `<service-account-name>`, and `<role-arn>` with the correct values. | |
| ```bash | |
| kubectl annotate serviceaccount <service-account-name> -n <namespace> \ | |
| eks.amazonaws.com/role-arn="<role-arn>" |
Check warning on line 215 in docs/manage/automate-s3-access.md
GitHub Actions / vale
[vale] docs/manage/automate-s3-access.md#L215
[Google.Will] Avoid using 'will'.
Raw output
{"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "docs/manage/automate-s3-access.md", "range": {"start": {"line": 215, "column": 39}}}, "severity": "WARNING"}
Check warning on line 219 in docs/manage/automate-s3-access.md
GitHub Actions / vale
[vale] docs/manage/automate-s3-access.md#L219
[Google.Will] Avoid using 'will'.
Raw output
{"message": "[Google.Will] Avoid using 'will'.", "location": {"path": "docs/manage/automate-s3-access.md", "range": {"start": {"line": 219, "column": 88}}}, "severity": "WARNING"}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The permissions in the S3 policy may be insufficient. The policy includes
s3:GetBucketLocationbut is missings3:ListBucketpermissions on the same resource level. Line 63 hass3:GetBucketLocationin the array with object-level permissions (arn:aws:s3:::your-pbm-bucket/*), butGetBucketLocationis a bucket-level operation and should be applied toarn:aws:s3:::your-pbm-bucket(without the/*). Consider movings3:GetBucketLocationto be withs3:ListBucketon lines 69-70, or add it as a separate statement.