Infrastructure
Your Identity Provider Cannot Sit Behind Its Own Login Gate
How to design Cloudflare Access and OIDC SSO without creating a recursive authentication dependency, while keeping the identity service private, recoverable, and useful as an authorization source.
- Identity
- SSO
- OIDC
- Cloudflare Access
- Authentik
- Zero Trust
Putting internal applications behind a single sign-on gateway feels simple until you remember that the gateway itself needs somewhere to send users to log in.
That creates one architectural rule worth writing on the whiteboard before configuring anything:
The identity provider cannot require the identity flow it is responsible for completing.
If it does, you have built a recursion loop instead of an authentication system.
I ran into this while designing a self-hosted identity plane where an OIDC provider supplies identity and group claims to an edge access layer. The exact products are less important than the dependency graph: the pattern applies to any setup where an edge proxy delegates authentication to an identity provider you also host.
Draw the login path before touching policy
For an ordinary protected application, the flow is straightforward:
user
↓
edge access policy
↓
identity provider
↓
OIDC callback
↓
edge authorization
↓
private application
The access layer asks the identity provider who the user is. The identity provider authenticates them, returns signed claims, and the access layer decides whether those claims satisfy policy.
Now draw the identity provider itself.
This is valid:
Internet
↓
edge network
↓
private tunnel / reverse proxy
↓
identity provider
This is not:
Internet
↓
Access
↓
identity provider
↓
Access
↓
identity provider
↓
...
If the identity provider hostname is protected by the same Access policy that depends on that identity provider, an unauthenticated user can never reach the component required to authenticate them.
It is the identity equivalent of locking the only key inside the safe.
“Not behind Access” does not mean “wide open”
Avoiding the recursive gate does not require exposing the identity server directly to the Internet.
The useful distinction is between network reachability and authentication delegation.
An identity service can still be protected with layers such as:
- outbound-only tunnel connectivity from the origin;
- no public NAT to the host;
- host and container firewalls;
- the identity product’s own authentication flows;
- MFA for administrator accounts;
- rate limiting and edge filtering;
- tightly scoped management access;
- a local break-glass path.
The edge can still proxy traffic to the identity service. It simply must not demand an OIDC session from that same service before allowing the OIDC flow to begin.
That distinction makes the architecture much easier to reason about.
Treat identity as infrastructure, not another app container
An identity provider has a different failure profile than a normal dashboard.
If a dashboard fails, one application is unavailable. If your identity provider fails, every application whose login depends on it may become unavailable at the same time.
That changes deployment decisions.
For a small environment, I like thinking in two profiles:
| Profile | Good at | Main risk |
|---|---|---|
| Dedicated VM | isolation, independent maintenance, smaller shared blast radius | another OS to patch and monitor |
| Existing Docker host | low overhead, fast deployment, reused operations | identity shares outage and compromise domains with unrelated workloads |
The application architecture should stay the same across both. Deployment location should be data, not a forked implementation.
For example:
identity_deployment_profile: dedicated_vm
# or
identity_deployment_profile: existing_docker_host
The common stack, backup behavior, application objects, and verification logic remain shared. Only host lifecycle and coexistence behavior change.
That lets you start small without making the migration to a dedicated failure domain a rewrite.
Run preflight before mutating a shared host
Deploying identity onto an existing Docker host deserves a stricter preflight than “Docker is installed.”
Before changing anything, verify:
- available CPU and memory;
- free disk space and inodes;
- Docker/Compose versions;
- existing project names and container names;
- port conflicts;
- storage paths;
- log rotation;
- backup destination reachability;
- whether firewall changes would affect unrelated services.
If preflight fails, stop before mutation.
This is a broadly useful infrastructure pattern: a shared host should be treated as somebody else’s failure domain even when you own everything on it.
Keep the database private to the application network
Most identity platforms are stateful. Their database contains the material that turns a collection of containers into your identity system.
Do not publish the database port just because it is convenient during setup.
A better default is:
edge/tunnel → identity server
↕
private DB network
The database should only be reachable by components that need it. Do not mount an unrestricted Docker socket into the identity stack unless a feature explicitly requires it and you have accepted that risk.
Pin image versions where practical, add health checks, and make persistent storage paths explicit enough that another operator can identify what must be recovered.
Separate authentication from authorization
SSO answers two different questions:
- Who is this?
- May this person use this application?
Do not stop after the first one.
A useful authorization model is to make the identity provider authoritative for application groups and pass those groups as a multi-value OIDC claim.
For example:
{
"email": "user@example.com",
"groups": ["app-monitoring", "app-ipam"]
}
Then the access layer evaluates membership rather than maintaining a second parallel user directory.
A naming scheme can stay simple:
platform-admins
app-monitoring
app-ipam
app-home-automation
app-internal-tools
The default should be deny. A user with no relevant group should not get an empty application account and be called “authorized.”
This also produces a clean grant/revoke workflow: change group membership at the identity source rather than editing policy in several products.
Be careful with declarative identity automation
Infrastructure-as-code is excellent for creating the shape of an identity system:
- groups;
- OIDC providers;
- applications;
- claim mappings;
- access policies;
- tunnel and DNS configuration.
Human membership is different.
If an administrator adds someone to app-monitoring through the identity UI, your next Ansible or Terraform run should not silently erase that membership unless membership itself is intentionally declared in code.
This is a common reconciliation bug: automation owns more state than the operator realizes.
Write down ownership for each object. “Managed by code” should be a deliberate contract, not a side effect of the provider API.
Session revocation is not necessarily instantaneous
Removing a user from a group changes future authorization, but the effective time depends on every session layer in the path.
You may have:
identity-provider session
↓
edge access session
↓
application session
If an urgent revocation matters, document how to invalidate active sessions rather than assuming a group edit immediately destroys every existing token and cookie.
For each protected application, know:
- identity session duration;
- access-layer session duration;
- application session duration;
- whether active sessions can be administratively revoked;
- the maximum expected time from access removal to effective denial.
That turns “we removed access” into a measurable security property.
Bootstrap without creating permanent bootstrap debt
Identity systems have an awkward first-run problem: before the identity system exists, it cannot authenticate the administrator who is creating it.
Make bootstrap deterministic but temporary.
Good rules include:
- generate stable application secrets only when absent;
- do not rotate secrets accidentally on every rerun;
- never print secrets to CI or terminal logs;
- keep secret files tightly permissioned;
- hand off from bootstrap administrator to named accounts;
- preserve one monitored local emergency administrator;
- protect administrator accounts with MFA;
- keep the emergency path independent of the normal federated login path.
That last point matters during an outage. A break-glass account that itself depends on the failed identity chain is not a break-glass account.
Design recovery before onboarding applications
Identity recovery deserves more than “PostgreSQL is backed up.”
Inventory the state required to reconstruct the service:
- database contents;
- application data directories;
- certificates and custom templates where applicable;
- blueprints/configuration;
- secret material;
- tunnel credentials;
- infrastructure state;
- the instructions needed to re-establish the edge OIDC relationship.
Then restore it somewhere isolated and prove the full flow:
test user
↓
identity login
↓
OIDC token
↓
edge policy
↓
test application
Recovering the database is only half a restore if nothing can complete an actual login afterward.
The design review I use now
Before I put another application behind a self-hosted identity stack, I want answers to these questions:
- Can the identity hostname be reached without requiring the OIDC flow it provides?
- Is the origin unreachable directly from the public Internet where possible?
- Does the identity service have its own MFA and abuse controls?
- Is there an independent local break-glass path?
- Is the database private?
- Are authorization groups owned by one source of truth?
- Is default authorization deny?
- Does automation have explicit ownership boundaries for human-managed state?
- Do we know how long revocation can take across every session layer?
- Can the entire identity flow be restored and tested away from production?
SSO is easy to demo. The harder part is making sure the login system remains reachable, recoverable, and authoritative when something underneath it breaks.
Draw the dependency graph first. It will usually reveal the dangerous parts before the configuration does.