I noticed that all of the tutorials i found for Discourse S3 access granted the user absolute authority over the bucket – they allow ‘s3:*’ authority.
This is an extremely unwise policy, since it allows significantly more control over the bucket than is reasonable. Should you be using S3 for Discourse backup storage, a rampaging attacker would be able to delete your bucket and your backups on the way out.
There are two ways to combat this: One, a tighter policy…
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:List*",
"s3:Get*",
"s3:AbortMultipartUpload",
"s3:DeleteObject",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::whatever-bucket",
"arn:aws:s3:::whatever-bucket/*"
]
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:HeadBucket"
],
"Resource": "*"
}
]
}
… and two, apply some sensible precautions to the bucket policy. (This is actually well beyond what the actual minimum would need to be, but I was in a hurry and didn’t have time to experiment, and it’s better than what I found.) I’d recommend turning on versioning, and then setting a lifecycle rule for “previous versions” that sees them reaped after a reasonable time, like 21 days. The given policy would permit log rotation and file deletion, but it would not allow the S3-credentialed user access to restore or purge previous versions, and that means that although they could delete a backup, a rampaging attacker couldn’t wipe it from the version history before an administrator with root credentials could salvage it.
Thanks!