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

Creates Backend for Merging User Accounts #117

Merged
merged 5 commits into from
Jan 9, 2024
Merged

Creates Backend for Merging User Accounts #117

merged 5 commits into from
Jan 9, 2024

Conversation

gbdubs
Copy link
Contributor

@gbdubs gbdubs commented Jan 5, 2024

User Merge is apparently a frequent support flow, and required some delicate thinking around audit logs. This PR implements the backend for it.

Additional changes:

  • Adds a new audit log type for TRANSFER_OWNERSHIP
  • Creates a DeleteOwner DB method
  • Updates DeleteUser to do the recursive deletion of their owned assets + return blobURIs
  • Updates /delete-user to delete the downstream blobs.

@gbdubs gbdubs requested a review from bcspragu January 5, 2024 23:27
}
}
numAuditLogsCreated = len(auditLogsToCreate)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Option I'm considering: we could do a lookup (by owner + by user) of each of the entity groups just transferred to ensure they're no longer present (similar to what I did at the end of the TXN to transfer audit log ownership). I'd like to hear your thoughts on whether that's a good idea - particularly because the db.DeleteUser call will then delete these elements if they don't transfer.

Copy link
Collaborator

@bcspragu bcspragu left a comment

Choose a reason for hiding this comment

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

LGTM, main thing is that I would not transfer audit records as part of the merge, or really ever modify them period.

cmd/server/pactasrv/admin.go Outdated Show resolved Hide resolved
cmd/server/pactasrv/admin.go Show resolved Hide resolved
Comment on lines 47 to 52
// Note we do an audit log transfer FIRST so that we don't transfer the audit logs generated from the transfer itself.
nal, err := s.DB.TransferAuditLogOwnership(tx, sourceUID, destUID, sourceOwner, destOwner)
if err != nil {
return fmt.Errorf("failed to transfer audit log ownership: %w", err)
}
numAuditLogs = nal
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd consider not moving existing audit logs, it seems tricky and error-prone, and breaks the idea that audit logs are "write-only".

If it's important to show the merged user info in the UI for this stuff, I'd record merges in a separate table (also without FKCs), and then just do that mapping when users look at the audit logs. A bit more work on the read-side, but it's a straightforward mapping and it removes a bunch of nuance around audit logs.

Instead of a separate table, you could use the TRANSFER_OWNERSHIP logs to get the same info, though that make audit logs "load-bearing"

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 generally agree that editing audit logs is an unstable paradigm.

I think what you propose is also dangerous however, because it introduces much less stable semantics around how audit logs can be accessed and retrieved, which are also an important security end. My thought with doing the data modification in place is that we only have to navigate the complexity of "who should get access to what" at exactly one juncture, and then afterwards queries and reads and creates all need no modification.

I agree using TRANSFER_OWNERSHIP logs is a nightmare which we don't want to descend into.

Not sure how to resolve/move forward on this one.

cmd/server/pactasrv/admin.go Outdated Show resolved Hide resolved
cmd/server/pactasrv/admin.go Outdated Show resolved Hide resolved
cmd/server/pactasrv/admin.go Outdated Show resolved Hide resolved
cmd/server/pactasrv/admin.go Outdated Show resolved Hide resolved
cmd/server/pactasrv/admin.go Outdated Show resolved Hide resolved
db/sqldb/audit_log.go Outdated Show resolved Hide resolved
@gbdubs
Copy link
Contributor Author

gbdubs commented Jan 9, 2024

LGTM, main thing is that I would not transfer audit records as part of the merge, or really ever modify them period.

Discussed this offline and was sufficently convinced that it's important for us to never edit these. Added some new mechanisms for recursively expanding the set of users used for a query, which will allow audit logs that reference via queries old entities to be visible post-merge.

@gbdubs gbdubs enabled auto-merge (squash) January 9, 2024 00:58
@gbdubs gbdubs merged commit 1a5a0cd into main Jan 9, 2024
2 checks passed
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.

2 participants