Allow use of AWS EC2 IAM roles with S3 file/image uploads
A feature request was made by windhamg1 to allow Discourse to use IAM roles for S3 uploads, without requiring Access Key/Secret Key. codinghorror deemed it reasonable if easily implementable. windhamg1 created a diff and later submitted a pull request (PR #2511) to implement the feature.
However, tgxworld pointed out that the feature might not be valid due to the removal of the fog gem. codinghorror and sam confirmed the removal of the fog gem due to its bloat, and sam added a #pr-welcome tag, encouraging someone to bring back the feature without introducing bloated dependencies.
As the “fog” gem (used by Discourse for S3 support) has the ability to use the keys from an IAM role, I respectfully submit a request to have Discourse use this option (:use_iam_profile => true) if the “use S3” option is enabled, but the “Access Key ID” and “Secret Key” fields are left blank.
Thanks, @codinghorror. I took a stab at it in my local instance; it was pretty easy and seems to work well. The change is in lib/file_store/s3_store.rb, and a diff is attached. I can submit a git pull request if desired.
This will create a 0001-Commit-message.patch file, which someone else can use git am on to apply the commit, keeping the author and timestamp. (These git tools were originally designed for emailing patches.)
Thanks, @riking. However, since my last post I went ahead and submitted a PR myself, using the prescribed methodology at discourse/CONTRIBUTING.md at main · discourse/discourse · GitHub. I cleaned it up a bit (adding an option instead of relying on the other fields to be blanks, and also making it work for S3 backups).
Putting a pr-welcome on this in case anyone wants to try bringing this feature back provided they don’t also bring back a swarm of bloated dependencies.