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

Remove fallback to global credentials in batches#41078

Merged
eseliger merged 14 commits into
mainfrom
es/no-global-credentials
Sep 8, 2022
Merged

Remove fallback to global credentials in batches#41078
eseliger merged 14 commits into
mainfrom
es/no-global-credentials

Conversation

@eseliger

@eseliger eseliger commented Aug 30, 2022

Copy link
Copy Markdown
Member

This PR completes the deprecation of external service tokens to be used with batch changes.
From now on, all ChangesetSources returned from Sourcer methods are ensured to be properly authenticated with either a site credential or user credential, where applicable. This will also make sure that we will never accidentally use other tokens. That also means that we don't need so strict constraints on the external service anymore, so we can simply read the repo.Sources.CloneURL field and don't have to check if an external service has a token configured. Overall, the logic got much simpler and I was able to eliminate many now redundant tests, as they all just use the already tested sourcer methods now.

Closes https://github.com/sourcegraph/sourcegraph/issues/25394

Test plan

Verified locally that things still work, also adjusted the test suite accordingly.

@cla-bot cla-bot Bot added the cla-signed label Aug 30, 2022
@eseliger eseliger force-pushed the es/no-global-credentials branch 2 times, most recently from 7748b2a to 8fc9580 Compare August 31, 2022 13:22

// Construct changeset source.
b.css, err = b.sourcer.ForRepo(ctx, b.tx, b.repo)
b.css, err = b.sourcer.ForUser(ctx, b.tx, job.UserID, b.repo)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No behavioral change here, we still only allow using credentials from the initiating user, or global credentials.

}

css, err = sources.WithAuthenticatorForChangeset(ctx, s, css, ch, repo, false)
css, err := sourcer.ForChangeset(ctx, s, ch)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The ForChangeset helper now only returns authenticated sources, so we don't need to do the authentication as step 2. The algorithm for determining it is unchanged.
Nice side-effect: Not possible to forget authentication anymore :)


css, err := s.sourcer.ForExternalService(ctx, s.store, store.GetExternalServiceIDsOpts{
// Get a changeset source for the external service and use the given authenticator.
css, err := s.sourcer.ForExternalService(ctx, s.store, &auth.OAuthBearerToken{Token: token}, store.GetExternalServiceIDsOpts{

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No behavioral change here, we still only allow using the current authenticator. No fallback, just consolidated into one call to make sure it's not possible to forget and accidentally fall back to external service auth.

}

css, err := s.sourcer.ForExternalService(ctx, s.store, store.GetExternalServiceIDsOpts{
// Get a changeset source for the external service and use the given authenticator.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No behavioral change here, we still only allow using the current authenticator. No fallback, just consolidated into one call to make sure it's not possible to forget and accidentally fall back to external service auth.

@eseliger eseliger force-pushed the es/no-global-credentials branch 2 times, most recently from 58a8f53 to 9d089f7 Compare September 7, 2022 11:39

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this test is fully covered by the sourcer testsuite

@eseliger eseliger changed the title WIP: Remove fallback to global credentials in batches Remove fallback to global credentials in batches Sep 7, 2022
@eseliger eseliger marked this pull request as ready for review September 7, 2022 12:09
@eseliger eseliger requested a review from a team September 7, 2022 12:09
@sourcegraph-bot

sourcegraph-bot commented Sep 7, 2022

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff f963915...6a5ce2d.

Notify File(s)
@courier-new client/web/src/enterprise/batches/list/BatchChangesChangelogAlert.tsx
doc/batch_changes/how-tos/configuring_credentials.md

@BolajiOlajide BolajiOlajide 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.

🎉

@courier-new courier-new 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.

The changes read SO WELL! It's a loooot clearer from the code how we use the two different authentication types, now. Thanks for the added code comments, as well! 🙌

Comment thread CHANGELOG.md Outdated
Comment thread client/web/src/enterprise/batches/list/BatchChangesChangelogAlert.tsx Outdated
Comment thread doc/batch_changes/how-tos/configuring_credentials.md Outdated
Comment thread doc/batch_changes/how-tos/configuring_credentials.md Outdated
Comment on lines 99 to 100

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.

This is something I haven't thought much about before, that a repo could be tracked by multiple external services. I feel like I remember this coming up in conversation before once but it's very fuzzy, and I'm curious but having a bit of trouble tracing in the code how we handle this in the context of Batch Changes!

I see that in loadExternalService we prioritize a globally-configured external service over a user-owned one, but after that it looks like we just return the first one that's for a BC-compatible code host type. Does that mean that even if a repo is associated with many external services across multiple different code hosts, Batch Changes will only ever acknowledge it on the (compatible) external service that was added to Sourcegraph first?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, that's correct. That's always been the case and is a problem of our external service model - they all have config flags for the code host, which technically should be the same on all configs but mightn't be. Like the TLS cert for a GHE instance. If one of them doesn't have it but they need it, it would be misconfiguration, but we don't really surface that well. 2 years ago Thorsten and I pitched to introduce a code host model to the product that would capture all global settings for it, like URL, TLS, ssh mode etc, and then an external service would be just the auth part and the repo scope. Then batch changes would only look at the code host for creating the client but.. we don't have that so that's the best we can do for now :)

@LawnGnome LawnGnome 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.

+1

Comment thread enterprise/internal/batches/sources/sources.go Outdated
@eseliger eseliger force-pushed the es/no-global-credentials branch from 8a3231f to a005279 Compare September 8, 2022 11:57
@eseliger eseliger enabled auto-merge (squash) September 8, 2022 12:12
@eseliger eseliger merged commit 6955e6b into main Sep 8, 2022
@eseliger eseliger deleted the es/no-global-credentials branch September 8, 2022 12:13
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.

Remove Batch Changes code host connection token

6 participants