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

Remote repository: Keep in sync when repos are moved to another org/users #9178

Merged
merged 10 commits into from
May 31, 2022

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented May 10, 2022

We were doing some checks to avoid removing the remote organization
from a remote repo when this is listed from the /users/repos/ endpoint
or changing the organization when the project was moved.

But, since we are hitting the GitHub API directly,
we can always trust the result from there,
which includes the type of owner of the repository,
we can use that to decide if the repository belongs to an organization or not.

Fixes #8715

Front logo Front conversations

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

This approach looks good. I'm a bit worried, tho. I'm not sure that I'm understanding 100% what it conveys and what problems this change can bring.

The main thing I'm thinking about is if we may need to trigger a re-sync for all users that has access to a repository when its organization is changed? I'm trying to think if when a project is moved from one organization to the other users won't lose permissions on it because being out-of-sync.

@stsewd stsewd force-pushed the keep-in-sync-remote-repos branch from ad68360 to 4c7f257 Compare May 10, 2022 19:37
@stsewd
Copy link
Member Author

stsewd commented May 10, 2022

The main thing I'm thinking about is if we may need to trigger a re-sync for all users that has access to a repository when its organization is changed? I'm trying to think if when a project is moved from one organization to the other users won't lose permissions on it because being out-of-sync.

I think this is a problem with the current implementation as well, like when a project is transferred to another user or a user is removed from an org/project, it looks like we are refreshing the permissions every 4 hours. Anyway, those problems should be solved by subscribing to a webhook if we aren't already.

@stsewd stsewd marked this pull request as ready for review May 10, 2022 19:47
@stsewd stsewd requested a review from a team as a code owner May 10, 2022 19:47
if (
organization
and owner_type == "Organization"
and organization.remote_id == fields["owner"]["id"]
Copy link
Member Author

Choose a reason for hiding this comment

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

This shouldn't be needed since we are passing the org from where the projects were fetched from, but just in case.

…ser.

We were doing some checks to avoid removing the remote organization
from a remote repo when this is listed from the /users/repos/ endpoint
or changing the organization when the project was moved.

But, since we are hitting the GitHub API directly,
we can always trust the result from there,
which includes the type of owner of the repository,
we can use that to decide if the repository belongs to an organization or not.

Fixes #8715
@stsewd stsewd force-pushed the keep-in-sync-remote-repos branch from 4c7f257 to 8c7c362 Compare May 10, 2022 19:54
@stsewd stsewd force-pushed the keep-in-sync-remote-repos branch from 1248df5 to eb8d042 Compare May 10, 2022 21:09
@humitos
Copy link
Member

humitos commented May 11, 2022

Anyway, those problems should be solved by subscribing to a webhook if we aren't already.

Yeah, we tried to do this, but we can't do it properly being a OAuth application. It will be possible when using a GitHub Application instead. See #7336 (comment)

@stsewd stsewd requested a review from humitos May 11, 2022 14:40
Copy link
Member

@humitos humitos 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 is fine. I've made more suggestions after a deeper review. Note this is changing a core part of our auth permissions and we should be careful here. I'd like another pair of eyes reviewing this as well just in case I'm missing something -- cc @ericholscher @agjohnson

readthedocs/oauth/services/github.py Show resolved Hide resolved
readthedocs/oauth/services/github.py Outdated Show resolved Hide resolved
readthedocs/oauth/services/github.py Outdated Show resolved Hide resolved
readthedocs/rtd_tests/tests/test_oauth.py Outdated Show resolved Hide resolved
readthedocs/rtd_tests/tests/test_oauth.py Outdated Show resolved Hide resolved
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 don't have much else to add here, but do echo the concerns @humitos has around auth/SSO and simplicity. For that, trading performance optimization for more simplicity makes sense.

readthedocs/oauth/services/github.py Outdated Show resolved Hide resolved
Comment on lines -224 to -244
def create_repository(self, fields, privacy=None, organization=None):
"""
Update or create a repository from API response.

:param fields: dictionary of response data from API
:param privacy: privacy level to support
:param organization: remote organization to associate with
:type organization: RemoteOrganization
:rtype: RemoteRepository
"""
raise NotImplementedError

def create_organization(self, fields):
"""
Update or create remote organization from API response.

:param fields: dictionary response of data from API
:rtype: RemoteOrganization
"""
raise NotImplementedError

Copy link
Member Author

Choose a reason for hiding this comment

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

the signature is different for the github provider now, we don't make any reference to these methods outside the class (we use the sync method) so we are fine having a different signature.

Copy link
Member

Choose a reason for hiding this comment

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

We should implement the same logic for the other providers as well if that's technically possible. Otherwise, we will have different behavior between GH SSO and the others.

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Looks good to me! I wonder if we should implement the same logic for GitLab and Bitbucket also to keep consistency between providers and avoid future problems with inconsistency on SSO accounts

readthedocs/oauth/services/github.py Outdated Show resolved Hide resolved
Comment on lines -224 to -244
def create_repository(self, fields, privacy=None, organization=None):
"""
Update or create a repository from API response.

:param fields: dictionary of response data from API
:param privacy: privacy level to support
:param organization: remote organization to associate with
:type organization: RemoteOrganization
:rtype: RemoteRepository
"""
raise NotImplementedError

def create_organization(self, fields):
"""
Update or create remote organization from API response.

:param fields: dictionary response of data from API
:rtype: RemoteOrganization
"""
raise NotImplementedError

Copy link
Member

Choose a reason for hiding this comment

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

We should implement the same logic for the other providers as well if that's technically possible. Otherwise, we will have different behavior between GH SSO and the others.

readthedocs/oauth/services/github.py Outdated Show resolved Hide resolved
readthedocs/oauth/services/github.py Outdated Show resolved Hide resolved
readthedocs/rtd_tests/tests/test_oauth.py Show resolved Hide resolved
readthedocs/rtd_tests/tests/test_oauth.py Outdated Show resolved Hide resolved
@stsewd stsewd requested review from humitos and agjohnson May 31, 2022 16:39
@humitos
Copy link
Member

humitos commented May 31, 2022

Ops, I didn't add the comment to the approval. I'm fine merging these changes since they are good and they will solve some issues we have. However, we should add a new issue to track the work required for the other VCS and implement the same logic for them.

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.

Out of sync remote repositories when they are trasfered from another organization
3 participants