apache / apache/libcloud

Deletion of S3 objects fails for object paths starting with a slash

Ouverte
#1,654 7 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
api: storage drivers: aws s3
Langage dominant
Python
Étoiles
2.1k
Forks
931
Merge moyen
1 j 2 h
PR mergées (30 j)
4

Description

## Summary

When trying to delete all objects in an S3 bucket, the deletion fails for objects with a leading slash in their path.
The `delete_object` method returns `True` for these objects, even though they are not deleted.

## Detailed Information

To delete an S3 bucket we use `Container.list_objects()` and `delete_object` to first delete all objects in the bucket. This doesn't work for objects, where the object path starts with a slash. The `delete_object` function returns `True` for these objects even though they are not deleted because the DELETE request is sent to the wrong URL.
For example to delete the object `s3://container-name//path/to/object` the DELETE request is sent to
https://s3-eu-west-1.amazonaws.com/container-name/path/to/object
but it should be sent to this path instead:
https://s3-eu-west-1.amazonaws.com//container-name/path/to/object
The problem is that double slashes are replaced in the request URL in the method `Connection.morph_action_hook`. This is a similar issue to #1529.

To reproduce the issue, you can use the following code (replace credentials and bucket name):
```python
from libcloud.storage.types import Provider
from libcloud.storage.providers import get_driver

driver = get_driver(Provider.S3)
client = driver("key", "secret", region="eu-west-1")

container = client.get_container("container-name")
objects = container.list_objects()
for obj in objects:
client.delete_object(obj)
client.delete_container(container)
```
This will result in an `ContainerIsNotEmptyError` if the bucket "container-name" contains objects where the object path starts with a slash.

Libcloud version: 3.4.1
Python version: 3.7.12

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par Connection.morph_action_hook et reproduisez le problème avec l’exemple S3 en utilisant un chemin d’objet qui commence par une barre oblique. Suivez la manière dont l’URL de la requête DELETE est normalisée ; le travail est terminé lorsque la barre oblique initiale est conservée, que l’objet est effectivement supprimé et que le bucket peut ensuite être supprimé.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
aws, python
Domaine
cloud
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Clairement spécifiée
Accessibilité débutants
42/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.