What is the Google Cloud Storage public read uri? - google-cloud-platform

I created a google cloud storage bucket and set it's ACL to public-read.
What is the unauthenticated URI to objects in my new bucket?
I tried this:
https://www.googleapis.com/storage/v1/my-new-bucket/my-object
as outlined here but it returns "Not found"

Here's an example public object URL: http://pub.storage.googleapis.com/shakespeare/rose.txt
Other examples of the same resource:
https://storage.googleapis.com/pub/shakespeare/rose.txt
https://pub.storage.googleapis.com/shakespeare/rose.txt
Our JSON API also allows for object downloads, but it's not designed for serving web requests.These URLs will usually involve some redirects and/or the server instructing the browser to treat the object as an attachment:
https://www.googleapis.com/storage/v1/b/pub/o/shakespeare%2Frose.txt?alt=media

To access public objects, you need to edit its permissions by following these steps either for an individual object or a group of objects. After you set your permissions, a link icon will appear in the public access column. That's the public URL for your object.

Related

AWS s3 - difference between "Download" and "Object URL"

Read as I might, I can't find the answer. I have set up a bucket and user with GetObject permission. In the AWS console, I can use the download and open links (green arrows below) successfully, which seems to indicate the permissions are set right. However, when clicking on the Object URL link (red arrow below), I get an Access Denied XML error.
What is the purpose of the Object URL? What is the difference between it and the download/open buttons? Also, why is the owner field blank? I left the config to default which "should" have the uploader as the owner, no?
By default all buckets and objects are private and not accessible from the internet. To make your private objects accessible from the internet without the need for IAM credentials, you have to create S3 pre-signed url. And this is exactly what open/download links do - they generate S3 pre-signed url for you to use. So when you click them, AWS will generate the S3 pre-signed urls and a browser will request the object using the url.
Clicking Object URL does not work, because when browser makes request to AWS for that object, it does not sign the request using IAM credentials. The Object URL would only work if the bucket or the object allowed for anonymous access. In that case, no IAM credentials are required. This is mostly useful for serving static webpages from S3.
Simply put, Object URL is an external link which checks for public permissions for access.
Download and Open uses your currently signed-in user permissions to verify whether you should have access to them, which is why they work for you.
The owner field may be blank because it was uploaded by a public/anonymous user that doesn't have an IAM User in your system.
By default, an Amazon S3 object is owned by the identity that uploaded the object. This means that if you allow public write access to your bucket, the objects uploaded by public (anonymous) users are publicly owned.
https://aws.amazon.com/premiumsupport/knowledge-center/s3-object-change-anonymous-ownership/

Prevent anyone from accessing my bucket unless a certain condition

I have an ec2 instance with a load balancer and cloudfront attached and I want to prevent my s3 bucket files from being viewed unless the files are being requested on my website. How would I be able to do this? I've tried "referrer" (which doesn't work sometimes, and apprently not the best option) and I've tried using the "source ip" condition which just doesn't work, I've put in my website ip, my vpc ip from my load balancer, etc, just doesn't work (unless there's another way I have to do it, I would appreciate it if anyone told me). I just want a bucket policty that has a condition like so:
"Condition": {
** person is on my website **
}
If anyone has any ideas, that would be nice, thanks.
I can immediately think of 2 options:
Make your bucket private and instead reverse-proxy the images through your own website.
Make your bucket use Query String Authentication and have your website generate a short-lived QSA token (5 minutes?) for each visitor.
If your content is being served from Amazon S3 or Amazon CloudFront, you can use pre-signed URLs to grant time-limited access to private content.
For example, let's say that you have a photo-sharing website and all photos are private by default. Access can be provided as follows:
Users authenticate to your application
The user then requests access to a private object, or your application wishes to generate an HTML page that includes a link to a private object (eg in an <img> tag).
The application checks whether the user is permitted to access the object. If they are, the application generates a pre-signed URL and provides it in the HTML page or as a link.
The user's browser then uses the URL to request the private object, which sends the request to CloudFront or S3
CloudFront or S3 then checks whether the pre-signed URL is correctly signed and is still within the validity period. If so, it provides access to the object. If not, it returns Access Denied.
For more information, see:
Amazon S3 pre-signed URLs
Using Amazon CloudFront Signed URLs

Accessing file in Amazon S3 via object url returns AccessDenied

I am clicking into my s3 bucket in the Amazon S3 management console and I'm trying to view an object via its url:
However, I see this:
Any idea what the error is?
Objects in Amazon S3 are private by default. This way, other people cannot access your data.
If you wish to access a private Amazon S3 object in the management console, click the Open or Download button. This will generate a URL that includes authorization information that will give you access to the object.
Merely clicking the URL of an object will cause your browser to access the object without authentication. If the object is private, then the request will (correctly) fail. If the object is public, the URL will work (for you and for anyone on the Internet).

Block s3 public url access for my image and only show the image in mobile app or website

I have upload all my images in s3 bucket and allowing it to show in my website using s3 url, but when I access the s3 url directly in browser it showing the image, I want to block those access
Can anyone help me on how to Block s3 public url access for my image and only show the image in mobile app or website.
All objects in Amazon S3 are private by default.
Access to objects can be granted in several ways:
A Bucket Policy can make a whole bucket (or a part of a bucket) public to everyone. It is also possible to specify restrictions, such as IP address and referer.
An Access Control List on an object can make the object public (for everyone)
An IAM Policy can grant access to objects for specific IAM Users
A pre-signed URL can provide temporary access to a private object
Based upon your question, I would recommend:
Keep the objects private (remove Bucket Policies and ACLs)
When a user wishes to access an image or other object, your application determines whether the user is permitted to access the object (this logic is totally up to you to write in your application)
If they are permitted, your application can create a pre-signed URL in a few lines of code, which will allow the mobile app or website to access the object for a limited time period that your app specifies (eg 5 minutes). After this time period, the URL will no longer provide access.
Thus, your application has full control over whether somebody is permitted to access the image, while still serving the content directly from Amazon S3 (eg in a web page via a <img> tag).
See: Share an Object with Others - Amazon Simple Storage Service

Amazon S3 see private files

I am using Amazon S3 to upload files into different folders. All folders and files are public and can be seen by anyone. I created a private folder, where i want to put private images so that only i can see them. I already created a bucket policy rule that will deny the access to that folder. But how can i see the files ? Is there a special link like this https://s3.amazonaws.com/bucket/private_folder/file.jpg?secret_key=123 that will let me and someone who know`s that secret key to see the files ?
Is there any way of uploading private files that can be seen by using a secret_key, url or something like that ?
By default, all objects in Amazon S3 are private. Objects can then be made "public" by adding permissions, via one of:
Object Access Control List (ACL): Setting the permission directly on the object
Bucket Policy: Relates to the bucket, can define rules relating to sub-directories, key name (filenames), time-of-day, IP address, etc
IAM Policy: Relates to specific Users or Groups
As long as one of these methods grants access, the person will be able to access the object. It is also possible to assign Deny permissions that override Allow permissions.
When an object is being accessed via an un-authenticated URL (eg s3.amazonaws.com/bucket-name/object-key), the above rules determine access. However, even "private" files can be accessed if you authenticate against the service, such as calling an S3 API with your user credentials or using a pre-signed URL.
To see how this works, click a private file in the Amazon S3 Management Console, then choose Open from the Actions menu. The object will be opened. This is done by providing the browser with a pre-signed URL that includes a cryptographically-sized URL and a period of validity. The URL will work to Get the private file only until a defined time.
So, to answer your question, you can still access private files via:
The Open command in the console
Pre-Signed URLs in a web browser
Authenticated API calls
Just be careful that you don't define DENY rules that override even your ability to access files. It's easier to simply ALLOW the directories you'd like to be public.
See: Query String Request Authentication Alternative
You may access s3 private file by creating a temporary Url using temporaryUrl method.
$url = Storage::temporaryUrl(
'file.jpg', now()->addMinutes(5)
);
The params of temporaryUrl method are $path, $expiration and $option = []. The first two params are required and the default value of $option is an empty array.