Skip to content

Commit 56806b5

Browse files
authored
fix: Remove uso de ACL nos uploads para S3 (#111)
## Problema Ao tentar fazer upload de arquivos para S3, ocorria o erro: ``` An error occurred (AccessControlListNotSupported) when calling the PutObject operation: The bucket does not allow ACLs ``` Isso acontece porque buckets S3 modernos frequentemente têm a configuração 'Object Ownership' definida como 'Bucket owner enforced', o que **desabilita ACLs completamente**. ## Solução Esta PR remove todos os parâmetros ACL das operações de upload no módulo `storage/digital_ocean_spaces.py`: - `upload_content()` - Removido `ExtraArgs={"ACL": permission}` - `upload_file()` - Removido `ExtraArgs={"ACL": permission}` - `upload_file_multipart()` - Removido parâmetro `ACL=permission` ## Como controlar acesso público agora? O acesso público deve ser controlado através de **políticas de bucket** ao invés de ACLs em nível de objeto, seguindo as melhores práticas da AWS: ```json { "Version": "2012-10-17", "Statement": [{ "Sid": "PublicRead", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::nome-do-bucket/*" }] } ``` ## Testes - ✅ Testes unitários atualizados em `tests/digital_ocean_spaces.py` - ✅ Código compatível com AWS S3, Digital Ocean Spaces e outros serviços S3-compatíveis ## Nota Este não era um problema de permissão IAM faltante, mas sim uma incompatibilidade entre o código (que tentava definir ACLs) e a configuração do bucket (que desabilita ACLs).
2 parents 191ed48 + 103aeb6 commit 56806b5

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

storage/digital_ocean_spaces.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def upload_content(
101101
if isinstance(content_to_be_uploaded, str):
102102
f = BytesIO(content_to_be_uploaded.encode())
103103
self._client.upload_fileobj(
104-
f, self._bucket, file_key, ExtraArgs={"ACL": permission}
104+
f, self._bucket, file_key
105105
)
106106
# Explicit cleanup
107107
f.close()
@@ -110,7 +110,6 @@ def upload_content(
110110
content_to_be_uploaded,
111111
self._bucket,
112112
file_key,
113-
ExtraArgs={"ACL": permission},
114113
)
115114

116115
def upload_file(
@@ -121,7 +120,7 @@ def upload_file(
121120
) -> None:
122121
logging.debug(f"Uploading {file_key}")
123122
self._client.upload_file(
124-
file_path, self._bucket, file_key, ExtraArgs={"ACL": permission}
123+
file_path, self._bucket, file_key
125124
)
126125

127126
def upload_file_multipart(
@@ -134,7 +133,7 @@ def upload_file_multipart(
134133
logging.debug(f"Uploading {file_key} with multipart")
135134

136135
multipart_upload = self._client.create_multipart_upload(
137-
Bucket=self._bucket, Key=file_key, ACL=permission
136+
Bucket=self._bucket, Key=file_key
138137
)
139138
upload_id = multipart_upload["UploadId"]
140139

tests/digital_ocean_spaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,5 @@ def test_should_upload_content(self, upload_fileobj_mock, bytesio_mock):
149149
content_to_be_uploaded = "content of bucket"
150150
spaces.upload_content(file_key, content_to_be_uploaded)
151151
upload_fileobj_mock.assert_called_once_with(
152-
sentinel.bytesio, self.BUCKET, file_key, ExtraArgs={"ACL": "public-read"}
152+
sentinel.bytesio, self.BUCKET, file_key
153153
)

0 commit comments

Comments
 (0)