-
Notifications
You must be signed in to change notification settings - Fork 0
headobject apifix #1
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
base: master
Are you sure you want to change the base?
Conversation
why - if file not found headobject api returns 403
|
@justjkk Can you also merge this PR? |
|
Hey @nit-practo we are not using this repository. Across Practo we are using https://github.com/practo/base-images/tree/master/custom_services/db-archiver |
| s3_client.head_object(Bucket=bucket_name, Key=s3_path) | ||
| except ClientError as e: | ||
| if e.response['Error']['Code'] == '404': | ||
| if e.response['Error']['Code'] in ['404', '403']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of the method is to check if the file exists in s3, if so then the caller appends variable version to the fiel name.
If there is no access then the method should raise exception as it was earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boto returns 403 when we check for the existence of file (if it does not exist)
botocore.exceptions.ClientError: An error occurred (403) when calling the HeadObject operation: Forbidden
cc : @justjkk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this stackoverflow answer, s3 returns 403 instead of 404 if the ListBucket access is not present. In our case, the ListBucket access was present but restricted to a folder. I checked and found that the restriction was using StringEquals instead of StringLike which was preventing the ListBucket call from succeeding when applied on any path other than the top-level folder. I fixed the IAM permissions and it is now returning 404 as expected. However, it still makes sense to treat 403 also as a not found and not require the ListBucket permission.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Final working IAM permissions for reference:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::<bucket-name>",
"Condition": {
"StringLike": {
"s3:prefix": "<db-name>/*"
}
}
},
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:AbortMultipartUpload",
"s3:ListMultipartUploadParts"
],
"Resource": "arn:aws:s3:::<bucket-name>/<db-name>/*"
},
{
"Sid": "VisualEditor2",
"Effect": "Allow",
"Action": "s3:ListBucketMultipartUploads",
"Resource": "arn:aws:s3:::<bucket-name>"
}
]
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@justjkk @nit-practo the problem with treating 403 as 404 is:
If the IAM user does not have list/read access but has write access (unlikely but techinically possible) then
check_if_s3_file_exists()will returnFalse- and
get_usable_s3_path()will end up returning the path it just examined - and
upload_to_s3()will end up overriding the file with a new version, which defeats the entire purpose ofcheck_if_s3_file_exists()
Since as Kishore mentioned this is not a blocking problem any more(which we presumed earlier), we should update the ReadMe to have this document and call it done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anujith-singh agreed with your reasoning.
Add: Ability to configure a different mysql host for transient archival
why - if file not found headobject api returns 403