Amazon S3 IAM Policy
Best practice: tạo IAM user chỉ có quyền tối thiểu cần thiết cho plugin, không phải full S3 access.
Policy JSON
Tạo policy trong IAM → Policies → Create policy → JSON tab:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListBucket",
"Effect": "Allow",
"Action": [
"s3:ListBucket",
"s3:GetBucketLocation"
],
"Resource": "arn:aws:s3:::your-bucket-name"
},
{
"Sid": "ObjectOperations",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:GetObjectAcl",
"s3:PutObjectAcl",
"s3:AbortMultipartUpload",
"s3:ListMultipartUploadParts"
],
"Resource": "arn:aws:s3:::your-bucket-name/*"
}
]
}
⚠️ Thay your-bucket-name bằng tên bucket thực tế ở cả hai dòng Resource.
Giải thích từng action
| Action | Vì sao cần |
|---|---|
s3:ListBucket |
List archive trong bucket (xem danh sách backup) |
s3:GetBucketLocation |
Detect region cho multipart upload |
s3:PutObject |
Upload archive |
s3:GetObject |
Download archive khi restore |
s3:DeleteObject |
Xóa backup cũ (retention policy) |
s3:GetObjectAcl + s3:PutObjectAcl |
Set ACL private cho archive |
s3:AbortMultipartUpload |
Cleanup nếu upload fail |
s3:ListMultipartUploadParts |
Resume upload |
Gán policy vào user
- Save policy với tên
SLMigrationsS3 - IAM → Users →
sl-migrations-backup→ Permissions → Add permissions → Attach policies directly - Tick
SLMigrationsS3→ Next → Add
Anti-pattern
- Không attach
AmazonS3FullAccess— quá nhiều quyền không cần thiết - Không dùng root account access key — luôn tạo IAM user riêng
- Không commit Access Key vào git hoặc public repository
Restrict by IP (tùy chọn nâng cao)
Thêm condition vào policy để chỉ accept request từ IP server của site:
{
"Condition": {
"IpAddress": {
"aws:SourceIp": "1.2.3.4/32"
}
}
}
Nếu key bị leak, attacker không dùng được từ IP khác. Lưu ý: IP server phải static, không đổi.
Test policy
Sau khi attach policy, vào plugin → Storage → Test Connection. Phải PASS cả List + Put + Get + Delete operations.