Skip to content
nikhil.

~/work/varnue-sso-marketplace

VarnueAI: one sign-in and one marketplace for five products

VarnueAI sells five products, each on its own domain, each with its own login, user table and idea of an organization. I put one self-hosted Keycloak in front of all of them and built Edge, a single marketplace with an admin panel that manages the whole suite. Customers now have one account, one 2FA setup and one sign-out. Every product still owns its own organizations, roles and data.

client
VarnueAI Business Solutions Pvt. Ltd.
year
2026
duration
Nov 2026 – present
role
Cloud DevOps Engineer · SSO and platform owner
KeycloakOIDCPKCEkeycloak-config-cliPostgreSQLDockerGitHub ActionsGHCRNginxNode.jsExpressReactTrivyGitleaks

5

products on one sign-in

5 → 1

logins per customer

7

OIDC clients (web + mobile)

0

forced password resets

Challenge

VarnueAI builds a suite of business products:

ProductWhat it does
AssetSphereAsset management for organizations
VarnueVedAIAn AI assistant over an organization's documents, on web and mobile
Vitye AIAI-assisted forecasting and reporting
LeadOpsLead and sales-pipeline management
Chem GemsA private, customised AssetSphere built for one client

They had grown up separately. Each one lived on its own domain (asm.varnueai.com, varnuevedai.varnueai.com, vityeai.varnueai.com, leadops.varnueai.com, …) with its own login screen, its own password table, its own "forgot password" email and its own idea of what an organization is. A customer who bought three products had three accounts and three passwords. Staff had no single place to see which organization used which product, or to switch a product on for a client.

The company wanted two things:

  1. One account for the whole suite. Sign in once, move between products without signing in again, sign out once.
  2. One marketplace. A single front door (Edge) where an organization sees its products and launches them, and an admin panel where staff manage the catalogue, organizations, subscriptions and billing for every product.

The constraints made it harder than it sounds:

  • Products must stay independent. Five teams, five databases, five release cycles. No product may write into another product's database, and the identity layer must not become a shared database everyone reaches into.
  • Nobody loses their account. Every product already had live users with data. A migration that forces everyone to reset their password, or orphans their records, was not acceptable.
  • It's self-hosted. The identity system runs on the company's own VM, so backups, upgrades and recovery are our problem, not a vendor's.

Approach

Decide who owns what

The first deliverable was a table, not code. It settled most later arguments:

ConcernOwner
Accounts, passwords, email verification, password resetKeycloak
Authenticator-app 2FA and recovery codesKeycloak (optional, enrolled by the user)
Google and Microsoft sign-inKeycloak identity brokering
Brute-force lockout, session lifetimeKeycloak
Organizations, roles, permissions, profile dataEach product, in its own database
The link between the twoThe Keycloak user id (sub), stored in each product's user table

Keycloak answers exactly one question, who is this person. Each product keeps answering what may they do here. That kept the change inside each product small: a new column (keycloak_sub) and one endpoint, not a new permission model.

One public PKCE client per product, one audience per backend

Every product SPA is a public OIDC client using Authorization Code + PKCE (S256). Password and implicit grants are disabled. Each client stamps its own audience into the access token, so a token minted for Vitye is useless at AssetSphere's API:

ProductKeycloak clientToken audience
Edgeedge-webedge-api
AssetSphereassetsphere-webassetsphere-api
VarnueVedAI (web / mobile)varnuevedai-web, varnuevedai-mobilevarnuevedai-api
Vitye AIvitye-webvitye-api
LeadOpsleadsuite-webleadsuite-api
Chem Gemschemgems-webchemgems-api

The exchange: one contract every backend implements

Products keep their own session tokens. The SPA sends the Keycloak access token to its own backend once (POST …/sso/exchange), and the backend:

  1. verifies the signature against the realm's JWKS, RS256 only;
  2. checks iss exactly, aud contains its audience, azp is its client, and email_verified is true;
  3. finds the user by sub, or links an invitation row with the same verified email, or answers 403 NO_ACCOUNT so the SPA can offer Create your organization;
  4. issues its own 15-minute session token carrying kc_sub and the Keycloak session id sid.

One written contract meant five product backends could adopt SSO in parallel, each in its own codebase. An end-to-end test in the SSO repo (register → verify email → token contract → user import) proves the contract on every pull request.

Sign-in that is safer than what it replaced

  • 2FA everywhere, never skipped. Users can enrol Google or Microsoft Authenticator and generate recovery codes from one account page. A custom post broker 2FA flow asks for the code after Google or Microsoft sign-in too, so a social login is never a way around 2FA.
  • No silent account takeover. If someone signs in with a Microsoft identity whose email matches an existing account, Keycloak makes them prove ownership before linking. Microsoft emails are not trusted as verified, because the tenant controls them.
  • Sign out once. Logging out ends the Keycloak session. Other tabs notice through keycloak-js's session iframe, and each backend receives a signed back-channel logout token and starts refusing session tokens with that sid.
  • Lockout and policy in one place: 10-character minimum, no reuse of the last 3, progressive lockout after 5 failures.

Migrate users without a reset

Each product was switched over in the same order, first on UAT, then production:

  1. Deploy the backend with SSO configured but the old login still working (AUTH_MODE=local).
  2. Export the product's users, import them into Keycloak without passwords, and write each new sub back into the product's user table.
  3. Rebuild the frontend with the Keycloak settings. Users get a "set up your sign-in" email.
  4. After a 48–72 hour soak, set AUTH_MODE=sso. Legacy password routes close and old tokens are refused.
  5. Point Keycloak's back-channel logout at the backend.

Production accounts were copied from UAT with their ids preserved, so links tested on UAT kept working in production. When Chem Gems arrived as a new client product, joining the suite took one realm client and one pull request.

Realm as code, deployed like any other service

The realm (settings, flows, clients, identity providers) lives in realm/varnueai.yaml and is applied by keycloak-config-cli on every deploy. Changing a redirect URI is a reviewed pull request, not a click in the admin console. CI boots Keycloak and Postgres, applies the realm twice to prove the import is idempotent, runs the end-to-end flow and scans the image with Trivy.

The SSO image follows the same promotion pipeline as every other VarnueAI service: main builds dev-<sha> and deploys it to auth.varnue.com, and a manual dispatch promotes that exact image to auth.varnueai.com. Keycloak is the one service that does not go blue/green: it is stateful and a version upgrade migrates its database, so two versions can't serve the same data. It gets an in-place restart behind a health gate, with a verified backup first and an automatic rollback. The details are in Self-hosted Keycloak for five products: realms, tokens, deploys and backups.

Edge: one marketplace for the suite

Edge is the customer-facing front door, built on the admin panel's API:

  • For an organization: sign in once, see the products it has, launch any of them in a new tab. The product signs the person in silently through the shared session and creates their account there on first visit (just-in-time onboarding).
  • For VarnueAI staff, in the admin panel: the product catalogue (name, icon, launch URL, which environments it's switched on in), organizations and which products each one can use, subscriptions and trials, invoices and payments, usage analytics, audit logs.
  • Private products: a client's customised copy (Chem Gems) is a private product that replaces the base product on that client's dashboard only. Its backend asks the admin API which organizations a person may use it in, keyed by their Keycloak sub.

The admin panel never connects to a product database. Creating an organization in Edge creates nothing inside a product; each product creates its own records from the SSO token the first time a member opens it.

Architecture

What shipped

  • Self-hosted Keycloak on auth.varnue.com (dev/UAT) and auth.varnueai.com (production): a custom-themed image, its own Postgres, Nginx with TLS in front, and the admin console not exposed publicly.
  • Five products (seven clients, including VarnueVedAI mobile) signing in through it in production.
  • Email + password, Google and Microsoft sign-in, authenticator apps, recovery codes, one account page, sign-out everywhere.
  • Import, export and keycloak_sub backfill tooling per product, with dry runs and audit queries.
  • The Edge marketplace and staff admin panel managing every product as a module: catalogue, per-organization access, private products, subscriptions, billing and analytics.
  • Nightly pg_dump backups verified with pg_restore --list, copied off the VM, a 14-day local retention, and a restore drill into a throwaway container.

Results: what it changed for the company

  • Customers have one account. One password, one 2FA setup and one sign-out across the suite, instead of a separate login per product. Moving from Edge into a product needs no second sign-in.
  • Cross-selling got easier. A customer can try another product without creating another account, and staff can switch a product on for an organization from the admin panel.
  • Security moved up, effort moved down. 2FA, brute-force protection, email verification, password policy and social login are configured once and every product inherits them. Products no longer run their own password reset or OTP code.
  • Onboarding a client-specific product is cheap. Chem Gems joined with one realm client and one catalogue entry, not a forked login system.
  • Product teams stayed independent. No shared database, one written contract, and each switch-over was a configuration change behind a soak period.
  • Identity is recoverable. Every product points at Keycloak user ids, so losing that database would orphan every account in the suite. Verified off-machine backups and rehearsed restores turned that from a company-ending risk into a runbook.

What I'd do differently

  • Back-channel logout from day one. It was the last step of each switch-over. Until it was configured, a product's own session lived up to its 15-minute expiry after a sign-out elsewhere.
  • A shared verification library. Five backends implemented the same exchange checks. The contract and the end-to-end test kept them honest, but one small package per language would have removed the duplication.
  • High availability for Keycloak. Today it is one instance per environment with health-gated restarts. A second node with a shared cache is the next step once traffic justifies it.
Share

More case studies

Related writing

// need something similar?

Let's talk about your system.

A 15-minute call is enough to tell you whether I can help and roughly what it takes.