Lesson 2 of 3 Amazon CloudFront and AWS Global Accelerator

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.

OriginProtection
S3Origin access control (OAC): bucket policy allows only the CloudFront service principal for the distribution; replaces legacy OAI; supports SSE-KMS
Public ALB or custom originCloudFront managed prefix list in security groups, plus a secret custom header checked by the ALB
Private ALBVPC origins

The following diagram shows the protection for each kind of origin.

How each kind of origin accepts traffic only from CloudFront. An S3 origin uses origin access control: CloudFront signs its requests and the bucket policy allows only the CloudFront service principal for the distribution. A public ALB allows only the CloudFront managed prefix list and checks a secret custom header. A VPC origin lets CloudFront reach a load balancer or instance in a private subnet directly.
The prefix list alone admits every CloudFront distribution, which is why the secret header is also checked.
Match the pairs

Protecting origins

Exam skills 1.2.3 · 1.2.1

Match each origin type with how it is protected.

Log in to try this activity Interactive activities are free with an account.

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.

CloudFront signed URLs / cookies
PathThrough the CDN, with caching
ScopeSigned URL: one file. Signed cookies: many files
RestrictionsDate range, IP address; trusted key groups
S3 presigned URLs
PathDirectly to S3
ScopeOne object
RestrictionsSigner's IAM permissions and expiry

For content delivered through CloudFront, use CloudFront signing.

Scenario questions

Private content

Exam skills 1.2.3 · 1.3.6

Choose how to restrict access to private content.

Log in to try this activity Interactive activities are free with an account.

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.

Worked example

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.

RequirementFeature
The bucket can be read only by CloudFrontOrigin access control (OAC) with a bucket policy for the distribution
Only subscribers can watchSigned cookies issued by the application after sign-in (many files per user)
One-off download linksSigned URLs
Block countries where the content is not licensedGeographic restrictions
HTTPS onlyViewer 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.

Check yourself

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.