İçeriğe geç
Korur
Başarı Öykülerine dön

Segregated Identity Domains: Staff and Customer Trust Separated and Codified in Terraform

Microsoft sign-in and permanent lockout for staff, verified self-registration and a strict password policy for customers, every realm setting reviewed as code before it reaches production.

Can the people who run a business and the customers who buy from it share one sign-in platform without sharing a trust boundary? For Fepatex, a B2B supplier whose clients include companies in defence and automotive manufacturing, Korur answered that question with two separate identity domains on one Keycloak installation: one for staff, one for customers, each with its own rules, and both defined in Terraform so that no setting changes without a reviewed plan.

Client
Fepatex B.V.
Website
fepatex.nl
Engagement
Identity architecture and identity as code
Identity domains
Two: staff and customers
Managed as code since
October 2026
Change path
Pull request plan, applied on merge
Industry
B2B supplier

Context

Fepatex runs five production applications that Korur built and operates: an API, a staff portal, a client portal, offer pages for external recipients and a webshop. Two very different groups of people sign in to them. Fepatex's own employees use the staff portal to manage products, organisations, dossiers, offers and the people who may act on behalf of a customer. Customers, and the contact persons of customer organisations, use the client portal, the webshop and the offer pages to order, follow their dossiers and accept offers.

Those two groups have nothing in common from a security point of view. Employees are known people with a Microsoft work account that Fepatex already manages. Customers register themselves, choose their own passwords and change over time as organisations change contacts. A supplier whose clients include companies in defence and automotive manufacturing is also asked, sooner or later, to show how it separates the two: who can sign in where, how an account is locked, and how a change to that configuration is controlled.

Korur's brief was to give each group the sign-in experience it needs, to keep their trust boundaries apart so that a weakness on one side cannot become access on the other, and to make the whole configuration reviewable, repeatable and recoverable rather than a set of choices clicked into an administration console.

The problem

A single identity domain for everyone is the common starting point and the common mistake. When staff and customers live in the same realm, they share one password policy, one set of sign-in options and one token issuer. Self-registration, which customers need, then sits next to administrative roles, which only staff should ever hold. A token issued to a customer is signed by the same issuer as a token issued to an administrator, so every application has to tell them apart by claims alone, and a single misconfigured role mapping is enough to blur the line.

The second problem is drift. Identity configuration is usually built in the administration console. Over time nobody knows why a session lasts as long as it does, who switched a setting off, or whether the test environment still matches production. When an auditor asks how account lockout is configured, the honest answer becomes a screenshot from today, not a controlled history.

The risks Korur designed against were therefore concrete:

  • A customer account, or a self-registered account created for the purpose, gaining any path to staff functions.
  • Password guessing against staff accounts, which hold the widest access to customer data.
  • Weak or reused customer passwords on a platform that carries orders, offers and personal data.
  • Unreviewed changes to sign-in settings, and no reliable record of what the configuration was at a given moment.
  • Secrets of the identity platform, such as client secrets, ending up in version control or in infrastructure state files.

Architecture

Fepatex's identity runs on one Keycloak installation that Korur operates, served under Fepatex's own domain. Inside it, Fepatex has two realms. A realm in Keycloak is a fully separate identity domain: its own users, its own credentials, its own sign-in rules, its own signing keys and its own token issuer. Nothing a user does in one realm grants anything in the other.

The two identity domains and how they differ
SettingStaff realmCustomer realm
Who signs inFepatex employeesCustomers and contact persons of customer organisations
How accounts are createdNo self-registration; staff are invitedSelf-registration with the email address as username
Sign-in methodMicrosoft work account through an identity providerEmail address and password
Email verificationNot needed; the work account is already managedRequired before the account is usable
Self-service password resetOffOn
Remember meOffOn
Password policyGoverned by the Microsoft accountLength, history, character classes, no username or email, yearly forced change
Access token lifetimeOne hourFive minutes
Token signatureRS256RS256

Each application is registered in exactly one realm. The staff portal is a public client in the staff realm and signs in with the authorization code flow and PKCE (S256); it has no client secret to leak, and the direct password grant is switched off for it. The three customer-facing applications share one confidential client in the customer realm and complete the sign-in on their own server side, so the client secret never reaches a browser. That secret is held in Korur's secret store, outside every repository.

Because every realm has its own issuer, the separation does not end at sign-in. The Fepatex API accepts a staff token only on staff routes and a customer token only on customer routes, each checked against the issuer it expects. That enforcement layer is the subject of the companion case on issuer-bound API authorization.

Above the realms sits the control layer: a Terraform root that describes every realm setting, client, role, identity provider and required action, keyed by readable names rather than Keycloak's internal identifiers. A pull request produces a plan that shows the exact change; merging the pull request applies that plan and nothing else.

What we built

The work came down to a small number of deliberate choices. Each is recorded below with the reason for it and the alternative we turned down, so a reader can judge the engineering and not only the outcome.

Decision 1

Decision
Two realms, one for staff and one for customers, instead of one realm with roles.
Why
A realm is the strongest boundary Keycloak offers. Separate realms give separate users, credentials, policies and token issuers, so a customer account cannot be promoted into a staff account by a role mapping mistake, and every API can verify by issuer which side a token comes from. It also lets each side have the rules it needs without compromise: self-registration for customers, none at all for staff.
Alternative rejected
One shared realm with staff and customer roles. Simpler to set up, but every policy becomes a compromise between two populations and the separation rests entirely on role claims being right everywhere.

Decision 2

Decision
Staff sign in with their Microsoft work account through an identity provider, with self-registration, self-service password reset and remember-me all switched off.
Why
Fepatex already manages its employees in Microsoft. Brokering that sign-in means the joiner and leaver process stays where it is: an employee who leaves loses the Microsoft account and with it the way into the staff portal. With registration off, nobody can create a staff account by visiting a page, and with password reset off there is no email-based recovery path for an attacker to abuse.
Alternative rejected
Separate Keycloak passwords for staff. That adds a second credential per employee for Fepatex to manage, and a second account to remember to close when someone leaves.

Decision 3

Decision
Permanent lockout in the staff realm after 15 failed sign-ins, released only by an administrator.
Why
Staff accounts hold the widest access to customer data. A permanent lockout turns sustained password guessing into a visible event that a person has to resolve, instead of a slow attack that waits out a timer. The threshold of 15 leaves room for honest mistakes, and a short quick-login check catches automated bursts.
Alternative rejected
Temporary lockouts with an increasing wait. Kinder to users, but an attacker who paces guesses below the wait time can continue indefinitely without anyone noticing.

Decision 4

Decision
Customers register themselves, but only with a verified email address and under a strict password policy.
Why
Customers must be able to start without a phone call, so self-registration stays. Email verification proves the address before the account is usable, and the email address doubles as the username so there is one identifier per person. The policy requires at least eight characters with upper case, lower case, a digit and a special character, refuses passwords that contain the username or email address, refuses the last three passwords and any password used in the past 60 days, and forces a change once a year. Customer access tokens live for five minutes, so a stolen token is short-lived.
Alternative rejected
Registration by invitation only. Safer on paper, but it would push every new customer through Fepatex staff and slow down the sales process the platform exists to support.

Decision 5

Decision
PKCE for the staff portal, a confidential server-side client for the customer applications.
Why
The staff portal is a single-page application that cannot keep a secret, so it is a public client protected by PKCE with the S256 method and direct password grants off. The customer applications render on the server and can keep a secret there, so they use a confidential client whose secret never reaches a browser.
Alternative rejected
One public client for every application. It would remove the server-side secret as a second factor for the customer applications without any gain.

Decision 6

Decision
Every realm setting in Terraform, planned on a pull request and applied on merge, never from a laptop.
Why
Identity configuration is security configuration. In Terraform every setting has a reviewed history: who changed it, why, and what it was before. The apply step can only use a plan produced by a pull request run, and a fresh plan is compared with it before anything is applied, so a plan nobody looked at cannot reach production. A change made in the console outside that path appears as drift in the next plan.
Alternative rejected
Exports of the realm configuration as JSON files. They document a moment but control nothing, and they carry secrets that should never be committed.

Decision 7

Decision
Existing realms adopted in place, not recreated.
Why
Fepatex's realms already held real users. Recreating them would have meant new signing keys, broken sessions and re-registered customers. Instead the Terraform rows describe the live configuration exactly, and the first apply after adoption changes nothing a user can notice; from then on, every change is a reviewed diff.
Alternative rejected
A clean rebuild of both realms from code. Tidier, but the cost would fall on Fepatex's customers.

Decision 8

Decision
No secret in Terraform, its state or its plans.
Why
Plans and state files are read by more people and systems than the identity platform itself. A confidential client carries only a version number in code; raising the version rotates the secret to a value nobody knows, which also serves as an emergency revocation. Identity provider secrets stay in Keycloak and are never read back. The pipeline credentials hold only the realm and client rights they need, and cannot read or manage users, so a pull request plan cannot list Fepatex's customers.
Alternative rejected
Secrets stored as Terraform variables. Convenient, but every plan artifact would then contain them.
staff = {
  registration_allowed   = false
  reset_password_allowed = false
  remember_me            = false
  ssl_required           = "external"

  security_defenses = {
    brute_force_detection = {
      permanent_lockout  = true
      max_login_failures = 15
    }
  }
}
Excerpt of the staff realm's sign-in rules as code, with the realm name generalised

Evidence

Every statement in this document is taken from the configuration itself, not from a description of it. The Terraform root holds one row per realm, client, role and identity provider, and the pipeline that applies it runs only on a merged pull request. The table below lists what a reviewer can check in that code.

Controls and where they are defined
ControlWhere it is enforced
Staff realm without registration, password reset or remember-meRealm row of the staff realm in Terraform
Permanent lockout after 15 failuresBrute-force settings of the staff realm in Terraform
Microsoft sign-in for staffIdentity provider row of the staff realm in Terraform
Verified self-registration and password policy for customersRealm row of the customer realm in Terraform
PKCE (S256) and no password grant for the staff portalClient row of the staff portal in Terraform
Plan on pull request, apply on mergeThe Keycloak workflow of Korur's infrastructure repository
No user rights for the pipelineService account roles of the plan and apply clients
  1. An engineer changes a realm setting on a branch and opens a pull request.
  2. The pipeline validates the code and posts the plan: exactly which settings will change.
  3. A reviewer reads the plan and approves the merge.
  4. On merge, the pipeline applies the plan produced for that pull request, after checking it against a fresh plan.

Outcome

Fepatex's staff and customers sign in through two separate identity domains, each with rules that fit the people in it. Staff use the Microsoft account Fepatex already manages, cannot be self-registered, and are locked out permanently after sustained password guessing. Customers register themselves, but only with a verified address and a password that meets a written policy.

Both realms have been under Terraform since October 2026. A change to either reaches production only as a reviewed plan from a pull request, and the history of every setting is in version control. When one of Fepatex's own clients asks how sign-in and account lockout are controlled, the answer is a file and its history, not a screenshot.

What we would do next

Identity work is never finished. These are the next steps Korur recommends, in order of value:

  • Retain sign-in and administrator events on both realms and forward them to central monitoring, so a lockout or an unusual sign-in pattern raises an alert rather than waiting to be found.
  • Offer a second factor to customer accounts, starting with the administrators of customer organisations. The one-time password setup is already prepared in code and needs one setting to switch on.
  • Confirm that the Microsoft sign-in for staff requires multi-factor authentication through Fepatex's conditional access policies, and record that requirement next to the realm configuration.
  • Review session lifetimes in both realms against the way people actually work, and shorten them where a long session adds risk without adding convenience.

Stack

  • Keycloak
  • Microsoft Entra ID
  • Terraform
  • GitHub Actions
  • OpenID Connect
  • PKCE

Siz de işinizi güvene almak ister misiniz?

Yükümlülüksüz görüşme. Sabit fiyat.

Buraya nasıl geldiğinizi ölçebilir miyiz?

Hangi sayfaların işe yaradığını ve sizi buraya hangi reklamın getirdiğini görmek için analitik çerezler kullanıyoruz. Reddederseniz site tamamen aynı şekilde çalışır ve hiçbir analitik çerez yerleştirmeyiz. Çerez politikası