Under the hood
Private origin: a Laravel container only the CDN can reach
A CDN in front of a serverless Laravel container does not lock its own address. How edge.private_origin lets Scaleway refuse a direct request before it wakes.
In this post
- Can anyone reach a Laravel container behind a CDN directly?
- Why a direct request costs more than it looks
- Why the edge secret does not close the door
- A container that only answers with a token
- What a deploy does, and in which order
- What changes for you
- What it needs
- How strong is it?
- When to turn it on
You put a CDN in front of your Laravel app, pointed your domain at it, and from then on every visitor came through the edge. It is easy to conclude that the edge is now the only door. It is not. The container behind it still has an address of its own, and that address answers anyone who asks.
On a server that runs all day that is a matter of tidiness. On a serverless container it decides whether the container ever sleeps. This post explains why the address behind your CDN stays open, why a secret between the CDN and your app does not close it, and how edge.private_origin in Brewless lets Scaleway refuse those requests itself.
Can anyone reach a Laravel container behind a CDN directly?
Yes. A CDN is a second way in to your application, not a lock on the first. A serverless container at Scaleway has a public address of its own, and unless the provider is told to refuse requests there, it answers them like any other.
With Brewless an environment has two such addresses. The first is the one Scaleway gave the web container, which ends in .scw.cloud. The second is the test address, such as acme-shop-production.brewless.dev: a CNAME that leads straight to the container, so that an environment works before it has a domain of its own. Neither goes through bunny.net.
Why a direct request costs more than it looks
A request that comes through the edge often never reaches your container: bunny.net keeps the pages that are the same for everybody and answers them itself. That is what lets a container scale to zero. On Scaleway it sleeps after 15 minutes without a request.
On the container's own address nothing is kept. There is no cache in front of it, so every request there is answered by PHP, and every one of them starts the 15 minutes again. Crawlers find both addresses and ask them now and then. A crawler that comes by every few minutes is enough to keep a container awake that the edge would have let sleep all night.
It is also hard to spot. A request that goes straight to the container never passes bunny.net, so no log of the edge shows it. What you see is a container that ran in hours in which the edge sent it nothing.
Why the edge secret does not close the door
Most setups with a CDN in front already have a shared secret: the edge adds it to every request, and the application only believes headers such as the visitor's hostname and address when the secret comes with them. Brewless sets one up for every environment behind bunny.net, and it can be replaced without a gap.
That secret answers a different question. It decides what your application believes about a request. It does not decide whether the container runs for it. A request without the secret is still answered, as the container itself, and to answer it the container has to be awake. Checking a secret in middleware comes too late for a container that was asleep: by the time Laravel can say no, the bill has started.
| Who refuses | Does the container wake? | |
|---|---|---|
| Nothing | Nobody: the request is answered | Yes |
| Edge secret | Your application, for the headers it would otherwise believe | Yes |
| Private origin | Scaleway, before the container | No |
So the refusal has to come from in front of the container, and on a serverless platform that means from the provider.
A container that only answers with a token
Scaleway has a setting for exactly this. A container whose privacy is private is only called with a token in the X-Auth-Token header. Scaleway answers any other request with a 403 itself, and the container does not start for it.
The edge then has to send that token with every request. In brewless.yml it is one line:
environments:
production:
edge:
private_origin: true
It is off unless the file says so, and brewless plan shows the change before you deploy it.
What a deploy does, and in which order
The order matters here. Make the container private before the edge sends the token, and every visitor gets a 403. A deploy with edge.private_origin: true therefore does this after the release is live:
- The token. It makes an identity in your Scaleway organisation,
brewless-<application>-<environment>-origin, that may call the private containers of the application's project and nothing else, and a key for it. The secret key of that key is the token. It is kept in your own Secret Manager and made once: the next deploy uses the same one. - The edge. It gives the pull zone a rule,
brewless: origin token, that adds the token to every request the edge sends your container, and waits two minutes for the rule to reach every edge server. While the container is still public the token is simply ignored, so nothing changes yet. - The container. Only then it makes the web container private, and asks its health route the way the edge does, with the token.
When the container keeps refusing for two minutes, it is made public again and the deploy says so. The site keeps answering, and the next deploy tries again.
Turning it off goes the other way. A deploy whose file no longer says private_origin: true makes the container public first and only then takes the rule off the pull zone. Every change is written to the audit trail. The token never is.
Note
Brewless only undoes what it did. A web container you made private yourself in the Scaleway console, without the rule at the edge, is left as it is.
What changes for you
Your test address stops answering. It points straight at the container, so a browser gets Scaleway's 403. That is the point, but it surprises the colleague who had it bookmarked. Use your own domain, or the address of the pull zone (<pull zone>.b-cdn.net).
You can check it from a terminal. This should say 403 once the deploy is through, while your own domain answers as before:
curl -I https://acme-shop-production.brewless.dev
Only the web container is private. The release and worker containers keep their own addresses and stay public. Release commands, the queue and the scheduler reach them as they did.
Brewless still reaches it. Every call Brewless makes straight to a container, such as the health check of a release, adds the token when that container is private. The edge's own requests carry it through the rule, the warm-up after a release included.
What it needs
- An edge. Without a pull zone nothing would send the token. The container stays public and the deploy says why.
- A Scaleway key that may manage identities (IAMManager). Without it the container stays public and the deploy says so.
- No mail through Scaleway. Scaleway reports what became of a mail to the web container's own address and cannot send a token along. A file with both
mail: scalewayandprivate_origin: trueis refused. Lettermint is not affected.
How strong is it?
It is a shared token, and it is worth being exact about what it is and is not.
The token lets whoever has it call every private container of the application's project, and nothing else at Scaleway. Like the edge secret, it sits in a rule of your pull zone, where anyone with the bunny.net key of your account can read it. It keeps crawlers and scanners off the container's address. It is not a replacement for authentication in your application, and the edge secret keeps doing its own job next to it.
To take the token away, delete the key of the identity in the Scaleway console. Scaleway then refuses the edge as well, so make the container public first.
Warning
A private web container whose token is gone is not given a new release, because it would refuse every visitor too.
When to turn it on
Not every environment needs it. An application whose public pages cannot be kept at the edge anyway is awake for its visitors, and a few crawlers on the side change little. It earns its place on an environment that is meant to sleep: a site whose pages the edge keeps, with a container that still runs in hours the edge was quiet.
If that is your environment, turn it on for one environment first, open the site on its own domain, and check the test address for the 403. The full description is on the Private origin page of the documentation, next to The edge secret.
Frequently asked questions
Can visitors reach my Laravel container without going through the CDN?
Yes, unless you close it. A serverless container at Scaleway has a public address of its own, and with Brewless the test address of an environment points straight at it as well. A CDN in front adds a second way in. It does not take the first one away.
Does the edge secret not already protect the container?
It protects what your application believes, not whether the container runs. Without the secret the application ignores the hostname and visitor address a request claims, but it still answers, and to answer it has to be awake. A private origin has Scaleway refuse the request before the container starts.
What happens to the test address with a private origin?
It stops answering. The test address leads straight to the web container, so a browser gets a 403 from Scaleway. Open the site on your own domain or on the address of the pull zone at bunny.net instead.
Do the queue worker and the scheduler still work with a private origin?
Yes. Only the web container is made private. The release and worker containers keep their own addresses and stay public, so release commands, queue triggers and the scheduler reach them as before.
Can I use a private origin when my app sends mail through Scaleway?
No. Scaleway reports what became of a mail to the web container's own address and cannot send a token along, so Brewless refuses edge.private_origin together with mail through Scaleway. Mail through Lettermint is not affected.