You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(self-host): refuse instance-org resolution when the slug is ambiguous
organization.slug has no unique constraint, and the lookup took the first of
however many matched. The choice is unordered, so two replicas could resolve
different organizations and split new signups between them.
Resolution is now three-state. Ambiguity is distinct from absence, so it both
declines to adopt an arbitrary organization and declines to provision another
one on top of the duplicates.
* Resolves the single organization holding this slug.
111
+
*
112
+
* Matching on slug is deliberate — it is what lets the mode adopt an
113
+
* organization that already exists, such as one the consolidate script created
114
+
* before `INSTANCE_ORG_NAME` was set. But `organization.slug` carries no unique
115
+
* constraint, so duplicates are possible, and taking the first of several would
116
+
* be worse than wrong: the choice is unordered, so two replicas could resolve
117
+
* different organizations and split new signups between them.
118
+
*
119
+
* Refuses instead. Instance-organization mode stays off until the operator
120
+
* renames the duplicate or pins `INSTANCE_ORG_SLUG` at the one they mean, which
121
+
* is recoverable — silently sorting users into two organizations is not.
122
+
*/
123
+
typeSlugResolution=
124
+
|{status: 'found';organizationId: string}
125
+
|{status: 'none'}
126
+
|{status: 'ambiguous'}
127
+
128
+
asyncfunctionresolveInstanceOrganizationBySlug(
129
+
executor: DbOrTx,
130
+
slug: string
131
+
): Promise<SlugResolution>{
132
+
constrows=awaitexecutor
105
133
.select({id: organization.id})
106
134
.from(organization)
107
-
.where(eq(organization.slug,config.slug))
108
-
.limit(1)
135
+
.where(eq(organization.slug,slug))
136
+
.limit(2)
109
137
110
-
returnrow?.id??null
138
+
if(rows.length>1){
139
+
logger.error(
140
+
'Refusing to resolve the instance organization: more than one organization uses this slug. Rename the duplicate or set INSTANCE_ORG_SLUG to the intended one.',
0 commit comments