Skip to content
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

fix(dal,sdf): when finding change sets, ensure it belongs to the relevant workspace #5245

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

britmyerss
Copy link
Contributor

@britmyerss britmyerss commented Jan 13, 2025

This change introduces ChangeSet::find_across_workspaces to differentiate from ChangeSet::find to ensure we're not acting on ChangeSets that don't belong to the Workspace in question.

Copy link

github-actions bot commented Jan 13, 2025

Dependency Review

✅ No vulnerabilities or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

@britmyerss britmyerss requested a review from fnichol January 13, 2025 20:21
@github-actions github-actions bot added A-sdf Area: Primary backend API service [Rust] A-dal labels Jan 13, 2025
@@ -87,7 +87,7 @@ impl SnapshotGraphMigrator {
info!("Migrating {} snapshot(s)", open_change_sets.len(),);

for change_set in open_change_sets {
let mut change_set = ChangeSet::find(ctx, change_set.id)
let mut change_set = ChangeSet::find_across_workspaces(ctx, change_set.id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is correct - @zacharyhamm could use a check

Copy link
Contributor

Choose a reason for hiding this comment

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

It's hard to imagine this isn't correct, given the fact that these change set IDs came from list_open_for_all_workspaces()!. (Again, it at least doesn't make things worse.)

Copy link
Contributor

Choose a reason for hiding this comment

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

this is what we want, yes. The migrator will set up the dal context for the right visibility and tenancy but only after it finds the workspace, so this is definitely necessary

@britmyerss britmyerss force-pushed the brit/ensure-change-sets-belong-to-workspaces branch 2 times, most recently from 425cd9c to a5c49bb Compare January 13, 2025 22:36
@britmyerss
Copy link
Contributor Author

/try

Copy link

github-actions bot commented Jan 13, 2025

Okay, starting a try! I'll update this comment once it's running...\n
🚀 Try running here! 🚀

@britmyerss britmyerss force-pushed the brit/ensure-change-sets-belong-to-workspaces branch 2 times, most recently from bded452 to f7f8e33 Compare January 14, 2025 00:28
pub async fn update_snapshot_to_visibility(&mut self) -> TransactionsResult<()> {
let change_set = ChangeSet::find(self, self.change_set_id())
let change_set = ChangeSet::find_across_workspaces(self, self.change_set_id())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could do a similar move here to have a tenancy-scoped version of this method, but not in this PR. Note that scoping this to the workspace breaks all of our integration tests at the moment.

.expect("could not build dal context");

//first, let's ensure we can't find it when using the user 1 dal ctx
let user_2_change_set_unfound = ChangeSet::find(&user_1_dal_context, user_2_change_set.id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

before this change, we would User-1-Workspace-1 would successfully find (and be able to abandon) the change set in User-2's Workspace.

@britmyerss britmyerss marked this pull request as ready for review January 14, 2025 00:32
jkeiser
jkeiser previously approved these changes Jan 14, 2025
Copy link
Contributor

@jkeiser jkeiser left a comment

Choose a reason for hiding this comment

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

Super glad to see it narrowed down to just a few callers!

@@ -698,7 +739,7 @@ impl ChangeSet {
#[instrument(level = "info", skip_all)]
pub async fn apply_to_base_change_set(ctx: &mut DalContext) -> ChangeSetApplyResult<ChangeSet> {
// Apply to the base change with the current change set (non-editing) and commit.
let mut change_set_to_be_applied = Self::find(ctx, ctx.change_set_id())
let mut change_set_to_be_applied = Self::find_across_workspaces(ctx, ctx.change_set_id())
Copy link
Contributor

Choose a reason for hiding this comment

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

This one might be able to be ChangeSet::find() (it seems like if we really need find_across_workspaces than we have been given a busted DalContext). But if you're worried about it or noticed it breaks things, I'm 100% on board with "fix most stuff and then look at these in another PR").

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I think you're right! Will fix

@@ -87,7 +87,7 @@ impl SnapshotGraphMigrator {
info!("Migrating {} snapshot(s)", open_change_sets.len(),);

for change_set in open_change_sets {
let mut change_set = ChangeSet::find(ctx, change_set.id)
let mut change_set = ChangeSet::find_across_workspaces(ctx, change_set.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's hard to imagine this isn't correct, given the fact that these change set IDs came from list_open_for_all_workspaces()!. (Again, it at least doesn't make things worse.)

@britmyerss britmyerss force-pushed the brit/ensure-change-sets-belong-to-workspaces branch from f7f8e33 to 2603a0a Compare January 14, 2025 15:24
@britmyerss
Copy link
Contributor Author

/try

Copy link

github-actions bot commented Jan 14, 2025

Okay, starting a try! I'll update this comment once it's running...\n
🚀 Try running here! 🚀

}
Ok(Some(change_set))
}
None => Ok(None),
Copy link
Contributor

Choose a reason for hiding this comment

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

If we emitted an info or error here, we could track any time this returns None. Which should be almost never, except maybe stale URLs in cache for applied/abandoned change sets

Copy link
Contributor

Choose a reason for hiding this comment

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

(or set an attribute, whichever makes the most sense for a honeycomb query)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good shout - will add!

jkeiser
jkeiser previously approved these changes Jan 14, 2025
@britmyerss britmyerss force-pushed the brit/ensure-change-sets-belong-to-workspaces branch from 2603a0a to 8e15c47 Compare January 14, 2025 19:27
@britmyerss britmyerss requested a review from jkeiser January 15, 2025 02:20
Copy link
Contributor

@jkeiser jkeiser left a comment

Choose a reason for hiding this comment

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

Lock it down!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dal A-sdf Area: Primary backend API service [Rust]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants