Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Allow multiple auth providers with the same URL, adjust UI#54289

Merged
pjlast merged 15 commits into
mainfrom
pjlast/multi-auth-providers-same-url
Jul 17, 2023
Merged

Allow multiple auth providers with the same URL, adjust UI#54289
pjlast merged 15 commits into
mainfrom
pjlast/multi-auth-providers-same-url

Conversation

@pjlast

@pjlast pjlast commented Jun 27, 2023

Copy link
Copy Markdown
Contributor

This PR removes the restrictions of having one Auth provider per URL, and instead allows one auth provider for each URL+ClientID combination.

The URL restriction came from the way our old permissions table worked, but with the user_repo_permissions table, this restriction no longer applies as permissions are stored against individual external accounts.

This has also become an increasingly common ask from customers, and it also eases the transitioning when switching from one auth provider to another, like switching from traditional GitHub OAuth to GitHub App Oauth.

One caveat that remains: Having multiple auth providers for the same URL does not play well with repo-centric permissions syncing, as we cannot from the repo token's perspective determine which user external account a permission should be bound to. There isn't a clean workaround to make this work, and the suggestion is to turn off repo-centric permissions syncing when using multiple auth providers to the same URL.

The idea is to have a follow-up PR that allows us to disable repo-centric permissions syncs for individual code host connections.

Having two auth providers and account connections that both point to github.com:

image

Some follow-up tasks:

  • Change this code so that auth providers are grouped by UniqueID and not ServiceID
    • This will require changes to each individual auth provider. But it would allow us to not sync permissions using an external account that no longer has an active auth provider.
  • Allow users to delete external accounts that are no longer associated with a valid auth provider
  • Add a code host connection option that allows disabling repo-permissions syncing on a code host connection level

Test plan

Lots of tests updated and adjusted to fit the new criteria.

Comment thread enterprise/cmd/frontend/internal/auth/azureoauth/provider.go Outdated
}
if configured {
problems = append(problems, conf.NewSiteProblem("Cannot have more than one auth provider for Azure Dev Ops, only the first one will be used"))
problems = append(problems, conf.NewSiteProblem(fmt.Sprintf("Cannot have more than one auth provider for Azure Dev Ops with Client ID %q, only the first one will be used", pr.AzureDevOps.ClientID)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
problems = append(problems, conf.NewSiteProblem(fmt.Sprintf("Cannot have more than one auth provider for Azure Dev Ops with Client ID %q, only the first one will be used", pr.AzureDevOps.ClientID)))
problems = append(problems, conf.NewSiteProblem(fmt.Sprintf("Cannot have more than one auth provider for Azure Dev Ops with the same Client ID %q, only the first one will be used", pr.AzureDevOps.ClientID)))

Comment thread enterprise/cmd/frontend/internal/auth/azureoauth/provider.go Outdated
@pjlast pjlast marked this pull request as ready for review June 28, 2023 09:37
@pjlast pjlast requested a review from a team June 28, 2023 09:37
@sourcegraph-bot

sourcegraph-bot commented Jun 28, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 58d9a0b...fa897f3.

Notify File(s)
@unknwon enterprise/cmd/frontend/internal/auth/azureoauth/BUILD.bazel
enterprise/cmd/frontend/internal/auth/azureoauth/provider.go
enterprise/cmd/frontend/internal/auth/azureoauth/provider_test.go
enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/BUILD.bazel
enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/config.go
enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/config_test.go
enterprise/cmd/frontend/internal/auth/gerrit/BUILD.bazel
enterprise/cmd/frontend/internal/auth/gerrit/config.go
enterprise/cmd/frontend/internal/auth/gerrit/config_test.go
enterprise/cmd/frontend/internal/auth/githuboauth/BUILD.bazel
enterprise/cmd/frontend/internal/auth/githuboauth/config.go
enterprise/cmd/frontend/internal/auth/githuboauth/config_test.go
enterprise/cmd/frontend/internal/auth/gitlaboauth/BUILD.bazel
enterprise/cmd/frontend/internal/auth/gitlaboauth/config.go
enterprise/cmd/frontend/internal/auth/gitlaboauth/config_test.go

@sourcegraph-bot

sourcegraph-bot commented Jun 28, 2023

Copy link
Copy Markdown
Contributor

📖 Storybook live preview

@sashaostrikov sashaostrikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Left some comments, none of them are critical

Comment thread client/web/src/user/settings/auth/ExternalAccountsSignIn.tsx Outdated
Comment thread client/web/src/user/settings/auth/ExternalAccountsSignIn.tsx
Comment on lines +96 to +98
let accountMap = accumulator[account.serviceID] ?? []
accountMap.push(account)
accumulator[account.serviceID] = accountMap

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice try, Mr. Array.

Suggested change
let accountMap = accumulator[account.serviceID] ?? []
accountMap.push(account)
accumulator[account.serviceID] = accountMap
let accountArray = accumulator[account.serviceID] ?? []
accountArray.push(account)
accumulator[account.serviceID] = accountArray

@pjlast pjlast Jun 28, 2023

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

And I would have gotten away with it too, if it weren't for that meddling kid! - Mr. Array, probably

Comment thread enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/config.go Outdated
Comment thread enterprise/cmd/frontend/internal/auth/gerrit/config.go Outdated
Comment thread enterprise/cmd/frontend/internal/auth/githuboauth/config.go Outdated
Comment thread enterprise/cmd/frontend/internal/auth/gitlaboauth/config.go Outdated
@pjlast pjlast force-pushed the pjlast/multi-auth-providers-same-url branch from 80f8d7e to 0502adc Compare July 14, 2023 12:55
@pjlast pjlast force-pushed the pjlast/multi-auth-providers-same-url branch from 765c02b to fa897f3 Compare July 17, 2023 08:07
@pjlast pjlast merged commit 4ae7ee4 into main Jul 17, 2023
@pjlast pjlast deleted the pjlast/multi-auth-providers-same-url branch July 17, 2023 09:44
github-actions Bot pushed a commit that referenced this pull request Jul 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants