How to Protect S3 Objects via CloudFront with Origin Access Control
A CloudFront distribution can serve objects stored in Amazon S3 without making the bucket public. That is the central purpose of CloudFront Origin Access Control (OAC): it lets an authorized distribution send authenticated requests to a supported origin while the origin blocks direct requests that lack the required permissions. For S3, the practical result is that a viewer cannot simply switch a CloudFront URL to an S3 URL and bypass the distribution’s access rules—provided the bucket policy and object permissions are configured correctly.
OAC solves one boundary, not the entire content-security problem. It establishes how CloudFront authenticates to its origin; it does not decide which individual viewers may watch a paid video or download a private report. That distinction is especially important for developers replacing Origin Access Identity (OAI), configuring signed URLs, or assuming that an encrypted bucket automatically enforces application user permissions.
Imagine a training service storing private lesson files in an S3 bucket. Its application delivers the files through a CloudFront distribution so customers receive a cached response from an edge location. If the S3 bucket also allows anonymous GetObject requests, someone who learns the S3 object URL may retrieve the same content without passing through CloudFront. Rate limits, viewer authorization, logs and other controls at the distribution could be bypassed entirely. An S3 origin with an appropriately restricted bucket policy closes that direct-origin path.
With OAC, CloudFront signs origin requests using the configured signing behavior. In the common S3 model, the bucket policy grants the CloudFront service principal permission to read the intended objects and constrains that permission to the expected distribution through its AWS source ARN. It should not include a broad public-read statement or a wildcard allowing every distribution. Identity and resource-policy details matter more than whether the diagram shows a padlock icon.
Before deploying anything, distinguish the identities in the request. The viewer is a browser, mobile client or another caller. CloudFront is a delivery service making a separate request to S3. S3 authorizes that origin request based on AWS policy. An application may make a third, independent decision about whether the viewer has a valid subscription. OAC addresses the CloudFront-to-origin step; it does not make the application decision on behalf of the developer.
For the common private-bucket pattern, use the S3 bucket’s regular REST-style origin rather than its static-website endpoint. This difference is operationally important. Amazon S3 static-website endpoints are treated as CloudFront custom origins and do not support OAC or legacy OAI for that S3 website endpoint. A configuration tutorial that selects a website endpoint and later recommends enabling S3 OAC has combined incompatible steps.
Keep S3 Block Public Access and object-ownership settings aligned with the security model. AWS recommends Bucket owner enforced for Object Ownership when using an S3 bucket origin with OAC; this disables object ACLs and relies on policies. If existing integrations still require ACL behavior, check the supported ownership alternatives and the implications for uploads instead of blindly disabling protection. For SSE-KMS encrypted content, access to the S3 object is not enough: the relevant AWS KMS key policy must also permit the intended CloudFront access pattern.
OAC is not a general authentication mechanism for every custom HTTP server. AWS supports OAC for a defined set of origin types, including S3 and certain AWS MediaStore, MediaPackage v2 and Lambda function URL configurations. A conventional arbitrary custom HTTP origin, a server outside AWS or an S3 website endpoint cannot simply use the S3 OAC steps. Those deployments need origin-specific mechanisms, network controls or application-layer security suited to the actual origin type.
A production S3 policy should make the authorized relationship explicit. The principal is CloudFront’s service principal, not an anonymous user. The permitted action is often s3:GetObject for a read-only delivery workload. The resource should be the intended object path within the specific bucket. A condition ties requests to the expected CloudFront distribution ARN. If the application needs write behavior, create a separately justified write flow with scoped permissions; do not add blanket write access merely because OAC can support dynamic requests.
Think about scope using two tests. Can an unrelated CloudFront distribution read this bucket? Can a user obtain the S3 object directly without being signed by the intended distribution? If either answer is yes, the origin may still be accessible through an unapproved path. Also consider whether the account’s other IAM principals or existing cross-account policies intentionally permit access; OAC does not erase every other grant automatically.
The signing behavior changes the transport story. AWS recommends “always sign” origin requests. For an S3 origin that uses this setting, CloudFront communicates with S3 over HTTPS. Other signing modes can alter how headers are forwarded and which protocol requirements apply. Avoid treating “the website uses HTTPS” as proof that every downstream origin request is authenticated. Verify the origin signing behavior and the viewer protocol policy separately.
Origin Access Identity is the older way to restrict CloudFront access to an S3 origin. It may still be present in established distributions, but AWS recommends OAC for new configurations. OAC adds capabilities that OAI did not cover consistently, including support for newer S3 Regions, SSE-KMS scenarios and signed dynamic S3 requests. The existence of that improvement does not mean that an OAI-protected site was previously public or that migration automatically fixes viewer authorization flaws.
Migration should be planned in stages. Inspect the current bucket policy and object access, create the intended OAC, add the new CloudFront permission while preserving the working old route during transition where appropriate, attach the OAC to the distribution and wait for configuration deployment. Test the application and direct-origin denial before removing obsolete grants. Deleting the old permission before the new distribution setting is effective can create an avoidable outage.
For encrypted objects, include actual decryption tests and a review of the KMS key policy. A successfully deployed distribution can still return errors when CloudFront reaches an object but lacks permission to use its encryption key. Capture error codes and relevant logs rather than weakening the entire bucket policy to resolve a KMS problem.
If a service sells access to video lessons, a private origin is necessary but may not be sufficient. A CloudFront URL that anybody can request is still a publicly usable CloudFront URL even when the S3 bucket itself cannot be read directly. User login, entitlement checks and access expiration need their own design. CloudFront offers signed URLs and signed cookies for selected private content; the application is responsible for issuing those credentials under conditions that match user permissions.
Choose the viewer mechanism around the access pattern. A short-lived signed URL may suit one downloadable report. Signed cookies can suit a collection of media segments or a group of related paths. In both cases, decide how the application handles expiration, cache behavior, key rotation, clock skew and an account whose access was revoked. A token with a future expiry is not automatically cancelled simply because a user clicked “log out.”
Cache behavior also deserves care. If the same cache key is used for objects whose content differs by user, the application can leak one user’s response to another. Conversely, forwarding every personal cookie or authorization header without a reason may destroy cache efficiency. Treat personalized content differently from static private assets and document what CloudFront is allowed to cache. OAC controls origin fetch authorization, not application response variation or the semantics of HTTP caching.
A useful security test has more than a successful download through the distribution. First, in a disposable or approved environment, retrieve a known object through its intended CloudFront hostname and confirm the response. Then try the corresponding direct S3 access anonymously. That request should fail when the object is supposed to be private. Check the bucket’s other grants as well as the OAC policy. The exact HTTP error is evidence to interpret, not a guarantee that every unauthorized path has been closed.
Next, test two types of viewers: an account that is entitled to the object and an account that is not. If the application relies on CloudFront signed URLs or cookies, verify an authorized request, an expired signature, a malformed signature and a request for a path outside the authorized scope. Try navigating from a previously authorized asset to a different asset by guessing the path. Origin restriction alone will not reject every such guess; the viewer mechanism must enforce it.
Finally, test a legitimate change in configuration. Rotate a signing key, deploy a bucket policy modification, make an object unreadable, and observe how application monitoring distinguishes a cache hit from a failed origin request. A cached response may remain available for some time after origin permissions change, depending on cache and invalidation rules. A team that cannot explain this behavior should not declare its access controls fully validated.
CloudFront changes can affect availability for customers in many places at once, while an S3 bucket policy can affect several distribution and application workloads. Keep the identity of the policy owner, the approved distribution ARNs, the expected object paths and the maintenance procedure in a change record. Monitor access errors, configuration drift and abnormal access patterns. Make sure logs do not expose unnecessary personal information or secrets merely because more logging was enabled.
Use least privilege, but recognize that least privilege is a tested relationship, not just a shorter policy statement. A condition can be too narrow and break production, or too broad and allow the wrong distribution. Review those cases through an approved change process with a safe rollback path. Protecting the origin, authorizing viewers and validating cache behavior are three separate responsibilities that have to agree for private content delivery to work as intended.
CloudFront OAC is valuable precisely because it solves a specific origin-authentication problem well. It is not a replacement for application entitlements, encryption planning, viewer signing or monitoring. A credible CloudFront/S3 design can explain the identity at each hop, why an unapproved direct-origin request fails, how an authorized viewer obtains access and what evidence confirms the configuration continues to behave that way.