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

Re-sync GitHub (RemoteRepository and RemoteOrganization) on webhook #7336

Closed
wants to merge 7 commits into from

Conversation

humitos
Copy link
Member

@humitos humitos commented Jul 29, 2020

Add member event when creating the Read the Docs' webhook on each repository
imported under Read the Docs.

This webhook will communicate back to us when a collaborator was
added/removed/changed from that repository in particular. This allow us to
trigger the re-sync method for the GitHub service on that user and
create/delete/change RemoteRepository objects for that user.

Examples,

  • user is removed from having access to a repository -> remove RemoteRepository
  • user is added access to a repository -> create RemoteRepository
  • user is removed admin access but keep read access -> .admin=False

Related to #7185

Documentation reference: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#member

@humitos humitos added the Needed: tests Tests are required label Jul 29, 2020
@stale
Copy link

stale bot commented Sep 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: stale Issue will be considered inactive soon label Sep 12, 2020
@humitos humitos added Accepted Accepted issue on our roadmap and removed Status: stale Issue will be considered inactive soon labels Sep 14, 2020
@humitos
Copy link
Member Author

humitos commented Sep 14, 2020

This PR is useful. I haven't had the time to update it with the newer code, but we will eventually need it.

@humitos
Copy link
Member Author

humitos commented Sep 16, 2020

This webhook will communicate back to us when a collaborator was added/removed/changed from that repository in particular

Take into account that this only works for repository collaborators. There is another webhook called membership that works for users added/removed from an organization's team: https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads#membership . However, it's only available for organization webhooks and we are not making usage of them.


Even if we merge this PR, all the Read the Docs projects have to re-sync their webhooks (:disappointed: ) to make usage of the new member event. New projects will use it automatically.

Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

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

I'd agree that celery task is the most correct here. We've had issues lately with blocking web processes and should avoid that pattern going forward.

readthedocs/api/v2/views/integrations.py Outdated Show resolved Hide resolved
@humitos
Copy link
Member Author

humitos commented Sep 6, 2021

We are moving away from OAuth Application to GitHub Application: #8445

If anything, we will implement the re-sync via the events we can subscribe there.

@humitos humitos closed this Sep 6, 2021
@stsewd stsewd deleted the humitos/auto-sync-github-repositories branch September 6, 2021 16:05
@ericholscher ericholscher restored the humitos/auto-sync-github-repositories branch October 7, 2021 22:20
@ericholscher
Copy link
Member

I'd love to get this working via Celery. I think it might help us keep SSO in sync.

@ericholscher ericholscher reopened this Oct 7, 2021
@humitos humitos requested a review from a team as a code owner October 20, 2021 11:53
@humitos humitos force-pushed the humitos/auto-sync-github-repositories branch from 3a95a08 to aafe258 Compare October 20, 2021 12:00
@humitos
Copy link
Member Author

humitos commented Oct 20, 2021

I updated this PR to use a Celery task to sync but...

Note this PR does not cover exactly what we want, and I'm not sure if is worth merging it and maintaining it:

  • only works for new imported projects
  • old projects would need to re-sync their webhooks to subscribe to the new member event
  • only works over GH collaborators on repositories --it does not work over permissions granted via teams or organizations
  • when a GH webhook is received it will re-sync all the VCS connected accounts for the user

Taking into account all of these points, and considering that we added a scheduled Celery task to re-sync in #8601 it may not make sense to merge it.

@ericholscher
Copy link
Member

@humitos I don't fully understand the issues with it, but I do think we want some kind of way to do real-time updates on permissions. Having permissions be out of sync for users for a whole day feels like bad UX, so I feel like we need to at least attempt to do this.

Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

I think this makes sense, and doesn't seem like a lot of code to maintain?

readthedocs/api/v2/views/integrations.py Outdated Show resolved Hide resolved
saadmk11 and others added 6 commits October 21, 2021 14:09
Add a Django Admin Action under `SSOIntegration` to trigger one
`sync_remote_repositories` task per each user member of the organization.

This allows us to easily re-sync `RemoteRepository` and
`RemoteRepositoryRelation` for the whole organization.
Add `member` event when creating the Read the Docs' webhook on each repository
imported under Read the Docs.

This webhook will communicate back to us when a collaborator was
added/removed/changed from that repository in particular. This allow us to
trigger the re-sync method for the GitHub service on that user and
create/delete/change `RemoteRepository` objects for that user.

Examples,

* user is removed from having access to a repository -> remove RemoteRepository
* user is added access to a repository -> create RemoteRepository
* user is removed admin access but keep read access -> `.admin=False`
@humitos humitos force-pushed the humitos/auto-sync-github-repositories branch 2 times, most recently from 53226cd to 05904e1 Compare October 21, 2021 12:18
@humitos humitos force-pushed the humitos/auto-sync-github-repositories branch from 05904e1 to 423347b Compare October 21, 2021 12:19
@humitos
Copy link
Member Author

humitos commented Oct 21, 2021

@ericholscher

I don't fully understand the issues with it, but I do think we want some kind of way to do real-time updates on permissions.

The implementation of this webhook may make you feel that it solves the problem, where it does not. That's what I'm trying to say. It will keep permissions over repositories updated, but it won't for permissions granted via organizations and teams --which is the main problem we want to solve here.

That said, it may help in some cases and add more confusion in others.

The bad UX because we update permissions once a day, will still be present even with this webhook.

@ericholscher
Copy link
Member

@humitos Good points. I think I'm OK leaving this out for now if we want, and just doing nightly updates. That seems cleanest and easiest to explain for now, until we can find a better solution. I agree this does add a good bit of confusion, and "it might work" situations, which is probably not great.

@ericholscher
Copy link
Member

Closing this again... Seems we were correct the first time 🙃

@stsewd stsewd deleted the humitos/auto-sync-github-repositories branch October 26, 2021 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Needed: tests Tests are required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants