How to create a security group that allows only traffic coming from CloudFront?
Posted on March 5, 2026 • 4 min read • 768 wordsWhy the question “How can I allow only CloudFront traffic in a security group?” keeps coming up on AWS, what it reveals about the limits of the network model, and how to answer it properly in production.

In the AWS world, some questions come up again and again.
Not because they are poorly phrased, but because they point to a real friction between security, networking, and application architecture.
At first glance, the question seems simple—almost trivial.
In reality, it reveals an excellent architectural intuition… and a structural limitation of the AWS network model.
This question almost always appears in the same concrete scenarios:
The underlying reasoning is perfectly sound:
“If all traffic goes through CloudFront, then my backend should only accept traffic from CloudFront.”
The instinctive answer therefore makes sense:
“I’ll just restrict my security group to CloudFront only.”
That is precisely where the problem starts.
An AWS Security Group works with:
But CloudFront:
It is therefore impossible to express in a security group:
“Allow only CloudFront”
Without:
0.0.0.0/0 is a false solution
In many projects, you eventually come across a rule like this:
Inbound: 443 from 0.0.0.0/0Often justified with reasoning such as:
“Anyway, only clients go through CloudFront.”
In practice, however, this means:
CloudFront becomes optional, which cancels out a large part of its value.
This question is interesting because it highlights several realities that are often underestimated:
In other words:
Once the problem is reframed this way, the solutions become clear.
(the most common pattern)
CloudFront allows you to add a custom header to requests sent to the origin, for example:
X-Origin-Secret: s3cr3t-valueOn the Application Load Balancer or application side:
Advantages:
With AWS WAF:
Advantages:
This is often the preferred solution in enterprise or compliance-driven environments.
When the origin is an Amazon S3 bucket:
This is the gold standard for static websites.
Honestly, this question is rarely asked by accident.
It usually indicates that the person asking it:
The question:
“How can I create a security group that allows only traffic coming from CloudFront?”
is interesting because it:
The correct answer is not:
“Here is the right CIDR.”
The correct answer is:
“The control must be implemented somewhere other than the security group.”
And that is exactly what makes the difference between
an infrastructure that merely works
and one that stands the test of time.
CloudFront – Restricting access to the origin
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RestrictingAccessToOrigins.html
AWS WAF – Concepts and use cases
https://docs.aws.amazon.com/waf/latest/developerguide/what-is-aws-waf.html