Set download to particular ip in s3 using bucket policy - amazon-s3-select

I want to be able to allow test.tar file to be downloaded my these ips using this posted policy. Works perfectly for reading files.
{
"Version": "2008-10-17",
"Id": "S3PolicyIdRestricted",
"Statement": [
{
"Sid": "IPDeny",
"Effect": "Deny",
"Principal": {
"AWS": "*"
},
"Action": "s3:*",
"Resource": "arn:aws:s3:::mydomain/*",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": [
"95.86.79.101",
"67.119.90.17"
]
}
}
}
]
}

Related

Scheduled AWS Batch Job with EventBridge Not Working

What I am trying to do:
Use Eventbridge to schedule an AWS Batch job to run daily.
The problem:
I've created a rule in Eventbridge for a working AWS batch job., but it's is not being kicked off at the scheduled time.
The only thing that I can think of that is going wrong is maybe I don't have the correct role type, trust relationship and policy for the rule? Any help provided would be greatly appreciated, thank you!
Role Information
Role use case type: Allows EC2 instances to call aws services on your behalf
Trust Relationships
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
},
{
"Effect": "Allow",
"Principal": {
"Service": "events.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Permissions (related to EventBridge only): AWSBatchServiceEventTargetRole
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"batch:SubmitJob"
],
"Resource": "*"
}
]
}
Question answered by [AWS-User-0570900] in below link:
https://repost.aws/questions/QUTY4nNS7jRMir8on3U8Ntwg/scheduled-aws-batch-job-with-event-bridge-not-working
Provided Role has following Trust Relationship:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "events.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
And following permission in the Policy:
{
"Statement": [
{
"Action": [
"batch:SubmitJob"
],
"Effect": "Allow",
"Resource": [
"arn:aws:batch:region:account-number:job-definition/our-job-xxxxxxx",
"arn:aws:batch:region:account-number:job-definition/our-job-xxxxxxx:*",
"arn:aws:batch:region:account-number:job-queue/our-job-xxxxxxx"
]
}
],
"Version": "2012-10-17"
}

403 Forbidden after processed variant of image Active Storage (s3)

I am using active storage (on s3) for saving resources of my app (rails). i need generate url for existing images with changed size - i used for it - Rails.application.routes.url_helpers.rails_representation_url(column.variant(resize: '250x250').processed, only_path: true, disposition: :inline)
But in this peace of code - column.variant(resize: '250x250').processed returns
Aws::S3::Errors::Forbidden (Aws::S3::Errors::Forbidden)
backet policy
{
"Version": "2012-10-17",
"Id": "Policy*****4140",
"Statement": [
{
"Sid": "Stmt*******38628",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": [
"arn:aws:s3:::my_project/*"
]
}
]
}
How can i fix it?

S3 "Access Denied" to Bucket

I try to allow one of our Devs (myapp-dev1) the access to one explicit S3-Bucket.
I created a policy which should allow CRUD options (he should be able to write and read image files into that bucket, and only into this.
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListObjects"
I created a User named dev1 and assigned him to that new policy (the user is not in a Group nor has a Role)
I created a Bucket named accordingly ARN: arn:aws:s3:::myapp-dev1-bucket
Then in this bucket I switched to "Bucket Policy" and used the "Policy Generator" and allowed every action for that moment. All other settings failed so far, this one too. It looks like this:
{
"Id": "Policy123456789",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt123456789",
"Action": "s3:*",
"Effect": "Allow",
"Resource": "arn:aws:s3:::myapp-dev1-bucket",
"Principal": {
"AWS": [
"arn:aws:iam::1234567890:user/myapp-dev1"
]
}
}
]
}
But I still get an
Excon::Error::Forbidden: Expected(200) <=> Actual(403 Forbidden)
What I have done wrong?
What I am missing?
Does the User must also be allowed to list buckets?
Please help!
Try this,
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::Bucket_Name"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject",
"s3:ListObject"
],
"Resource": [
"arn:aws:s3:::Bucket_Name/*"
]
}
]
}

Access Denied for new bucket with same IAM, Cognito, and permission configuration

For the last month, I've been successfully using Cognito with the iOS SDK to upload and download files from an s3 bucket in my app. I recently created a new bucket in which to store the files instead, and I suddenly can't download anything (although uploads continue to work). I get this error:
Error downloading from S3: Error Domain=com.amazonaws.AWSS3ErrorDomain
Code=1 "The operation couldn’t be completed.
(com.amazonaws.AWSS3ErrorDomain error 1.)" UserInfo=0x157da330
{HostId=xlPbd8nAQvYPesh0JZ5yH7LFuV562FK85qd5MEgg3DNXn9U0m1K6e8kji
CsC4NXf, Code=AccessDenied, Message=Access Denied,
RequestId=EF39DF70A50540EA}
I'm using exactly the same configuration as I was with the old bucket, with the name of the new bucket changed where it needs to be.
Here's the Unauth IAM policy I've been using:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"mobileanalytics:PutEvent",
"cognito-sync:*"
],
"Resource": [
"*"
]
},
{
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Effect": "Allow",
"Resource": [
"*"
]
}
]
}
And here's my bucket policy:
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket_name/*"
}
]
}
The new bucket is the same region as the old. Right now, I'm at a complete loss as to what simply changing to a new bucket changed (and why uploads work, but downloads don't). If it's relevant, my files are now being stored in a subdirectory of the bucket, but I've updated all the key strings on the client. Thank you very much for your help.
I see your resource in the IAM policy is set to *. Try being explicit about the resource in your IAM policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::mybucketname"
]
},
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:DeleteObject"
]
}
]
}

AWS S3 bucket policy - how to allow access only from my website?

I have a paperclip text file attachment (in Rails).
My bucket policy is:
{
"Version": "2008-10-17",
"Id": "Policy123",
"Statement": [
{
"Sid": "Stmt123",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"s3:GetObjectVersion",
"s3:DeleteObject",
"s3:DeleteObjectVersion",
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::my_bucket/*"
}
]
}
I want to restrict access to these actions to only be allowed when the request comes from my website. Is it simply a case of updating this to: "Principal": {"AWS": "mywebsite.com"} ?
You can check some examples in S3 Documentations
To restrict the access from your web site, you can use the condition on Referrer:
{
"Version":"2008-10-17",
"Id":"http referer policy example",
"Statement":[
{
"Sid":"Allow get requests referred by www.mysite.com and mysite.com",
"Effect":"Allow",
"Principal":"*",
"Action":"s3:GetObject",
"Resource":"arn:aws:s3:::example-bucket/*",
"Condition":{
"StringLike":{
"aws:Referer":[
" http://www.mysite.com/*",
" http://mysite.com/*"
]
}
}
}
]
}
Bucket policy :
{
"Version": "2012-10-17",
"Id": "http referer policy example",
"Statement": [
{
"Sid": "Allow get requests originating from www.example.com and example.com.",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::00000000:user/example-user" // IAM User ARN
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket-example/*", // bucket ARN
"Condition": {
"StringLike": {
"aws:Referer": [
"http://example.com/*" // Website link
]
}
}
}
]
}

Resources