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

CBG-4025 Invalidate user roles after resync #6942

Merged
merged 2 commits into from
Jul 9, 2024
Merged

CBG-4025 Invalidate user roles after resync #6942

merged 2 commits into from
Jul 9, 2024

Conversation

adamcfraser
Copy link
Collaborator

@adamcfraser adamcfraser commented Jul 6, 2024

CBG-4025

As part of this change, modified access invalidation functions to perform invalidation in a single update to the principal document, instead of once per collection (and one additional time for roles). To support this:

  • Switched existing invalidation functions (invalRoleChannels, invalUserChannels, etc) to have *DatabaseContext receiver instead of *DatabaseCollection, and added a ScopeAndCollectionNames parameter to specify the set of collections that should have access invalidated.
  • For ease of use, maintained the existing invalidation functions on *DatabaseCollection - they now just call in to the *DatabaseContext functions with their single collection
  • Added a new invalUserRolesAndChannels to invalidate a user’s roles and channels in a single user doc update. Only currently used by resync

Query based resync still processes a single collection’s updates at a time - it’s structured a bit differently and didn’t seem to be worth refactoring at this point. It has been updated to properly invalidate user roles.

The new test TestResyncInvalidatePrincipals covers the fix - have verified it with SG_TEST_USE_DEFAULT_COLLECTION=true/false. Also made a test utility change to remove the password parameter from GetRolePayload since roles don’t have passwords.

Integration Tests

As part of this change, modified access invalidation functions to perform invalidation in a single update to the principal document, instead of once per collection (and one additional time for roles).  To support this:
- Switched existing invalidation functions (invalRoleChannels, invalUserChannels, etc) to have *DatabaseContext receiver instead of *DatabaseCollection, and added a ScopeAndCollectionNames parameter to specify the set of collections that should have access invalidated.
- For ease of use, maintained the existing invalidation functions on *DatabaseCollection - they now just call in to the *DatabaseContext functions with their single collection
- Added a new invalUserRolesAndChannels to invalidate a user’s roles and channels in a single user doc update.  Only currently used by resync

Query based resync still processes a single collection’s updates at a time - it’s structured a bit differently and didn’t seem to be worth refactoring at this point.  It has been updated to properly invalidate user roles.

The new test TestResyncInvalidatePrincipals covers the fix - have verified it with SG_TEST_USE_DEFAULT_COLLECTION=true/false.  Also made a test utility change to remove the password parameter from GetRolePayload since roles don’t have passwords.
}

if subdocStore, ok := base.AsSubdocStore(auth.datastore); ok {
err := subdocStore.SubdocInsert(auth.LogCtx, docID, subdocPath, 0, invalSeq)
Copy link
Collaborator

Choose a reason for hiding this comment

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

sgbucket.SubDocStore is part of sgbucket.DataStore so we don't need to do this cast.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AsSubdocStore is also doing a check on ds.IsSupported(sgbucket.BucketStoreFeatureSubdocOperations) (which I believe is still relevant for walrus support for backports to 3.1 that support walrus). I think I'd prefer to leave this code as it was in this PR since we expect a backport.

Comment on lines +468 to +469
// Attempt to use subdoc if we're only modifying a single collection
if len(collections) == 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is more of an optimization than might be necessary, but can we change the API of SubdocInsert to be map[string]any so we can do multiple subdoc operations at once?

Later we are going to run through the logic of updating the document, though not the write operation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I considered adding that functionality in this PR, but decided against it due to the increase in scope/risk. Since the more common usage of InvalidateChannels (at write time) is always single collection, I thought it was reasonable to omit.

@adamcfraser adamcfraser assigned adamcfraser and gregns1 and unassigned adamcfraser Jul 8, 2024
Copy link
Contributor

@gregns1 gregns1 left a comment

Choose a reason for hiding this comment

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

LGTM

@adamcfraser adamcfraser merged commit 1409e08 into main Jul 9, 2024
34 checks passed
@adamcfraser adamcfraser deleted the CBG-4025 branch July 9, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants