Securing CloudFront Content and Origins
This lesson explains how to secure CloudFront, often the only public entry point to an application, and its origins.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how origin access control and restricted access protect origins.
- Distinguish CloudFront signed URLs, signed cookies and S3 presigned URLs.
- Describe how CloudFront enforces HTTPS and adds edge security.
Protecting origins
If users can reach the origin directly, they bypass CloudFront's caching, WAF rules and access controls, so the origin must accept traffic only from CloudFront. For an S3 origin, origin access control (OAC) makes CloudFront sign its requests, and the bucket policy allows only the CloudFront service principal acting for the specific distribution, so the bucket stays private. OAC replaces the older origin access identity and supports objects encrypted with SSE-KMS.
A public ALB or other custom origin cannot use OAC. Its security group allows inbound traffic only from the CloudFront managed prefix list, and because that list covers every CloudFront distribution, CloudFront also adds a secret custom header that the ALB's listener rules check. With VPC origins, CloudFront reaches an ALB, NLB or instance in a private subnet directly, so the origin has no public exposure at all. The following table summarises the protections.
| Origin | Protection |
|---|---|
| S3 | Origin access control (OAC): bucket policy allows only the CloudFront service principal for the distribution; replaces legacy OAI; supports SSE-KMS |
| Public ALB or custom origin | CloudFront managed prefix list in security groups, plus a secret custom header checked by the ALB |
| Private ALB | VPC origins |
The following diagram shows the protection for each kind of origin.

Protecting origins
Restricting viewers
Private content, such as paid downloads or subscriber videos, can be restricted with CloudFront signing or S3 presigning. CloudFront signed URLs and signed cookies are created by the application with a private key whose public key is in a trusted key group on the distribution, and CloudFront verifies them at the edge. Content is still served through the cache. A signed URL grants access to one file, signed cookies to many files under a path, and a custom policy can restrict access to a date range and an IP address range.
An S3 presigned URL is signed with the IAM credentials of its creator and gives access to one object directly in S3, without CloudFront, until it expires or the creator's permissions are removed. It suits uploads and occasional direct downloads. The following table summarises the differences.
For content delivered through CloudFront, use CloudFront signing.
Private content
HTTPS and edge security
CloudFront enforces HTTPS at two points. The viewer protocol policy controls the connection from users, for example redirecting HTTP requests to HTTPS; the certificate for a custom domain comes from AWS Certificate Manager in us-east-1. The origin protocol policy controls the connection from CloudFront to the origin, so traffic can be encrypted end to end.
Several features protect content at the edge. Geographic restrictions allow or block requests from particular countries, AWS WAF web ACLs attach directly to the distribution, and AWS Shield Standard protects every distribution against common DDoS attacks at no extra cost. Response headers policies add security headers, such as HTTP Strict Transport Security (HSTS), Content-Security-Policy and X-Frame-Options, without changes to the application.
Private videos for paying subscribers
A training company stores videos in a private S3 bucket. Only paying subscribers may watch them, and only through CloudFront.
| Requirement | Feature |
|---|---|
| The bucket can be read only by CloudFront | Origin access control (OAC) with a bucket policy for the distribution |
| Only subscribers can watch | Signed cookies issued by the application after sign-in (many files per user) |
| One-off download links | Signed URLs |
| Block countries where the content is not licensed | Geographic restrictions |
| HTTPS only | Viewer protocol policy: redirect HTTP to HTTPS |
Signed cookies suit this case because a subscriber watches many files; generating a signed URL for every video segment would be impractical.
How is an S3 bucket made reachable only through CloudFront?
Show answer
With origin access control and a bucket policy that allows only the CloudFront service principal for that distribution, while Block Public Access stays on.
Exam Tips
Remember for the exam
- When users must reach S3 content only through CloudFront, use origin access control.
- For premium video for paying subscribers, use signed URLs or signed cookies.
- To block viewers from certain countries, use CloudFront geographic restrictions.
- To restrict cached content to authorised users, use CloudFront signed URLs or cookies, not S3 presigned URLs.
- To add HSTS and other security headers centrally, use a CloudFront response headers policy.