Google storage bucket (google api link) integration with Cloud CDN - google-cloud-platform

Respected seniors!
I have hosted a website on GCE and storing all static content on GCS bucket. The content is then accessed using google API link e.g https://storage.googleapis.com/[BUCKET_NAME]/[OBJECT_NAME]...
Now the API link is embedded on webpage on my website as https://www.example.com/post/[random post number](this is an html link which I need to serve an updated copy every time so I set up a cookie to avoid caching in CDN)
I have enabled Cloud CDN on my load balancer backend GCE. My understanding was that the link embedded in webpage for static content will automatically be cached in CDN because the bucket access is made public.
Upon verifying using cURL I came to know that whenever I access the object using API link (https://storage.googleapis.com/[BUCKET_NAME]/[OBJECT_NAME]), the content is cached in CDN and whenever I use my site link (https://www.example.com/post/[random post number]), the content is not cached.
Kindly suggest any method to cache the content on bucket in clod CDN whose link is embedded in dynamic content url which has to be fetched fresh every time.
Thanks in advance

Based on your description, this look like working as intended. The reason why the content is not being cached is due to cookies header being present.
This article explain when content is non-cacheable: https://cloud.google.com/cdn/docs/caching#non-cacheable_content
This is also confirmed when you mentioned:"(https://storage.googleapis.com/[BUCKET_NAME]/[OBJECT_NAME]), the content is cached in CDN." The bucket doesn't have any cookies and this is why it's cached.

Related

Restrict all access to S3 static website except from our Elastic Beanstalk website

We have an Elastic Beanstalk instance that serves our PHP website (example.com). We just added an S3 bucket which serves a different static website (static.com).
The EB website (example.com) requires specific credentials which are supplied to the end-user for logging in. We would like to have the S3 website (static.com) only viewable to the logged-in users of the EB website (example.com) .
Use Cases:
A user is logged into “example.com”. Within the site there would be links to the files on “static.com”. Clicking on these links would take the user to the files on “static.com” and they could navigate around that site.
Someone has a URL to a page on “static.com”. Maybe someone shared that URL with them (that is expected behavior). When they attempt to load that URL in a browser, they are redirected to the login screen of “example.com” to login.
What is the best, and easiest, way to accomplish this? Cookies, Cloudfront, Lamda functions? “Signed URLs” sounded like a possible avenue, but the URLs cannot change over time. This is a requirement in case users do share the URLs (which is expected and ok). Example: Hey Johnny, check out the information at "static.com/docs/widget_1.html"
If you have private content, CloudFront signed URLs are the right choice to generate unique URLs for authenticated users of your application for a limited time. Each time a user loads a page, you generate new short-lived URLs.
If you'd like to enable someone to share links, one option is to provide users with a share option in your application that generates a SignedURL with a longer TTL of a fixed amount (e.g., 3 days) for sharing. Or enables the user to select the length of time the shareable link should be valid, with a maximum allowed time period of x hours/days. If the link expires, they can generate a new one in the application.

how do you stop downloads from AWS S3 with the object url

i have a website similar to video hosting where i need to display upload videos and images and have the images be visible and also the videos if they are purchased, however their locations are saved in the database (MongoDB) and are displayed on the web-page and therefore show up in the network tab in the developer console.
this means that if you click on the link e.g. "https://s3.Region.amazonaws.com/bucket-name/key-name/folder/file-name.mp4" it will auto download, this only happens on chrome though but not Firefox where it just displays the object with no download option. i have tried to change the bucket policy, add encryption but either that causes the images that i want to display to become invisible as they are not publicly accessible or just has no effect and still allows for the video to be downloaded. is there any way for me to have the images and videos in the same bucket and have them both be visible under the right circumstances but block access to the bucket and prevent them from being downloaded by anyone but the bucket owner?
You cannot stop the downloads because the ability to show videos and images in a browser also means that the files are accessible via URL (that's how the browser fetches them).
One option is to use an Amazon S3 pre-signed URL, which is a time-limited URL that provides temporary access to a private object. The way it would work is:
Users authenticate to your back-end service
When a user requests access to one of the videos or images, your back-end checks that they are authorized to access the file
If so, your back-end generates an Amazon S3 pre-signed URL and includes it in the web page (eg <img src='...'>)
When the user's browser accesses that URL, Amazon S3 will verify that the URL is correct and the time-limit has not expired. If it's OK, then the file is provided.
Once the time limit expires, the URL will not work
This will not prevent a file being downloaded, but it will limit the time during which it can be done.
Alternate methods would involve serving content via streaming instead of via a file, but that is a much more complex topic. (For example, think about how Netflix streams content to users rather than waiting for them to download files.)

How to restrict users from download files uploaded to aws s3

I am developing a LMS in Laravel and uploading all the video files to aws s3 bucket and can play them using video js player. But problem is, users can download the video files, which I want to stop. Can anybody suggest me is it possible or not? If possible, can anyone tell me how can I do that?
Objects in Amazon S3 are private by default.
However, if you wish students to make use of a file (eg a learning course video), you will need to grant access to the file. The best way to do this is by using Amazon S3 pre-signed URLs, which provide time-limited access to a private object.
For example, the flow would be:
A students logs into the LMS
A student requests access to a course
The LMS checks whether they are entitled to view the course (using your own business logic)
If they are permitted to use the course, the LMS generates a pre-signed URL using a few lines of code, and returns the link in a web page (eg via an <a> tag).
The student can access the content
Once the expiry duration has passed, the pre-signed URL no longer works
However, during the period where the student has access to the file, they can download it. This is because access has been granted to the object. This is necessary because the web browser needs access to the object.
The only way to avoid this would be to provide courseware on a 'streaming' basis, where there is a continuous connection between the frontend and backend. This is not likely to be how your LMS is designed.

AWS - Download Current Site With User Content

Is there a way to download the current site content, namely, the uploaded user images, from a web application on AWS? Everything I have found only gives access to previous code deployments, which do not include the user uploaded files.
I have tried the instructions here but it only seems to give access to the code as it was at the time of deployment.
Thank you for any help.
User uploaded images are usually stored in Amazon's S3 service, so go to your AWS dashboard and navigate to the S3 section, and you should find the files in a bucket there
Are you trying to download your own website ? Then you need to get not just code or user images; but also database containing data. You need to check the code where images are saved.. Are they on local EBS or EFS or S3 and correspondingly copy from there.
If you are trying to download some-one else website. Then surely you will not have access to database or code or other user images; but still you can download full website as seen to the public using many tools like WinHTTrack.

Is there anyway to make the URL of an object in my AWS S3 bucket inaccessible?

I have some images on my website that are loaded in via S3 however I want to make those URL's private/inaccessible without compromising the visibility of the image on my site.. Is this possible?
When I make the URL of the object private like so:
It addresses me with the following page upon attempting to view it:
I am fairly new at S3.. Any suggestions?
No. If the S3 URL is embedded in your page, then the client has to be able to read the file from S3, which means it needs to be public. S3 is no different from any other web resource in that way.