Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For users missing certain S3 permissions, files may be identified as directories #310

Open
adrianohrl opened this issue Jan 3, 2023 · 3 comments
Labels
bug Something isn't working S3

Comments

@adrianohrl
Copy link

adrianohrl commented Jan 3, 2023

Depending on the machine in which the upload happens, downloading works fine. However, when a different machine tries to download the S3 remote path, it downloads files as directory.

from pathlib import Path

from cloudpathlib import CloudPath

CWD = Path.cwd()
TMP = Path(tempfile.gettempdir())

remote_path = CloudPath(f's3://test/models/')

local_path = CWD / 'models/'
remote_path.upload_from(local_path)

for rp in remote_path.iterdir():
    lp = local_path / rp.relative_to(remote_path)
    assert rp.is_file() == lp.is_file(), f'The {rp} remote path must be a file!'
    assert rp.is_dir() == lp.is_dir(), f'The {rp} remote path must be a directory!'

local_path = TMP / 'models'
remote_path.download_to(local_path)

for rp in remote_path.iterdir():
    lp = local_path / rp.relative_to(remote_path)
    assert rp.is_file() == lp.is_file(), f'The {lp} local path must be a file!'
    assert rp.is_dir() == lp.is_dir(), f'The {lp} local path must be a directory!'
@adrianohrl adrianohrl changed the title download_to from S3 is Downloading files as directory from S3 Jan 3, 2023
@adrianohrl
Copy link
Author

Actually, I found the issue was related to the IAM policy. My local role is different of the remote one. I am not sure yet what is the solution.

Shouldn't cloudpathlib raise an Exception in this case?

@adrianohrl
Copy link
Author

In the cloudpathlib.s3.s3client.py:_s3_file_query, raised a ClientError due to HeadObject forbiddance. Then, on except, it considers it as a prefix.

@pjbull
Copy link
Member

pjbull commented Jan 3, 2023

@adrianohrl Sounds like the IAM had list permissions, but not some other permission (like GetObject or GetObjectAttributes). Do you know which ones you missing? That will be helpful.

We'll need to double check, but I think you may get a 403 both in the case that you do no have permissions for head_object and in the case that the object does not exist, which may complicate a fix here. If so, we may consider doing both a list check and then a get check on instantiation to ensure the user has the requisite permissions.

@pjbull pjbull added bug Something isn't working S3 labels Jan 3, 2023
@pjbull pjbull changed the title Downloading files as directory from S3 For users missing certain S3 permissions, files may be identified as directories Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working S3
Projects
None yet
Development

No branches or pull requests

2 participants