Amazon S3 - IAM Policy

Policy với quyền tối thiểu cho IAM user dùng với plugin.

SL MigrationsCập nhật 21/10/2026
s3iamsecurity

Amazon S3 IAM Policy

Lưu ý: bản SL Migrations hiện tại không kèm lưu trữ Amazon S3 hay các dịch vụ đám mây khác (các SDK này đã được gỡ khỏi bản này); chỉ có Local và FTP/SFTP. Bài này được giữ lại để tham khảo và không áp dụng cho bản hiện tại.

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/*"
        }
    ]
}

Lưu ý: 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

  1. Save policy với tên SLMigrationsS3
  2. IAM → Users → sl-migrations-backup → Permissions → Add permissions → Attach policies directly
  3. 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.

Tham khảo