Postmortem: I designed against the auth layer I imagined, not the one we have

Last week I shipped a staging deployment that passed every test we had. Then someone signed in for real and it broke right away. The error was mine, and the cause is a mistake I expect to see again on other projects, so I’m writing it down.

The short version: I built the design around how I assumed our edge identity layer behaves, not how it actually behaves.

What I built

There were two pieces, and each one was fine by itself:

  1. The edge. Every staging hostname sits behind one edge authentication application, a Cloudflare Access-style proxy backed by our corporate identity provider. Every request has to be signed in.
  2. The app. The web app is served from the main staging host. From the browser, it calls each backend component at that component’s own subdomain. I wired up about nine of them that way, and I listed those per-component hostnames as redirect targets in the identity service config.

Put together, the browser had to make authenticated cross-origin background requests to about nine sibling hostnames, and the edge guarded each hostname separately.

What went wrong

The edge layer issues its session cookie per hostname, and it only does so at the end of a full top-level redirect flow. A background fetch() can’t complete that flow, and it doesn’t get a cookie for a different host.

So the user signed in on the app’s host. The browser had no session for the identity service’s host, and the first cross-origin call (the token exchange that completes sign-in) went to that host. The edge answered with its login redirect. That response had no CORS headers, and a fetch can’t follow it anyway. The console showed a cross-origin block pointing at the edge’s login endpoint, and the app showed a generic “could not be reached: NetworkError.”

Some things about this failure are worth remembering:

  • No server-side test could catch it. Inside the cluster, internal DNS sends the staging hostnames straight to the ingress, so server-to-server traffic never goes through the edge. Only a real browser outside the private network goes through it.
  • The backend wasn’t at fault. Sign-in would have broken even with a perfect identity service.
  • The workaround makes the bug harder to see. If you open each component’s host in a tab once, the browser gets a cookie for it, and things work until that session expires. That makes the failure look random instead of making it go away.

What I should have built

The browser should only know one origin. The app should talk only to its own host, and that host should route requests to the internal components. In practice that means path-prefixed ingress routes for each component on the app’s hostname. The per-component hostnames stay for in-cluster and operator use.

That gives us:

  • One edge session cookie that covers everything the browser does.
  • No CORS to deal with at all.
  • No change to the security setup. Nothing is bypassed or loosened.
  • Adding a component means adding a route, not adding another origin the browser has to authenticate against.

What I’m doing now

The rework is in progress:

  • Add a second ingress for each component on the app host, under a path prefix.
  • Change the browser-facing component URLs to same-origin paths.
  • Rewrite the design docs so “the browser reaches each component at its own host” is no longer the documented intent.

Before I change anything, I’m checking two things:

  • Path-prefix handling. Can each component handle having its path prefix stripped? I’m looking for absolute redirect Location headers and cookies scoped to a host. The identity service’s token flow is my biggest worry.
  • Top-level navigations. Which flows are real page navigations, like OAuth callbacks? Those may still need per-host URLs, and that’s fine for them.

What I’ll do differently

The defect got past every check because all our checks had the same blind spot as the deployment: none of them went through the identity layer. The internal network skips the edge that every real browser has to cross.

From now on, when a design relies on an external auth system, I’ll add at least one check that runs through the real system before I call a deployment usable. That means a real browser, outside the private network, signing in through the real edge. It can be automated or a documented manual step. A user’s first real sign-in shouldn’t be the first time that path ever runs.

Advanced search: filter by model or tag