Skip to content

AccessDenied in old files of bucket

0

Hello, I have a problem with all of old files of my bucket. I try to open them and it returns me error:

<Error> <Code>AccessDenied</Code> <Message>Access Denied</Message> ....

Then, I tried to add this Bucket policy below (until now, bucket policy was blank and all work perfect) { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": "", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::bucket-name/" } ] }

and after this bucket policy it returns me this error: <Error> <Code>InvalidRequest</Code> <Message>The object was stored using a form of Server Side Encryption. The correct parameters must be provided to retrieve the object.</Message> ...

Note that new files uploaded from yesterday are ok, problem occurs only for older files. From us, nothing change happend

Please help me to solve this problem! Thank you in advance!

asked 2 years ago796 views

3 Answers
5

Hello,

My first guess was that your role might only have access to certain files in the bucket and not the older ones. But now, I think it looks more likely that the old files could be encrypted differently. Could you try using the AWS CLI to check the encryption type for these files? Here's the command:

aws s3api head-object --bucket <bucket-name> --key <file-key>

Look for the ServerSideEncryption field in the response:

  • If it shows aws:kms, the object is encrypted with a KMS key.
  • If it shows AES256, the object is encrypted with S3-managed encryption.
  • If no encryption is specified, the object is not encrypted.

If the old files are encrypted using KMS, you need to:

  • Identify the KMS key used to encrypt these objects.
  • Ensure your IAM Role/User has Decrypt permission for this KMS key.
  • Then you could re-encrypt older files if necessary

Note: I noticed your Principal field in the bucket policy is empty. Could that be causing some issues? Here’s an example of what it should look like:

"Principal": {
    "AWS": "*"
}

Hope it helps 😊

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

0

Hello,

Thank you very much for your answer!

Unfortunately I didn't manage to do it from aws cli.

I navigated to this file from AWS Management Console and I saw that it says that it is encrypted with this way (see screenshot): (Old file access denied https://snipboard.io/jFoQcm.jpg, new file access ok https://snipboard.io/P7gyrT.jpg).

Also, I added this "Principal": { "AWS": "*" } and in old files returns me error: <Error> <Code>InvalidRequest</Code> <Message>The object was stored using a form of Server Side Encryption. The correct parameters must be provided to retrieve the object.</Message> ....

Some days ago all files was ok! What changed now?

Thank you very much again!

answered 2 years ago

  • There is definitely an issue with your encryption. Could you try to re-encrypt them? aws s3 cp s3://bucket-name/old-file-key s3://bucket-name/old-file-key --metadata-directive REPLACE --sse AES256

  • How I can do this for all bucket files? Because it does this for all old files. Thank you

  • First, does it work for a file? If so then you can make a python script listing all the files in your s3 and modifying the encryption key

  • Unfortunately, i tried this but it returns me : fatal error: An error occurred (400) when calling the HeadObject operation: Bad Request

    How I can solve it please? Thank you

  • It looks like you don't have the permissions to run this command. You should modify your role and maybe your S3 VPC endpoint

0

I have a whole bucket with hundreds of thousands of files with this exact same issue. We changed nothing, they were all available 2 days ago, and now only things we uploaded in the last several hours are accessible. I also tried running the copy with new encryption from above and got the same error as the root level user on the account. I cant download in the S3 UI or through the, we have just completely lost access to a lot of very important files.

After trying everything above and looking around, I noticed every file had a last updated within a 4 hour period, and then found a warning.txt file that was left by the person who did this basically saying they encrypted all of the files and if I want them back, I ahve to pay them 0.3 bitcoin to an address. My errors and screenshot look just like yours so most likely you are dealing with ransomware too.

answered 2 years ago

  • Oh yes, thank you so much! I finally managed to figure out what could be wrong.

    But this is so bad. How could this happen and why?

    Please tell me, what should I do now please? I have to solve the problem as soon as possible, we have a really big problem.

    Thank you very much in advance.

  • I think you should contact the Amazon Technical support center for this kind of issue

  • Thank you very much.

    I have already done it, I have opened a Technical support case, but I haven't received a reply yet. I hope they reply soon. Thanks again.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.