NodeJS Multer-S3 can upload to S3 without using credentials? - node.js

I'm a little bit lost as to what's going on, I've been trying to solve this for a few days now. I'm trying to only allow my IAM user to upload an image with public access to read. However, I can comment out the IAM user credentials from AWS-SDK and it would still upload to my S3 bucket with no problem. This is not how I intended it to work. I have a feeling it's my policies but I'm not really sure where to start.
Here are the AWS-SDK credentials being commented out in my code
Here is the code for uploading an image to S3
Here is another piece of code used for uploading an image
For some reason, this is enough to upload to my S3 bucket. Just to clarify, I want to make sure the file is being uploaded only if it has the proper credentials. Currently, the file is being uploaded even when S3 credentials are commented out.
The following are my AWS S3 policies/permissions.
AWS public access bucket settings (my account settings also look like this, since those settings override the buckets settings)
AWS bucket policy
Bucket ACL
Bucket Cors
If you can point me in the right direction, that'll be fantastic. I'm pretty new to using AWS S3 and am a little lost.
Thanks a bunch.

this happened to me as well. if there are no credentials in your code, it will default to using those in your .aws directory if you have credentials stored there on your local filesystem.

Related

AWS cannot open or download after copy files to different Amazon S3 bucket using Boto3

I have created a lambda with boto3 that copies files from one Amazon S3 bucket to a different account's Amazon S3 bucket. Everything works fine, but when the other user is trying to open or download the files gets access denied or cannot download the files.
I have the bucket location of the other account and the kms key and i have created policy role for that on my bucket. My bucket has encryption enabled.
Do i need to decrypt my files and encrypt with the kms key of the other account ? I am testing with https://docs.aws.amazon.com/kms/latest/developerguide/programming-encryption.html#reencryption is this correct ?
Thanks
This is probably an object ownership issue. You will need to grant the destination bucket bucket-owner-full-control to the object when uploading. You can set a bucket policy which blocks uploads unless the uploader grants this access:
https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html

Can I get information on an S3 Bucket's public access bucket Settings from boto3?

I am using boto3 to extract information about my S3 buckets.
However, I am stuck at this point. I am trying to extract information about a bucket's public access (see attached screenshot).
How can I get this information? So far I have failed to find out any boto3 function that allows me to do so.
You can use get_public_access_block():
Retrieves the PublicAccessBlock configuration for an Amazon S3 bucket.
When Amazon S3 evaluates the PublicAccessBlock configuration for a bucket or an object, it checks the PublicAccessBlock configuration for both the bucket (or the bucket that contains the object) and the bucket owner's account. If the PublicAccessBlock settings are different between the bucket and the account, Amazon S3 uses the most restrictive combination of the bucket-level and account-level settings.
If you wish to modify the settings, you can use: put_public_access_block()

Uploading a file through boto3 upload_file api to AWS S3 bucket gives "Anonymous users cannot initiate multipart uploads. Please authenticate." error

I have a file of around 16mb in size and am using python boto3 upload_file api to upload this file into the S3 bucket. However, I believe the API is internally choosing multipart upload and gives me an "Anonymous users cannot initiate multipart upload" error.
In some of the runs of the application, the file generated may be smaller (few KBs) in size.
What's the best way to handle this scenario in general or fix the error I mentioned above?
I currently have a Django application that generates a file when run and uploads this file directly into an S3 bucket.
Ok, so unless you've opened your S3 bucket up for the world to upload to (which is very much NOT recommended), it sounds like you need to setup the permissions for access to your S3 bucket correctly.
How to do that will vary a little depending on how you're running this application - so let's cover off a few options - in all cases you will need to do two things:
Associate your script with an IAM Principal (an IAM User or an IAM Role depending on where / how this script is being run).
Add permissions for that principal to access the bucket (this can be accomplished either through an IAM Policy, or via the S3 Bucket Policy)
Lambda Function - You'll need to create an IAM Role for your application and associate it with your Lambda function. Boto3 should be able to assume this role transparently for you once configured.
EC2 Instance or ECS Task - You'll need to create an IAM Role for your application and associate it with your EC2 instance/ECS Task. Boto3 will be able to access the credentials for the role via instance metadata and should automatically assume the role.
Local Workstation Script - If you're running this script from your local workstation, then boto3 should be able to find and use the credentials you've setup for the AWS CLI. If those aren't the credentials you want to use you'll need to generate an access key and secret access key (be careful how you secure these if you go this route, and definitely follow least privilege).
Now, once you've got your principal you can either attach an IAM policy that grants Allow permissions to upload to the bucket to the IAM User or Role, or you can add a clause to the Bucket Policy that grants that IAM User or Role access. You only need to do one of these.
Multi-part uploads are performed via the same S3:PutObject call as single part uploads (though if your files are small I'd be surprised it was using multi-part for them). If you're using KMS one small trick to be aware of is that you need permission to use the KMS key for both Encrypt and Decrypt permissions if encrypting a multi-part upload.

Access Denied in file upload to Amazon s3

I am using aws-sdk for upload file to amazon s3 bucket.
And AccessDenied issue has been occured.
I change my access key id, secret key id, s3 bucket name with others then it works well.
So, there is no problem in code.
I think there is an issue in settings in s3 bucket or s3 bucket name that given in code.
I set the s3 bucket name like s3.amazonaws.com/[my bucket name]/[folder name]
And set Access control list and bucket policy to public.
But It doesn't working.
Please help me.
I figure out my problem.
I change the s3 bucket name like [my bucket name]/[folder name]
remove s3.amazonaws.com

AWS s3 accessing private data

I have stored data in the aws bucket using ACL private. So can i get the data back from third party app. I couldn't find any help on the documentation. Any example will be helpful.
Make sure you have your AWS config set up by following this: http://docs.aws.amazon.com/AWSJavaScriptSDK/guide/node-configuring.html
Then make sure permissions are set that correspond to that AWS config: http://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#permissions

Resources