I put a login in front of my workflow tool and left the webhooks outside it
The editor for my self-hosted workflow tool now sits behind an identity check at the network edge. The webhook paths are exempt on purpose, which makes every webhook a public endpoint that has to do its own checking.
As of today, the editor for my workflow tool sits behind a login at the network edge. Before a request reaches the tool's own sign-in page, an identity-aware proxy asks who is calling and lets exactly one person through. The webhook addresses on the same hostname are exempt from that check. I exempted them on purpose, and they are the part of this setup I would look at hardest.
What it replaced
The tool is n8n, self-hosted in a container at home. It has a public hostname for one reason, which is that outside services have to deliver webhooks to it. I publish the hostname through a Cloudflare Tunnel. Cloudflare's documentation describes the design as a daemon that "creates outbound-only connections" from your network to theirs, so there is no forwarded port on my router.
Until today the tunnel carried a path allowlist. Requests for webhook paths went through to the tool. Requests for anything else, the editor included, were refused at the tunnel with a 403. The editor could only be reached from inside the house.
That arrangement was safe, and it had a cost that I kept paying. When you connect an OAuth credential in the editor, the outside provider sends your browser back to the tool's public hostname, on a path that is not a webhook. With the allowlist in place, that redirect ran into the 403. So every reconnect meant editing the tunnel configuration by hand to open the editor to the internet, doing the reconnect, and editing the configuration again to close it.
Last month I wrote about a token that has to be renewed by hand every 60 days. It lapsed on September 17, on schedule. I did not renew it until October 9, so the pipeline behind it published nothing for three weeks. The renewal itself took an hour, and the procedure in the previous paragraph is why. The same day I added the thing I had admitted to not having: a reminder ten days ahead of the next expiry, and a check that notices when the pipeline has gone quiet.
A procedure that involves opening the front door by hand and remembering to close it afterward will be left open one day. I wanted the door to have a lock on it instead.
What I built
The tunnel now passes every path to the tool. In front of it, Cloudflare Access applies a policy that allows a single identity, mine. Sign-in is by one-time code. Cloudflare's documentation says Access "can send a one-time PIN (OTP) to approved email addresses," and that it "only sends the email if the user is allowed by an Access policy." An address that is not on the list gets nothing. After that check the tool's own login appears as before.
So there are now two logins in series, and the outer one is enforced before a request ever reaches my network.
Then I added the exemptions. The webhook paths and the tool's health check path are set to bypass the Access policy.
Two side effects followed, and both are worth knowing if you copy this.
Signing in over plain HTTP from inside the house stopped working. The tool has a setting that its documentation describes this way: "Ensures that cookies are only sent over HTTPS, enhancing security." With that on, a browser will not send the session cookie over a plain HTTP connection to a local address, so the old local login is gone. The tool's API still answers locally, because it authenticates with a key in a header and uses no cookie.
The OAuth callback is now behind the outer login as well. I expect that to work, because the browser being redirected is mine and already holds an Access session. I have not tested it with a real renewal. The next one is due in early December. If the redirect loses its authorization code on the way through, the fix is one more exemption for that single callback path.
The order mattered
I created the exemptions before I turned on the gate.
Done in the other order, there is a window in which every inbound webhook is answered with a redirect to a login page. The services sending those webhooks cannot sign in. Their deliveries fail on their side, and nothing on my side records a failure, because the requests never arrive.
That gives me a symptom to remember. If a webhook address on this hostname ever answers with a redirect to a login page, an exemption has been removed and the integrations behind it are already down.
The way back in
In May I wrote that you should build the way back in before you lock something down. This change put a new login in front of the tool and removed the old local one in the same afternoon, so I wrote the recovery steps before I finished.
There are two, and each is a single file restored from a copy I saved today. Restoring the previous Compose file brings back the local login. Restoring the previous tunnel configuration brings back the old allowlist. The written steps are stored in several places that do not depend on one another, including the hypervisor host, from which I can get a shell inside the container if I cannot reach it any other way.
What the login does not cover
Cloudflare's documentation is plain about the exemption I used: "Bypass does not enforce any Access security controls and requests are not logged."
So for the webhook paths, the edge does nothing, by my own configuration. They have to be reachable by services that cannot sign in, which is the point of a webhook.
That makes each webhook address a public API endpoint. Anyone who learns the address can send it a request, and whatever the workflow does next, it does for that caller. An address that is hard to guess helps less than it seems to. It appears in the sending service's settings, in logs along the way and in every screenshot of either.
The check has to live at the webhook itself. The n8n documentation says of its webhook trigger: "You can require authentication for any service calling your webhook URL." It lists basic auth, header auth and JWT auth as methods. It also lists None. There is an IP allowlist option described as a way "to limit who (or what) can invoke a Webhook trigger URL."
Cloudflare Access checks identity before a request reaches my network
One identity is allowed, signed in by one-time code
The tool's own login appears after that, as before
Bypass: no Access security controls and requests are not logged
Anyone who learns the address can send a request
The check has to live at the webhook itself
The health check path is exempt as well. I created the exemptions before I turned on the gate.
Where the sender signs its deliveries, verify the signature. GitHub's documentation describes the common pattern: a shared secret, a hash of the payload computed with it, and the result sent in a header, so that "your server only processes webhook deliveries that were sent by GitHub."
For machine callers that you control, Cloudflare suggests a third route in the same warning: "Consider using Service Auth if you would like to enforce policies and maintain logging." The caller presents a token at the edge and the request is checked and recorded there.
For each webhook, these are the questions I would ask.
- What does it start? A webhook that records a row is one thing. A webhook that starts an action on your own infrastructure deserves the strictest check you have.
- Does the trigger authenticate the caller, and where is that secret stored?
- What happens when a stranger sends it a well-formed request? What about the same valid request sent twice?
- Does anything still send to it? An unused webhook is the forgotten public link I wrote about in August.
The gate I built today covers the surface I use. The webhooks are the surface that other machines use, and each one has to carry its own check, because nothing at the edge will do it for them.
One caveat on the gate itself. It adds a dependency. If the provider's sign-in is unavailable, I cannot reach the editor from anywhere, since the local login is gone. That is the reason the recovery steps exist, and the reason they are not stored only on the machine they describe.
Sources
- https://developers.cloudflare.com/cloudflare-one/access-controls/policies/
- https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/
- https://developers.cloudflare.com/cloudflare-one/integrations/identity-providers/one-time-pin/
- https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.webhook/
- https://docs.n8n.io/hosting/configuration/environment-variables/security/
- https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries
Views are my own.