Skip to content

Commit 3330000

Browse files
AlexTugarevSimon Emms
authored and
Simon Emms
committed
[auth] fix missing updates to dynamic login providers
this primarily affects self-hosted installation where the `ownerId` is about to change during the initial setup of the login/git provider.
1 parent 77a055f commit 3330000

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

components/gitpod-db/src/auth-provider-entry.spec.db.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class AuthProviderEntryDBSpec {
8888
const loadedAp = await this.db.findByHost(ap.host);
8989
expect(loadedAp, "findByHost()").to.deep.equal(ap);
9090
expect(loadedAp?.oauthRevision, "findByHost()").to.equal(
91-
"e05ea6fab8efcaba4b3246c2b2d3931af897c3bc2c1cf075c31614f0954f9840",
91+
"b05eb3256a101f6cbca1d8885c8ee241891582e78c567b7305f097ab3556d5f0",
9292
);
9393
}
9494
}

components/gitpod-db/src/typeorm/auth-provider-entry-db-impl.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class AuthProviderEntryDBImpl implements AuthProviderEntryDB {
3131
async storeAuthProvider(ap: AuthProviderEntry, updateOAuthRevision: boolean): Promise<AuthProviderEntry> {
3232
const repo = await this.getAuthProviderRepo();
3333
if (updateOAuthRevision) {
34-
(ap.oauthRevision as any) = this.oauthContentHash(ap.oauth);
34+
(ap.oauthRevision as any) = this.oauthContentHash(ap);
3535
}
3636
return repo.save(ap);
3737
}
@@ -91,8 +91,10 @@ export class AuthProviderEntryDBImpl implements AuthProviderEntryDB {
9191
return query.getMany();
9292
}
9393

94-
protected oauthContentHash(oauth: AuthProviderEntry["oauth"]): string {
95-
const result = createHash("sha256").update(JSON.stringify(oauth)).digest("hex");
94+
protected oauthContentHash(entry: AuthProviderEntry): string {
95+
const result = createHash("sha256")
96+
.update(JSON.stringify({ oauth: entry.oauth, ownerId: entry.ownerId, status: entry.status }))
97+
.digest("hex");
9698
return result;
9799
}
98100
}

components/server/src/auth/host-context-provider-impl.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ export class HostContextProviderImpl implements HostContextProvider {
8484
const existingContext = this.dynamicHosts.get(host);
8585
const existingConfig = existingContext && existingContext.authProvider.params;
8686
if (existingConfig && config.id === existingConfig.id) {
87-
if (existingConfig.host !== config.host) {
87+
const sameHost = config.host === existingConfig.host;
88+
if (!sameHost) {
8889
log.warn("Ignoring host update for dynamic Auth Provider: " + host, { config, existingConfig });
8990
continue;
9091
}
91-
if (existingConfig.status === config.status) {
92-
if (!!config.oauthRevision && existingConfig.oauthRevision === config.oauthRevision) {
93-
continue;
94-
}
95-
if (JSON.stringify(existingConfig.oauth) === JSON.stringify(config.oauth)) {
96-
continue;
97-
}
92+
const sameOwner = config.ownerId === existingConfig.ownerId;
93+
const sameStatus = config.status === existingConfig.status;
94+
const sameOAuthRevision =
95+
!!config.oauthRevision && existingConfig.oauthRevision === config.oauthRevision;
96+
if (sameOwner && sameStatus && sameOAuthRevision) {
97+
continue;
9898
}
9999
log.debug("Updating existing dynamic Auth Provider: " + host, { config, existingConfig });
100100
} else {

components/server/src/auth/login-completion-handler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ export class LoginCompletionHandler {
105105
const hostCtx = this.hostContextProvider.get(hostname);
106106
if (hostCtx) {
107107
const { params: config } = hostCtx.authProvider;
108-
const { id, verified, ownerId, builtin } = config;
108+
const { id, verified, builtin } = config;
109109
if (!builtin && !verified) {
110110
try {
111-
await this.authProviderService.markAsVerified({ id, ownerId });
111+
await this.authProviderService.markAsVerified({ id, ownerId: user.id });
112112
} catch (error) {
113113
log.error(LogContext.from({ user }), `Failed to mark AuthProvider as verified!`, { error });
114114
}

0 commit comments

Comments
 (0)