Skip to content
HN On Hacker News ↗

Building reliable (and fast!) directory sync

▲ 23 points • 2 comments • by jamilbk • 1w ago • HN discussion ↗

Pangram verdict · v3.3

We believe this text is mainly human-written, with some AI content.

11 %

AI likelihood · overall

Human
98% human-written 2% AI-generated
SEGMENTS · HUMAN 2 of 4
SEGMENTS · AI 0 of 4
WORD COUNT 658
PEAK AI % 64% · §2
Analyzed
Oct 2
backend: pangram/v3.3
Segments scanned
4 windows
avg 165 words each
Distribution
98 / 2%
human / AI fraction
Verdict
Human
Pangram v3.3

Article text · 658 words · 4 segments analyzed

Human AI-generated
§1 Human · 6%

“Who’s your User?”— Master Control Program, TRON (1982) If user identity is important to your application, you need a way to manage it. Usually this means user accounts, and you create them when someone signs up. But allowing employees to sign up for whatever SaaS app strikes their fancy is a management nightmare. So organizations like ways to control which users exist (or do not exist) in your app. That controls who can sign in, but how about what they can do? For that you need roles, or groups, which, like the users, come from the organization's identity provider - Entra, Google, Okta, etc. Groups form the basis of Firezone's access model. They determine who can access what. The process of getting users and groups into your app is called directory sync, and it's surprisingly tricky to do well. In this post we'll cover what directory sync is exactly, the leading standard for implementing it, and why we opted to forgo it entirely to build our own engine from scratch. Directory sync: a gentle primer An organization's directory is the list of who works there and what they're allowed to access. It lives in the identity provider and is made of three things: Users: the people in the organization. Each has a name, an email, and a status like active or suspended. Groups: named collections of users, like Engineering or Product. Groups let you grant access to many people at once. Members: who belongs to what. A member of a group is either a user or another group. A user's access comes from every group they belong to, directly or through other groups. Directory sync is the process of copying that directory into your app and keeping it up to date. The identity provider is the source of truth, so what your app holds is a copy.

§2 Mixed · 64%

Over time that copy has to pick up three kinds of changes: new users and groups, updates like a name change, and removals. When someone joins, leaves, or changes teams, ideally your app finds out quickly.

§3 Human · 9%

It's worth clarifying what directory sync is not: Single Sign-On (SSO). This may seem obvious but many folks conflate the two. Leading authentication standards like OpenID Connect say nothing about how to bring users into the application. In directory sync we're referring to precisely the mechanism of bringing users (and groups) in, but not how they're authenticated (for that, see this post). A simple example Say your organization has the following directory: An example directory with a nested groupA directory with two groups and two users. The Product group has two members: the user Alice and the group Engineering. The Engineering group has one member: the user Bob. Because Engineering is a member of Product, Bob belongs to Product indirectly.Group: ProductUser: AliceGroup: EngineeringUser: Bob In your database it might look something like this: The example directory as database tablesThree tables. Users lists Alice and Bob. Groups lists Product and Engineering. Members has a user column, a group column, and a parent group column. Alice is a user in Product. Bob is a user in Engineering. The group Engineering is in Product. Each row leaves one of the first two columns empty, and answering whether Bob is in Product means following parent groups through recursive queries.UsersnameAliceBobGroupsnameProductEngineeringMembersusergroupparent_groupAlice-ProductBob-Engineering-EngineeringProduct To answer common access questions in your app like "is Bob a member of Product?", you'd have to look at Product's members, then the members of any groups in there, and so on until you find Bob. To avoid that, we can flatten groups, giving each user a row for every group they belong to, directly or not: The example directory with flattened membershipsThree tables.

§4 Mixed · 58%

Users lists Alice and Bob. Groups lists Product and Engineering. Members has a user column and a group column, with one row for every group a user belongs to, directly or indirectly: Alice is in Product, Bob is in Product, and Bob is in Engineering.