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

Add Bitbucket Cloud as an auth provider#46309

Merged
pjlast merged 19 commits into
mainfrom
pjlast/19782-bitbucket-cloud-auth-provider
Jan 16, 2023
Merged

Add Bitbucket Cloud as an auth provider#46309
pjlast merged 19 commits into
mainfrom
pjlast/19782-bitbucket-cloud-auth-provider

Conversation

@pjlast

@pjlast pjlast commented Jan 11, 2023

Copy link
Copy Markdown
Contributor

This PR adds Bitbucket Cloud as an Auth Provider option.

This allows users to sign into Sourcegraph using Bitbucket Cloud.

This is for sign-in and account creation only. It does not enable permissions syncing for Bitbucket Cloud.

Loom: https://www.loom.com/share/035a812559fb4e0b9629e74f9772b6b4

Test plan

Unit tests added, as well as a manual test (see Loom)

@sg-e2e-regression-test-bob

sg-e2e-regression-test-bob commented Jan 11, 2023

Copy link
Copy Markdown

Bundle size report 📦

Initial size Total size Async size Modules
0.00% (0.00 kb) 0.02% (+3.43 kb) 0.03% (+3.43 kb) 0.00% (0)

Look at the Statoscope report for a full comparison between the commits 24b5c73 and 57f3ed1 or learn more.

Open explanation
  • Initial size is the size of the initial bundle (the one that is loaded when you open the page)
  • Total size is the size of the initial bundle + all the async loaded chunks
  • Async size is the size of all the async loaded chunks
  • Modules is the number of modules in the initial bundle

@pjlast pjlast marked this pull request as ready for review January 11, 2023 08:57
@pjlast pjlast requested a review from a team January 11, 2023 08:57
@sourcegraph-bot

sourcegraph-bot commented Jan 11, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 57f3ed1...24b5c73.

Notify File(s)
@LawnGnome internal/extsvc/bitbucketcloud/client.go
internal/extsvc/bitbucketcloud/common.go
internal/extsvc/bitbucketcloud/repositories.go
internal/extsvc/bitbucketcloud/repositories_test.go
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-CreatePullRequest-Fork-recreated
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-CreatePullRequest-Fork-valid-omitted-destination-branch
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-CreatePullRequest-SameOrigin-recreated
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-CreatePullRequest-SameOrigin-valid-destination-branch
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-DeclinePullRequest-found
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-ForkRepository-success
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-GetPullRequest-found
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-MergePullRequest-found
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-Repo-valid-repo
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-UpdatePullRequest-found
internal/extsvc/bitbucketcloud/types.go
internal/extsvc/bitbucketcloud/user.go
internal/extsvc/bitbucketcloud/users.go
@eseliger enterprise/internal/batches/sources/mocks_test.go
internal/extsvc/bitbucketcloud/client.go
internal/extsvc/bitbucketcloud/common.go
internal/extsvc/bitbucketcloud/repositories.go
internal/extsvc/bitbucketcloud/repositories_test.go
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-CreatePullRequest-Fork-recreated
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-CreatePullRequest-Fork-valid-omitted-destination-branch
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-CreatePullRequest-SameOrigin-recreated
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-CreatePullRequest-SameOrigin-valid-destination-branch
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-DeclinePullRequest-found
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-ForkRepository-success
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-GetPullRequest-found
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-MergePullRequest-found
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-Repo-valid-repo
internal/extsvc/bitbucketcloud/testdata/golden/TestClient-UpdatePullRequest-found
internal/extsvc/bitbucketcloud/types.go
internal/extsvc/bitbucketcloud/user.go
internal/extsvc/bitbucketcloud/users.go
@indradhanush internal/repos/bitbucketcloud.go
@ryanslade internal/repos/bitbucketcloud.go
@sashaostrikov internal/repos/bitbucketcloud.go
@sourcegraph/delivery doc/admin/auth/index.md
doc/admin/external_service/bitbucket_cloud.md
@unknwon enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/config.go
enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/config_test.go
enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/middleware.go
enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/middleware_test.go
enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/provider.go
enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/provider_test.go
enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/session.go
enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/session_test.go
enterprise/cmd/frontend/internal/auth/init.go
enterprise/cmd/frontend/internal/auth/oauth/provider.go
enterprise/internal/authz/authz.go
enterprise/internal/authz/authz_test.go
enterprise/internal/authz/bitbucketcloud/authz.go
enterprise/internal/authz/bitbucketcloud/authz_test.go
enterprise/internal/authz/bitbucketcloud/provider.go
enterprise/internal/authz/bitbucketcloud/provider_test.go

Comment thread client/web/src/jscontext.ts
Comment on lines +100 to +106
// If allowSignup is true, we will create an account using the first verified
// email address from Bitbucket which we expect to be their primary address. Note
// that the order of attempts is important. If we manage to connect with an
// existing account we return early and don't attempt to create a new account.
if s.allowSignup {
attempts = append(attempts, attemptConfig{
email: emails[0].Email,

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.

I'm confused here. The comment says we try the first verified email address, but as far as I can see, we try with the first email address, which might or might not be verified.

Also, should we try with all verified email addresses instead of just the first one?

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.

+1 here. Why not use verifiedEmails?

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.

Yep that should be verifiedEmails[0].

I'm mimmicing the way we do the GitHub provider here, which only tries the first verified email. I'm guessing the logic is that, if the account does not exist, this should succeed.

Although I'm curious now how we handle the GitHub scenario if signup is restricted to certain addresses and the verified address that does not match the restriction is not the first address. Will have to check

Comment thread enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/session.go Outdated
Comment thread go.mod
Comment thread schema/site.schema.json
"default": "account,email,repository",
"enum": ["account", "email", "repository:read"]
},
"allowSignup": {

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.

We should think about how to filter users for signup, similar to how we allow filtering users who can signup via SAML or Github auth providers.

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.

Bitbucket has the concept of "Workspaces" which we could probably leverage for this. However, I do think I'd want to add that as a follow-up feature instead of adding more complexity here.

Comment thread doc/admin/auth/index.md Outdated
Comment thread doc/admin/auth/index.md Outdated
Comment thread enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/config.go Outdated
Comment thread enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/config.go Outdated
Comment thread enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/middleware_test.go Outdated
Comment thread enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/session.go Outdated
Comment thread enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/session.go Outdated
Comment on lines +100 to +106
// If allowSignup is true, we will create an account using the first verified
// email address from Bitbucket which we expect to be their primary address. Note
// that the order of attempts is important. If we manage to connect with an
// existing account we return early and don't attempt to create a new account.
if s.allowSignup {
attempts = append(attempts, attemptConfig{
email: emails[0].Email,

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.

+1 here. Why not use verifiedEmails?

Comment thread enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/session.go Outdated
Comment thread enterprise/cmd/frontend/internal/auth/bitbucketcloudoauth/session.go Outdated
@pjlast pjlast force-pushed the pjlast/19782-bitbucket-cloud-auth-provider branch from 239425f to 88f7b57 Compare January 16, 2023 08:49
@github-actions

Copy link
Copy Markdown
Contributor

Problem: the label i-acknowledge-this-goes-into-the-release is absent.
👉 What to do: we're in the next Sourcegraph release code freeze period. If you are 100% sure your changes should get released or provide no risk to the release, add the label your PR with i-acknowledge-this-goes-into-the-release.

@pjlast pjlast force-pushed the pjlast/19782-bitbucket-cloud-auth-provider branch from 0c9834e to 4a2747c Compare January 16, 2023 11:13
@pjlast pjlast merged commit b445895 into main Jan 16, 2023
@pjlast pjlast deleted the pjlast/19782-bitbucket-cloud-auth-provider branch January 16, 2023 12:20
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.

5 participants