A platform for community discussion. Free, open, simple.
DEV: Have media convert service set s3 output permissions (#35392)
Blake Erickson6467fba73f9a
diff --git a/app/services/video_conversion/aws_media_convert_adapter.rb b/app/services/video_conversion/aws_media_convert_adapter.rbindex cdd334f8c66..08514eaeb1e 100644--- a/app/services/video_conversion/aws_media_convert_adapter.rb+++ b/app/services/video_conversion/aws_media_convert_adapter.rb@@ -127,6 +127,10 @@ module VideoConversionbeginurl = "//#{s3_store.s3_bucket}.s3.dualstack.#{SiteSetting.s3_region}.amazonaws.com/#{path}"+ # Set the correct ACL based on the original upload's security status+ # This ensures the optimized video has the same permissions as the original+ s3_store.update_file_access_control(path, @upload.secure?)+optimized_video = create_optimized_video_record(output_path, new_sha1, object.size, url)if optimized_videodiff --git a/lib/file_store/s3_store.rb b/lib/file_store/s3_store.rbindex 2f0fb28571b..d5a069b1aa9 100644--- a/lib/file_store/s3_store.rb+++ b/lib/file_store/s3_store.rb@@ -331,6 +331,10 @@ module FileStoreupdate_access_control(optimized_image_key, secure, remove_existing_acl:)end+ def update_file_access_control(file_path, secure, remove_existing_acl: false)+ update_access_control(file_path, secure, remove_existing_acl:)+ end+def download_file(upload, destination_path)s3_helper.download_file(get_upload_key(upload), destination_path)enddiff --git a/spec/services/video_conversion/aws_media_convert_adapter_spec.rb b/spec/services/video_conversion/aws_media_convert_adapter_spec.rbindex 4669be26f77..6a8211e8d8f 100644--- a/spec/services/video_conversion/aws_media_convert_adapter_spec.rb+++ b/spec/services/video_conversion/aws_media_convert_adapter_spec.rb@@ -277,14 +277,19 @@ RSpec.describe VideoConversion::AwsMediaConvertAdapter doendit "creates optimized video record and rebakes posts" do- allow(s3_object).to receive(:exists?).and_return(true)- allow(s3_object).to receive(:size).and_return(1024)- allow(OptimizedVideo).to receive(:create_for).and_return(true)+ optimized_video_instance = instance_double(OptimizedVideo)+ allow(OptimizedVideo).to receive(:create_for).and_return(optimized_video_instance)+ allow(s3_store).to receive(:update_file_access_control)- adapter.handle_completion(job_id, output_path, new_sha1)+ result = adapter.handle_completion(job_id, output_path, new_sha1)+ expect(result).to be trueexpect(s3_object).to have_received(:exists?)expect(s3_object).to have_received(:size)+ expect(s3_store).to have_received(:update_file_access_control).with(+ "#{output_path}.mp4",+ upload.secure?,+ )expect(OptimizedVideo).to have_received(:create_for).with(upload,"video_converted.mp4",@@ -299,8 +304,6 @@ RSpec.describe VideoConversion::AwsMediaConvertAdapter do)expect(post).to have_received(:rebake!)expect(Rails.logger).to have_received(:info).with(/Rebaking post #{post.id}/)-- expect(adapter.handle_completion(job_id, output_path, new_sha1)).to be trueendcontext "when S3 object doesn't exist" do@@ -314,7 +317,9 @@ RSpec.describe VideoConversion::AwsMediaConvertAdapter docontext "when optimized video creation fails" dobefore doallow(s3_object).to receive(:exists?).and_return(true)+ allow(s3_object).to receive(:size).and_return(1024)allow(OptimizedVideo).to receive(:create_for).and_return(false)+ allow(s3_store).to receive(:update_file_access_control)endit "returns false and logs error" do@@ -331,6 +336,7 @@ RSpec.describe VideoConversion::AwsMediaConvertAdapter doallow(s3_object).to receive(:exists?).and_return(true)allow(s3_object).to receive(:size).and_return(1024)allow(OptimizedVideo).to receive(:create_for).and_raise(error)+ allow(s3_store).to receive(:update_file_access_control)endit "returns false and logs error" do@@ -352,11 +358,15 @@ RSpec.describe VideoConversion::AwsMediaConvertAdapter doallow(SiteSetting).to receive(:s3_use_acls).and_return(false)allow(s3_object).to receive(:exists?).and_return(true)allow(OptimizedVideo).to receive(:create_for).and_return(true)+ allow(s3_store).to receive(:update_file_access_control)end- it "skips ACL update and completes successfully" do+ it "still calls update_file_access_control but it handles the disabled ACL setting internally" doadapter.handle_completion(job_id, output_path, new_sha1)- expect(s3_object).not_to have_received(:acl)+ expect(s3_store).to have_received(:update_file_access_control).with(+ "#{output_path}.mp4",+ upload.secure?,+ )expect(adapter.handle_completion(job_id, output_path, new_sha1)).to be trueendend