Skip to content

[server] delete duplicate auth provider #17651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2023
Merged

Conversation

svenefftinge
Copy link
Contributor

@svenefftinge svenefftinge commented May 17, 2023

Description

Stumbled over this log message. Which is caused by two entries in d_b_auth_provider_entry with the same host. There is only this one duplicate case in the prdo DB and I don't know how it got there, but instead of always ignoring one entry we should enforce this on insert/update.

The message is logged because the actual config that is used alternates with every call.
And since we cache by host name it gets re-created every time.

const existingContext = this.dynamicHosts.get(host);
const existingConfig = existingContext && existingContext.authProvider.params;
if (existingConfig && config.id === existingConfig.id) {
const sameHost = config.host === existingConfig.host;
if (!sameHost) {
log.warn("Ignoring host update for dynamic Auth Provider: " + host, { config, existingConfig });
continue;
}
const sameOwner = config.ownerId === existingConfig.ownerId;
const sameStatus = config.status === existingConfig.status;
const sameOAuthRevision =
!!config.oauthRevision && existingConfig.oauthRevision === config.oauthRevision;
if (sameOwner && sameStatus && sameOAuthRevision) {
continue;
}
log.debug("Updating existing dynamic Auth Provider: " + host, { config, existingConfig });
} else {
log.debug("Creating new dynamic Auth Provider: " + host, { config });
}
const container = this.factory.createHostContext(config);
if (container) {
this.dynamicHosts.set(host, container);
} else {
log.warn("Did not update dynamic Auth Provider " + host, { config });
}

Related Issue(s)

Fixes #

How to test

Documentation

Preview status

gitpod:summary

Build Options:

  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish Options
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer Options
  • analytics=segment
  • with-dedicated-emulation
  • with-ws-manager-mk2
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated

Preview Environment Options:

  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • with-integration-tests=all
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh

/hold

@svenefftinge svenefftinge requested a review from a team May 17, 2023 13:08
@github-actions github-actions bot added the team: webapp Issue belongs to the WebApp team label May 17, 2023
@svenefftinge svenefftinge force-pushed the se/fix-duplicate-auth branch from 079d31e to 6567076 Compare May 17, 2023 13:20
await queryRunner.query(`
DELETE FROM d_b_auth_provider_entry
WHERE id NOT IN (
SELECT id FROM (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the middle SELECT id FROM (...) AS t seems to be redundant.
anyways, TIL how to delete duplicates 👍🏻

@AlexTugarev
Copy link
Member

[components/gitpod-db:dbtest]   1) AuthProviderEntryDBSpec
[components/gitpod-db:dbtest]        findByOrgId:
[components/gitpod-db:dbtest]      QueryFailedError: ER_DUP_ENTRY: Duplicate entry 'i.8713187.xyz-O1' for key 'unique_host_by_org'

🙈 db-tests are failing

@svenefftinge svenefftinge force-pushed the se/fix-duplicate-auth branch from 6567076 to 8281487 Compare May 17, 2023 14:58
@svenefftinge
Copy link
Contributor Author

/unhold

@roboquat roboquat merged commit 9a83e92 into main May 22, 2023
@roboquat roboquat deleted the se/fix-duplicate-auth branch May 22, 2023 08:28
@roboquat roboquat added deployed: webapp Meta team change is running in production deployed Change is completely running in production labels May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployed: webapp Meta team change is running in production deployed Change is completely running in production size/M team: webapp Issue belongs to the WebApp team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants